mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 19:37:09 +02:00
add support for all 3 types of artist matches
This commit is contained in:
@@ -94,6 +94,7 @@ public:
|
|||||||
void removeControl( const dyncontrol_ptr& control );
|
void removeControl( const dyncontrol_ptr& control );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void controlsInvalid( const QString& shortTitle, const QString& message );
|
||||||
void onDemandFailed();
|
void onDemandFailed();
|
||||||
void generated( const QList< Tomahawk::query_ptr>& queries );
|
void generated( const QList< Tomahawk::query_ptr>& queries );
|
||||||
void nextTrackGenerated( const Tomahawk::query_ptr& track );
|
void nextTrackGenerated( const Tomahawk::query_ptr& track );
|
||||||
|
@@ -31,6 +31,7 @@ Tomahawk::EchonestControl::EchonestControl( const QString& selectedType, const Q
|
|||||||
|
|
||||||
connect( &m_editingTimer, SIGNAL( timeout() ), this, SIGNAL( changed() ) );
|
connect( &m_editingTimer, SIGNAL( timeout() ), this, SIGNAL( changed() ) );
|
||||||
updateWidgets();
|
updateWidgets();
|
||||||
|
updateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget*
|
QWidget*
|
||||||
@@ -62,6 +63,11 @@ Tomahawk::EchonestControl::setSelectedType ( const QString& type )
|
|||||||
Echonest::DynamicPlaylist::PlaylistParamData
|
Echonest::DynamicPlaylist::PlaylistParamData
|
||||||
Tomahawk::EchonestControl::toENParam() const
|
Tomahawk::EchonestControl::toENParam() const
|
||||||
{
|
{
|
||||||
|
if( m_overrideType != -1 ) {
|
||||||
|
Echonest::DynamicPlaylist::PlaylistParamData newData = m_data;
|
||||||
|
newData.first = static_cast<Echonest::DynamicPlaylist::PlaylistParam>( m_overrideType );
|
||||||
|
return newData;
|
||||||
|
}
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +101,6 @@ void Tomahawk::EchonestControl::setMatch(const QString& match)
|
|||||||
updateWidgetsFromData();
|
updateWidgetsFromData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Tomahawk::EchonestControl::updateWidgets()
|
Tomahawk::EchonestControl::updateWidgets()
|
||||||
{
|
{
|
||||||
@@ -103,6 +108,7 @@ Tomahawk::EchonestControl::updateWidgets()
|
|||||||
delete m_input.data();
|
delete m_input.data();
|
||||||
if( !m_match.isNull() )
|
if( !m_match.isNull() )
|
||||||
delete m_match.data();
|
delete m_match.data();
|
||||||
|
m_overrideType = -1;
|
||||||
|
|
||||||
// make sure the widgets are the proper kind for the selected type, and hook up to their slots
|
// make sure the widgets are the proper kind for the selected type, and hook up to their slots
|
||||||
if( selectedType() == "Artist" ) {
|
if( selectedType() == "Artist" ) {
|
||||||
@@ -113,6 +119,7 @@ Tomahawk::EchonestControl::updateWidgets()
|
|||||||
|
|
||||||
match->addItem( "Limit To", Echonest::DynamicPlaylist::ArtistType );
|
match->addItem( "Limit To", Echonest::DynamicPlaylist::ArtistType );
|
||||||
match->addItem( "Similar To", Echonest::DynamicPlaylist::ArtistRadioType );
|
match->addItem( "Similar To", Echonest::DynamicPlaylist::ArtistRadioType );
|
||||||
|
match->addItem( "Description", Echonest::DynamicPlaylist::ArtistDescriptionType );
|
||||||
m_matchString = match->currentText();
|
m_matchString = match->currentText();
|
||||||
m_matchData = match->itemData( match->currentIndex() ).toString();
|
m_matchData = match->itemData( match->currentIndex() ).toString();
|
||||||
|
|
||||||
@@ -143,6 +150,10 @@ Tomahawk::EchonestControl::updateData()
|
|||||||
if( combo ) {
|
if( combo ) {
|
||||||
m_matchString = combo->currentText();
|
m_matchString = combo->currentText();
|
||||||
m_matchData = combo->itemData( combo->currentIndex() ).toString();
|
m_matchData = combo->itemData( combo->currentIndex() ).toString();
|
||||||
|
|
||||||
|
// EN HACK: artist-description radio needs description= fields not artist= fields
|
||||||
|
if( m_matchData.toInt() == Echonest::DynamicPlaylist::ArtistDescriptionType )
|
||||||
|
m_overrideType = Echonest::DynamicPlaylist::Description;
|
||||||
}
|
}
|
||||||
QLineEdit* edit = qobject_cast<QLineEdit*>( m_input.data() );
|
QLineEdit* edit = qobject_cast<QLineEdit*>( m_input.data() );
|
||||||
if( edit && !edit->text().isEmpty() ) {
|
if( edit && !edit->text().isEmpty() ) {
|
||||||
|
@@ -57,6 +57,7 @@ private:
|
|||||||
void updateWidgetsFromData();
|
void updateWidgetsFromData();
|
||||||
|
|
||||||
Echonest::DynamicPlaylist::PlaylistParam m_currentType;
|
Echonest::DynamicPlaylist::PlaylistParam m_currentType;
|
||||||
|
int m_overrideType;
|
||||||
|
|
||||||
QWeakPointer< QWidget > m_input;
|
QWeakPointer< QWidget > m_input;
|
||||||
QWeakPointer< QWidget > m_match;
|
QWeakPointer< QWidget > m_match;
|
||||||
@@ -70,8 +71,6 @@ private:
|
|||||||
friend class EchonestGenerator;
|
friend class EchonestGenerator;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QSharedPointer<EchonestControl> encontrol_ptr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
EchonestFactory::EchonestFactory()
|
EchonestFactory::EchonestFactory()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -77,22 +76,32 @@ void
|
|||||||
EchonestGenerator::generate ( int number )
|
EchonestGenerator::generate ( int number )
|
||||||
{
|
{
|
||||||
// convert to an echonest query, and fire it off
|
// convert to an echonest query, and fire it off
|
||||||
Echonest::DynamicPlaylist::PlaylistParams params = getParams();
|
try {
|
||||||
params.append( Echonest::DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Results, number ) );
|
Echonest::DynamicPlaylist::PlaylistParams params = getParams();
|
||||||
QNetworkReply* reply = Echonest::DynamicPlaylist::staticPlaylist( params );
|
|
||||||
qDebug() << "Generating a static playlist from echonest!" << reply->url().toString();
|
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( staticFinished() ) );
|
|
||||||
|
|
||||||
|
params.append( Echonest::DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Results, number ) );
|
||||||
|
QNetworkReply* reply = Echonest::DynamicPlaylist::staticPlaylist( params );
|
||||||
|
qDebug() << "Generating a static playlist from echonest!" << reply->url().toString();
|
||||||
|
connect( reply, SIGNAL( finished() ), this, SLOT( staticFinished() ) );
|
||||||
|
} catch( std::runtime_error& e ) {
|
||||||
|
qWarning() << "Got invalid controls!" << e.what();
|
||||||
|
emit controlsInvalid( "Controls were not valid", QString::fromLatin1( e.what() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EchonestGenerator::startOnDemand()
|
EchonestGenerator::startOnDemand()
|
||||||
{
|
{
|
||||||
Echonest::DynamicPlaylist::PlaylistParams params = getParams();
|
try {
|
||||||
|
Echonest::DynamicPlaylist::PlaylistParams params = getParams();
|
||||||
|
|
||||||
QNetworkReply* reply = m_dynPlaylist->start( params );
|
QNetworkReply* reply = m_dynPlaylist->start( params );
|
||||||
qDebug() << "starting a dynamic playlist from echonest!" << reply->url().toString();
|
qDebug() << "starting a dynamic playlist from echonest!" << reply->url().toString();
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( dynamicStarted() ) );
|
connect( reply, SIGNAL( finished() ), this, SLOT( dynamicStarted() ) );
|
||||||
|
} catch( std::runtime_error& e ) {
|
||||||
|
qWarning() << "Got invalid controls!" << e.what();
|
||||||
|
emit controlsInvalid( "Controls were not valid", QString::fromLatin1( e.what() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -136,7 +145,8 @@ EchonestGenerator::staticFinished()
|
|||||||
emit generated( queries );
|
emit generated( queries );
|
||||||
}
|
}
|
||||||
|
|
||||||
Echonest::DynamicPlaylist::PlaylistParams EchonestGenerator::getParams() const
|
Echonest::DynamicPlaylist::PlaylistParams
|
||||||
|
EchonestGenerator::getParams() const throw( std::runtime_error )
|
||||||
{
|
{
|
||||||
Echonest::DynamicPlaylist::PlaylistParams params;
|
Echonest::DynamicPlaylist::PlaylistParams params;
|
||||||
foreach( const dyncontrol_ptr& control, m_controls ) {
|
foreach( const dyncontrol_ptr& control, m_controls ) {
|
||||||
@@ -182,11 +192,46 @@ EchonestGenerator::dynamicFetched()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tries to heuristically determine what sort of radio this is based on the controls
|
|
||||||
Echonest::DynamicPlaylist::ArtistTypeEnum
|
Echonest::DynamicPlaylist::ArtistTypeEnum
|
||||||
EchonestGenerator::determineRadioType() const
|
EchonestGenerator::determineRadioType() const throw( std::runtime_error )
|
||||||
{
|
{
|
||||||
// TODO
|
/**
|
||||||
|
* so we try to match the best type of echonest playlist, based on the controls
|
||||||
|
* the types are artist, artist-radio, artist-description, catalog, catalog-radio, song-radio. we don't care about the catalog ones.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// 1. artist: If all the artist controls are Limit-To. If some were but not all, error out.
|
||||||
|
bool artistOnly = true;
|
||||||
|
bool someArtist = false;
|
||||||
|
foreach( const dyncontrol_ptr& control, m_controls ) {
|
||||||
|
if( control->selectedType() == "Artist" && static_cast<Echonest::DynamicPlaylist::ArtistTypeEnum>( control->match().toInt() ) != Echonest::DynamicPlaylist::ArtistType ) {
|
||||||
|
artistOnly = false;
|
||||||
|
} else if( control->selectedType() == "Artist" && static_cast<Echonest::DynamicPlaylist::ArtistTypeEnum>( control->match().toInt() ) == Echonest::DynamicPlaylist::ArtistType ) {
|
||||||
|
someArtist = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( someArtist && artistOnly ) {
|
||||||
|
return Echonest::DynamicPlaylist::ArtistType;
|
||||||
|
} else if( someArtist && !artistOnly ) {
|
||||||
|
throw std::runtime_error( "All artist match types must be the same" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 2. artist-description: If all the artist entries are Description. If some were but not all, error out.
|
||||||
|
bool artistDescOnly = true;
|
||||||
|
bool someArtistDescFound = false;
|
||||||
|
|
||||||
|
foreach( const dyncontrol_ptr& control, m_controls ) {
|
||||||
|
if( control->selectedType() == "Artist" && static_cast<Echonest::DynamicPlaylist::ArtistTypeEnum>( control->match().toInt() ) == Echonest::DynamicPlaylist::ArtistDescriptionType ) {
|
||||||
|
someArtistDescFound = true;
|
||||||
|
} else if( control->selectedType() == "Artist" && static_cast<Echonest::DynamicPlaylist::ArtistTypeEnum>( control->match().toInt() ) != Echonest::DynamicPlaylist::ArtistDescriptionType ) {
|
||||||
|
artistDescOnly = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( someArtistDescFound && artistDescOnly ) {
|
||||||
|
return Echonest::DynamicPlaylist::ArtistDescriptionType;
|
||||||
|
} else if( someArtistDescFound && !artistDescOnly ) // fail, must be all artist desc
|
||||||
|
throw std::runtime_error( "All artist match types must be the same" );
|
||||||
|
|
||||||
return Echonest::DynamicPlaylist::ArtistRadioType;
|
return Echonest::DynamicPlaylist::ArtistRadioType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#ifndef ECHONEST_GENERATOR_H
|
#ifndef ECHONEST_GENERATOR_H
|
||||||
#define ECHONEST_GENERATOR_H
|
#define ECHONEST_GENERATOR_H
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <echonest/Playlist.h>
|
#include <echonest/Playlist.h>
|
||||||
|
|
||||||
#include "playlist/dynamic/GeneratorInterface.h"
|
#include "playlist/dynamic/GeneratorInterface.h"
|
||||||
@@ -55,10 +56,10 @@ private slots:
|
|||||||
void dynamicFetched();
|
void dynamicFetched();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Echonest::DynamicPlaylist::PlaylistParams getParams() const;
|
Echonest::DynamicPlaylist::PlaylistParams getParams() const throw( std::runtime_error );
|
||||||
query_ptr queryFromSong( const Echonest::Song& song );
|
query_ptr queryFromSong( const Echonest::Song& song );
|
||||||
|
Echonest::DynamicPlaylist::ArtistTypeEnum determineRadioType() const throw( std::runtime_error );
|
||||||
|
|
||||||
Echonest::DynamicPlaylist::ArtistTypeEnum determineRadioType() const;
|
|
||||||
Echonest::DynamicPlaylist* m_dynPlaylist;
|
Echonest::DynamicPlaylist* m_dynPlaylist;
|
||||||
QPixmap m_logo;
|
QPixmap m_logo;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user