Advertisement
neo01124

dlgprefkey.cpp

Aug 15th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.77 KB | None | 0 0
  1. /***************************************************************************
  2.                           dlgprefkey.cpp  -  description
  3.                              -------------------
  4.     begin                : Thu Jun 7 2012
  5.     copyright            : (C) 2012 by Keith Salisbury
  6.     email                : keithsalisbury@gmail.com
  7. ***************************************************************************/
  8.  
  9. /***************************************************************************
  10. *                                                                         *
  11. *   This program is free software; you can redistribute it and/or modify  *
  12. *   it under the terms of the GNU General Public License as published by  *
  13. *   the Free Software Foundation; either version 2 of the License, or     *
  14. *   (at your option) any later version.                                   *
  15. *                                                                         *
  16. ***************************************************************************/
  17.  
  18. #include <qlineedit.h>
  19. #include <qfiledialog.h>
  20. #include <qwidget.h>
  21. #include <qspinbox.h>
  22. #include <qcheckbox.h>
  23. #include <qlabel.h>
  24. #include <qstring.h>
  25. #include <qpushbutton.h>
  26. #include <QtCore>
  27. #include <QMessageBox>
  28. #include "track/key_preferences.h"
  29.  
  30. #include "dlgprefkey.h"
  31. #include "xmlparse.h"
  32. #include "controlobject.h"
  33. //#include "dlgprefbeats.h"
  34. #include "vamp/vampanalyser.h"
  35.  
  36. using Vamp::Plugin;
  37. using Vamp::PluginHostAdapter;
  38. using Vamp::HostExt::PluginLoader;
  39. using Vamp::HostExt::PluginWrapper;
  40. using Vamp::HostExt::PluginInputDomainAdapter;
  41.  
  42.  
  43. #define CONFIG_KEY "[KEY]"
  44. bool firs = true;
  45. DlgPrefKey::DlgPrefKey(QWidget * parent,
  46.                        ConfigObject<ConfigValue> * _config) : QWidget(parent),m_pconfig(_config)
  47.   //Ui::DlgPrefKey()
  48. {
  49.     //config = _config;
  50.     //m_pconfig = _config;
  51.     setupUi(this);
  52.     //m_selectedAnalyser = "qm-tempotracker:0";
  53.     //setupUi(this);
  54.  
  55.    // populate();
  56.     loadSettings();
  57.     //Connections
  58.   //  connect(plugincombo, SIGNAL(currentIndexChanged(int)),
  59.     //        this, SLOT(pluginSelected(int)));
  60.     connect(banalyserenabled, SIGNAL(stateChanged(int)),
  61.           this, SLOT(analyserEnabled(int)));
  62.     connect(bfastAnalysisEnabled, SIGNAL(stateChanged(int)),
  63.             this, SLOT(fastAnalysisEnabled(int)));
  64.     connect(bfirstLastEnabled, SIGNAL(stateChanged(int)),
  65.             this, SLOT(firstLastEnabled(int)));
  66.    // connect(reset, SIGNAL(clicked(bool)), this, SLOT(setDefaults()));
  67.  
  68.     connect(breanalyzeEnabled, SIGNAL(stateChanged(int)),
  69.             this, SLOT(reanalyzeEnabled(int)));
  70.  
  71.     connect(bskipRelevantEnabled, SIGNAL(stateChanged(int)),
  72.             this, SLOT(skipRelevantEnabled(int)));
  73.  
  74.     connect(b1, SIGNAL(valueChanged(int)),
  75.             this, SLOT(notationValueChanged(int)));
  76.     connect(b2, SIGNAL(valueChanged(int)),
  77.             this, SLOT(notationValueChanged(int)));
  78.     connect(b3, SIGNAL(valueChanged(int)),
  79.             this, SLOT(notationValueChanged(int)));
  80.     connect(b4, SIGNAL(valueChanged(int)),
  81.             this, SLOT(notationValueChanged(int)));
  82.     connect(b5, SIGNAL(valueChanged(int)),
  83.             this, SLOT(notationValueChanged(int)));
  84.     connect(b6, SIGNAL(valueChanged(int)),
  85.             this, SLOT(notationValueChanged(int)));
  86.     connect(b7, SIGNAL(valueChanged(int)),
  87.             this, SLOT(notationValueChanged(int)));
  88.     connect(b8, SIGNAL(valueChanged(int)),
  89.             this, SLOT(notationValueChanged(int)));
  90.     connect(b9, SIGNAL(valueChanged(int)),
  91.             this, SLOT(notationValueChanged(int)));
  92.     connect(b10, SIGNAL(valueChanged(int)),
  93.             this, SLOT(notationValueChanged(int)));
  94.     connect(b11, SIGNAL(valueChanged(int)),
  95.             this, SLOT(notationValueChanged(int)));
  96.     connect(b12, SIGNAL(valueChanged(int)),
  97.             this, SLOT(notationValueChanged(int)));
  98.     connect(b13, SIGNAL(valueChanged(int)),
  99.             this, SLOT(notationValueChanged(int)));
  100.     connect(b14, SIGNAL(valueChanged(int)),
  101.             this, SLOT(notationValueChanged(int)));
  102.     connect(b15, SIGNAL(valueChanged(int)),
  103.             this, SLOT(notationValueChanged(int)));
  104.     connect(b16, SIGNAL(valueChanged(int)),
  105.             this, SLOT(notationValueChanged(int)));
  106.     connect(b17, SIGNAL(valueChanged(int)),
  107.             this, SLOT(notationValueChanged(int)));
  108.     connect(b18, SIGNAL(valueChanged(int)),
  109.             this, SLOT(notationValueChanged(int)));
  110.     connect(b19, SIGNAL(valueChanged(int)),
  111.             this, SLOT(notationValueChanged(int)));
  112.     connect(b20, SIGNAL(valueChanged(int)),
  113.             this, SLOT(notationValueChanged(int)));
  114.     connect(b21, SIGNAL(valueChanged(int)),
  115.             this, SLOT(notationValueChanged(int)));
  116.     connect(b22, SIGNAL(valueChanged(int)),
  117.             this, SLOT(notationValueChanged(int)));
  118.     connect(b23, SIGNAL(valueChanged(int)),
  119.             this, SLOT(notationValueChanged(int)));
  120.     connect(b24, SIGNAL(valueChanged(int)),
  121.             this, SLOT(notationValueChanged(int)));
  122.  
  123.     // connect(txtMaxBpm, SIGNAL(valueChanged(int)),
  124.       //      this, SLOT(maxBpmRangeChanged(int)));
  125.  
  126.     //connect(bReanalyse,SIGNAL(stateChanged(int)),
  127.         //    this, SLOT(slotReanalyzeChanged(int)));
  128.  
  129. }
  130.  
  131. DlgPrefKey::~DlgPrefKey()
  132. {
  133. }
  134.  
  135. void DlgPrefKey::loadSettings(){
  136.     //if(m_pconfig->getValueString(
  137.       //  ConfigKey(VAMP_CONFIG_KEY, VAMP_ANALYSER_KEY_PLUGIN_ID))==QString("")) {
  138.         //setDefaults();
  139.            // Write to config file so AnalyzerBeats can get the data
  140.         //return;
  141.     //}
  142.  
  143.    // QString pluginid = m_pconfig->getValueString(
  144.      //   ConfigKey(VAMP_CONFIG_KEY, VAMP_ANALYSER_BEAT_PLUGIN_ID));
  145.     //m_selectedAnalyser = pluginid;
  146.  
  147.     m_banalyserEnabled = static_cast<bool>(m_pconfig->getValueString(
  148.         ConfigKey(KEY_CONFIG_KEY, KEY_DETECTION_ENABLED)).toInt());
  149.  
  150.     m_bfastAnalysisEnabled = static_cast<bool>(m_pconfig->getValueString(
  151.         ConfigKey(KEY_CONFIG_KEY, KEY_FAST_ANALYSIS)).toInt());
  152.  
  153.     m_bfirstLastEnabled = static_cast<bool>(m_pconfig->getValueString(
  154.         ConfigKey(KEY_CONFIG_KEY, KEY_FIRST_LAST)).toInt());
  155.  
  156.     m_breanalyzeEnabled =  static_cast<bool>(m_pconfig->getValueString(
  157.         ConfigKey(KEY_CONFIG_KEY, KEY_REANALYZE)).toInt());
  158.  
  159.     m_bskipRelevantEnabled = static_cast<bool>(m_pconfig->getValueString(
  160.         ConfigKey(KEY_CONFIG_KEY, KEY_SKIP_RELEVANT)).toInt());
  161.     slotApply();
  162.   //  if (!m_listIdentifier.contains(pluginid)) {
  163.     //    setDefaults();
  164.     //}
  165.    // m_minBpm = m_pconfig->getValueString(ConfigKey(BPM_CONFIG_KEY, BPM_RANGE_START)).toInt();
  166.     //m_maxBpm = m_pconfig->getValueString(ConfigKey(BPM_CONFIG_KEY, BPM_RANGE_END)).toInt();
  167.  
  168.     slotUpdate();
  169. }
  170.  
  171. void DlgPrefKey::setDefaults() {
  172.     //if (!m_listIdentifier.contains("qm-tempotracker:0")) {
  173.       //  qDebug() << "DlgPrefBeats: qm-tempotracker Vamp plugin not found";
  174.         //return;
  175.     //}
  176.     //m_selectedAnalyser = "qm-tempotracker:0";
  177.     m_banalyserEnabled = false;
  178.     m_bfastAnalysisEnabled = false;
  179.     m_bfirstLastEnabled = false;
  180.     m_breanalyzeEnabled = false;
  181.     //m_FastAnalysisEnabled = false;
  182.     m_bskipRelevantEnabled = false;
  183.  
  184.     //m_minBpm = 70;
  185.     //m_maxBpm = 140;
  186.     //slotApply();
  187.     slotUpdate();
  188. }
  189.  
  190. void  DlgPrefKey::analyserEnabled(int i){
  191.     m_banalyserEnabled = static_cast<bool>(i);
  192.     slotUpdate();
  193. }
  194.  
  195. void  DlgPrefKey::fastAnalysisEnabled(int i){
  196.     m_bfastAnalysisEnabled = static_cast<bool>(i);
  197.     slotUpdate();
  198. }
  199.  
  200. void DlgPrefKey::firstLastEnabled(int i){
  201.     m_bfirstLastEnabled = static_cast<bool>(i);
  202.     slotUpdate();
  203. }
  204.  
  205. void DlgPrefKey::reanalyzeEnabled(int i){
  206.     m_breanalyzeEnabled = static_cast<bool>(i);
  207.     slotUpdate();
  208. }
  209.  
  210. void DlgPrefKey::skipRelevantEnabled(int i){
  211.     m_bskipRelevantEnabled = static_cast<bool>(i);
  212.     qDebug()<<m_bskipRelevantEnabled;
  213.     slotUpdate();
  214.     }
  215.  
  216. void DlgPrefKey::notationValueChanged(char *i){
  217.     m_bskipRelevantEnabled = static_cast<bool>(i);
  218.     qDebug()<<m_bskipRelevantEnabled;
  219.     slotUpdate();
  220.     }
  221.  
  222.  
  223. void DlgPrefKey::slotApply()
  224. {
  225.     //int selected = m_listIdentifier.indexOf(m_selectedAnalyser);
  226.     //if (selected == -1)
  227.      //   return;
  228.  
  229.     //m_pconfig->set(ConfigKey(
  230.       //  VAMP_CONFIG_KEY, VAMP_ANALYSER_BEAT_LIBRARY), ConfigValue(m_listLibrary[selected]));
  231.     //m_pconfig->set(ConfigKey(
  232.       //  VAMP_CONFIG_KEY, VAMP_ANALYSER_BEAT_PLUGIN_ID), ConfigValue(m_selectedAnalyser));
  233.     m_pconfig->set(ConfigKey(
  234.         KEY_CONFIG_KEY, KEY_DETECTION_ENABLED), ConfigValue(m_banalyserEnabled ? 1 : 0));
  235.     m_pconfig->set(ConfigKey(
  236.         KEY_CONFIG_KEY, KEY_FAST_ANALYSIS), ConfigValue(m_bfastAnalysisEnabled ? 1 : 0));
  237.     m_pconfig->set(ConfigKey(
  238.         KEY_CONFIG_KEY, KEY_FIRST_LAST), ConfigValue(m_bfirstLastEnabled ? 1 : 0));
  239.     m_pconfig->set(ConfigKey(
  240.         KEY_CONFIG_KEY, KEY_REANALYZE), ConfigValue(m_breanalyzeEnabled ? 1 : 0));
  241.     m_pconfig->set(ConfigKey(
  242.         KEY_CONFIG_KEY, KEY_SKIP_RELEVANT), ConfigValue(m_bskipRelevantEnabled ? 1 : 0));
  243.  
  244.     // m_pconfig->set(ConfigKey(
  245.      //   KEY_CONFIG_KEY, KEY_SKIP_RELEVANT), ConfigValue(1));
  246.     //  m_pconfig->set(ConfigKey(
  247.     //    BPM_CONFIG_KEY, BPM_FAST_ANALYSIS_ENABLED), ConfigValue(m_FastAnalysisEnabled ? 1 : 0));
  248.  
  249.     //m_pconfig->set(ConfigKey(BPM_CONFIG_KEY, BPM_RANGE_START), ConfigValue(m_minBpm));
  250.     //m_pconfig->set(ConfigKey(BPM_CONFIG_KEY, BPM_RANGE_END), ConfigValue(m_maxBpm));
  251.     m_pconfig->Save();
  252. }
  253.  
  254. void DlgPrefKey::slotUpdate()
  255. {
  256.     //bfixedtempo->setEnabled(m_banalyserEnabled);
  257.     //boffset->setEnabled((m_banalyserEnabled && m_bfixedtempoEnabled));
  258.     //plugincombo->setEnabled(m_banalyserEnabled);
  259.     banalyserenabled->setChecked(m_banalyserEnabled);
  260.     bfastAnalysisEnabled->setChecked(m_bfastAnalysisEnabled);
  261.     //txtMaxBpm->setEnabled(m_banalyserEnabled && m_bfixedtempoEnabled);
  262.     // txtMinBpm->setEnabled(m_banalyserEnabled && m_bfixedtempoEnabled);
  263.     bfirstLastEnabled->setChecked(m_bfirstLastEnabled);
  264.     breanalyzeEnabled->setChecked(m_breanalyzeEnabled);
  265.     bskipRelevantEnabled->setChecked(m_bskipRelevantEnabled);
  266.     slotApply();
  267.  
  268.     //if(!m_banalyserEnabled)
  269.       //  return;
  270.  
  271.     //bfixedtempo->setChecked(m_bfixedtempoEnabled);
  272.     //boffset->setChecked(m_boffsetEnabled);
  273.     //bFastAnalysis->setChecked(m_FastAnalysisEnabled);
  274.  
  275.     //int comboselected = m_listIdentifier.indexOf(m_selectedAnalyser);
  276.     //if( comboselected==-1){
  277.       //  qDebug()<<"DlgPrefBeats: Plugin not found in slotUpdate()";
  278.         //return;
  279.     //}
  280.  
  281.     //plugincombo->setCurrentIndex(comboselected);
  282.     //txtMaxBpm->setValue(m_maxBpm);
  283.     //txtMinBpm->setValue(m_minBpm);
  284.     //bReanalyse->setChecked(m_bReanalyze);
  285. }
  286.  
  287. //void DlgPrefBeats::populate() {
  288.   //  VampAnalyser::initializePluginPaths();
  289. //    QString selectedAnalyser = m_selectedAnalyser;
  290. //    m_listIdentifier.clear();
  291. //    m_listName.clear();
  292. //    m_listLibrary.clear();
  293. //    disconnect(plugincombo, SIGNAL(currentIndexChanged(int)),
  294. //            this, SLOT(pluginSelected(int)));
  295. //    plugincombo->clear();
  296. //    plugincombo->setDuplicatesEnabled(false);
  297. //    connect(plugincombo, SIGNAL(currentIndexChanged(int)),
  298. //            this, SLOT(pluginSelected(int)));
  299. //    VampPluginLoader *loader = VampPluginLoader::getInstance();
  300. //    std::vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
  301. //    qDebug() << "VampPluginLoader::listPlugins() returned" << plugins.size() << "plugins";
  302. //    for (unsigned int iplugin=0; iplugin < plugins.size(); iplugin++) {
  303. //        Plugin *plugin = loader->loadPlugin(plugins[iplugin], 48000);
  304. //        //TODO: find a way to add beat trackers only
  305. //        if (plugin) {
  306. //            Plugin::OutputList outputs = plugin->getOutputDescriptors();
  307. //            for (unsigned int ioutput=0; ioutput < outputs.size(); ioutput++) {
  308. //                QString displayname = QString::fromStdString(plugin->getIdentifier()) + ":"
  309. //                                            + QString::number(ioutput);
  310. //                QString displaynametext = QString::fromStdString(plugin->getName());
  311. //                qDebug() << "Plugin output displayname:" << displayname << displaynametext;
  312. //                bool goodones = ((displayname.contains("mixxxbpmdetection")||
  313. //                                  displayname.contains("qm-tempotracker:0"))||
  314. //                                 displayname.contains("beatroot:0")||
  315. //                                 displayname.contains("marsyas_ibt:0")||
  316. //                                 displayname.contains("aubiotempo:0")
  317. //                                 );
  318.  
  319. //                bool goodones = ((displaynametext.contains("Beat Track")));
  320.                 //validate and add rows to qcombobox
  321.  
  322. //                m_listVersion << QString::number(plugin->getPluginVersion());
  323. //                m_listMaker << QString::fromStdString(plugin->getMaker());
  324. //                m_listCopyright << QString::fromStdString(plugin->getCopyright());
  325. //                m_listOutput << QString::number(ioutput);
  326. //                m_listDescription << QString::fromStdString(outputs[ioutput].description);
  327.  
  328. //                if (goodones) {
  329. //                    m_listName << displaynametext;
  330. //                    QString pluginlibrary = QString::fromStdString(plugins[iplugin]).section(":",0,0);
  331. //                    m_listLibrary << pluginlibrary;
  332. //                    QString displayname = QString::fromStdString(plugin->getIdentifier()) + ":"
  333. //                            + QString::number(ioutput);
  334. //                    m_listIdentifier << displayname;
  335. //                    plugincombo->addItem(displaynametext, displayname);
  336. //                }
  337. //            }
  338. //            delete plugin;
  339. //            plugin = 0;
  340. //        }
  341. //    }
  342. //    m_selectedAnalyser = selectedAnalyser;
  343. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement