Ticket #7517: volume_control_mythplugins_r22928.patch

File volume_control_mythplugins_r22928.patch, 10.6 KB (added by mythtv@…, 14 years ago)
  • mythmusic/mythmusic/playbackbox.cpp

     
    9898
    9999    // Possibly (user-defined) control the volume
    100100
    101     volume_control = false;
    102     volume_display_timer = new QTimer(this);
    103     if (gContext->GetNumSetting("MythControlsVolume", 0))
     101    volume_control = VolumeControlManager::GetControl(gContext->GetSetting("MixerDevice"));
     102    if (volume_control)
    104103    {
    105         volume_control = true;
     104        connect(volume_control.data(), SIGNAL(changedVolume(int)),
     105                this, SLOT(VolumeChanged(int)));
     106        connect(volume_control.data(), SIGNAL(changedMute(bool)),
     107                this, SLOT(MuteChanged(bool)));
    106108    }
     109
     110    volume_display_timer = new QTimer(this);
    107111    volume_display_timer->setSingleShot(true);
    108112    volume_display_timer->start(2000);
    109113    connect(volume_display_timer, SIGNAL(timeout()),
     
    11711175    waiting_for_playlists_timer->start(100); // Restart Timer
    11721176}
    11731177
    1174 void PlaybackBoxMusic::changeVolume(bool up_or_down)
     1178void PlaybackBoxMusic::changeVolume(bool up)
    11751179{
    1176     if (volume_control && gPlayer->getOutput())
     1180    if (volume_control)
    11771181    {
    1178         if (up_or_down)
    1179             gPlayer->getOutput()->AdjustCurrentVolume(2);
     1182        if (up)
     1183            volume_control->increaseVolume();
    11801184        else
    1181             gPlayer->getOutput()->AdjustCurrentVolume(-2);
    1182         showVolume(true);
     1185            volume_control->decreaseVolume();
    11831186    }
    11841187}
    11851188
     
    11971200
    11981201void PlaybackBoxMusic::toggleMute()
    11991202{
    1200     if (volume_control && gPlayer->getOutput())
    1201     {
    1202         gPlayer->getOutput()->ToggleMute();
    1203         showVolume(true);
    1204     }
     1203    if (volume_control)
     1204        volume_control->setMute(!volume_control->mute());
    12051205}
    12061206
    12071207void PlaybackBoxMusic::toggleUpmix()
     
    12321232        speed_status->refresh();
    12331233    }
    12341234
    1235     if (volume_control && gPlayer->getOutput())
     1235    if (volume_control)
    12361236    {
    12371237        if (volume_status)
    12381238        {
    12391239            if (on_or_off)
    12401240            {
    1241                 volume_status->SetUsed(gPlayer->getOutput()->GetCurrentVolume());
     1241                volume_status->SetUsed(volume_control->mute() ? 0 : volume_control->volume());
    12421242                volume_status->SetOrder(0);
    12431243                volume_status->refresh();
    12441244                volume_display_timer->setSingleShot(true);
     
    12471247                    lcd->switchToVolume("Music");
    12481248
    12491249                volume_level =
    1250                     (gPlayer->IsMuted()) ? 0.0f : gPlayer->GetVolume() * 0.01f;
     1250                    (volume_control->mute()) ? 0.0f : volume_control->volume() * 0.01f;
    12511251
    12521252                if (class LCD *lcd = LCD::Get())
    12531253                    lcd->setVolumeLevel(volume_level);
     
    24312431    return true;
    24322432}
    24332433
     2434void PlaybackBoxMusic::VolumeChanged(int)
     2435{
     2436    showVolume(true);
     2437}
     2438
     2439void PlaybackBoxMusic::MuteChanged(bool)
     2440{
     2441    showVolume(true);
     2442}
     2443
    24342444QString PlaybackBoxMusic::getTimeString(int exTime, int maxTime)
    24352445{
    24362446    QString time_string;
  • mythmusic/mythmusic/miniplayer.cpp

     
    11// mythtv
    22#include <mythcontext.h>
    33#include <lcddevice.h>
     4#include <libmyth/audiooutput.h>
    45
    56// mythui
    67#include <mythuitext.h>
     
    2526    m_coverImage = NULL;
    2627    m_progressBar = NULL;
    2728
     29    m_volumeControl = VolumeControlManager::GetControl(gContext->GetSetting("MixerDevice"));
     30    if (m_volumeControl)
     31    {
     32        connect(m_volumeControl.data(), SIGNAL(changedVolume(int)),
     33                this, SLOT(VolumeChanged(int)));
     34        connect(m_volumeControl.data(), SIGNAL(changedMute(bool)),
     35                this, SLOT(MuteChanged(bool)));
     36    }
     37
    2838    m_displayTimer = new QTimer(this);
    2939    m_displayTimer->setSingleShot(true);
    3040    connect(m_displayTimer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
     
    6878    m_coverImage = dynamic_cast<MythUIImage *> (GetChild("coverart"));
    6979    m_progressBar = dynamic_cast<MythUIProgressBar *> (GetChild("progress"));
    7080
    71     if (m_volText && gPlayer->getOutput())
     81    if (m_volText && m_volumeControl)
    7282    {
    7383        m_volFormat = m_volText->GetText();
    7484        m_volText->SetText(QString(m_volFormat)
    75                 .arg((int) gPlayer->getOutput()->GetCurrentVolume()));
     85                .arg((int) m_volumeControl->volume()));
    7686    }
    7787
    7888    gPlayer->setListener(this);
     
    172182        }
    173183        else if (action == "VOLUMEDOWN")
    174184        {
    175             if (gPlayer->getOutput())
    176             {
    177                 gPlayer->getOutput()->AdjustCurrentVolume(-2);
    178                 showVolume();
    179             }
     185            if (m_volumeControl)
     186                m_volumeControl->decreaseVolume();
    180187        }
    181188        else if (action == "VOLUMEUP")
    182189        {
    183             if (gPlayer->getOutput())
    184             {
    185                 gPlayer->getOutput()->AdjustCurrentVolume(2);
    186                 showVolume();
    187             }
     190            if (m_volumeControl)
     191                m_volumeControl->increaseVolume();
    188192        }
    189193        else if (action == "MUTE")
    190194        {
    191             if (gPlayer->getOutput())
     195            if (m_volumeControl)
    192196            {
    193                 gPlayer->getOutput()->ToggleMute();
     197                m_volumeControl->setMute(!m_volumeControl->mute());
    194198
    195199                if (m_infoText)
    196200                {
    197201                    m_showingInfo = true;
    198                     if (gPlayer->IsMuted())
     202                    if (m_volumeControl->mute())
    199203                        m_infoText->SetText(tr("Mute: On"));
    200204                    else
    201205                        m_infoText->SetText(tr("Mute: Off"));
     
    209213
    210214                if (m_volText)
    211215                {
    212                     if (gPlayer->IsMuted())
     216                    if (m_volumeControl->mute())
    213217                        m_volText->SetText(QString(m_volFormat).arg(0));
    214218                    else
    215219                        m_volText->SetText(QString(m_volFormat)
    216                                 .arg((int) gPlayer->getOutput()->GetCurrentVolume()));
     220                                .arg(m_volumeControl->volume()));
    217221                }
    218222            }
    219223        }
     
    554558        lcd->switchToMusic(mdata->Artist(), mdata->Album(), mdata->Title());
    555559}
    556560
     561void MiniPlayer::VolumeChanged(int)
     562{
     563    showVolume();
     564}
     565
     566void MiniPlayer::MuteChanged(bool)
     567{
     568    showVolume();
     569}
     570
    557571void MiniPlayer::showShuffleMode(void)
    558572{
    559573    if (m_infoText)
     
    645659
    646660void MiniPlayer::showVolume(void)
    647661{
    648     float level = (float)gPlayer->getOutput()->GetCurrentVolume();
    649     bool muted = gPlayer->IsMuted();
     662    float level = static_cast<float>(m_volumeControl->volume());
     663    bool muted = m_volumeControl->mute();
    650664
    651665    if (m_infoText)
    652666    {
  • mythmusic/mythmusic/musicplayer.h

     
    2222    void setVisual(MainVisual *visual);
    2323    void setCDDevice(const QString &dev) { m_CDdevice = dev; }
    2424
    25     void mute(void) {};
    26     void unMute(void) {};
    27     void setVolume(void) {};
    28 
    2925    void setSpeed(float speed);
    3026    void incSpeed();
    3127    void decSpeed();
     
    5248
    5349    Decoder     *getDecoder(void) { return m_decoder; }
    5450    AudioOutput *getOutput(void) { return m_output; }
    55     MuteState    GetMuteState(void) const;
    56     uint         GetVolume(void) const;
    57     bool         IsMuted(void) const { return GetMuteState() == kMuteAll; }
    5851
    5952    GenericTree *constructPlaylist(void);
    6053    GenericTree *getPlaylistTree() { return m_playlistTree; }
  • mythmusic/mythmusic/musicplayer.cpp

     
    359359
    360360    // TODO: Error checking that device is opened correctly!
    361361    m_output = AudioOutput::OpenAudio(adevice, pdevice, 16, 2, 0, 44100,
    362                                       AUDIOOUTPUT_MUSIC, true, false,
     362                                      AUDIOOUTPUT_MUSIC, false,
    363363                                      gContext->GetNumSetting("MusicDefaultUpmix", 0) + 1);
    364364    m_output->setBufferSize(256 * 1024);
    365365    m_output->SetBlocking(false);
     
    852852    m_playSpeed -= 0.05;
    853853    setSpeed(m_playSpeed);
    854854}
    855 
    856 uint MusicPlayer::GetVolume(void) const
    857 {
    858     if (m_output)
    859         return m_output->GetCurrentVolume();
    860     return 0;
    861 }
    862 
    863 MuteState MusicPlayer::GetMuteState(void) const
    864 {
    865     if (m_output)
    866         return m_output->GetMuteState();
    867     return kMuteAll;
    868 }
  • mythmusic/mythmusic/playbackbox.h

     
    88// mythtv
    99#include <mythwidgets.h>
    1010#include <dialogbox.h>
    11 #include <audiooutput.h>
     11#include <libmyth/volumecontrolmanager.h>
    1212
    1313// mythmusic
    1414#include "mainvisual.h"
     
    101101    bool getInsertPLOptions(InsertPLOption &insertOption,
    102102                            PlayPLOption &playOption, bool &bRemoveDups);
    103103
     104  protected slots:
     105    void VolumeChanged(int volume);
     106    void MuteChanged(bool mute);
     107
    104108  signals:
    105109
    106110    void dummy();   // debugging
     
    172176    bool show_album_art;
    173177    bool show_whole_tree;
    174178    bool keyboard_accelerators;
    175     bool volume_control;
     179    QSharedPointer<VolumeControl> volume_control; ///< Volume Control interface
    176180
    177181    QString exit_action;
    178182
  • mythmusic/mythmusic/miniplayer.h

     
    11#ifndef MINIPLAYER_H_
    22#define MINIPLAYER_H_
    33
     4#include <libmyth/volumecontrolmanager.h>
    45#include <mythscreentype.h>
    56
    67class MusicPlayer;
     
    2728    void timerTimeout(void);
    2829    void showInfoTimeout(void);
    2930
     31  protected slots:
     32    void VolumeChanged(int volume);
     33    void MuteChanged(bool mute);
     34
    3035  private:
    3136    QString getTimeString(int exTime, int maxTime);
    3237    void    updateTrackInfo(Metadata *mdata);
     
    4449    int           m_currTime, m_maxTime;
    4550
    4651    MusicPlayer  *m_parentPlayer;
     52    QSharedPointer<VolumeControl> m_volumeControl; ///< Volume Control interface
    4753
    4854    QTimer       *m_displayTimer;
    4955    QTimer       *m_infoTimer;