Ticket #2595: visualisation_refactor_r12452.patch

File visualisation_refactor_r12452.patch, 31.3 KB (added by mythtv@…, 13 years ago)

Patch refresh against head revision 12452

  • mythmusic/mythmusic/playbackbox.cpp

     
    8686    showrating = gContext->GetNumSetting("MusicShowRatings", 0);
    8787    listAsShuffled = gContext->GetNumSetting("ListAsShuffled", 0);
    8888    cycle_visualizer = gContext->GetNumSetting("VisualCycleOnSongChange", 0);
     89    random_visualizer = gContext->GetNumSetting("VisualRandomize", 0);
    8990
    9091    // Through the magic of themes, our "GUI" already exists we just need to
    9192    // wire up it
     
    177178    else
    178179        mainvisual->setGeometry(screenwidth + 10, screenheight + 10, 160, 160);
    179180    mainvisual->show();   
    180  
    181     visual_mode = gContext->GetSetting("VisualMode");
    182     visual_mode.simplifyWhiteSpace();
    183     visual_mode.replace(QRegExp("\\s"), ",");
    184181
     182    fullscreen_blank = false;
     183    visual_modes = QStringList::split(';', gContext->GetSetting("VisualMode"));
     184    if (!visual_modes.count())
     185        visual_modes.push_front("Blank");
     186    current_visual = random_visualizer ? rand() % visual_modes.count() : 0;
     187
    185188    QString visual_delay = gContext->GetSetting("VisualModeDelay");
    186189    bool delayOK;
    187190    visual_mode_delay = visual_delay.toInt(&delayOK);
     
    201204    //
    202205    // Suspicion: in most modes, SDL is not happy if the
    203206    // window doesn't fully exist yet  (????)
    204    
     207
    205208    mainvisual->setVisual("Blank");
    206209
    207210    // Ready to go. Let's update the foreground just to be safe.
     
    390393            if (action == "ESCAPE" || action == "4")
    391394            {
    392395                visualizer_status = 1;
    393                 QString visual_workaround = mainvisual->getCurrentVisual();
    394  
    395                 // We may have gotten to full screen by pushing 7
    396                 // (full screen blank). Or it may be blank because
    397                 // the user likes "Blank". Figure out what to do ...
    398            
    399                 if (visual_workaround == "Blank" && visual_mode != "Blank")
    400                     visual_workaround = visual_mode;
    401396
    402397                mainvisual->setVisual("Blank");
    403398                if (visual_blackhole)
     
    407402                                            screenheight + 10,
    408403                                            160, 160);
    409404                setUpdatesEnabled(true);
    410                 mainvisual->setVisual(visual_workaround);
     405                mainvisual->setVisual(visual_modes[current_visual]);
    411406                bannerDisable();
    412407
    413408                if (!m_parent->IsExitingToMain())
     
    942937                else
    943938                    setContext(2);
    944939                updateForeground();
    945                 mainvisual->setVisual(visual_mode);
     940                mainvisual->setVisual(visual_modes[current_visual]);
    946941
    947942                if (curMeta)
    948943                    updateTrackInfo(curMeta);
     
    11771172
    11781173void PlaybackBoxMusic::CycleVisualizer()
    11791174{
    1180     QString new_visualizer;
    1181 
    11821175    // Only change the visualizer if there is more than 1 visualizer
    11831176    // and the user currently has a visualizer active
    1184     if (mainvisual->numVisualizers() > 1 && visualizer_status > 0)
     1177    if (visual_modes.count() > 1 && visualizer_status > 0)
    11851178    {
    1186         QStringList allowed_modes = QStringList::split(",", visual_mode);
    1187         if (allowed_modes[0].stripWhiteSpace().endsWith("*"))
     1179        if (random_visualizer)
    11881180        {
    1189             //User has a favorite, but requested the next in the list
    1190             //Find the current position in the list
    1191             QString current_visual = mainvisual->getCurrentVisual();
    1192             unsigned int index = 0;
    1193             while ((index < allowed_modes.size()) &&
    1194                    (!allowed_modes[index++].stripWhiteSpace().startsWith(current_visual))) { }
    1195             // index is 1 greater than the current visualizer's index
    1196             if (index >= allowed_modes.size()) {
    1197                 index = 0;
    1198             }
    1199             new_visualizer = allowed_modes[index].stripWhiteSpace();
    1200             // Make sure the asterisk isn't passed through
    1201             if (new_visualizer.endsWith("*")) {
    1202                 new_visualizer.truncate(new_visualizer.length() - 1);
    1203             }
    1204         }
    1205         else if (visual_mode != "Random")
    1206         {
    12071181            //Find a visual thats not like the previous visual
     1182            unsigned int next_visualizer;
    12081183            do
    1209             {
    1210                 new_visualizer =  allowed_modes[rand() % allowed_modes.size()];
    1211             }
    1212             while (new_visualizer == mainvisual->getCurrentVisual() &&
    1213                    allowed_modes.count() > 1);
     1184                next_visualizer = rand() % visual_modes.count();
     1185            while (next_visualizer == current_visual);
     1186            current_visual = next_visualizer;
    12141187        }
    12151188        else
    12161189        {
    1217             new_visualizer = visual_mode;
     1190            //Change to the next selected visual
     1191            current_visual = (current_visual + 1) % visual_modes.count();
    12181192        }
    12191193
    12201194        //Change to the new visualizer
    12211195        visual_mode_timer->stop();
    12221196        mainvisual->setVisual("Blank");
    1223         mainvisual->setVisual(new_visualizer);
    1224     } 
    1225     else if (mainvisual->numVisualizers() == 1 && visual_mode == "AlbumArt" &&
     1197        mainvisual->setVisual(visual_modes[current_visual]);
     1198    }
     1199    else if (visual_modes.count() == 1 && visual_modes[current_visual] == "AlbumArt" &&
    12261200             visualizer_status > 0)
    12271201    {
    12281202        // If only the AlbumArt visualization is selected, then go ahead and
    12291203        // restart the visualization.  This will give AlbumArt the opportunity
    12301204        // to change images if there are multiple images available.
    1231         new_visualizer = visual_mode;
    12321205        visual_mode_timer->stop();
    12331206        mainvisual->setVisual("Blank");
    1234         mainvisual->setVisual(new_visualizer);
     1207        mainvisual->setVisual(visual_modes[current_visual]);
    12351208    }
    12361209}
    12371210
     
    17571730                    info_text->SetText(info_string);
    17581731                if (current_visualization_text)
    17591732                {
    1760                     current_visualization_text->SetText(mainvisual->getCurrentVisualDesc());
     1733                    current_visualization_text->SetText(visual_modes[current_visual]);
    17611734                    current_visualization_text->refresh();
    17621735                }
    17631736            }
     
    19281901
    19291902void PlaybackBoxMusic::toggleFullBlankVisualizer()
    19301903{
    1931     if( mainvisual->getCurrentVisual() == "Blank" &&
    1932         visualizer_status == 2)
     1904    if(fullscreen_blank)
    19331905    {
     1906        fullscreen_blank = false;
     1907
    19341908        //
    19351909        //  If we are already full screen and
    19361910        //  blank, go back to regular dialog
     
    19411915        else
    19421916            mainvisual->setGeometry(screenwidth + 10, screenheight + 10,
    19431917                                    160, 160);
    1944         mainvisual->setVisual(visual_mode);
     1918        mainvisual->setVisual(visual_modes[current_visual]);
    19451919        bannerDisable();
    19461920        visualizer_status = 1;
    19471921        if(visual_mode_delay > 0)
     
    19501924        }
    19511925        if (current_visualization_text)
    19521926        {
    1953             current_visualization_text->SetText(mainvisual->getCurrentVisualDesc());
     1927            current_visualization_text->SetText(visual_modes[current_visual]);
    19541928            current_visualization_text->refresh();
    19551929        }
    19561930        setUpdatesEnabled(true);
     
    19611935        //  Otherwise, go full screen blank
    19621936        //
    19631937
     1938        fullscreen_blank = true;
    19641939        mainvisual->setVisual("Blank");
    19651940        mainvisual->setGeometry(0, 0, screenwidth, screenheight);
    19661941        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;
     
    385374    return true;
    386375}
    387376
    388 const QString &AlbumArtFactory::name(void) const
     377static class AlbumArtFactory: public VisFactory
    389378{
    390     static QString name("AlbumArt");
    391     return name;
    392 }
     379public:
     380    const QString& name() const {static QString name("AlbumArt"); return name;}
     381    VisualBase* create(MainVisual* parent, long int) const {return new AlbumArt(parent);}
     382} AlbumArtFactory;
    393383
    394 const QString &AlbumArtFactory::description(void) const
    395 {
    396     static QString name("Displays album art from .folder.png during playback");
    397     return name;
    398 }
    399384
    400 VisualBase *AlbumArtFactory::create(MainVisual *parent, long int winid)
    401 {
    402     (void)winid;
    403     return new AlbumArt(parent);
    404 }
    405 
    406 
    407385Blank::Blank()
    408386    : VisualBase(true)
    409387{
     
    433411    return true;
    434412}
    435413
    436 const QString &BlankFactory::name(void) const
     414static class BlankFactory : public VisFactory
    437415{
    438     static QString name("Blank");
    439     return name;
    440 }
     416public:
     417    const QString& name() const {static QString name("Blank"); return name;}
     418    VisualBase* create(MainVisual*, long int) const {return new Blank;}
     419} BlankFactory;
    441420
    442 const QString &BlankFactory::description(void) const
    443 {
    444     static QString name(QObject::tr("Blank"));
    445     return name;
    446 }
    447421
    448 VisualBase *BlankFactory::create(MainVisual *parent, long int winid)
    449 {
    450     (void)parent;
    451     (void)winid;
    452     return new Blank();
    453 }
    454 
    455422Squares::Squares()
    456423{
    457424    number_of_squares = 16;
     
    531498    return true;
    532499}
    533500
    534 const QString &SquaresFactory::name(void) const
     501static class SquaresFactory: public VisFactory
    535502{
    536     static QString name("Squares");
    537     return name;
    538 }
     503public:
     504    const QString& name() const {static QString name("Squares"); return name;}
     505    VisualBase* create(MainVisual*, long int) const {return new Squares;}
     506} SquaresFactory;
    539507
    540 const QString &SquaresFactory::description(void) const
    541 {
    542     static QString name("Square visualizer");
    543     return name;
    544 }
    545508
    546 VisualBase *SquaresFactory::create(MainVisual *parent, long int winid)
    547 {
    548     (void)winid;
    549     (void)parent;
    550     return new Squares();
    551 }
    552 
    553509#ifdef OPENGL_SUPPORT
    554510
    555511//        Need this for the Gears Object (below)
     
    975931    drawTheGears();
    976932}
    977933
    978 const QString &GearsFactory::name(void) const
     934static class GearsFactory: public VisFactory
    979935{
    980     static QString name("Gears");
    981     return name;
    982 }
     936public:
     937    const QString& name() const {static QString name("Gears"); return name;}
     938    VisualBase* create(MainVisual* parent, long int) const {return new Gears(parent);}
     939} GearsFactory;
    983940
    984 const QString &GearsFactory::description(void) const
    985 {
    986     static QString name(QObject::tr("Gears"));
    987     return name;
    988 }
    989 
    990 VisualBase *GearsFactory::create(MainVisual *parent, long int winid)
    991 {
    992     (void)winid;
    993     return new Gears(parent);
    994 }
    995 
    996941#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>
     
    328329{
    329330    HostComboBox *gc = new HostComboBox("PlayMode");
    330331    gc->setLabel(QObject::tr("Play mode"));
    331     gc->addSelection(QObject::tr("Normal"), "Normal");
    332     gc->addSelection(QObject::tr("Random"), "Random");
    333     gc->addSelection(QObject::tr("Intelligent"), "Intelligent");
     332    gc->addSelection(QObject::tr("Normal"), "none");
     333    gc->addSelection(QObject::tr("Random"), "random");
     334    gc->addSelection(QObject::tr("Intelligent"), "intelligent");
     335    gc->addSelection(QObject::tr("Album"), "album");
     336    gc->setCurrent(0);
    334337    gc->setHelpText(QObject::tr("Starting shuffle mode for the player.  Can be "
    335                     "either normal, random, or intelligent (random)."));
     338                    "either normal, random, intelligent (random), or Album."));
    336339    return gc;
    337340};
    338341
     
    352355    gc->setLabel(QObject::tr("Change Visualizer on each song"));
    353356    gc->setValue(false);
    354357    gc->setHelpText(QObject::tr("Change the visualizer when the song "
    355                     "change."));
     358                    "changes."));
    356359    return gc;
    357360};
    358361
     362static HostCheckBox *VisualRandomize()
     363{
     364    HostCheckBox *gc = new HostCheckBox("VisualRandomize");
     365    gc->setLabel(QObject::tr("Randomize Visualizer order"));
     366    gc->setValue(false);
     367    gc->setHelpText(QObject::tr("On changing the visualizer pick "
     368                    "a new one at random."));
     369    return gc;
     370};
     371
    359372static HostSpinBox *VisualScaleWidth()
    360373{
    361374    HostSpinBox *gc = new HostSpinBox("VisualScaleWidth", 1, 2, 1);
     
    380393    return gc;
    381394};
    382395
    383 static HostLineEdit *VisualizationMode()
     396static HostListBox *VisualizationMode()
    384397{
    385     HostLineEdit *gc = new HostLineEdit("VisualMode");
     398    HostListBox *gc = new HostListBox("VisualMode", MythListBox::Multi);
    386399    gc->setLabel(QObject::tr("Visualizations"));
    387     gc->setValue("Random");
    388     gc->setHelpText(QObject::tr("List of visualizations to use during playback. "
    389                     "Possible values are space-separated list of ") + "Random, "
    390                     "MonoScope, StereoScope, Spectrum, BumpScope, Goom, "
    391                     "Synaesthesia, AlbumArt, Gears, Squares " + QObject::tr("and") +
    392                     " Blank");
     400
     401    QStringList visualizations = MainVisual::VisFactories();
     402    visualizations.sort();
     403    for (unsigned i = 0; i < visualizations.size(); i++)
     404        gc->SelectSetting::addSelection(visualizations[i]);
     405
     406    gc->setHelpText(QObject::tr("List of visualizations possible to use during playback."));
    393407    return gc;
    394408};
    395409
     
    566580    playersettings2->setLabel(QObject::tr("Visualization Settings"));
    567581    playersettings2->addChild(VisualizationMode());
    568582    playersettings2->addChild(VisualCycleOnSongChange());
     583    playersettings2->addChild(VisualRandomize());
    569584    playersettings2->addChild(VisualModeDelay());
    570585    playersettings2->addChild(VisualScaleWidth());
    571586    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