mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
move dynamic control code to the new DynamicModel
This commit is contained in:
@@ -101,6 +101,7 @@ set( libSources
|
|||||||
playlist/dynamic/GeneratorFactory.cpp
|
playlist/dynamic/GeneratorFactory.cpp
|
||||||
playlist/dynamic/GeneratorInterface.cpp
|
playlist/dynamic/GeneratorInterface.cpp
|
||||||
playlist/dynamic/DynamicView.cpp
|
playlist/dynamic/DynamicView.cpp
|
||||||
|
playlist/dynamic/DynamicModel.cpp
|
||||||
playlist/dynamic/echonest/EchonestGenerator.cpp
|
playlist/dynamic/echonest/EchonestGenerator.cpp
|
||||||
playlist/dynamic/echonest/EchonestControl.cpp
|
playlist/dynamic/echonest/EchonestControl.cpp
|
||||||
playlist/dynamic/echonest/EchonestSteerer.cpp
|
playlist/dynamic/echonest/EchonestSteerer.cpp
|
||||||
@@ -240,6 +241,7 @@ set( libHeaders
|
|||||||
playlist/dynamic/GeneratorFactory.h
|
playlist/dynamic/GeneratorFactory.h
|
||||||
playlist/dynamic/GeneratorInterface.h
|
playlist/dynamic/GeneratorInterface.h
|
||||||
playlist/dynamic/DynamicView.h
|
playlist/dynamic/DynamicView.h
|
||||||
|
playlist/dynamic/DynamicModel.h
|
||||||
playlist/dynamic/echonest/EchonestGenerator.h
|
playlist/dynamic/echonest/EchonestGenerator.h
|
||||||
playlist/dynamic/echonest/EchonestControl.h
|
playlist/dynamic/echonest/EchonestControl.h
|
||||||
playlist/dynamic/echonest/EchonestSteerer.h
|
playlist/dynamic/echonest/EchonestSteerer.h
|
||||||
|
105
src/libtomahawk/playlist/dynamic/DynamicModel.cpp
Normal file
105
src/libtomahawk/playlist/dynamic/DynamicModel.cpp
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/****************************************************************************************
|
||||||
|
* Copyright (c) 2011 Leo Franchi <lfranchi@kde.org> *
|
||||||
|
* *
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>. *
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#include "playlist/dynamic/DynamicModel.h"
|
||||||
|
#include "GeneratorInterface.h"
|
||||||
|
#include "StationModelItem.h"
|
||||||
|
#include "audio/audioengine.h"
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
DynamicModel::DynamicModel( QObject* parent )
|
||||||
|
: PlaylistModel( parent )
|
||||||
|
, m_startOnResolved( false )
|
||||||
|
, m_onDemandRunning( false )
|
||||||
|
, m_currentAttempts( 0 )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicModel::~DynamicModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
||||||
|
{
|
||||||
|
m_playlist = playlist;
|
||||||
|
|
||||||
|
|
||||||
|
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( newTrackGenerated( Tomahawk::query_ptr ) ) );
|
||||||
|
PlaylistModel::loadPlaylist( m_playlist );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::startOnDemand()
|
||||||
|
{
|
||||||
|
m_playlist->generator()->startOnDemand();
|
||||||
|
|
||||||
|
m_onDemandRunning = true;
|
||||||
|
m_startOnResolved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query )
|
||||||
|
{
|
||||||
|
if( m_onDemandRunning ) {
|
||||||
|
connect( query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolveFinished( bool ) ) );
|
||||||
|
connect( query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ), this, SLOT( trackResolved() ) );
|
||||||
|
|
||||||
|
append( query );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::stopOnDemand()
|
||||||
|
{
|
||||||
|
m_onDemandRunning = false;
|
||||||
|
AudioEngine::instance()->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::trackResolved()
|
||||||
|
{
|
||||||
|
m_currentAttempts = 0;
|
||||||
|
|
||||||
|
if( m_startOnResolved ) { // on first start
|
||||||
|
m_startOnResolved = false;
|
||||||
|
AudioEngine::instance()->play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::trackResolveFinished( bool success )
|
||||||
|
{
|
||||||
|
if( !success ) { // if it was successful, we've already gotten a trackResolved() signal
|
||||||
|
m_currentAttempts++;
|
||||||
|
if( m_currentAttempts < 100 ) {
|
||||||
|
m_playlist->generator()->fetchNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::newTrackLoading()
|
||||||
|
{
|
||||||
|
if( m_onDemandRunning && m_currentAttempts == 0 ) { // if we're in dynamic mode and we're also currently idle
|
||||||
|
m_playlist->generator()->fetchNext();
|
||||||
|
}
|
||||||
|
}
|
60
src/libtomahawk/playlist/dynamic/DynamicModel.h
Normal file
60
src/libtomahawk/playlist/dynamic/DynamicModel.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************************
|
||||||
|
* Copyright (c) 2011 Leo Franchi <lfranchi@kde.org> *
|
||||||
|
* *
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>. *
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DYNAMIC_MODEL_H
|
||||||
|
#define DYNAMIC_MODEL_H
|
||||||
|
|
||||||
|
#include "playlistmodel.h"
|
||||||
|
#include "query.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class StationModelItem;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends PlaylistModel with support for handling StationModelItems
|
||||||
|
*/
|
||||||
|
class DynamicModel : public PlaylistModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DynamicModel( QObject* parent = 0 );
|
||||||
|
virtual ~DynamicModel();
|
||||||
|
|
||||||
|
void startOnDemand();
|
||||||
|
void stopOnDemand();
|
||||||
|
|
||||||
|
void loadPlaylist( const dynplaylist_ptr& playlist );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void newTrackGenerated( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
|
void trackResolveFinished( bool );
|
||||||
|
void trackResolved();
|
||||||
|
void newTrackLoading();
|
||||||
|
|
||||||
|
private:
|
||||||
|
dynplaylist_ptr m_playlist;
|
||||||
|
bool m_startOnResolved;
|
||||||
|
bool m_onDemandRunning;
|
||||||
|
int m_currentAttempts;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@@ -23,8 +23,7 @@
|
|||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
|
||||||
#include "DynamicControlList.h"
|
#include "DynamicControlList.h"
|
||||||
#include "playlistview.h"
|
#include "dynamic/DynamicModel.h"
|
||||||
#include "playlistmodel.h"
|
|
||||||
#include "trackproxymodel.h"
|
#include "trackproxymodel.h"
|
||||||
#include "dynamic/GeneratorInterface.h"
|
#include "dynamic/GeneratorInterface.h"
|
||||||
#include "dynamic/GeneratorFactory.h"
|
#include "dynamic/GeneratorFactory.h"
|
||||||
@@ -43,8 +42,6 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
|||||||
, m_resolveOnNextLoad( false )
|
, m_resolveOnNextLoad( false )
|
||||||
, m_seqRevLaunched( 0 )
|
, m_seqRevLaunched( 0 )
|
||||||
, m_runningOnDemand( false )
|
, m_runningOnDemand( false )
|
||||||
, m_startOnResolved( false )
|
|
||||||
, m_songsSinceLastResolved( 0 )
|
|
||||||
, m_steering( 0 )
|
, m_steering( 0 )
|
||||||
, m_headerText( 0 )
|
, m_headerText( 0 )
|
||||||
, m_headerLayout( 0 )
|
, m_headerLayout( 0 )
|
||||||
@@ -88,7 +85,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
|||||||
m_controls = new CollapsibleControls( this );
|
m_controls = new CollapsibleControls( this );
|
||||||
m_layout->addWidget( m_controls );
|
m_layout->addWidget( m_controls );
|
||||||
|
|
||||||
m_model = new PlaylistModel( this );
|
m_model = new DynamicModel( this );
|
||||||
m_view = new DynamicView( this );
|
m_view = new DynamicView( this );
|
||||||
m_view->setModel( m_model );
|
m_view->setModel( m_model );
|
||||||
m_view->setContentsMargins( 0, 0, 0, 0 );
|
m_view->setContentsMargins( 0, 0, 0, 0 );
|
||||||
@@ -140,7 +137,6 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
|||||||
if( !m_playlist.isNull() ) {
|
if( !m_playlist.isNull() ) {
|
||||||
disconnect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
|
disconnect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
|
||||||
disconnect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ), this, SLOT(onRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ) );
|
disconnect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ), this, SLOT(onRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ) );
|
||||||
disconnect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( onDemandFetched( Tomahawk::query_ptr ) ) );
|
|
||||||
disconnect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), m_view, SLOT( showMessageTimeout( QString, QString ) ) );
|
disconnect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), m_view, SLOT( showMessageTimeout( QString, QString ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +153,6 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
|||||||
applyModeChange( m_playlist->mode() );
|
applyModeChange( m_playlist->mode() );
|
||||||
connect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
|
connect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
|
||||||
connect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
|
connect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
|
||||||
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( onDemandFetched( Tomahawk::query_ptr ) ) );
|
|
||||||
connect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), m_view, SLOT( showMessageTimeout( QString, QString ) ) );
|
connect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), m_view, SLOT( showMessageTimeout( QString, QString ) ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -211,11 +206,11 @@ DynamicWidget::generateOrStart()
|
|||||||
} else if( m_playlist->mode() == OnDemand ) {
|
} else if( m_playlist->mode() == OnDemand ) {
|
||||||
if( m_runningOnDemand == false ) {
|
if( m_runningOnDemand == false ) {
|
||||||
m_runningOnDemand = true;
|
m_runningOnDemand = true;
|
||||||
m_startOnResolved = true;
|
m_model->startOnDemand();
|
||||||
m_playlist->generator()->startOnDemand();
|
|
||||||
|
|
||||||
m_generateButton->setText( tr( "Stop" ) );
|
m_generateButton->setText( tr( "Stop" ) );
|
||||||
|
|
||||||
|
|
||||||
// show the steering controls
|
// show the steering controls
|
||||||
if( m_playlist->generator()->onDemandSteerable() ) {
|
if( m_playlist->generator()->onDemandSteerable() ) {
|
||||||
// position it horizontally centered, above the botton.
|
// position it horizontally centered, above the botton.
|
||||||
@@ -230,8 +225,8 @@ DynamicWidget::generateOrStart()
|
|||||||
m_steering->show();
|
m_steering->show();
|
||||||
}
|
}
|
||||||
} else { // stop
|
} else { // stop
|
||||||
|
m_model->stopOnDemand();
|
||||||
m_runningOnDemand = false;
|
m_runningOnDemand = false;
|
||||||
m_startOnResolved = false;
|
|
||||||
m_steering = 0;
|
m_steering = 0;
|
||||||
m_generateButton->setText( tr( "Start" ) );
|
m_generateButton->setText( tr( "Start" ) );
|
||||||
}
|
}
|
||||||
@@ -271,52 +266,6 @@ DynamicWidget::tracksGenerated( const QList< query_ptr >& queries )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DynamicWidget::onDemandFetched( const Tomahawk::query_ptr& track )
|
|
||||||
{
|
|
||||||
connect( track.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolveFinished( bool ) ) );
|
|
||||||
connect( track.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ), this, SLOT( trackResolved() ) );
|
|
||||||
|
|
||||||
m_model->append( track );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DynamicWidget::trackResolved()
|
|
||||||
{
|
|
||||||
m_songsSinceLastResolved = 0;
|
|
||||||
|
|
||||||
if( m_startOnResolved ) {
|
|
||||||
m_startOnResolved = false;
|
|
||||||
AudioEngine::instance()->play();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DynamicWidget::trackResolveFinished( bool success )
|
|
||||||
{
|
|
||||||
if( !success ) { // if it was successful, we've already gotten a trackResolved() signal
|
|
||||||
m_songsSinceLastResolved++;
|
|
||||||
if( m_songsSinceLastResolved < 100 ) {
|
|
||||||
m_playlist->generator()->fetchNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DynamicWidget::newTrackLoading()
|
|
||||||
{
|
|
||||||
if( m_runningOnDemand && m_songsSinceLastResolved == 0 ) { // if we're in dynamic mode and we're also currently idle
|
|
||||||
m_playlist->generator()->fetchNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicWidget::onDemandFailed()
|
|
||||||
{
|
|
||||||
if( m_runningOnDemand )
|
|
||||||
generateOrStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicWidget::controlsChanged()
|
DynamicWidget::controlsChanged()
|
||||||
|
@@ -38,6 +38,9 @@ class ReadOrWriteWidget;
|
|||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class DynamicModel;
|
||||||
|
|
||||||
|
|
||||||
class DynamicView;
|
class DynamicView;
|
||||||
|
|
||||||
|
|
||||||
@@ -68,13 +71,6 @@ private slots:
|
|||||||
void generateOrStart();
|
void generateOrStart();
|
||||||
void tracksGenerated( const QList< Tomahawk::query_ptr>& queries );
|
void tracksGenerated( const QList< Tomahawk::query_ptr>& queries );
|
||||||
|
|
||||||
// used by on demand mode
|
|
||||||
void onDemandFailed();
|
|
||||||
void newTrackLoading();
|
|
||||||
void onDemandFetched( const Tomahawk::query_ptr& track );
|
|
||||||
void trackResolveFinished( bool );
|
|
||||||
void trackResolved();
|
|
||||||
|
|
||||||
void controlsChanged();
|
void controlsChanged();
|
||||||
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
|
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
|
||||||
|
|
||||||
@@ -88,8 +84,6 @@ private:
|
|||||||
|
|
||||||
// used in OnDemand mode
|
// used in OnDemand mode
|
||||||
bool m_runningOnDemand;
|
bool m_runningOnDemand;
|
||||||
bool m_startOnResolved;
|
|
||||||
int m_songsSinceLastResolved;
|
|
||||||
QWidget* m_steering;
|
QWidget* m_steering;
|
||||||
|
|
||||||
// layout and stuff
|
// layout and stuff
|
||||||
@@ -103,7 +97,7 @@ private:
|
|||||||
CollapsibleControls* m_controls;
|
CollapsibleControls* m_controls;
|
||||||
|
|
||||||
DynamicView* m_view;
|
DynamicView* m_view;
|
||||||
PlaylistModel* m_model;
|
DynamicModel* m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user