changeset 374:11f804c7582a macness_autotpl

method to map from genre string to template choice; and to use it when importing from itunes
author Dan Stowell <dan.stowell@eecs.qmul.ac.uk>
date Fri, 15 Oct 2010 13:30:41 +0100
parents 80d91b72ae7d
children 62e9f62752e1
files main/MainWindow.cpp main/MainWindow.h
diffstat 2 files changed, 59 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Fri Oct 15 13:29:27 2010 +0100
+++ b/main/MainWindow.cpp	Fri Oct 15 13:30:41 2010 +0100
@@ -2161,6 +2161,57 @@
     }
 }
 
+void
+MainWindow::initGenreToTemplateMap()
+{
+    // Note that the set of templates must always be kept small, for reasons of usability, manageability, code size.
+    
+    // TODO add all the standard ID3 + winamp genre labels (lowercased).
+
+    m_genreToTemplateMap["classical"]   = "classical";
+
+    // 'dance' template is for things where beat and rhythm are particularly important
+    m_genreToTemplateMap["dance"] = "dance";
+    m_genreToTemplateMap["disco"] = "dance";
+    m_genreToTemplateMap["electronic"]  = "dance";
+    m_genreToTemplateMap["funk"] = "dance";
+    m_genreToTemplateMap["hip-hop"]     = "dance";
+    m_genreToTemplateMap["industrial"] = "dance";
+    m_genreToTemplateMap["rap"] = "dance";
+    m_genreToTemplateMap["techno"] = "dance";
+
+    m_genreToTemplateMap["acoustic"] = "melodic";
+    m_genreToTemplateMap["alternative"] = "melodic"; // ???
+    m_genreToTemplateMap["blues"]       = "melodic";
+    m_genreToTemplateMap["classic rock"] = "melodic";
+    m_genreToTemplateMap["country"] = "melodic";
+    m_genreToTemplateMap["grunge"] = "melodic";
+    m_genreToTemplateMap["jazz"]        = "melodic";
+    m_genreToTemplateMap["metal"] = "melodic";
+    m_genreToTemplateMap["new age"] = "melodic";
+    m_genreToTemplateMap["oldies"] = "melodic";
+    m_genreToTemplateMap["other"] = "melodic";
+    m_genreToTemplateMap["pop"] = "melodic";
+    m_genreToTemplateMap["r&b"] = "melodic";
+    m_genreToTemplateMap["reggae"] = "melodic";
+    m_genreToTemplateMap["rock"]        = "melodic";
+    m_genreToTemplateMap["ska"] = "melodic";
+    m_genreToTemplateMap["soundtrack"]        = "melodic";
+}
+
+
+QString 
+MainWindow::templateNameFromGenre(QString genre){
+    if(m_genreToTemplateMap.isEmpty())
+        initGenreToTemplateMap();
+    
+    QString tplName = m_genreToTemplateMap.value(genre.toLower(), "");
+    
+    //return tplName;
+    return QString("testtemplate"); // TODO TEMPORARY - remove once templates are made
+}
+
+
 #ifdef Q_WS_MAC
 void
 MainWindow::importITunesAudio()
@@ -2169,9 +2220,10 @@
     QString path = nowPlaying.at(0);
     QString genre = (nowPlaying.size() > 1) ? nowPlaying.at(1) : "";
     std::cerr << "MainWindow::importITunesAudio(): genre is " << genre.toStdString() << std::endl;
+    QString tplName = templateNameFromGenre(genre);
 
     if (path != "") {
-    if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
+    if (openAudio(path, ReplaceMainModel, tplName) == FileOpenFailed) {
             emit hideSplash();
         QMessageBox::critical(this, tr("Failed to open file"),
                   tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
--- a/main/MainWindow.h	Fri Oct 15 13:29:27 2010 +0100
+++ b/main/MainWindow.h	Fri Oct 15 13:30:41 2010 +0100
@@ -68,6 +68,9 @@
                bool withOSCSupport = true);
     virtual ~MainWindow();
 
+    // maps from known genre tags to template choices
+    QString templateNameFromGenre(QString genre);
+
 signals:
     virtual void canChangeSolo(bool);
     virtual void canAlign(bool);
@@ -278,6 +281,9 @@
     virtual bool shouldCreateNewSessionForRDFAudio(bool *cancel);
     
     virtual void connectLayerEditDialog(ModelDataTableDialog *);
+    
+    void initGenreToTemplateMap();
+    QHash<QString, QString> m_genreToTemplateMap;
 };