Ticket #2595: visualisation_refactor_r12786.patch

File visualisation_refactor_r12786.patch, 31.5 KB (added by mythtv@…, 13 years ago)

Patch refresh against head revision 12786

  • mythmusic/mythmusic/playbackbox.cpp

     
    8585    showrating = gContext->GetNumSetting("MusicShowRatings", 0);
    8686    listAsShuffled = gContext->GetNumSetting("ListAsShuffled", 0);
    8787    cycle_visualizer = gContext->GetNumSetting("VisualCycleOnSongChange", 0);
     88    random_visualizer = gContext->GetNumSetting("VisualRandomize", 0);
    8889
    8990    // Through the magic of themes, our "GUI" already exists we just need to
    9091    // wire up it
     
    176177    else
    177178        mainvisual->setGeometry(screenwidth + 10, screenheight + 10, 160, 160);
    178179    mainvisual->show();   
    179  
    180     visual_mode = gContext->GetSetting("VisualMode");
    181     visual_mode.simplifyWhiteSpace();
    182     visual_mode.replace(QRegExp("\\s"), ",");
    183180
     181    fullscreen_blank = false;
     182    visual_modes = QStringList::split(';', gContext->GetSetting("VisualMode"));
     183    if (!visual_modes.count())
     184        visual_modes.push_front("Blank");
     185    current_visual = random_visualizer ? rand() % visual_modes.count() : 0;
     186
    184187    QString visual_delay = gContext->GetSetting("VisualModeDelay");
    185188    bool delayOK;
    186189    visual_mode_delay = visual_delay.toInt(&delayOK);
     
    200203    //
    201204    // Suspicion: in most modes, SDL is not happy if the
    202205    // window doesn't fully exist yet  (????)
    203    
     206
    204207    mainvisual->setVisual("Blank");
    205208
    206209    // Ready to go. Let's update the foreground just to be safe.
     
    389392            if (action == "ESCAPE" || action == "4")
    390393            {
    391394                visualizer_status = 1;
    392                 QString visual_workaround = mainvisual->getCurrentVisual();
    393  
    394                 // We may have gotten to full screen by pushing 7
    395                 // (full screen blank). Or it may be blank because
    396                 // the user likes "Blank". Figure out what to do ...
    397            
    398                 if (visual_workaround == "Blank" && visual_mode != "Blank")
    399                     visual_workaround = visual_mode;
    400395
    401396                mainvisual->setVisual("Blank");
    402397                if (visual_blackhole)
     
    406401                                            screenheight + 10,
    407402                                            160, 160);
    408403                setUpdatesEnabled(true);
    409                 mainvisual->setVisual(visual_workaround);
     404                mainvisual->setVisual(visual_modes[current_visual]);
    410405                bannerDisable();
    411406
    412407                if (!m_parent->IsExitingToMain())
     
    941936                else
    942937                    setContext(2);
    943938                updateForeground();
    944                 mainvisual->setVisual(visual_mode);
     939                mainvisual->setVisual(visual_modes[current_visual]);
    945940
    946941                if (curMeta)
    947942                    updateTrackInfo(curMeta);
     
    11781173
    11791174void PlaybackBoxMusic::CycleVisualizer()
    11801175{
    1181     QString new_visualizer;
    1182 
    11831176    // Only change the visualizer if there is more than 1 visualizer
    11841177    // and the user currently has a visualizer active
    1185     if (mainvisual->numVisualizers() > 1 && visualizer_status > 0)
     1178    if (visual_modes.count() > 1 && visualizer_status > 0)
    11861179    {
    1187         QStringList allowed_modes = QStringList::split(",", visual_mode);
    1188         if (allowed_modes[0].stripWhiteSpace().endsWith("*"))
     1180        if (random_visualizer)
    11891181        {
    1190             //User has a favorite, but requested the next in the list
    1191             //Find the current position in the list
    1192             QString current_visual = mainvisual->getCurrentVisual();
    1193             unsigned int index = 0;
    1194             while ((index < allowed_modes.size()) &&
    1195                    (!allowed_modes[index++].stripWhiteSpace().startsWith(current_visual))) { }
    1196             // index is 1 greater than the current visualizer's index
    1197             if (index >= allowed_modes.size()) {
    1198                 index = 0;
    1199             }
    1200             new_visualizer = allowed_modes[index].stripWhiteSpace();
    1201             // Make sure the asterisk isn't passed through
    1202             if (new_visualizer.endsWith("*")) {
    1203                 new_visualizer.truncate(new_visualizer.length() - 1);
    1204             }
    1205         }
    1206         else if (visual_mode != "Random")
    1207         {
    12081182            //Find a visual thats not like the previous visual
     1183            unsigned int next_visualizer;
    12091184            do
    1210             {
    1211                 new_visualizer =  allowed_modes[rand() % allowed_modes.size()];
    1212             }
    1213             while (new_visualizer == mainvisual->getCurrentVisual() &&
    1214                    allowed_modes.count() > 1);
     1185                next_visualizer = rand() % visual_modes.count();
     1186            while (next_visualizer == current_visual);
     1187            current_visual = next_visualizer;
    12151188        }
    12161189        else
    12171190        {
    1218             new_visualizer = visual_mode;
     1191            //Change to the next selected visual
     1192            current_visual = (current_visual + 1) % visual_modes.count();
    12191193        }
    12201194
    12211195        //Change to the new visualizer
    12221196        visual_mode_timer->stop();
    12231197        mainvisual->setVisual("Blank");
    1224         mainvisual->setVisual(new_visualizer);
    1225     } 
    1226     else if (mainvisual->numVisualizers() == 1 && visual_mode == "AlbumArt" &&
     1198        mainvisual->setVisual(visual_modes[current_visual]);
     1199    }
     1200    else if (visual_modes.count() == 1 && visual_modes[current_visual] == "AlbumArt" &&
    12271201             visualizer_status > 0)
    12281202    {
    12291203        // If only the AlbumArt visualization is selected, then go ahead and
    12301204        // restart the visualization.  This will give AlbumArt the opportunity
    12311205        // to change images if there are multiple images available.
    1232         new_visualizer = visual_mode;
    12331206        visual_mode_timer->stop();
    12341207        mainvisual->setVisual("Blank");
    1235         mainvisual->setVisual(new_visualizer);
     1208        mainvisual->setVisual(visual_modes[current_visual]);
    12361209    }
    12371210
    1238     bannerEnable(tr("Visualization: ") + new_visualizer, 4000);
     1211    bannerEnable(tr("Visualization: ") + visual_modes[current_visual], 4000);
    12391212}
    12401213
    12411214void PlaybackBoxMusic::setTrackOnLCD(Metadata *mdata)
     
    17741747                    info_text->SetText(info_string);
    17751748                if (current_visualization_text)
    17761749                {
    1777                     current_visualization_text->SetText(mainvisual->getCurrentVisualDesc());
     1750                    current_visualization_text->SetText(visual_modes[current_visual]);
    17781751                    current_visualization_text->refresh();
    17791752                }
    17801753            }
     
    19451918
    19461919void PlaybackBoxMusic::toggleFullBlankVisualizer()
    19471920{
    1948     if( mainvisual->getCurrentVisual() == "Blank" &&
    1949         visualizer_status == 2)
     1921    if(fullscreen_blank)
    19501922    {
     1923        fullscreen_blank = false;
     1924
    19511925        //
    19521926        //  If we are already full screen and
    19531927        //  blank, go back to regular dialog
     
    19581932        else
    19591933            mainvisual->setGeometry(screenwidth + 10, screenheight + 10,
    19601934                                    160, 160);
    1961         mainvisual->setVisual(visual_mode);
     1935        mainvisual->setVisual(visual_modes[current_visual]);
    19621936        bannerDisable();
    19631937        visualizer_status = 1;
    19641938        if(visual_mode_delay > 0)
     
    19671941        }
    19681942        if (current_visualization_text)
    19691943        {
    1970             current_visualization_text->SetText(mainvisual->getCurrentVisualDesc());
     1944            current_visualization_text->SetText(visual_modes[current_visual]);
    19711945            current_visualization_text->refresh();
    19721946        }
    19731947        setUpdatesEnabled(true);
     
    19781952        //  Otherwise, go full screen blank
    19791953        //
    19801954
     1955        fullscreen_blank = true;
    19811956        mainvisual->setVisual("Blank");
    19821957        mainvisual->setGeometry(0, 0, screenwidth, screenheight);
    19831958        visualizer_status = 2;
  • mythmusic/mythmusic/synaesthesia.cpp

     
    684684#endif
    685685}
    686686
    687 const QString &SynaesthesiaFactory::name(void) const
     687static class SynaesthesiaFactory : public VisFactory
    688688{
    689     static QString name("Synaesthesia");
    690     return name;
    691 }
    692 
    693 const QString &SynaesthesiaFactory::description(void) const
    694 {
    695     static QString name(QObject::tr("Synaesthesia"));
    696     return name;
    697 }
    698 
    699 VisualBase *SynaesthesiaFactory::create(MainVisual *parent, long int winid)
    700 {
    701     (void)parent;
    702     return new Synaesthesia(winid);
    703 }
     689public:
     690    const QString& name() const {static QString name("Synaesthesia"); return name;}
     691    VisualBase* create(MainVisual*, long int winid) const {return new Synaesthesia(winid);}
     692} SynaesthesiaFactory;
  • mythmusic/mythmusic/visualize.cpp

     
    275275    return true;
    276276}
    277277
    278 const QString &SpectrumFactory::name(void) const
     278static class SpectrumFactory : public VisFactory
    279279{
    280     static QString name("Spectrum");
    281     return name;
    282 }
     280public:
     281    const QString& name() const {static QString name("Spectrum"); return name;}
     282    VisualBase* create(MainVisual*, long int) const {return new Spectrum;}
     283} SpectrumFactory;
    283284
    284 const QString &SpectrumFactory::description(void) const
    285 {
    286     static QString name(QObject::tr("Spectrum"));
    287     return name;
    288 }
    289285
    290 VisualBase *SpectrumFactory::create(MainVisual *parent, long int winid)
    291 {
    292     (void)parent;
    293     (void)winid;
    294     return new Spectrum();
    295 }
    296 
    297286AlbumArt::AlbumArt(MainVisual *parent)
    298287{
    299288    pParent = parent;
     
    387376    return true;
    388377}
    389378
    390 const QString &AlbumArtFactory::name(void) const
     379static class AlbumArtFactory: public VisFactory
    391380{
    392     static QString name("AlbumArt");
    393     return name;
    394 }
     381public:
     382    const QString& name() const {static QString name("AlbumArt"); return name;}
     383    VisualBase* create(MainVisual* parent, long int) const {return new AlbumArt(parent);}
     384} AlbumArtFactory;
    395385
    396 const QString &AlbumArtFactory::description(void) const
    397 {
    398     static QString name("Displays album art from .folder.png during playback");
    399     return name;
    400 }
    401386
    402 VisualBase *AlbumArtFactory::create(MainVisual *parent, long int winid)
    403 {
    404     (void)winid;
    405     return new AlbumArt(parent);
    406 }
    407 
    408 
    409387Blank::Blank()
    410388    : VisualBase(true)
    411389{
     
    435413    return true;
    436414}
    437415
    438 const QString &BlankFactory::name(void) const
     416static class BlankFactory : public VisFactory
    439417{
    440     static QString name("Blank");
    441     return name;
    442 }
     418public:
     419    const QString& name() const {static QString name("Blank"); return name;}
     420    VisualBase* create(MainVisual*, long int) const {return new Blank;}
     421} BlankFactory;
    443422
    444 const QString &BlankFactory::description(void) const
    445 {
    446     static QString name(QObject::tr("Blank"));
    447     return name;
    448 }
    449423
    450 VisualBase *BlankFactory::create(MainVisual *parent, long int winid)
    451 {
    452     (void)parent;
    453     (void)winid;
    454     return new Blank();
    455 }
    456 
    457424Squares::Squares()
    458425{
    459426    number_of_squares = 16;
     
    533500    return true;
    534501}
    535502
    536 const QString &SquaresFactory::name(void) const
     503static class SquaresFactory: public VisFactory
    537504{
    538     static QString name("Squares");
    539     return name;
    540 }
     505public:
     506    const QString& name() const {static QString name("Squares"); return name;}
     507    VisualBase* create(MainVisual*, long int) const {return new Squares;}
     508} SquaresFactory;
    541509
    542 const QString &SquaresFactory::description(void) const
    543 {
    544     static QString name("Square visualizer");
    545     return name;
    546 }
    547510
    548 VisualBase *SquaresFactory::create(MainVisual *parent, long int winid)
    549 {
    550     (void)winid;
    551     (void)parent;
    552     return new Squares();
    553 }
    554 
    555511#ifdef OPENGL_SUPPORT
    556512
    557513//        Need this for the Gears Object (below)
     
    977933    drawTheGears();
    978934}
    979935
    980 const QString &GearsFactory::name(void) const
     936static class GearsFactory: public VisFactory
    981937{
    982     static QString name("Gears");
    983     return name;
    984 }
     938public:
     939    const QString& name() const {static QString name("Gears"); return name;}
     940    VisualBase* create(MainVisual* parent, long int) const {return new Gears(parent);}
     941} GearsFactory;
    985942
    986 const QString &GearsFactory::description(void) const
    987 {
    988     static QString name(QObject::tr("Gears"));
    989     return name;
    990 }
    991 
    992 VisualBase *GearsFactory::create(MainVisual *parent, long int winid)
    993 {
    994     (void)winid;
    995     return new Gears(parent);
    996 }
    997 
    998943#endif
  • mythmusic/mythmusic/mainvisual.h

     
    1919#include <qptrlist.h>
    2020#include <qstringlist.h>
    2121
     22
    2223class Buffer;
    2324class Output;
    2425class VisualNode;
    2526class LogScale;
    2627class QTimer;
    27 class VisFactory;
    2828class InfoWidget;
     29class MainVisual;
    2930
     31
    3032class VisualNode
    3133{
    3234public:
     
    6668    bool xscreensaverenable;
    6769};
    6870
     71class VisFactory
     72{
     73public:
     74    VisFactory() {m_pNextVisFactory = g_pVisFactories; g_pVisFactories = this;}
     75
     76    const VisFactory* next() const {return m_pNextVisFactory;}
     77    virtual const QString &name(void) const = 0;
     78    virtual VisualBase* create(MainVisual *parent, long int winid) const = 0;
     79
     80    static const VisFactory* VisFactories() {return g_pVisFactories;}
     81
     82protected:
     83    static VisFactory* g_pVisFactories;
     84    VisFactory*        m_pNextVisFactory;
     85};
     86
    6987// base class to handle things like frame rate...
    7088class MainVisual : public QWidget, public MythTV::Visual
    7189{
     
    7694    virtual ~MainVisual();
    7795
    7896    VisualBase *visual() const { return vis; }
    79     void setVis( VisualBase *newvis );
    80     void setVisual( const QString &visualname );
     97    void setVisual(const QString &name);
    8198
    82     QString getCurrentVisual() const;
    83     QString getCurrentVisualDesc() const;
    84     int numVisualizers() const;
    85 
    8699    void add(uchar *, unsigned long, unsigned long, int, int);
    87100    void prepare();
    88101
     
    99112
    100113    void addInformation(const QString &);
    101114
    102     static void registerVisFactory(VisFactory *);
    103     static VisualBase *createVis(const QString &name,
    104                                  MainVisual *parent, long int winid);
     115    static QStringList VisFactories();
    105116
    106117public slots:
    107118    void timeout();
     
    119130    int fps;
    120131
    121132    QString current_visual_name;
    122     QStringList allowed_modes;
    123133};
    124134
    125135class InfoWidget : public QWidget
     
    136146    QPixmap info_pixmap;
    137147};
    138148
    139 class VisFactory
    140 {
    141   public:
    142     virtual const QString &name(void) const = 0;
    143     virtual const QString &description(void) const = 0;
    144     virtual VisualBase *create(MainVisual *parent, long int winid) = 0;
    145     virtual ~VisFactory() {}
    146 };
    147 
    148149class StereoScope : public VisualBase
    149150{
    150151public:
     
    173174   bool draw( QPainter *p, const QColor &back );
    174175}; 
    175176
    176 class StereoScopeFactory : public VisFactory
    177 {
    178   public:
    179     const QString &name(void) const;
    180     const QString &description(void) const;
    181     VisualBase *create(MainVisual *parent, long int winid);
    182 };
    183177
    184 class MonoScopeFactory : public VisFactory
    185 {
    186   public:
    187     const QString &name(void) const;
    188     const QString &description(void) const;
    189     VisualBase *create(MainVisual *parent, long int winid);
    190 };
    191 
    192178class LogScale
    193179{
    194180public:
  • mythmusic/mythmusic/globalsettings.cpp

     
    33#include <unistd.h>
    44
    55#include "globalsettings.h"
     6#include "mainvisual.h"
    67#include <qfile.h>
    78#include <qdialog.h>
    89#include <qcursor.h>
     
    310311{
    311312    HostComboBox *gc = new HostComboBox("PlayMode");
    312313    gc->setLabel(QObject::tr("Play mode"));
    313     gc->addSelection(QObject::tr("Normal"), "Normal");
    314     gc->addSelection(QObject::tr("Random"), "Random");
    315     gc->addSelection(QObject::tr("Intelligent"), "Intelligent");
     314    gc->addSelection(QObject::tr("Normal"), "none");
     315    gc->addSelection(QObject::tr("Random"), "random");
     316    gc->addSelection(QObject::tr("Intelligent"), "intelligent");
     317    gc->addSelection(QObject::tr("Album"), "album");
     318    gc->setCurrent(0);
    316319    gc->setHelpText(QObject::tr("Starting shuffle mode for the player.  Can be "
    317                     "either normal, random, or intelligent (random)."));
     320                    "either normal, random, intelligent (random), or Album."));
    318321    return gc;
    319322};
    320323
     
    334337    gc->setLabel(QObject::tr("Change Visualizer on each song"));
    335338    gc->setValue(false);
    336339    gc->setHelpText(QObject::tr("Change the visualizer when the song "
    337                     "change."));
     340                    "changes."));
    338341    return gc;
    339342};
    340343
     344static HostCheckBox *VisualRandomize()
     345{
     346    HostCheckBox *gc = new HostCheckBox("VisualRandomize");
     347    gc->setLabel(QObject::tr("Randomize Visualizer order"));
     348    gc->setValue(false);
     349    gc->setHelpText(QObject::tr("On changing the visualizer pick "
     350                    "a new one at random."));
     351    return gc;
     352};
     353
    341354static HostSpinBox *VisualScaleWidth()
    342355{
    343356    HostSpinBox *gc = new HostSpinBox("VisualScaleWidth", 1, 2, 1);
     
    362375    return gc;
    363376};
    364377
    365 static HostLineEdit *VisualizationMode()
     378static HostListBox *VisualizationMode()
    366379{
    367     HostLineEdit *gc = new HostLineEdit("VisualMode");
     380    HostListBox *gc = new HostListBox("VisualMode", MythListBox::Multi);
    368381    gc->setLabel(QObject::tr("Visualizations"));
    369     gc->setValue("Random");
    370     gc->setHelpText(QObject::tr("List of visualizations to use during playback. "
    371                     "Possible values are space-separated list of ") + "Random, "
    372                     "MonoScope, StereoScope, Spectrum, BumpScope, Goom, "
    373                     "Synaesthesia, AlbumArt, Gears, Squares " + QObject::tr("and") +
    374                     " Blank");
     382
     383    QStringList visualizations = MainVisual::VisFactories();
     384    visualizations.sort();
     385    for (unsigned i = 0; i < visualizations.size(); i++)
     386        gc->SelectSetting::addSelection(visualizations[i]);
     387
     388    gc->setHelpText(QObject::tr("List of visualizations possible to use during playback."));
    375389    return gc;
    376390};
    377391
     
    548562    playersettings2->setLabel(QObject::tr("Visualization Settings"));
    549563    playersettings2->addChild(VisualizationMode());
    550564    playersettings2->addChild(VisualCycleOnSongChange());
     565    playersettings2->addChild(VisualRandomize());
    551566    playersettings2->addChild(VisualModeDelay());
    552567    playersettings2->addChild(VisualScaleWidth());
    553568    playersettings2->addChild(VisualScaleHeight());
  • mythmusic/mythmusic/bumpscope.h

     
    6363    unsigned int icolor;
    6464};
    6565
    66 class BumpScopeFactory : public VisFactory
    67 {
    68   public:
    69     const QString &name(void) const;
    70     const QString &description(void) const;
    71     VisualBase *create(MainVisual *parent, long int winid);
    72 };
    73 
    7466#endif
    7567
    7668#endif // __mainvisual_h
  • mythmusic/mythmusic/synaesthesia.h

     
    7575#endif
    7676};
    7777
    78 class SynaesthesiaFactory : public VisFactory
    79 {
    80   public:
    81     const QString &name(void) const;
    82     const QString &description(void) const;
    83     VisualBase *create(MainVisual *parent, long int winid);
    84 };
    85 
    86 
    87 #endif // __mainvisual_h
     78#endif // SYNAETHESIA
  • mythmusic/mythmusic/bumpscope.cpp

     
    581581    return false;
    582582}
    583583
    584 const QString &BumpScopeFactory::name(void) const
     584static class BumpScopeFactory : public VisFactory
    585585{
    586     static QString name("BumpScope");
    587     return name;
    588 }
     586public:
     587    const QString& name() const {static QString name("BumpScope"); return name;}
     588    VisualBase* create(MainVisual*, long int winid) const {return new BumpScope(winid);}
     589} BumpScopeFactory;
    589590
    590 const QString &BumpScopeFactory::description(void) const
    591 {
    592     static QString name(QObject::tr("BumpScope"));
    593     return name;
    594 }
    595 
    596 VisualBase *BumpScopeFactory::create(MainVisual *parent, long int winid)
    597 {
    598     (void)parent;
    599     return new BumpScope(winid);
    600 }
    601 
    602591#endif
  • mythmusic/mythmusic/playbackbox.h

     
    158158
    159159    MainVisual *mainvisual;
    160160
    161     QString visual_mode;
     161    bool fullscreen_blank;
     162    QStringList visual_modes;
     163    unsigned int current_visual;
    162164    int visual_mode_delay;
    163165    QTimer *visual_mode_timer;
    164166    QTimer *lcd_update_timer;
     
    179181    GenericTree *playlist_tree;
    180182   
    181183    bool cycle_visualizer;
     184    bool random_visualizer;
    182185    bool show_whole_tree;
    183186    bool keyboard_accelerators;
    184187    bool volume_control;
  • mythmusic/mythmusic/mainvisual.cpp

     
    77#include "mainvisual.h"
    88#include "constants.h"
    99#include <mythtv/audiooutput.h>
    10 #include "synaesthesia.h"
    11 #include "bumpscope.h"
    1210#include "visualize.h"
    13 #include "goom/mythgoom.h"
    1411
    1512#include <qtimer.h>
    1613#include <qpainter.h>
     
    3532#include <iostream>
    3633using namespace std;
    3734
    38 static QPtrList<VisFactory> *visfactories = 0;
     35VisFactory* VisFactory::g_pVisFactories = 0;
    3936
    40 static void checkVisFactories(void)
    41 {
    42     if (!visfactories)
    43     {
    44         visfactories = new QPtrList<VisFactory>;
    45 
    46         MainVisual::registerVisFactory(new BlankFactory);
    47 
    48         MainVisual::registerVisFactory(new MonoScopeFactory);
    49         MainVisual::registerVisFactory(new StereoScopeFactory);
    50         MainVisual::registerVisFactory(new SynaesthesiaFactory);
    51         MainVisual::registerVisFactory(new SpectrumFactory);
    52         MainVisual::registerVisFactory(new AlbumArtFactory);
    53         MainVisual::registerVisFactory(new SquaresFactory);
    54 #ifdef OPENGL_SUPPORT
    55         MainVisual::registerVisFactory(new GearsFactory);
    56 #endif
    57 #ifdef SDL_SUPPORT
    58         MainVisual::registerVisFactory(new BumpScopeFactory);
    59         MainVisual::registerVisFactory(new GoomFactory);
    60 #endif
    61     }
    62 }
    63 
    6437VisualBase::VisualBase(bool screensaverenable)
    6538    : xscreensaverenable(screensaverenable)
    6639{
     
    134107    nodes.clear();
    135108}
    136109
    137 void MainVisual::setVisual( const QString &visualname )
     110void MainVisual::setVisual(const QString &name)
    138111{
    139     if (vis)
     112    if(vis)
    140113    {
    141114        delete vis;
    142         vis = NULL;
     115        vis = 0;
    143116    }
    144117
    145     VisualBase *newvis = 0;
    146 
    147     allowed_modes = QStringList::split(",", visualname);
    148 
    149     if (allowed_modes[0].stripWhiteSpace().endsWith("*"))
     118    for (const VisFactory* pVisFactory = VisFactory::VisFactories(); pVisFactory; pVisFactory = pVisFactory->next())
    150119    {
    151         // User has a favorite
    152         // The asterisk should only be passed in at startup, so start with
    153         // the user's favorite
    154 
    155         current_visual_name = allowed_modes[0].stripWhiteSpace();
    156         current_visual_name.truncate(current_visual_name.length() - 1);
     120        if (pVisFactory->name() == name)
     121        {
     122            vis = pVisFactory->create(this, winId());
     123            vis->resize(size());
     124            fps = vis->getDesiredFPS();
     125            break;
     126        }
    157127    }
    158     else if (allowed_modes.contains("Random"))
    159     {
    160         //
    161         //  Pick anything from compile time options
    162         //
    163128
    164         checkVisFactories();
    165         int numvis = visfactories->count() - 1;
    166         int i = 1 + (int)((double)rand() / (RAND_MAX + 1.0) * numvis);
    167         VisFactory *fact = visfactories->at(i);
    168         current_visual_name = fact->name();
    169        
    170     }
    171     else
    172     {
    173         //
    174         //  Pick anything from run time options
    175         //
    176         int vis_mode_index = 0;
    177         if (allowed_modes.size() > 1)
    178             vis_mode_index = rand() % allowed_modes.size();
    179 
    180         current_visual_name = allowed_modes[vis_mode_index].stripWhiteSpace();
    181     }
    182 
    183     newvis = createVis(current_visual_name, this, winId());
    184     setVis( newvis );
    185 }
    186 
    187 void MainVisual::setVis( VisualBase *newvis )
    188 {
    189     if (vis)
    190     {
    191         delete vis;
    192     }
    193 
    194     vis = newvis;
    195     if ( vis )
    196     {
    197         vis->resize( size() );
    198         fps = vis->getDesiredFPS();
    199     }
    200 
    201129    // force an update
    202130    timer->stop();
    203     timer->start( 1000 / fps );
     131    timer->start(1000 / fps);
    204132}
    205133
    206 int MainVisual::numVisualizers( void ) const
    207 {
    208     QString visualname = gContext->GetSetting("VisualMode");
    209     visualname.simplifyWhiteSpace();
    210     visualname.replace(QRegExp("\\s"), ",");
    211     QStringList visualizers = QStringList::split(",", visualname);
    212 
    213     if (visualizers.contains("Random"))
    214         return visfactories->count() - 1;
    215     else
    216         return visualizers.size();
    217 }
    218 
    219 QString MainVisual::getCurrentVisual(void) const
    220 {
    221     return current_visual_name;
    222 }
    223 
    224 QString MainVisual::getCurrentVisualDesc(void) const
    225 {
    226     /* XXX This should be changed to a real call to visual->description()
    227      * it works as long as ::name and ::desc uses the same string */
    228     return QObject::tr(current_visual_name);
    229 }
    230 
    231134void MainVisual::prepare()
    232135{
    233136    nodes.setAutoDelete(TRUE);
     
    363266
    364267void MainVisual::hideEvent(QHideEvent *e)
    365268{
    366     setVis(0);
     269    delete vis;
     270    vis = 0;
    367271    emit hidingVisualization();
    368272    QWidget::hideEvent(e);
    369273}
    370274
    371 void MainVisual::registerVisFactory(VisFactory *vis)
    372 {
    373     visfactories->append(vis);
    374 }
    375 
    376275void MainVisual::addInformation(const QString &new_info) {
    377276    info_widget->addInformation(new_info);
    378277}
    379278
    380 VisualBase *MainVisual::createVis(const QString &name, MainVisual *parent,
    381                                   long int winid)
     279// static member function
     280QStringList MainVisual::VisFactories()
    382281{
    383     checkVisFactories();
    384 
    385     VisualBase *vis = 0;
    386 
    387     VisFactory *fact = visfactories->first();
    388     while (fact)
    389     {
    390         if (fact->name() == name)
    391         {
    392             vis = fact->create(parent, winid);
    393             break;
    394         }
    395         fact = visfactories->next();
    396     }
    397 
    398     return vis;
     282    QStringList visualizations;
     283    for (const VisFactory* pVisFactory = VisFactory::VisFactories(); pVisFactory; pVisFactory = pVisFactory->next())
     284        visualizations.append(pVisFactory->name());
     285    return visualizations;
    399286}
    400287
    401 /*
    402288
    403 VisualBase *MainVisual::randomVis(MainVisual *parent, long int winid)
    404 {
    405     checkVisFactories();
    406 
    407     VisualBase *vis = 0;
    408 
    409     int numvis = visfactories->count() - 1;
    410     int i = 1 + (int)((double)rand() / (RAND_MAX + 1.0) * numvis);
    411 
    412     VisFactory *fact = visfactories->at(i);
    413 
    414     if (fact)
    415     {
    416         vis = fact->create(parent, winid);
    417     }   
    418 
    419     return vis;
    420 }
    421 */
    422 
    423289InfoWidget::InfoWidget(QWidget *parent)
    424290    : QWidget( parent)
    425291{
     
    838704    return true;
    839705}
    840706
    841 const QString &StereoScopeFactory::name(void) const
     707class StereoScopeFactory : public VisFactory
    842708{
    843     static QString name("StereoScope");
    844     return name;
    845 }
     709public:
     710    const QString& name() const {static QString name("StereoScope"); return name;}
     711    VisualBase* create(MainVisual*, long int) const {return new StereoScope;}
     712} StereoScopeFactory;
    846713
    847 const QString &StereoScopeFactory::description(void) const
     714class MonoScopeFactory : public VisFactory
    848715{
    849     static QString name(QObject::tr("StereoScope"));
    850     return name;
    851 }
     716public:
     717    const QString& name() const {static QString name("MonoScope"); return name;}
     718    VisualBase* create(MainVisual*, long int) const {return new MonoScope;}
     719} MonoScopeFactory;
    852720
    853 VisualBase *StereoScopeFactory::create(MainVisual *parent, long int winid)
    854 {
    855     (void)parent;
    856     (void)winid;
    857     return new StereoScope();
    858 }
    859721
    860 const QString &MonoScopeFactory::name(void) const
    861 {
    862     static QString name("MonoScope");
    863     return name;
    864 }
    865 
    866 const QString &MonoScopeFactory::description(void) const
    867 {
    868     static QString name(QObject::tr("MonoScope"));
    869     return name;
    870 }
    871 
    872 VisualBase *MonoScopeFactory::create(MainVisual *parent, long int winid)
    873 {
    874     (void)parent;
    875     (void)winid;
    876     return new MonoScope();
    877 }
    878 
    879722LogScale::LogScale(int maxscale, int maxrange)
    880723    : indices(0), s(0), r(0)
    881724{
  • mythmusic/mythmusic/goom/mythgoom.cpp

     
    174174    return false;
    175175}
    176176
    177 const QString &GoomFactory::name(void) const
     177static class GoomFactory : public VisFactory
    178178{
    179     static QString name("Goom");
    180     return name;
    181 }
     179public:
     180    const QString& name() const {static QString name("Goom"); return name;}
     181    VisualBase* create(MainVisual*, long int winid) const {return new Goom(winid);}
     182} GoomFactory;
    182183
    183 const QString &GoomFactory::description(void) const
    184 {
    185     static QString name(QObject::tr("Goom"));
    186     return name;
    187 }
    188 
    189 VisualBase *GoomFactory::create(MainVisual *parent, long int winid)
    190 {
    191     (void)parent;
    192     return new Goom(winid);
    193 }
    194 
    195184#endif
  • mythmusic/mythmusic/goom/mythgoom.h

     
    2828    int scalew, scaleh;
    2929};
    3030
    31 class GoomFactory : public VisFactory
    32 {
    33   public:
    34     const QString &name(void) const;
    35     const QString &description(void) const;
    36     VisualBase *create(MainVisual *parent, long int winid);
    37 };
    38 
    3931#endif
    4032
    4133#endif // __mainvisual_h
  • mythmusic/mythmusic/visualize.h

     
    7676#endif
    7777};
    7878
    79 class SpectrumFactory : public VisFactory
    80 {
    81   public:
    82     const QString &name(void) const;
    83     const QString &description(void) const;
    84     VisualBase *create(MainVisual *parent, long int winid);
    85 };
    86 
    8779class AlbumArt : public VisualBase
    8880{
    8981  public:
     
    10496    QImage image;
    10597};
    10698
    107 class AlbumArtFactory : public VisFactory
    108 {
    109   public:
    110     const QString &name(void) const;
    111     const QString &description(void) const;
    112     VisualBase *create(MainVisual *parent, long int winid);
    113 };
    114 
    11599class Blank : public VisualBase
    116100{
    117101    // This draws ... well ... nothing 
     
    127111    QSize size;
    128112};
    129113
    130 class BlankFactory : public VisFactory
    131 {
    132   public:
    133     const QString &name(void) const;
    134     const QString &description(void) const;
    135     VisualBase *create(MainVisual *parent, long int winid);
    136 };
    137 
    138114class Squares : public Spectrum
    139115{
    140116  public:
     
    152128    int number_of_squares;
    153129};
    154130
    155 class SquaresFactory : public VisFactory
    156 {
    157   public:
    158     const QString &name(void) const;
    159     const QString &description(void) const;
    160     VisualBase *create(MainVisual *parent, long int winid);
    161 };
    162 
    163131#ifdef OPENGL_SUPPORT
    164132
    165133class Gears : public QGLWidget, public VisualBase
     
    200168#endif
    201169};
    202170
    203 class GearsFactory : public VisFactory
    204 {
    205   public:
    206     const QString &name(void) const;
    207     const QString &description(void) const;
    208     VisualBase *create(MainVisual *parent, long int winid);
    209 };
    210 
    211 
    212171#endif // opengl_support       
    213172
    214173#endif // __visualize_h