[mythtv] music playbackbox

Andy Davidoff dert at pobox.com
Sat Feb 22 19:06:05 EST 2003


This patch fixes these items...
	- visualizer crashes mythmusic when it arrives during paused music
	- output broadly defined as Output while actually AudioOutput
	- pause button does the right thing during inline playlist editing

...and includes the earlier fixes...
	- keyboard acceleration only survived one shuffle/repeat mode toggle
	- pause button depresses to indicate play mode
	- track indicator jumps around to follow indicate current track

...and as it turns out, also fixed another bug...
	1. start in "play music" with an empty playlist in shuffle mode
	2. edit the playlist and add several tracks
	3. the top-most track is played regardless of shufflemode setting
-------------- next part --------------
Index: mythmusic/mythmusic/audiooutput.h
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/audiooutput.h,v
retrieving revision 1.2
diff -d -u -r1.2 audiooutput.h
--- mythmusic/mythmusic/audiooutput.h	2 Aug 2002 19:33:29 -0000	1.2
+++ mythmusic/mythmusic/audiooutput.h	22 Feb 2003 23:57:04 -0000
@@ -24,6 +24,7 @@
     virtual ~AudioOutput();
 
     bool initialized() const { return inited; }
+    bool isPaused() { return paus; }
 
     bool initialize();
     void configure(long, int, int, int);
Index: mythmusic/mythmusic/playbackbox.cpp
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/playbackbox.cpp,v
retrieving revision 1.24
diff -d -u -r1.24 playbackbox.cpp
--- mythmusic/mythmusic/playbackbox.cpp	16 Feb 2003 05:00:05 -0000	1.24
+++ mythmusic/mythmusic/playbackbox.cpp	22 Feb 2003 23:57:05 -0000
@@ -99,8 +99,9 @@
     prevb->setIconSet(scalePixmap((const char **)prev_pix));
     connect(prevb, SIGNAL(clicked()), this, SLOT(seekback()));
 
-    MythToolButton *pauseb = new MythToolButton(this);
+    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;
  
@@ -274,7 +275,7 @@
     visual_mode_timer = new QTimer();
     if(visual_mode_delay > 0)
     {
-    	visual_mode_timer->start(visual_mode_delay * 1000);
+    	visual_mode_timer->start(visual_mode_delay * 1000, true);
         connect(prevfileb, SIGNAL(clicked()), this, SLOT(resetTimer()));
         connect(pauseb, SIGNAL(clicked()), this, SLOT(resetTimer()));
         connect(playb, SIGNAL(clicked()), this, SLOT(resetTimer()));
@@ -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()
@@ -462,6 +465,11 @@
         if (!output->initialize())
             return;
     }
+    else if(output->isPaused())
+    {
+       pause();
+       return;
+    }
 
     if (!sourceurl.isLocalFile()) {
         StreamInput streaminput(sourceurl);
@@ -493,15 +501,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 +531,8 @@
 
         isplaying = true;
         
+        playlist_timer->start(1, true);
+
         gContext->LCDswitchToChannel(curMeta.Artist(), curMeta.Title(), "");
     }
 }
@@ -552,6 +554,8 @@
     if (output) {
         output->mutex()->lock();
         output->pause();
+        isplaying = !isplaying;
+        pauseb->setOn(!isplaying);
         output->mutex()->unlock();
     }
 
@@ -652,8 +656,6 @@
 
 void PlaybackBox::previous()
 {
-    stop();
-
     listlock.lock();
 
     shuffleindex--;
@@ -671,8 +673,6 @@
 
 void PlaybackBox::next()
 {
-//    stop();
-
     listlock.lock();
 
     shuffleindex++;
@@ -749,19 +749,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 +770,7 @@
         repeat->setText("Repeat: Track");
     else
         repeat->setText("Repeat: Playlist");
+    repeat->setAccel(Key_2);
 }
 
 void PlaybackBox::editPlaylist()
Index: mythmusic/mythmusic/playbackbox.h
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/playbackbox.h,v
retrieving revision 1.13
diff -d -u -r1.13 playbackbox.h
--- mythmusic/mythmusic/playbackbox.h	16 Feb 2003 05:00:05 -0000	1.13
+++ mythmusic/mythmusic/playbackbox.h	22 Feb 2003 23:57:05 -0000
@@ -12,13 +12,14 @@
 #include <mythtv/mythwidgets.h>
 
 #include "metadata.h"
+#include "audiooutput.h"
 
 class QLabel;
 class QString;
 class MQ3;
 class Buffer;
 class Decoder;
-class Output;
+class AudioOutput;
 class QIODevice;
 class QSqlDatabase;
 class QListViewItem;
@@ -50,7 +51,6 @@
     void seekforward();
     void seekback();
     void seek(int);
-    void changeSong();
     void stopAll();
     void toggleShuffle();
     void toggleRepeat();
@@ -59,20 +59,20 @@
     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);
 
     QIODevice *input;
-    Output *output;
+    AudioOutput *output;
     Decoder *decoder;
 
     QString playfile;
@@ -102,6 +102,9 @@
 
     MythToolButton *randomize;
     MythToolButton *repeat;
+    MythToolButton *pledit;
+    MythToolButton *vis;
+    MythToolButton *pauseb;
 
     bool shufflemode;
     bool repeatmode;
@@ -114,6 +117,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