[mythtv] music playbackbox

Andy Davidoff dert at pobox.com
Sat Feb 22 08:24:34 EST 2003


A few minor fixes in one patch:
	- consistency cleanups WRT buttons
	- keyboard acceleration didn't work for me WRT shuffle/repeat buttons
		+ I reinstalled the accel key in the callback
	- pause button toggles
	- removed apparently vestigial changeSong()
	- selection bar did not highlight the current track when launching
	  in random-shuffle mode or while progressing to the next track via
	  nextAuto(), despite the fact that the same code was executed and
	  works fine when the track is changed manually.
		+ my fix exploits this behavior with a timer callback

I spent an inordinate amount of time on this last issue, so if someone
could verify this on their system, I'd appreciate it.  It's trivial code,
but I'm trying to learn Qt, and that includes the undocumented features.
-------------- 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 08:01:38.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);
@@ -205,7 +206,7 @@
     playview->addColumn("Length");
     playview->setFont(buttonfont);
 
-    playview->setFocusPolicy(NoFocus);
+    playview->setFocusPolicy(QWidget::NoFocus);
 
     playview->setColumnWidth(0, (int)(50 * wmult));
     playview->setColumnWidth(1, (int)(210 * wmult));
@@ -220,36 +221,32 @@
 
     playview->setSorting(-1);
     playview->setAllColumnsShowFocus(true);
-
-    plist = playlist;
-    playlistindex = 0;
-    setupListView();
-
     vbox->addWidget(playview, 1);
 
-    if(keyboard_accelerator_flag.lower() != "true")
-    {
-        playb->setFocus();
-    }
-
+    isplaying = false;
     input = 0; decoder = 0; seeking = false; remainingTime = false;
     output = 0; outputBufferSize = 256;
-
-    shufflemode = false;
     repeatmode = false;  
-
-    curMeta = ((*plist)[playlistindex]);
+    shufflemode = false;
+    plist = playlist;
 
     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];
 
-    isplaying = false;
+    setupListView();
+    // 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()));
+
+    if(keyboard_accelerator_flag.lower() != "true")
+    {
+        playb->setFocus();
+    }
  
     if (plist->size() > 0)
     { 
@@ -260,8 +257,6 @@
     //
     //	Load Visualization settings and set up timer
     //
-	
-    visual_mode = gContext->GetSetting("VisualMode");
     QString visual_delay = gContext->GetSetting("VisualModeDelay");
     
     bool delayOK;
@@ -353,32 +348,35 @@
         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");
@@ -391,7 +389,7 @@
         {
             playlistorder.push_back(i);
             if (curMeta == (*plist)[i])
-                playlistindex = i;
+                playlistindex = shuffleindex = i;
         } 
     }
     else
@@ -404,32 +402,28 @@
         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;
         }
     }
-
-    curMeta = (*plist)[playlistindex];
-    shuffleindex = playlistorder.findIndex(playlistindex);
 }
 
 void PlaybackBox::play()
@@ -493,15 +487,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,18 +517,25 @@
 
         isplaying = true;
         
+        playlist_timer->start(1, true);
+
         gContext->LCDswitchToChannel(curMeta.Artist(), curMeta.Title(), "");
     }
 }
 
 void PlaybackBox::visEnable()
 {
+    // get the list of preferred vis modes
+    QString visual_mode = gContext->GetSetting("VisualMode");
+    QStringList modes = QStringList::split(",", visual_mode);
+
     if (!visualizer_is_active)
     {
         visual_mode_timer->stop();
         mainvisual->setVisual("Blank");
         mainvisual->showFullScreen();
-        mainvisual->setVisual(visual_mode);
+        // select one of the list of visualization modes
+        mainvisual->setVisual(modes[rand() % modes.size()]);
         visualizer_is_active = true;
     }
 }
@@ -652,8 +645,6 @@
 
 void PlaybackBox::previous()
 {
-    stop();
-
     listlock.lock();
 
     shuffleindex--;
@@ -671,8 +662,6 @@
 
 void PlaybackBox::next()
 {
-//    stop();
-
     listlock.lock();
 
     shuffleindex++;
@@ -749,19 +738,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 +759,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