diff options
| -rw-r--r-- | src/qmmp/soundcore.cpp | 4 | ||||
| -rw-r--r-- | src/qmmp/soundcore.h | 1 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol.cpp | 27 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol.h | 9 | ||||
| -rw-r--r-- | src/ui/display.cpp | 83 | ||||
| -rw-r--r-- | src/ui/display.h | 3 | ||||
| -rw-r--r-- | src/ui/eqtitlebar.h | 2 | ||||
| -rw-r--r-- | src/ui/eqwidget.cpp | 11 | ||||
| -rw-r--r-- | src/ui/eqwidget.h | 8 | ||||
| -rw-r--r-- | src/ui/mainwindow.cpp | 118 | ||||
| -rw-r--r-- | src/ui/mainwindow.h | 3 |
11 files changed, 63 insertions, 206 deletions
diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index b104a8403..7c242948a 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -62,6 +62,7 @@ SoundCore::SoundCore(QObject *parent) connect(m_handler, SIGNAL(metaDataChanged ()), SIGNAL(metaDataChanged ())); connect(m_handler, SIGNAL(stateChanged (Qmmp::State)), SIGNAL(stateChanged(Qmmp::State))); m_volumeControl = VolumeControl::create(this); + connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); } @@ -180,6 +181,7 @@ void SoundCore::stop() //update VolumeControl delete m_volumeControl; m_volumeControl = VolumeControl::create(this); + connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); } void SoundCore::pause() @@ -279,6 +281,8 @@ void SoundCore::setVolume(int L, int R) void SoundCore::volume(int *left, int *right) { + *left = 0; + *right = 0; QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); bool sofVolume = settings.value("Volume/software_volume", FALSE).toBool(); if (sofVolume) diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index 9ad766bce..645a0cc7e 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -147,6 +147,7 @@ signals: void metaDataChanged (); void stateChanged (Qmmp::State newState); void finished(); + void volumeChanged(int left, int right); private slots: bool decode(); diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp index ab6d142c9..637427a98 100644 --- a/src/qmmp/volumecontrol.cpp +++ b/src/qmmp/volumecontrol.cpp @@ -18,13 +18,16 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include <QTimer> #include "output.h" #include "volumecontrol.h" VolumeControl::VolumeControl(QObject *parent) - : QObject(parent) + : QObject(parent) { + m_left = 0; + m_right = 0; } @@ -34,5 +37,25 @@ VolumeControl::~VolumeControl() VolumeControl *VolumeControl::create(QObject *parent) { - return Output::currentFactory()->createVolumeControl(parent); + VolumeControl *control = Output::currentFactory()->createVolumeControl(parent); + QTimer *m_timer = new QTimer(control); + connect(m_timer, SIGNAL(timeout()), control, SLOT(checkVolume())); + m_timer->start(125); + return control; +} + +void VolumeControl::checkVolume() +{ + int l = 0, r = 0; + volume(&l, &r); + l = (l > 100) ? 100 : l; + r = (r > 100) ? 100 : r; + l = (l < 0) ? 0 : l; + r = (r < 0) ? 0 : r; + if (m_left != l || m_right != r) + { + m_left = l; + m_right = r; + emit volumeChanged(m_left, m_right); + } } diff --git a/src/qmmp/volumecontrol.h b/src/qmmp/volumecontrol.h index 0f81a707a..72e0bbe7e 100644 --- a/src/qmmp/volumecontrol.h +++ b/src/qmmp/volumecontrol.h @@ -37,9 +37,18 @@ public: static VolumeControl *create(QObject *parent = 0); +signals: + void volumeChanged(int left, int right); + +public slots: + void checkVolume(); + protected: virtual void volume(int *left, int *right) = 0; +private: + int m_left, m_right; + }; #endif diff --git a/src/ui/display.cpp b/src/ui/display.cpp index c338050bb..74c946fd3 100644 --- a/src/ui/display.cpp +++ b/src/ui/display.cpp @@ -138,6 +138,14 @@ MainDisplay::MainDisplay (QWidget *parent) m_timeIndicator = new TimeIndicator(this); m_timeIndicator->move(34,26); m_timeIndicator->show(); + + m_core = SoundCore::instance(); + connect(m_core, SIGNAL(elapsedChanged(qint64)), SLOT(setTime(qint64))); + connect(m_core, SIGNAL(bitrateChanged(int)), m_kbps, SLOT(display(int))); + connect(m_core, SIGNAL(frequencyChanged(int)), SLOT(setSampleRate(int))); + connect(m_core, SIGNAL(channelsChanged(int)), m_monoster, SLOT(setChannels(int))); + connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(setState(Qmmp::State))); + connect(m_core, SIGNAL(volumeChanged(int,int)), SLOT(setVolume(int, int))); } @@ -170,11 +178,6 @@ void MainDisplay::setState(Qmmp::State state) setDuration(m_core->length()); break; } - /*case OutputState::Buffering: - { - //ui.label->setText("Buffering"); - break; - }*/ case Qmmp::Paused: { m_playstatus->setStatus(PlayStatus::PAUSE); @@ -192,6 +195,14 @@ void MainDisplay::setState(Qmmp::State state) } } +void MainDisplay::setVolume(int left, int right) +{ + int maxVol = qMax(left, right); + m_volumeBar->setValue(maxVol); + if (maxVol && !m_volumeBar->isPressed()) + m_balanceBar->setValue((right - left) * 100/maxVol); +} + void MainDisplay::updateSkin() { setPixmap (m_skin->getMain()); @@ -218,68 +229,6 @@ void MainDisplay::setPL (QWidget* w) connect (m_playlist, SIGNAL (closed ()), m_plButton, SLOT (click())); } -/*void MainDisplay::setInfo(const OutputState &st) -{ - - - switch ((int) st.type()) - { - case OutputState::Info: - { - //if (seeking) - // break; - setTime (st.elapsedSeconds()); - m_kbps->display (st.bitrate()); - m_freq->display (st.frequency() /1000); - m_monoster->setChannels (st.channels()); - update(); - break; - } - case OutputState::Playing: - { - m_playstatus->setStatus(PlayStatus::PLAY); - m_timeIndicator->setNeedToShowTime(true); - break; - } - case OutputState::Buffering: - { - //ui.label->setText("Buffering"); - break; - } - case OutputState::Paused: - { - m_playstatus->setStatus(PlayStatus::PAUSE); - break; - } - case OutputState::Stopped: - { - m_playstatus->setStatus(PlayStatus::STOP); - m_monoster->setChannels (0); - //m_timeIndicator->setNeedToShowTime(false); - break; - } - case OutputState::Volume: - //qDebug("volume %d, %d", st.rightVolume(), st.leftVolume()); - int maxVol = qMax(st.leftVolume(),st.rightVolume()); - m_volumeBar->setValue(maxVol); - if (maxVol && !m_volumeBar->isPressed()) - m_balanceBar->setValue((st.rightVolume()-st.leftVolume())*100/maxVol); - break; - - } -}*/ - -void MainDisplay::setSoundCore(SoundCore *core) -{ - m_core = core; - connect(core, SIGNAL(elapsedChanged(qint64)), SLOT(setTime(qint64))); - //connect(core, SIGNAL(totalTimeChanged(qint64 time) - connect(core, SIGNAL(bitrateChanged(int)), m_kbps, SLOT(display(int))); - connect(core, SIGNAL(frequencyChanged(int)), SLOT(setSampleRate(int))); - connect(core, SIGNAL(channelsChanged(int)), m_monoster, SLOT(setChannels(int))); - connect(core, SIGNAL(stateChanged(Qmmp::State)), SLOT(setState(Qmmp::State))); -} - bool MainDisplay::isPlaylistVisible() const { return m_plButton->isChecked(); diff --git a/src/ui/display.h b/src/ui/display.h index 4e7623f2f..43ee35c5d 100644 --- a/src/ui/display.h +++ b/src/ui/display.h @@ -57,8 +57,6 @@ public: void setEQ(QWidget*); void setPL(QWidget*); - //void setInfo(const OutputState &st); - void setSoundCore(SoundCore *core); bool isEqualizerVisible()const; bool isPlaylistVisible()const; bool isRepeatable()const; @@ -84,6 +82,7 @@ private slots: void setSampleRate(int rate); void setTime(qint64); void setState(Qmmp::State state); + void setVolume(int left, int right); private: QWidget* m_equlizer; diff --git a/src/ui/eqtitlebar.h b/src/ui/eqtitlebar.h index 4dd1d64d1..70ef88fe4 100644 --- a/src/ui/eqtitlebar.h +++ b/src/ui/eqtitlebar.h @@ -42,6 +42,8 @@ public: ~EqTitleBar(); void setActive(bool); + +public slots: void setVolume(int left, int right); private slots: diff --git a/src/ui/eqwidget.cpp b/src/ui/eqwidget.cpp index b9c5ede33..8906389f1 100644 --- a/src/ui/eqwidget.cpp +++ b/src/ui/eqwidget.cpp @@ -23,6 +23,7 @@ #include <QInputDialog> #include <QCloseEvent> #include <qmmpui/filedialog.h> +#include <qmmp/soundcore.h> #include "skin.h" #include "eqslider.h" @@ -86,6 +87,7 @@ EqWidget::EqWidget (QWidget *parent) } readSettings(); createActions(); + connect(SoundCore::instance(), SIGNAL(volumeChanged(int, int)), m_titleBar, SLOT(setVolume(int, int))); } EqWidget::~EqWidget() @@ -364,15 +366,6 @@ void EqWidget::loadPreset(const QString &name) } } -/*void EqWidget::setInfo(const OutputState &st) -{ - if (st.type() == OutputState::Volume) - { - m_titleBar->setVolume(st.leftVolume(),st.rightVolume()); - - } -}*/ - EQPreset *EqWidget::findPreset(const QString &name) { foreach(EQPreset *preset, m_autoPresets) diff --git a/src/ui/eqwidget.h b/src/ui/eqwidget.h index 7b3680a45..7e30eec86 100644 --- a/src/ui/eqwidget.h +++ b/src/ui/eqwidget.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Ilya Kotov * + * Copyright (C) 2006-2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -36,6 +36,7 @@ class EQGraph; class Button; class EQPreset; class PlayListItem; +class SoundCore; class EqWidget : public PixmapWidget { @@ -53,11 +54,6 @@ public: */ void loadPreset(const QString &name); - /*! - * shows output volume and balance. Necessare for the shaded mode - */ - //void setInfo(const OutputState &st); - signals: void valueChanged(); void closed(); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 22a975b69..0e2d1ade9 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -62,6 +62,7 @@ MainWindow::MainWindow(const QStringList& args, BuiltinCommandLineOption* option m_paused = FALSE; m_elapsed = 0; m_option_manager = option_manager; + m_core = new SoundCore(this); setWindowIcon(QIcon(":/32x32/qmmp.png")); @@ -113,7 +114,6 @@ MainWindow::MainWindow(const QStringList& args, BuiltinCommandLineOption* option createActions(); - m_core = new SoundCore(this); m_titlebar = new TitleBar(this); m_titlebar->move(0,0); m_titlebar->show(); @@ -124,25 +124,12 @@ MainWindow::MainWindow(const QStringList& args, BuiltinCommandLineOption* option display->setEQ(m_equalizer); display->setPL(m_playlist); - display->setSoundCore(m_core); m_vis = MainVisual::getPointer(); - //m_core->addVisualization(m_vis); - //m_core->showVisualization(this); - - /*connect(m_core, SIGNAL(outputStateChanged(const OutputState&)), - SLOT(showOutputState(const OutputState&))); - connect(m_core, SIGNAL(decoderStateChanged(const DecoderState&)), - SLOT(showDecoderState(const DecoderState&))); - connect(m_core, SIGNAL(titleChanged(const QString&)), - SLOT(changeTitle(const QString&))); - */ Visual::initialize(this, m_visMenu, SLOT(updateActions())); Visual::add(m_vis); - - connect(m_core, SIGNAL(finished()), SLOT(next())); connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(showState(Qmmp::State))); connect(m_core, SIGNAL(elapsedChanged(qint64)),m_playlist, SLOT(setTime(qint64))); @@ -200,12 +187,7 @@ void MainWindow::play() if (s.isEmpty()) return; if (m_core->play(s)) - { - //display->setTime(0); - //qDebug("play"); m_generalHandler->setTime(0); - //display->setDuration(m_core->totalTime()); - } else { //find out the reason why playback failed @@ -358,104 +340,6 @@ void MainWindow::showState(Qmmp::State state) } } } - -/*void MainWindow::showOutputState(const OutputState &st) - -{ - if (seeking) - return; - - //display->setInfo(st); - //m_playlist->setInfo(st, m_core->length(), m_playListModel->totalLength()); - //m_titlebar->setInfo(st); - // m_equalizer->setInfo(st); - /*switch ((int) st.type()) - { - case OutputState::Playing: - { - m_generalHandler->setState(General::Playing); - if (m_playListModel->currentItem()) - { - SongInfo info = *m_playListModel->currentItem(); - if (info.isEmpty()) - info.setValue(SongInfo::TITLE, m_playlist->currentItem()->text()); - m_generalHandler->setSongInfo(info); - } - break; - } - case OutputState::Paused: - { - m_generalHandler->setState(General::Paused); - break; - } - case OutputState::Stopped: - { - m_generalHandler->setState(General::Stopped); - break; - } - case OutputState::Info: - { - m_generalHandler->setTime(st.elapsedSeconds()); - m_elapsed = st.elapsedSeconds(); - break; - } - case OutputState::Volume: - { - m_generalHandler->setVolume(st.leftVolume(), st.rightVolume()); - break; - } - case OutputState::VisualRemoved: - { - m_visMenu->updateActions(); - } - }*/ -//} -/*void MainWindow::showDecoderState(const DecoderState &st) -{ - switch ((int) st.type()) - { - case DecoderState::Finished: - { - next(); - break; - } - case DecoderState::Info: - { - qDebug("file info:"); - qDebug("ARTIST = %s", qPrintable(st.tag()->artist())); - qDebug("TITLE = %s", qPrintable(st.tag()->title())); - qDebug("ALBUM = %s", qPrintable(st.tag()->album())); - qDebug("COMMENT = %s", qPrintable(st.tag()->comment())); - qDebug("GENRE = %s", qPrintable(st.tag()->genre())); - qDebug("YEAR = %d", st.tag()->year()); - qDebug("TRACK = %d", st.tag()->track()); - qDebug("LENGTH = %d", st.tag()->length()); - if (m_playlist->currentItem()) - { - if (!st.tag()->isEmpty()) - { - SongInfo info; - info.setValue(SongInfo::TITLE, st.tag()->title()); - info.setValue(SongInfo::ARTIST, st.tag()->artist()); - info.setValue(SongInfo::ALBUM, st.tag()->album()); - info.setValue(SongInfo::COMMENT, st.tag()->comment()); - info.setValue(SongInfo::GENRE, st.tag()->genre()); - info.setValue(SongInfo::YEAR, st.tag()->year()); - info.setValue(SongInfo::TRACK, st.tag()->track()); - info.setValue(SongInfo::LENGTH, st.tag()->length()); - info.setValue(SongInfo::STREAM, - m_playlist->currentItem()->path().startsWith("http://")); - info.setValue(SongInfo::PATH, m_playlist->currentItem()->path()); - m_generalHandler->setSongInfo(info); - } - m_playlist->currentItem()->updateTags(st.tag()); - m_playlist->listWidget()->updateList(); - } - break; - } - } -}*/ - void MainWindow::showMetaData() { qDebug("===== metadata ======"); diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 515ab685c..0f7890460 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -93,8 +93,6 @@ protected: virtual void keyPressEvent ( QKeyEvent* ); private slots: - //void showOutputState(const OutputState&); - //void showDecoderState(const DecoderState&); void showState(Qmmp::State state); void showMetaData(); void changeTitle(const QString&); @@ -105,7 +103,6 @@ private slots: void updateEQ(); void forward(); void backward(); - //void trayActivated(QSystemTrayIcon::ActivationReason); void about(); void handleCloseRequest(); |
