[mythtv] music playbackbox

Andy Davidoff dert at pobox.com
Sat Feb 22 15:21:51 EST 2003


#if Isaac Richards /* Feb 22, 09:22 */
> It properly highlights the current track for me.  I am using a recent
> version of Qt, though.

Which?  I'm using 3.0.5.  Do your keyboard accelerators work too?

> > -    playview->setFocusPolicy(NoFocus);
> > +    playview->setFocusPolicy(QWidget::NoFocus);
> 
> Why this?  The object inherits from QWidget, so there's no need to explicitly 
> say it.. 

Ah, the inconsistent qualification is just there to confuse us newbies. :-)

> Any particular reason for most of the reordering here?  Seems fairly 
> gratuitous.

Okay, it's more subtle now.

> Removing the curMeta assignment breaks editing the selection list in place 
> from the Edit Playlist button.
>
> Could've picked up on how I modified your previous patch, here.
#endif /* ijr at po.cwru.edu */

Fixed, thanks.
-------------- next part --------------
diff -Naurb mythmusic/mythmusic/playbackbox.cpp mymythmusic/mythmusic/playbackbox.cpp
--- mythmusic/mythmusic/playbackbox.cpp	2003-02-16 00:00:05.000000000 -0500
+++ mymythmusic/mythmusic/playbackbox.cpp	2003-02-22 15:19:03.000000000 -0500
@@ -101,6 +101,7 @@
 
     MythToolButton *pauseb = new MythToolButton(this);
     pauseb->setAutoRaise(true);
+    pauseb->setToggleButton(true);
     pauseb->setIconSet(scalePixmap((const char **)pause_pix));
     connect(pauseb, SIGNAL(clicked()), this, SLOT(pause()));
 
@@ -151,14 +152,14 @@
     secondcontrol->addWidget(repeat);
     connect(repeat, SIGNAL(clicked()), this, SLOT(toggleRepeat()));
 
-    MythToolButton *pledit = new MythToolButton(this);
+    pledit = new MythToolButton(this);
     pledit->setAutoRaise(true);
     pledit->setText("Edit Playlist");
     pledit->setFont(buttonfont);
     secondcontrol->addWidget(pledit);
     connect(pledit, SIGNAL(clicked()), this, SLOT(editPlaylist()));
 
-    MythToolButton *vis = new MythToolButton(this);
+    vis = new MythToolButton(this);
     vis->setAutoRaise(true);
     vis->setText("Visualize");
     vis->setFont(buttonfont);
@@ -222,7 +223,7 @@
     playview->setAllColumnsShowFocus(true);
 
     plist = playlist;
-    playlistindex = 0;
+    shuffleindex = 0;
     setupListView();
 
     vbox->addWidget(playview, 1);
@@ -237,17 +238,17 @@
 
     shufflemode = false;
     repeatmode = false;  
-
-    curMeta = ((*plist)[playlistindex]);
-
     QString playmode = gContext->GetSetting("PlayMode");
-    if (playmode == "random")
-    {
+    if (playmode.lower() == "random")
         toggleShuffle();
-        curMeta = ((*plist)[shuffleindex]);
-    }
-
+    else // setupPlaylist() already called by toggleShuffle()
     setupPlaylist();
+    playlistindex = playlistorder[shuffleindex];
+    curMeta = (*plist)[playlistindex];
+
+    // this is a hack to fix the playlist's refusal to update w/o a SIG
+    playlist_timer = new QTimer();
+    connect(playlist_timer, SIGNAL(timeout()), this, SLOT(jumpToItem()));
 
     isplaying = false;
  
@@ -353,35 +354,39 @@
         it--; count--;
     }
 
-    QListViewItem *curItem = listlist.at(playlistindex);
+    jumpToItem(listlist.at(playlistindex));
+}
+
+void PlaybackBox::jumpToItem(void)
+{
+    if(playlist_timer->isActive())
+        playlist_timer->stop();
+    jumpToItem(listlist.at(playlistindex));
+}
 
+void PlaybackBox::jumpToItem(QListViewItem *curItem)
+{
     if (curItem)
     {
-        playview->setCurrentItem(curItem);
-        playview->setSelected(curItem, true);
-
         if (curItem->itemBelow())
             playview->ensureItemVisible(curItem->itemBelow());
         if (curItem->itemAbove())
             playview->ensureItemVisible(curItem->itemAbove());
+        playview->setCurrentItem(curItem);
+        playview->setSelected(curItem, true);
         playview->ensureItemVisible(curItem);
     }
 }
 
-void PlaybackBox::setupPlaylist(bool toggle)
+void PlaybackBox::setupPlaylist()
 {
-    if (toggle)
-        shufflemode = !shufflemode;
-
     if (playlistorder.size() > 0)
         playlistorder.clear();
 
-    playlistindex = 0;
-    shuffleindex = 0;
-
     if (plist->size() == 0)
     {
         curMeta = Metadata("dummy.music");
+        shuffleindex = 0;
         return;
     }
 
@@ -391,7 +396,7 @@
         {
             playlistorder.push_back(i);
             if (curMeta == (*plist)[i])
-                playlistindex = i;
+                playlistindex = shuffleindex = i;
         } 
     }
     else
