X-Git-Url: http://git.maemo.org/git/?p=someplayer;a=blobdiff_plain;f=src%2Fplayer%2Fplayer.cpp;h=17976ba8dab84aaf935689acbf8c5a17f3ec30aa;hp=577a4dc002cd1ea94595657fac1ac2870a7bf1d3;hb=6bc16ab7b14486a857e4947edfd06e16d3ea686e;hpb=b0e8612b3fe8ff513f9c63637c4a546a4a0cea58 diff --git a/src/player/player.cpp b/src/player/player.cpp index 577a4dc..17976ba 100644 --- a/src/player/player.cpp +++ b/src/player/player.cpp @@ -1,8 +1,33 @@ +/* + * SomePlayer - An alternate music player for Maemo 5 + * Copyright (C) 2010 Nikolay (somebody) Tischenko + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #include "player.h" #include +#include +#include +#include +#include "../config.h" +#include using namespace SomePlayer::Playback; using namespace SomePlayer::DataObjects; +using namespace SomePlayer::Storage; Player::Player(QObject *parent) : QObject(parent) @@ -10,13 +35,33 @@ Player::Player(QObject *parent) : _player = new Phonon::MediaObject(this); _output = new Phonon::AudioOutput(Phonon::MusicCategory, this); _player->setTickInterval(1000); + _equalizer = NULL; + _equalizer_enabled = false; connect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(_stateChanged(Phonon::State,Phonon::State))); connect(_player, SIGNAL(tick(qint64)), this, SLOT(_tick(qint64))); - Phonon::createPath(_player, _output); - int seed = reinterpret_cast (_player); + _path = Phonon::createPath(_player, _output); + QList effects = Phonon::BackendCapabilities::availableAudioEffects(); + foreach (Phonon::EffectDescription desc, effects) { + if (desc.name() == "equalizer-10bands") { + _equalizer = new Phonon::Effect(desc, this); + Config config; + if (config.getValue("equalizer/equalizer").toString() == "enabled") { + for (int i = 0; i < 10; i++) { + QVariant var = config.getValue(QString("equalizer/band%1").arg(i)); + setEqualizerValue(i, var.toDouble()); + } + enableEqualizer(); + } else if (config.getValue("equalizer/equalizer") == "") { + for (int i = 0; i < 10; i++) { + config.setValue(QString("equalizer/band%1").arg(i), 0); + } + } + } + } + int seed = QTime::currentTime().msec(); qsrand(seed); - _random = false; - _repeat = false; + _random = _config.getValue("playback/random").toBool(); + _repeat = _config.getValue("playback/repeat").toBool(); _current = -1; } @@ -56,6 +101,8 @@ void Player::next() { _history.push(_current % count); if (!_queue.isEmpty()) { _current = _queue.dequeue(); + } else if (!_prev_history.isEmpty()) { + _current = _prev_history.pop(); } else { if (_random) { _current = (count + (qrand() + qrand() + qrand()) % count) % count; @@ -82,7 +129,7 @@ void Player::_set_source() { void Player::prev() { if (_history.count() > 0) { - _queue.push_front(_current); + _prev_history.push(_current); _current = _history.pop(); _track = _playlist.tracks().at(_current); } @@ -90,7 +137,7 @@ void Player::prev() { play(); } -void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) { +void Player::_stateChanged(Phonon::State newState, Phonon::State /*oldState*/) { switch (newState) { case Phonon::PlayingState: if (_state == PLAYER_LOADING) { @@ -112,8 +159,8 @@ void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) { case Phonon::BufferingState: break; case Phonon::ErrorState: - _state = PLAYER_ERROR; - qDebug() << _player->errorString(); + play(); // force +// _state = PLAYER_ERROR; break; } } @@ -131,6 +178,8 @@ void Player::_tick(qint64 ticks) { void Player::setPlaylist(Playlist playlist) { _playlist = playlist; _history.clear(); + _prev_history.clear(); + _queue.clear(); } void Player::seek(int s) { @@ -138,6 +187,8 @@ void Player::seek(int s) { } void Player::play() { + if (_playlist.tracks().isEmpty()) + return; _state = PLAYER_PLAYING; emit stateChanged(_state); if (_current == -1) { @@ -151,3 +202,63 @@ void Player::play() { void Player::enqueue(int id) { _queue.enqueue(id); } + +void Player::toggleRandom() { + _random = !_random; + _config.setValue("playback/random", _random); +} + +void Player::toggleRepeat() { + _repeat = !_repeat; + _config.setValue("playback/repeat", _repeat); +} + +void Player::setVolume(int v) { + _output->setVolume(v*0.01); +} + +void Player::equalizerValue(int band, double *val) { + if (_equalizer == NULL) { + *val = 0; + return; + } + if (band < 0 || band > 9) { + *val = -24; + return; + } + if (_equalizer_enabled) { + QList plist = _equalizer->parameters(); + QVariant var = _equalizer->parameterValue(plist[band]); + *val = var.toDouble(); + } +} + +void Player::enableEqualizer() { + if (_equalizer == NULL) + return; + _equalizer_enabled = true; + _path.insertEffect(_equalizer); + Config config; + config.setValue("equalizer/equalizer", "enabled"); +} + +void Player::disableEqualizer() { + if (_equalizer == NULL) + return; + _equalizer_enabled = false; + _path.removeEffect(_equalizer); + Config config; + config.setValue("equalizer/equalizer", "disabled"); +} + +void Player::setEqualizerValue(int band, double value) { + if (_equalizer == NULL) + return; + if (band < 0 || band > 9 || value < -24 || value > 12) { + return; + } + QList plist = _equalizer->parameters(); + _equalizer->setParameterValue(plist[band], QVariant::fromValue(value)); + Config config; + config.setValue(QString("equalizer/band%1").arg(band), value); +}