comparison widgets/PropertyBox.cpp @ 769:336ccf8fc3f8 tony_integration

Restore selection of playback sample for note layers. Also default to new elecpiano clip.
author Chris Cannam
date Wed, 07 May 2014 16:51:04 +0100
parents b6dc57688c72
children 037a7c22bec8
comparison
equal deleted inserted replaced
766:65eb27ea08fd 769:336ccf8fc3f8
22 #include "layer/Layer.h" 22 #include "layer/Layer.h"
23 #include "layer/ColourDatabase.h" 23 #include "layer/ColourDatabase.h"
24 #include "base/UnitDatabase.h" 24 #include "base/UnitDatabase.h"
25 #include "base/RangeMapper.h" 25 #include "base/RangeMapper.h"
26 26
27 #include "plugin/RealTimePluginFactory.h"
28 #include "plugin/RealTimePluginInstance.h"
29 #include "plugin/PluginXml.h"
30
31 #include "AudioDial.h" 27 #include "AudioDial.h"
32 #include "LEDButton.h" 28 #include "LEDButton.h"
33 #include "IconLoader.h" 29 #include "IconLoader.h"
34 30
35 #include "NotifyingCheckBox.h" 31 #include "NotifyingCheckBox.h"
44 #include <QLabel> 40 #include <QLabel>
45 #include <QFrame> 41 #include <QFrame>
46 #include <QApplication> 42 #include <QApplication>
47 #include <QColorDialog> 43 #include <QColorDialog>
48 #include <QInputDialog> 44 #include <QInputDialog>
45 #include <QDir>
49 46
50 #include <cassert> 47 #include <cassert>
51 #include <iostream> 48 #include <iostream>
52 #include <cmath> 49 #include <cmath>
53 50
186 this, SLOT(playAudibleChanged(bool))); 183 this, SLOT(playAudibleChanged(bool)));
187 layout->setAlignment(m_playButton, Qt::AlignVCenter); 184 layout->setAlignment(m_playButton, Qt::AlignVCenter);
188 185
189 layout->insertStretch(-1, 10); 186 layout->insertStretch(-1, 10);
190 187
191 /*!!! todo: restore playback sample selection 188 if (params->getPlayClipId() != "") {
192 if (params->getPlayPluginId() != "") { 189 QPushButton *playParamButton =
193 QPushButton *pluginButton = new QPushButton(QIcon(":icons/faders.png"), ""); 190 new QPushButton(QIcon(":icons/faders.png"), "");
194 pluginButton->setFixedWidth(24); 191 playParamButton->setFixedWidth(24);
195 pluginButton->setFixedHeight(24); 192 playParamButton->setFixedHeight(24);
196 layout->addWidget(pluginButton); 193 layout->addWidget(playParamButton);
197 connect(pluginButton, SIGNAL(clicked()), 194 connect(playParamButton, SIGNAL(clicked()),
198 this, SLOT(editPlugin())); 195 this, SLOT(editPlayParameters()));
199 } 196 }
200 */
201 197
202 AudioDial *gainDial = new AudioDial; 198 AudioDial *gainDial = new AudioDial;
203 layout->addWidget(gainDial); 199 layout->addWidget(gainDial);
204 gainDial->setMeterColor(Qt::darkRed); 200 gainDial->setMeterColor(Qt::darkRed);
205 gainDial->setMinimum(-50); 201 gainDial->setMinimum(-50);
461 457
462 //!!! should be a proper colour combobox class that 458 //!!! should be a proper colour combobox class that
463 // manages its own Add New Colour entry... 459 // manages its own Add New Colour entry...
464 460
465 ColourDatabase *db = ColourDatabase::getInstance(); 461 ColourDatabase *db = ColourDatabase::getInstance();
466 for (size_t i = 0; i < db->getColourCount(); ++i) { 462 for (int i = 0; i < db->getColourCount(); ++i) {
467 QString name = db->getColourName(i); 463 QString name = db->getColourName(i);
468 cb->addItem(db->getExamplePixmap(i, QSize(12, 12)), name); 464 cb->addItem(db->getExamplePixmap(i, QSize(12, 12)), name);
469 } 465 }
470 cb->addItem(tr("Add New Colour...")); 466 cb->addItem(tr("Add New Colour..."));
471 } 467 }
744 CommandHistory::getInstance()->addCommand(command, true, true); 740 CommandHistory::getInstance()->addCommand(command, true, true);
745 } 741 }
746 742
747 updateContextHelp(obj); 743 updateContextHelp(obj);
748 } 744 }
749 /*!!! todo: restore playback sample selection 745
750 void 746 void
751 PropertyBox::editPlugin() 747 PropertyBox::editPlayParameters()
752 { 748 {
753 //!!! should probably just emit and let something else do this
754
755 PlayParameters *params = m_container->getPlayParameters(); 749 PlayParameters *params = m_container->getPlayParameters();
756 if (!params) return; 750 if (!params) return;
757 751
758 QString pluginId = params->getPlayPluginId(); 752 QString clip = params->getPlayClipId();
759 QString configurationXml = params->getPlayPluginConfiguration();
760 753
761 PlayParameterRepository::EditCommand *command = 754 PlayParameterRepository::EditCommand *command =
762 new PlayParameterRepository::EditCommand(params); 755 new PlayParameterRepository::EditCommand(params);
763 756
764 RealTimePluginFactory *factory = 757 QInputDialog *dialog = new QInputDialog(this);
765 RealTimePluginFactory::instanceFor(pluginId); 758
766 if (!factory) return; 759 QDir dir(":/samples");
767 760 QStringList clipFiles = dir.entryList(QStringList() << "*.wav", QDir::Files);
768 RealTimePluginInstance *instance = 761
769 factory->instantiatePlugin(pluginId, 0, 0, 48000, 1024, 1); 762 QStringList clips;
770 if (!instance) return; 763 foreach (QString str, clipFiles) {
771 764 clips.push_back(str.replace(".wav", ""));
772 PluginXml(instance).setParametersFromXml(configurationXml); 765 }
773 766 dialog->setComboBoxItems(clips);
774 PluginParameterDialog *dialog = new PluginParameterDialog(instance); 767
775 connect(dialog, SIGNAL(pluginConfigurationChanged(QString)), 768 dialog->setLabelText(tr("Set playback clip:"));
776 this, SLOT(pluginConfigurationChanged(QString))); 769
770 QComboBox *cb = dialog->findChild<QComboBox *>();
771 if (cb) cb->setCurrentText(clip);
772
773 connect(dialog, SIGNAL(textValueChanged(QString)),
774 this, SLOT(playClipChanged(QString)));
777 775
778 if (dialog->exec() == QDialog::Accepted) { 776 if (dialog->exec() == QDialog::Accepted) {
779 QString newConfiguration = PluginXml(instance).toXmlString(); 777 QString newClip = dialog->textValue();
780 command->setPlayPluginConfiguration(newConfiguration); 778 command->setPlayClipId(newClip);
781 CommandHistory::getInstance()->addCommand(command, true); 779 CommandHistory::getInstance()->addCommand(command, true);
782 } else { 780 } else {
783 delete command; 781 delete command;
784 // restore in case we mucked about with the configuration 782 // restore in case we mucked about with the configuration
785 // as a consequence of signals from the dialog 783 // as a consequence of signals from the dialog
786 params->setPlayPluginConfiguration(configurationXml); 784 params->setPlayClipId(clip);
787 } 785 }
788 786
789 delete dialog; 787 delete dialog;
790 delete instance; 788 }
791 } 789
792 790 void
793 void 791 PropertyBox::playClipChanged(QString id)
794 PropertyBox::pluginConfigurationChanged(QString configurationXml)
795 { 792 {
796 PlayParameters *params = m_container->getPlayParameters(); 793 PlayParameters *params = m_container->getPlayParameters();
797 if (!params) return; 794 if (!params) return;
798 795
799 params->setPlayPluginConfiguration(configurationXml); 796 params->setPlayClipId(id);
800 } 797 }
801 */ 798
802 void 799 void
803 PropertyBox::layerVisibilityChanged(bool visible) 800 PropertyBox::layerVisibilityChanged(bool visible)
804 { 801 {
805 if (m_showButton) m_showButton->setState(visible); 802 if (m_showButton) m_showButton->setState(visible);
806 } 803 }