1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-17 14:28:24 +01:00

change EchonestGenerator to the new Genre API of libechonest

needs libechonest 2.3
This commit is contained in:
Stefan Derkits 2014-09-09 12:00:04 +02:00
parent 798fcf7025
commit 52c9ff6b13
4 changed files with 123 additions and 5 deletions

View File

@ -301,8 +301,8 @@ if(LIBCPP_FOUND AND APPLE)
endif()
macro_optional_find_package(Echonest 2.2.0)
macro_log_feature(ECHONEST_FOUND "Echonest" "Qt library for communicating with The Echo Nest" "http://projects.kde.org/libechonest" TRUE "" "libechonest 2.2.0 is needed for dynamic playlists and the infosystem")
macro_optional_find_package(Echonest 2.3.0)
macro_log_feature(ECHONEST_FOUND "Echonest" "Qt library for communicating with The Echo Nest" "http://projects.kde.org/libechonest" TRUE "" "libechonest 2.3.0 is needed for dynamic playlists and the infosystem")
find_package(Boost REQUIRED COMPONENTS filesystem system)
macro_log_feature(Boost_FOUND "Boost" "Provides free peer-reviewed portable C++ source libraries" "http://www.boost.org" TRUE "" "") #FIXME: give useful explanation

View File

@ -509,6 +509,49 @@ Tomahawk::EchonestControl::updateWidgets()
m_match = QPointer< QWidget >( match );
m_input = QPointer< QWidget >( combo );
}
else if( selectedType() == "Distribution" )
{
m_currentType = Echonest::DynamicPlaylist::Distribution;
QLabel* match = new QLabel( tr( "is" ) );
QComboBox* combo = new QComboBox();
combo->addItem( tr( "Focused", "Distribution: Songs that are tightly clustered around the seeds" ), "focused" );
combo->addItem( tr( "Wandering", "Distribution: Songs from a broader range of artists"), "wandering" );
m_matchString = match->text();
m_matchData = match->text();
connect( combo, SIGNAL( activated( int ) ), this, SLOT( updateData() ) );
connect( combo, SIGNAL( activated( int ) ), this, SLOT( editingFinished() ) );
m_match = QPointer<QWidget>( match );
m_input = QPointer<QWidget>( combo );
}
else if( selectedType() == "Genre Preset" )
{
m_currentType = Echonest::DynamicPlaylist::GenrePreset;
QComboBox* match = new QComboBox();
match->addItem( tr( "Classics", "Genre preset: songs intended to introduce the genre to a novice listener" ), "core" );
match->addItem( tr( "Popular", "Genre preset: most popular songs being played in the genre today" ), "in_rotation" );
match->addItem( tr( "Emerging", "Genre preset: songs that are more popular than expected, but which are unfamiliar to most listeners" ), "emerging" );
QComboBox* combo = new QComboBox();
combo->addItem( tr( "Best", "Genre preset: optimal collection of songs" ), "best" );
combo->addItem( tr( "Mix", "Genre preset: a varying collection of songs" ), "shuffled" );
m_matchString = match->currentText();
m_matchData = match->itemData( match->currentIndex() ).toString();
connect( match, SIGNAL( activated( int ) ), this, SLOT( updateData() ) );
connect( match, SIGNAL( activated( int ) ), this, SLOT( editingFinished() ) );
connect( combo, SIGNAL( activated( int ) ), this, SLOT( updateData() ) );
connect( combo, SIGNAL( activated( int ) ), this, SLOT( editingFinished() ) );
m_match = QPointer<QWidget>( match );
m_input = QPointer<QWidget>( combo );
}
else
{
m_match = QPointer<QWidget>( new QWidget );
@ -627,7 +670,31 @@ Tomahawk::EchonestControl::updateData()
}
}
else if( selectedType() == "Distribution" )
{
QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() );
if ( combo )
{
m_data.first = Echonest::DynamicPlaylist::Distribution;
m_data.second = combo->itemData( combo->currentIndex() ).toString();
}
}
else if( selectedType() == "Genre Preset" )
{
QComboBox* match = qobject_cast<QComboBox*>( m_match.data() );
QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() );
if ( match && combo )
{
m_matchString = match->currentText();
m_matchData = match->itemData( match->currentIndex() ).toString();
QString presetType = m_matchData.append( "_%1" );
presetType = presetType.arg( combo->itemData( combo->currentIndex() ).toString() );
m_data.first = Echonest::DynamicPlaylist::GenrePreset;
m_data.second = presetType;
}
}
calculateSummary();
}
@ -745,6 +812,13 @@ Tomahawk::EchonestControl::updateWidgetsFromData()
combo->setCurrentIndex( combo->findData( songType ) );
}
}
else if( selectedType() == "Distribution" )
{
QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() );
if ( combo ) {
combo->setCurrentIndex( combo->findData( m_data.second.toString() ));
}
}
calculateSummary();
}
@ -1005,6 +1079,42 @@ Tomahawk::EchonestControl::calculateSummary()
else
summary = tr( "where song type is not %1" ).arg( text );
}
else if ( selectedType() == "Distribution" )
{
Q_ASSERT( !m_input.isNull() );
Q_ASSERT( qobject_cast< QComboBox* >( m_input.data() ) );
QString text = qobject_cast< QComboBox* >( m_input.data() )->currentText().toLower();
summary = tr( "with a %1 distribution" ).arg( text );
}
else if( selectedType() == "Genre Preset" )
{
Q_ASSERT( !m_input.isNull() );
Q_ASSERT( qobject_cast< QComboBox* >( m_input.data() ) );
QComboBox* input = qobject_cast< QComboBox* >( m_input.data() );
Q_ASSERT( !m_match.isNull() );
Q_ASSERT( qobject_cast< QComboBox* >( m_match.data() ) );
QComboBox* match = qobject_cast< QComboBox* >( m_match.data() );
summary = tr( "preset to %1 collection of %2 genre songs" );
if ( input->itemData( input->currentIndex() ) == "best" )
summary = summary.arg( tr( "an optimal" ) );
else
summary = summary.arg( tr( "a mixed" ) );
if ( match->itemData( match->currentIndex() ) == "core" )
{
summary = summary.arg( tr( "classic" ) );
}
else
{
if ( match->itemData( match->currentIndex() ) == "in_rotation" )
summary = summary.arg( tr( "popular" ) );
else
summary = summary.arg( tr( "emerging" ) );
}
}
m_summary = summary;
}

