diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2011-06-26 14:08:17 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2011-06-26 14:08:17 +0000 |
| commit | cd09ad84c0ee44a0cb34b4d9efb7bb244070a25c (patch) | |
| tree | b76936164c015155e15e96eff6dd832c618409b3 | |
| parent | 810d7042df700ce8d8e01e788708c4008ce44af2 (diff) | |
| download | qmmp-cd09ad84c0ee44a0cb34b4d9efb7bb244070a25c.tar.gz qmmp-cd09ad84c0ee44a0cb34b4d9efb7bb244070a25c.tar.bz2 qmmp-cd09ad84c0ee44a0cb34b4d9efb7bb244070a25c.zip | |
using events instead of some signals
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2235 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | qmmp.pro | 5 | ||||
| -rw-r--r-- | src/plugins/Effect/Effect.pro | 6 | ||||
| -rw-r--r-- | src/plugins/Engines/mplayer/mplayerengine.cpp | 2 | ||||
| -rw-r--r-- | src/plugins/Input/Input.pro | 24 | ||||
| -rw-r--r-- | src/plugins/Output/Output.pro | 17 | ||||
| -rw-r--r-- | src/plugins/Visual/Visual.pro | 5 | ||||
| -rw-r--r-- | src/qmmp/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/qmmp/abstractengine.h | 2 | ||||
| -rw-r--r-- | src/qmmp/metadatachangedevent.cpp | 39 | ||||
| -rw-r--r-- | src/qmmp/metadatachangedevent.h | 50 | ||||
| -rw-r--r-- | src/qmmp/qmmp.h | 12 | ||||
| -rw-r--r-- | src/qmmp/qmmp.pro | 8 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 10 | ||||
| -rw-r--r-- | src/qmmp/soundcore.cpp | 36 | ||||
| -rw-r--r-- | src/qmmp/soundcore.h | 2 | ||||
| -rw-r--r-- | src/qmmp/statechangedevent.cpp | 40 | ||||
| -rw-r--r-- | src/qmmp/statechangedevent.h | 45 | ||||
| -rw-r--r-- | src/qmmp/statehandler.cpp | 39 | ||||
| -rw-r--r-- | src/qmmp/statehandler.h | 9 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.cpp | 28 |
20 files changed, 287 insertions, 98 deletions
@@ -29,7 +29,10 @@ else { message(Found lrelease executable: $$LRELEASE_EXECUTABLE) } - message(generating translations) unix:system(find . -name *.ts | xargs $$LRELEASE_EXECUTABLE) win32:system(for /r %B in (*.ts) do $$LRELEASE_EXECUTABLE %B) + +message("******* BUILD CONFIGURATION *******") +for(out, CONFIG):message($$out) +message("*** END OF BUILD CONFIGURATION ****") diff --git a/src/plugins/Effect/Effect.pro b/src/plugins/Effect/Effect.pro index 64fc2a658..22dd33513 100644 --- a/src/plugins/Effect/Effect.pro +++ b/src/plugins/Effect/Effect.pro @@ -3,14 +3,8 @@ TEMPLATE = subdirs SUBDIRS += srconverter crossfade stereo contains(CONFIG, BS2B_PLUGIN){ -message(***********************) -message(* BS2B plugin enabled *) -message(***********************) SUBDIRS += bs2b } contains(CONFIG, LADSPA_PLUGIN){ -message(*************************) -message(* LADSPA plugin enabled *) -message(*************************) SUBDIRS += ladspa } diff --git a/src/plugins/Engines/mplayer/mplayerengine.cpp b/src/plugins/Engines/mplayer/mplayerengine.cpp index 2cf0a19fb..0e2d1a0b8 100644 --- a/src/plugins/Engines/mplayer/mplayerengine.cpp +++ b/src/plugins/Engines/mplayer/mplayerengine.cpp @@ -203,7 +203,7 @@ void MplayerEngine::readStdOut() { if (m_process->state() == QProcess::Running) m_process->waitForFinished(3500); - emit playbackFinished(); + StateHandler::instance()->sendFinished(); if(!m_sources.isEmpty()) { StateHandler::instance()->dispatch(Qmmp::Stopped); diff --git a/src/plugins/Input/Input.pro b/src/plugins/Input/Input.pro index 78d715863..cc65fe64b 100644 --- a/src/plugins/Input/Input.pro +++ b/src/plugins/Input/Input.pro @@ -7,58 +7,34 @@ unix{ SUBDIRS += vorbis sndfile wavpack contains(CONFIG, MODPLUG_PLUGIN){ SUBDIRS += modplug - message(***************************) - message(* Modplug plugin enabled *) - message(***************************) } contains(CONFIG, MUSEPACK_PLUGIN){ SUBDIRS += mpc - message(***************************) - message(* Musepack plugin enabled *) - message(***************************) } contains(CONFIG, FLAC_PLUGIN){ SUBDIRS += flac - message(***********************) - message(* FLAC plugin enabled *) - message(***********************) } contains(CONFIG, FFMPEG_PLUGIN){ SUBDIRS += ffmpeg - message(*************************) - message(* FFMPEG plugin enabled *) - message(*************************) } contains(CONFIG, AAC_PLUGIN){ SUBDIRS += aac - message(**********************) - message(* AAC plugin enabled *) - message(**********************) } contains(CONFIG, CDAUDIO_PLUGIN){ SUBDIRS += cdaudio - message(***************************) - message(* CD Audio plugin enabled *) - message(***************************) } contains(CONFIG, WILDMIDI_PLUGIN){ SUBDIRS += wildmidi - message(*******************) - message(* WildMidi Plugin *) - message(*******************) } contains(CONFIG, GME_PLUGIN){ SUBDIRS += gme - message(**************) - message(* GME Plugin *) - message(**************) } } diff --git a/src/plugins/Output/Output.pro b/src/plugins/Output/Output.pro index cb392662d..4dde76900 100644 --- a/src/plugins/Output/Output.pro +++ b/src/plugins/Output/Output.pro @@ -1,6 +1,6 @@ include(../../../qmmp.pri) -CONFIG += release warn_on +CONFIG += release warn_on TEMPLATE = subdirs win32:SUBDIRS += waveout unix{ @@ -9,37 +9,22 @@ SUBDIRS += null contains(CONFIG, JACK_PLUGIN){ SUBDIRS += jack - message(***********************) - message(* JACK plugin enabled *) - message(***********************) } contains(CONFIG, OSS_PLUGIN){ SUBDIRS += oss - message(**********************) - message(* OSS plugin enabled *) - message(**********************) } contains(CONFIG, PULSE_AUDIO_PLUGIN){ SUBDIRS += pulseaudio - message(******************************) - message(* PULSE AUDIO plugin enabled *) - message(******************************) } contains(CONFIG, ALSA_PLUGIN){ SUBDIRS += alsa - message(***********************) - message(* ALSA plugin enabled *) - message(***********************) } contains(CONFIG, OSS4_PLUGIN){ SUBDIRS += oss4 - message(***********************) - message(* OSS4 plugin enabled *) - message(***********************) } } diff --git a/src/plugins/Visual/Visual.pro b/src/plugins/Visual/Visual.pro index c2cde3f8f..6bb50e6a4 100644 --- a/src/plugins/Visual/Visual.pro +++ b/src/plugins/Visual/Visual.pro @@ -5,8 +5,5 @@ SUBDIRS += analyzer unix{ contains(CONFIG, PROJECTM_PLUGIN){ SUBDIRS += projectm - message(***************************) - message(* projectM plugin enabled *) - message(***************************) } -}
\ No newline at end of file +} diff --git a/src/qmmp/CMakeLists.txt b/src/qmmp/CMakeLists.txt index ea86fb497..655aff57b 100644 --- a/src/qmmp/CMakeLists.txt +++ b/src/qmmp/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 2.4.7) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 OLD) cmake_policy(SET CMP0005 OLD) -endif(COMMAND cmake_policy) +endif(COMMAND cmake_policy) # qt lib ADD_DEFINITIONS( -Wall ) @@ -57,6 +57,8 @@ SET(libqmmp_SRCS qmmpsettings.cpp audioconverter.cpp eqsettings.cpp + statechangedevent.cpp + metadatachangedevent.cpp ) SET(libqmmp_MOC_HDRS @@ -93,6 +95,8 @@ SET(libqmmp_MOC_HDRS qmmpsettings.h audioconverter.h eqsettings.h + statechangedevent.h + metadatachangedevent.h ) SET(libqmmp_DEVEL_HDRS diff --git a/src/qmmp/abstractengine.h b/src/qmmp/abstractengine.h index 5c0b7eaaf..ea1c29281 100644 --- a/src/qmmp/abstractengine.h +++ b/src/qmmp/abstractengine.h @@ -119,7 +119,7 @@ signals: /*! * Emitted when the decoder has finished playback. */ - void playbackFinished(); + //void playbackFinished(); private: QMutex m_mutex; diff --git a/src/qmmp/metadatachangedevent.cpp b/src/qmmp/metadatachangedevent.cpp new file mode 100644 index 000000000..210f03f50 --- /dev/null +++ b/src/qmmp/metadatachangedevent.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "metadatachangedevent.h" + +MetaDataChangedEvent::MetaDataChangedEvent(const QMap<Qmmp::MetaData, QString> &metaData) + : QEvent (QEvent::Type(Qmmp::MetaDataChanged)) +{ + m_metaData = metaData; +} + +MetaDataChangedEvent::~MetaDataChangedEvent(){} + +QMap<Qmmp::MetaData, QString>MetaDataChangedEvent::metaData() +{ + return m_metaData; +} + +QString MetaDataChangedEvent::metaData(Qmmp::MetaData key) +{ + return m_metaData.value(key); +} diff --git a/src/qmmp/metadatachangedevent.h b/src/qmmp/metadatachangedevent.h new file mode 100644 index 000000000..f49c87f33 --- /dev/null +++ b/src/qmmp/metadatachangedevent.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef METADATACHANGEDEVENT_H +#define METADATACHANGEDEVENT_H + +#include <QEvent> +#include <QMap> +#include <QString> +#include "qmmp.h" + +/*! @internal + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +class MetaDataChangedEvent : public QEvent +{ +public: + MetaDataChangedEvent(const QMap<Qmmp::MetaData, QString> &metaData); + virtual ~MetaDataChangedEvent(); + /*! + * Returns all meta data in map. + */ + QMap <Qmmp::MetaData, QString> metaData(); + /*! + * Returns the metdata string associated with the given \b key. + */ + QString metaData(Qmmp::MetaData key); + +private: + QMap<Qmmp::MetaData, QString> m_metaData; +}; + +#endif // METADATACHANGEDEVENT_H diff --git a/src/qmmp/qmmp.h b/src/qmmp/qmmp.h index ebc7d226f..fb1609f05 100644 --- a/src/qmmp/qmmp.h +++ b/src/qmmp/qmmp.h @@ -21,6 +21,7 @@ #define QMMP_H #include <QUrl> +#include <QEvent> /*! @brief The Qmmp class stores global settings and enums. * @author Ilya Kotov <forkotov02@hotmail.ru> @@ -41,6 +42,17 @@ public: FatalError /*!< This means unrecorvable error die audio output problems. Player should abort playback. */ }; /*! + * Even types + */ + enum EventType + { + StateChanged = QEvent::User, + NextTrackRequest, + Finished, + MetaDataChanged + }; + + /*! * Metadata keys */ enum MetaData diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index f92ca88a3..2160de85e 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -32,7 +32,9 @@ HEADERS += recycler.h \ replaygain.h \ audioconverter.h \ qmmpsettings.h \ - eqsettings.h + eqsettings.h \ + statechangedevent.h \ + metadatachangedevent.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -58,7 +60,9 @@ SOURCES += recycler.cpp \ replaygain.cpp \ audioconverter.cpp \ qmmpsettings.cpp \ - eqsettings.cpp + eqsettings.cpp \ + statechangedevent.cpp \ + metadatachangedevent.cpp FORMS += unix:TARGET = ../../lib/qmmp win32:TARGET = ../../../bin/qmmp diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index e80294914..3b811d355 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -244,6 +244,8 @@ void QmmpAudioEngine::stop() m_user_stop = true; mutex()->unlock(); + wait(); + if (m_output) { m_output->mutex()->lock (); @@ -264,8 +266,6 @@ void QmmpAudioEngine::stop() m_output->recycler()->mutex()->unlock(); } - wait(); - if (m_output) { m_output->wait(); @@ -311,7 +311,7 @@ void QmmpAudioEngine::finish() m_output->finish(); m_output->mutex()->unlock(); } - emit playbackFinished(); + StateHandler::instance()->sendFinished(); } void QmmpAudioEngine::updateReplayGainSettings() @@ -373,7 +373,7 @@ void QmmpAudioEngine::run() { m_next = false; qDebug("QmmpAudioEngine: switching to the next track"); - emit playbackFinished(); + StateHandler::instance()->sendFinished(); StateHandler::instance()->dispatch(Qmmp::Stopped); //fake stop/start cycle StateHandler::instance()->dispatch(Qmmp::Buffering); StateHandler::instance()->dispatch(Qmmp::Playing); @@ -394,7 +394,7 @@ void QmmpAudioEngine::run() prepareEffects(m_decoder); if(m_ap == m_output->audioParameters()) { - emit playbackFinished(); + StateHandler::instance()->sendFinished(); StateHandler::instance()->dispatch(Qmmp::Stopped); //fake stop/start cycle StateHandler::instance()->dispatch(Qmmp::Buffering); StateHandler::instance()->dispatch(Qmmp::Playing); diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index b58556083..deba8e6c0 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -23,6 +23,8 @@ #include <QApplication> #include <QSettings> #include <QDir> +#include "statechangedevent.h" +#include "metadatachangedevent.h" #include "qmmpaudioengine.h" #include "decoderfactory.h" #include "effect.h" @@ -52,10 +54,6 @@ SoundCore::SoundCore(QObject *parent) connect(m_handler, SIGNAL(frequencyChanged(quint32)), SIGNAL(frequencyChanged(quint32))); connect(m_handler, SIGNAL(precisionChanged(int)), SIGNAL(precisionChanged(int))); connect(m_handler, SIGNAL(channelsChanged(int)), SIGNAL(channelsChanged(int))); - connect(m_handler, SIGNAL(metaDataChanged ()), SIGNAL(metaDataChanged ())); - connect(m_handler, SIGNAL(stateChanged (Qmmp::State)), SIGNAL(stateChanged(Qmmp::State))); - connect(m_handler, SIGNAL(stateChanged (Qmmp::State)), SLOT(startPendingEngine())); - connect(m_handler, SIGNAL(nextTrackRequest()), SIGNAL(nextTrackRequest())); connect(m_handler, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); updateVolume(); connect(QmmpSettings::instance(), SIGNAL(eqSettingsChanged()), SIGNAL(eqSettingsChanged())); @@ -102,6 +100,7 @@ bool SoundCore::play(const QString &source, bool queue, qint64 offset) void SoundCore::stop() { + qApp->sendPostedEvents(this, 0); m_url.clear(); if(m_pendingEngine) delete m_pendingEngine; @@ -109,7 +108,7 @@ void SoundCore::stop() if(m_engine) { m_engine->stop(); - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); + qApp->sendPostedEvents(this, 0); } qDeleteAll(m_pendingSources); m_pendingSources.clear(); @@ -211,12 +210,12 @@ Qmmp::State SoundCore::state() const QMap <Qmmp::MetaData, QString> SoundCore::metaData() { - return m_handler->metaData(); + return m_metaData; } QString SoundCore::metaData(Qmmp::MetaData key) { - return m_handler->metaData(key); + return m_metaData[key]; } bool SoundCore::enqueue() @@ -253,7 +252,6 @@ bool SoundCore::enqueue() { if((m_engine = AbstractEngine::create(s, this))) { - connect(m_engine, SIGNAL(playbackFinished()), SIGNAL(finished())); m_engine->play(); m_handler->setCurrentEngine(m_engine); return true; @@ -288,7 +286,6 @@ bool SoundCore::enqueue() m_error = true; return false; } - connect(engine, SIGNAL(playbackFinished()), SIGNAL(finished())); if (m_handler->state() == Qmmp::Playing || m_handler->state() == Qmmp::Paused) { if(m_pendingEngine) @@ -330,3 +327,24 @@ SoundCore* SoundCore::instance() { return m_instance; } + +bool SoundCore::event(QEvent *e) +{ + if(e->type() == QEvent::Type(Qmmp::StateChanged)) + { + emit stateChanged(((StateChangedEvent *) e)->currentState()); + startPendingEngine(); + } + else if(e->type() == QEvent::Type(Qmmp::MetaDataChanged)) + { + m_metaData = ((MetaDataChangedEvent *) e)->metaData(); + emit metaDataChanged(); + } + else if(e->type() == QEvent::Type(Qmmp::NextTrackRequest)) + emit nextTrackRequest(); + else if(e->type() == QEvent::Type(Qmmp::Finished)) + emit finished(); + else + return QObject::event(e); + return true; +} diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index affa728f6..a1ceca3d0 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -202,6 +202,8 @@ private slots: void updateVolume(); private: + bool event(QEvent *e); + QMap <Qmmp::MetaData, QString> m_metaData; Decoder* m_decoder; QString m_url; bool m_error; diff --git a/src/qmmp/statechangedevent.cpp b/src/qmmp/statechangedevent.cpp new file mode 100644 index 000000000..24483ce61 --- /dev/null +++ b/src/qmmp/statechangedevent.cpp @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "statechangedevent.h" + +StateChangedEvent::StateChangedEvent(Qmmp::State currentState, Qmmp::State previousState) + : QEvent((QEvent::Type)Qmmp::StateChanged) +{ + m_state = currentState; + m_prevState = previousState; +} + +StateChangedEvent::~StateChangedEvent(){} + +Qmmp::State StateChangedEvent::currentState() const +{ + return m_state; +} + +Qmmp::State StateChangedEvent::previousState() const +{ + return m_prevState; +} diff --git a/src/qmmp/statechangedevent.h b/src/qmmp/statechangedevent.h new file mode 100644 index 000000000..96841e6a7 --- /dev/null +++ b/src/qmmp/statechangedevent.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef STATECHANGEDEVENT_H +#define STATECHANGEDEVENT_H + +#include <QEvent> +#include "qmmp.h" + +/*! @internal + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +class StateChangedEvent : public QEvent +{ +public: + StateChangedEvent(Qmmp::State currentState, Qmmp::State previousState); + virtual ~StateChangedEvent(); + + Qmmp::State currentState() const; + Qmmp::State previousState() const; + +private: + Qmmp::State m_state; + Qmmp::State m_prevState; + +}; + +#endif // STATECHANGEDEVENT_H diff --git a/src/qmmp/statehandler.cpp b/src/qmmp/statehandler.cpp index b6a9a062f..fb9ae7aef 100644 --- a/src/qmmp/statehandler.cpp +++ b/src/qmmp/statehandler.cpp @@ -19,8 +19,10 @@ ***************************************************************************/ #include <QStringList> - +#include <QApplication> #include "soundcore.h" +#include "statechangedevent.h" +#include "metadatachangedevent.h" #include "statehandler.h" #define TICK_INTERVAL 250 @@ -71,7 +73,7 @@ void StateHandler::dispatch(qint64 elapsed, { m_sendAboutToFinish = false; if(SoundCore::instance()->totalTime() - m_elapsed > PREFINISH_TIME/2) - emit nextTrackRequest(); + qApp->postEvent(parent(), new QEvent(QEvent::Type(Qmmp::NextTrackRequest))); } } if (m_frequency != frequency) @@ -113,11 +115,16 @@ void StateHandler::dispatch(const QMap<Qmmp::MetaData, QString> &metaData) if (m_metaData != tmp) { m_metaData = tmp; - emit metaDataChanged (); + //emit metaDataChanged (); + qDebug("added = %s", qPrintable(m_metaData.value(Qmmp::URL))); + qApp->postEvent(parent(), new MetaDataChangedEvent(m_metaData)); } } else + { + qDebug("cached = %s", qPrintable(tmp.value(Qmmp::URL))); m_cachedMetaData = tmp; + } m_mutex.unlock(); } @@ -144,11 +151,15 @@ void StateHandler::dispatch(Qmmp::State state) states << "Playing" << "Paused" << "Stopped" << "Buffering" << "NormalError" << "FatalError"; qDebug("StateHandler: Current state: %s; previous state: %s", qPrintable(states.at(state)), qPrintable(states.at(m_state))); + Qmmp::State prevState = state; m_state = state; - emit stateChanged(state); + qApp->postEvent(parent(), new StateChangedEvent(m_state, prevState)); + + //emit stateChanged(state); if(m_state == Qmmp::Playing && !m_cachedMetaData.isEmpty()) { m_mutex.unlock(); + qDebug("from cache = %s", qPrintable(m_cachedMetaData.value(Qmmp::URL))); dispatch(m_cachedMetaData); m_mutex.lock(); m_cachedMetaData.clear(); @@ -219,11 +230,16 @@ void StateHandler::sendNextTrackRequest() if(m_sendAboutToFinish) { m_sendAboutToFinish = false; - emit nextTrackRequest(); + qApp->postEvent(parent(), new QEvent(QEvent::Type(Qmmp::NextTrackRequest))); } m_mutex.unlock(); } +void StateHandler::sendFinished() +{ + qApp->postEvent(parent(), new QEvent(QEvent::Type(Qmmp::Finished))); +} + AbstractEngine *StateHandler::nextEngine() { return m_next_engine; @@ -234,6 +250,19 @@ AbstractEngine *StateHandler::currentEngine() return m_current_engine; } +/*void StateHandler::addReceiver(QObject *receiver) +{ + if(m_receivers.contains(receiver)) + return; + m_receivers.append(receiver); + connect(receiver, SIGNAL(destroyed(QObject*)), SLOT(removeReceiver(QObject*))); +} + +void StateHandler::removeReceiver(QObject *receiver) +{ + m_receivers.removeAll(receiver); +}*/ + StateHandler *StateHandler::instance() { return m_instance; diff --git a/src/qmmp/statehandler.h b/src/qmmp/statehandler.h index 2e60f327e..21eae7528 100644 --- a/src/qmmp/statehandler.h +++ b/src/qmmp/statehandler.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Ilya Kotov * + * Copyright (C) 2008-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -112,6 +112,7 @@ public: * Sends \b nextTrackRequest() signal manually. */ void sendNextTrackRequest(); + void sendFinished(); /*! * Returns a pointer to the audio engine which will be used to play next (queued) audio source. * Otherwise returns \b 0 @@ -122,6 +123,7 @@ public: * Otherwise returns \b 0 */ AbstractEngine *currentEngine(); + /*! * Returns a pointer to the first created StateHandler instance. */ @@ -164,17 +166,18 @@ signals: /*! * Emitted when playback has finished. */ - void finished(); + //void finished(); /*! * Emitted before the playback ends. */ - void nextTrackRequest(); + //void nextTrackRequest(); /*! * This signal is emitted when the stream reader fills it's buffer. * The argument \b progress indicates the current percentage of buffering completed. */ void bufferingProgress(int progress); + private: qint64 m_elapsed; quint32 m_frequency; diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp index 04bddf6a2..c4dc178e0 100644 --- a/src/qmmpui/mediaplayer.cpp +++ b/src/qmmpui/mediaplayer.cpp @@ -22,6 +22,8 @@ #include <QString> #include <QTranslator> #include <QLocale> +#include <qmmp/statechangedevent.h> +#include <qmmp/metadatachangedevent.h> #include "playlistitem.h" #include "mediaplayer.h" @@ -115,32 +117,18 @@ void MediaPlayer::stop() void MediaPlayer::next() { - if (!m_pl_manager->currentPlayList()->next()) - { - stop(); - return; - } - if (m_core->state() != Qmmp::Stopped) - { - stop(); + bool playNext = m_core->state() != Qmmp::Stopped; + stop(); + if (m_pl_manager->currentPlayList()->next() && playNext) play(); - } } void MediaPlayer::previous() { - if (!m_pl_manager->currentPlayList()->previous()) - { - stop(); - return; - } - - if (m_core->state() != Qmmp::Stopped) - { - if (m_core->state() == Qmmp::Paused) - stop(); + bool playNext = m_core->state() != Qmmp::Stopped; + stop(); + if (m_pl_manager->currentPlayList()->next() && playNext) play(); - } } void MediaPlayer::setRepeatable(bool r) |
