[mythtv] [PATCH] MythMusic Visualizer Change on song change

Dan M dan at milkcarton.com
Mon Apr 7 18:00:56 EDT 2003


Attached is a patch for MythMusic which changes the visualizer when the 
song changes (Either automaticly when the previous song ends, or the 
user presses the "Next" button.  Its mainly useful if you have 
VisualMode=Random or a list 
(VisualMode=Goom,StereoScope,BumpScope,etc).  This updated version makes 
sure the same visualizer doesn't get run twice in a row (Except for 
VisualMode=Random as that's done inside of mainvisual.cpp.  Though, if 
there is enough support I'll investigate this and impliment it).

Accompining (sp?) this patch is a setting in mythmusic-settings.txt:
# Change Visual when song changes?
VisualCycleOnSongChange=1

Please let me know of any changes which have to be done to get this 
committed.

-dan
-------------- next part --------------
Index: mythmusic/mainvisual.cpp
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/mainvisual.cpp,v
retrieving revision 1.17
diff -u -d -r1.17 mainvisual.cpp
--- mythmusic/mainvisual.cpp	26 Feb 2003 23:41:11 -0000	1.17
+++ mythmusic/mainvisual.cpp	8 Apr 2003 00:39:23 -0000
@@ -24,6 +24,7 @@
 #include <qpixmap.h>
 #include <qimage.h>
 #include <qcursor.h>
+#include <qstring.h>

 #include <math.h>
 #include <stdio.h>
@@ -89,11 +90,29 @@
     {
         newvis = randomVis(this, winId());
     }
-    else 
-        newvis = createVis(allowed_modes[rand() % allowed_modes.size()], 
-                           this, winId());
-    	
+    else
+    {
+        current_visual_name = allowed_modes[rand() % allowed_modes.size()];
+        newvis = createVis(current_visual_name, this, winId());
+    }
+
     setVis( newvis );
+}
+
+int MainVisual::numVisualizers( void ) const
+{
+    QString visualname = gContext->GetSetting("VisualMode");
+    QStringList visualizers = QStringList::split(",", visualname);
+
+    if (visualizers.contains("Random"))
+        return visfactories->count() - 1;
+    else
+        return visualizers.size();
+}
+
+QString MainVisual::getVisual( void ) const
+{
+    return current_visual_name;
 }

 void MainVisual::setVis( VisualBase *newvis )
Index: mythmusic/mainvisual.h
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/mainvisual.h,v
retrieving revision 1.9
diff -u -d -r1.9 mainvisual.h
--- mythmusic/mainvisual.h	26 Feb 2003 23:41:11 -0000	1.9
+++ mythmusic/mainvisual.h	8 Apr 2003 00:39:23 -0000
@@ -73,6 +73,8 @@
     VisualBase *visual() const { return vis; }
     void setVis( VisualBase *newvis );
     void setVisual( const QString &visualname );
+    QString getVisual() const;
+    int numVisualizers() const;

     void add(Buffer *, unsigned long, int, int);
     void prepare();
@@ -111,6 +113,8 @@
     QTimer *timer;
     bool playing;
     int fps;
+
+    QString current_visual_name;

     QStringList allowed_modes;
 };
Index: mythmusic/playbackbox.cpp
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/playbackbox.cpp,v
retrieving revision 1.38
diff -u -d -r1.38 playbackbox.cpp
--- mythmusic/playbackbox.cpp	6 Apr 2003 15:53:17 -0000	1.38
+++ mythmusic/playbackbox.cpp	8 Apr 2003 00:39:23 -0000
@@ -944,6 +944,31 @@
     }
 }
 
+void PlaybackBox::cycleVisualizer()
+{
+    QString new_visualizer = mainvisual->getVisual();
+
+    //Only change the visualizer if there is more than 1 visualizer
+    if ( mainvisual->numVisualizers() > 1 )
+    {
+        if ( visual_mode != "Random" )
+        {
+            QStringList allowed_modes = QStringList::split(",", visual_mode);
+            do
+            {
+                new_visualizer =  allowed_modes[rand() % allowed_modes.size()];
+            } while ( new_visualizer == mainvisual->getVisual() );
+        }
+
+        //Change to the new visualizer
+        visual_mode_timer->stop();
+        mainvisual->setVisual("Blank");
+        mainvisual->showFullScreen();
+        mainvisual->setVisual(new_visualizer);
+        visualizer_is_active = true;
+    }
+}
+
 void PlaybackBox::pause(void)
 {
     if(plist->count() < 1)
@@ -1095,13 +1120,19 @@
     listlock.unlock();

     play();
+
+    //Call cycleVisualizer to cycle the visualizer IF: Its currently on,
+    // and the user wants to cycle the visualizer when the song changes
+    int cycle_visualizer = gContext->GetNumSetting("VisualCycleOnSongChange", 0);
+    if (visualizer_is_active && cycle_visualizer)
+        cycleVisualizer();
 }

 void PlaybackBox::next()
 {
     if(plist->count() < 1)
         return;
-        
+
     listlock.lock();
 
     plElapsed += curMeta->Length() / 1000;
@@ -1123,6 +1154,12 @@
         stop();
     else
         play();
+
+    //Call cycleVisualizer to cycle the visualizer IF: Its currently on,
+    // and the user wants to cycle the visualizer when the song changes
+    int cycle_visualizer = gContext->GetNumSetting("VisualCycleOnSongChange", 0);
+    if (visualizer_is_active && cycle_visualizer)
+        cycleVisualizer();
 }
 
 void PlaybackBox::nextAuto()
@@ -1133,7 +1170,7 @@

     if (repeatmode == REPEAT_TRACK)
         play();
-    else
+    else
         next();
 }

Index: mythmusic/playbackbox.h
===================================================================
RCS file: /var/lib/cvs/mythmusic/mythmusic/playbackbox.h,v
retrieving revision 1.21
diff -u -d -r1.21 playbackbox.h
--- mythmusic/playbackbox.h	3 Apr 2003 15:33:14 -0000	1.21
+++ mythmusic/playbackbox.h	8 Apr 2003 00:39:23 -0000
@@ -67,6 +67,7 @@
     void togglePlaylistView();
     void nextAuto();
     void visEnable();
+    void cycleVisualizer();
     void resetTimer();
     void restartTimer();
     void jumpToItem(QListViewItem *curItem);


More information about the mythtv-dev mailing list