@@ -404,32 +409,30 @@
         for (i = 0; i < max; i++)
             usedList[i] = false;
 
-        bool used = true;
         int index = 0; 
         int lastindex = 0;
 
         for (i = 0; i < max; i++)
         {
-            while (used)
+            for(;;)
             {
                 index = (int)((double)rand() / (RAND_MAX + 1.0) * max);
-                if (usedList[index] == false)
-                    used = false;
                 if (max - i > 50 && abs(index - lastindex) < 10)
-                    used = true;
+                    continue;
+                if (usedList[index] == false)
+                    break;
             }
             usedList[index] = true;
             playlistorder.push_back(index);
-            used = true;
             lastindex = index;
-
             if (curMeta == (*plist)[i])
                 playlistindex = i;
+            if (curMeta == (*plist)[index])
+                shuffleindex = i;
         }
     }
-
+    playlistindex = playlistorder[shuffleindex];
     curMeta = (*plist)[playlistindex];
-    shuffleindex = playlistorder.findIndex(playlistindex);
 }
 
 void PlaybackBox::play()
@@ -493,15 +496,7 @@
                    "  ~   " + curMeta.Title();
     titlelabel->setText(disp);
 
-    QListViewItem *curItem = listlist.at(playlistindex);
-    playview->setCurrentItem(curItem);
-    playview->setSelected(curItem, true);
-
-    if (curItem->itemBelow())
-        playview->ensureItemVisible(curItem->itemBelow());
-    if (curItem->itemAbove())
-        playview->ensureItemVisible(curItem->itemAbove());
-    playview->ensureItemVisible(curItem);
+    jumpToItem(listlist.at(playlistindex));
 
     currentTime = 0;
     maxTime = curMeta.Length() / 1000;
@@ -531,6 +526,8 @@
 
         isplaying = true;
         
+        playlist_timer->start(1, true);
+
         gContext->LCDswitchToChannel(curMeta.Artist(), curMeta.Title(), "");
     }
 }
@@ -652,8 +649,6 @@
 
 void PlaybackBox::previous()
 {
-    stop();
-
     listlock.lock();
 
     shuffleindex--;
@@ -671,8 +666,6 @@
 
 void PlaybackBox::next()
 {
-//    stop();
-
     listlock.lock();
 
     shuffleindex++;
@@ -749,19 +742,17 @@
     }
 }
 
-void PlaybackBox::changeSong()
-{
-    stop();
-    play();
-}
-
 void PlaybackBox::toggleShuffle()
 {
-    setupPlaylist(true);
+    shufflemode = !shufflemode;
+
     if (shufflemode)
         randomize->setText("Shuffle: Random");
     else
         randomize->setText("Shuffle: Normal"); 
+    randomize->setAccel(Key_1);
+
+    setupPlaylist();
 }
 
 void PlaybackBox::toggleRepeat()
@@ -772,6 +763,7 @@
         repeat->setText("Repeat: Track");
     else
         repeat->setText("Repeat: Playlist");
+    repeat->setAccel(Key_2);
 }
 
 void PlaybackBox::editPlaylist()
diff -Naurb mythmusic/mythmusic/playbackbox.h mymythmusic/mythmusic/playbackbox.h
--- mythmusic/mythmusic/playbackbox.h	2003-02-16 00:00:05.000000000 -0500
+++ mymythmusic/mythmusic/playbackbox.h	2003-02-22 07:58:32.000000000 -0500
@@ -50,7 +50,6 @@
     void seekforward();
     void seekback();
     void seek(int);
-    void changeSong();
     void stopAll();
     void toggleShuffle();
     void toggleRepeat();
@@ -59,15 +58,15 @@
     void visEnable();
     void resetTimer();
     void restartTimer();
-    
+    void jumpToItem(QListViewItem *curItem);
+    void jumpToItem(void);
   private slots:
     void startseek();
     void doneseek();
 
   private:
     void setupListView(void);
-
-    void setupPlaylist(bool toggle = false);
+    void setupPlaylist(void);
 
     QPixmap scalePixmap(const char **xpmdata);
 
@@ -102,6 +101,8 @@
 
     MythToolButton *randomize;
     MythToolButton *repeat;
+    MythToolButton *pledit;
+    MythToolButton *vis;
 
     bool shufflemode;
     bool repeatmode;
@@ -114,6 +115,7 @@
     int	visual_mode_delay;
     QTimer *visual_mode_timer;
     QTimer *lcd_update_timer;
+    QTimer *playlist_timer;
     bool visualizer_is_active;
 };
 


More information about the mythtv-dev mailing list