View File

@ -28,6 +28,7 @@
#include "database/Database.h"
#include "utils/Logger.h"
#include "SourceList.h"
#include <QFile>
#include <QDir>
#include <QReadWriteLock>
@ -84,7 +85,8 @@ EchonestFactory::typeSelectors() const
<< QT_TRANSLATE_NOOP( "Type selector", "Song Hotttnesss" ) << QT_TRANSLATE_NOOP( "Type selector", "Longitude" )
<< QT_TRANSLATE_NOOP( "Type selector", "Latitude" ) << QT_TRANSLATE_NOOP( "Type selector", "Mode" )
<< QT_TRANSLATE_NOOP( "Type selector", "Key" ) << QT_TRANSLATE_NOOP( "Type selector", "Sorting" )
<< QT_TRANSLATE_NOOP( "Type selector", "Song Type" );
<< QT_TRANSLATE_NOOP( "Type selector", "Song Type" ) << QT_TRANSLATE_NOOP( "Type selector", "Distribution" )
<< QT_TRANSLATE_NOOP( "Type selector", "Genre Preset" );
return types;
}
@ -713,7 +715,7 @@ EchonestGenerator::loadGenres()
{
s_genres_lock.lockForWrite();
tLog() << "Genres not in cache or too old, refetching genres ...";
s_genresJob = Echonest::Artist::fetchGenres();
s_genresJob = Echonest::Genre::fetchList( Echonest::GenreInformation(), 2000 );
connect( s_genresJob, SIGNAL( finished() ), this, SLOT( genresReceived() ) );
}
}
@ -798,7 +800,11 @@ EchonestGenerator::genresReceived()
try
{
s_genres = Echonest::Artist::parseGenreList( r ).toList();
Echonest::Genres genrelist = Echonest::Genre::parseList( r );
foreach( const Echonest::Genre& genre, genrelist )
{
s_genres << genre.name();
}
}
catch( Echonest::ParseError& e )
{

View File

@ -31,8 +31,10 @@
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#include <echonest5/Playlist.h>
#include <echonest5/Genre.h>
#else
#include <echonest/Playlist.h>
#include <echonest/Genre.h>
#endif
namespace Tomahawk