Mercurial > hg > svapp
changeset 22:7f32bb07629a
* Add editing for auralisation plugin parameters and programs
* Rename and reorganise the sample plugin sample set
author | Chris Cannam |
---|---|
date | Thu, 23 Mar 2006 15:49:41 +0000 |
parents | ebe07d3560e6 |
children | cb23944ce9e2 |
files | audioio/AudioGenerator.cpp audioio/AudioGenerator.h |
diffstat | 2 files changed, 120 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp Mon Mar 20 15:10:07 2006 +0000 +++ b/audioio/AudioGenerator.cpp Thu Mar 23 15:49:41 2006 +0000 @@ -41,6 +41,15 @@ m_sourceSampleRate(0), m_targetChannelCount(1) { + connect(PlayParameterRepository::instance(), + SIGNAL(playPluginIdChanged(const Model *, QString)), + this, + SLOT(playPluginIdChanged(const Model *, QString))); + + connect(PlayParameterRepository::instance(), + SIGNAL(playPluginConfigurationChanged(const Model *, QString)), + this, + SLOT(playPluginConfigurationChanged(const Model *, QString))); } AudioGenerator::~AudioGenerator() @@ -77,37 +86,108 @@ } } - SparseOneDimensionalModel *sodm = - dynamic_cast<SparseOneDimensionalModel *>(model); - if (sodm) { - QString pluginId = QString("dssi:%1:sample_player"). - arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); - RealTimePluginInstance *plugin = loadPlugin(pluginId, "cowbell"); - if (plugin) { - QMutexLocker locker(&m_mutex); - m_synthMap[sodm] = plugin; - return true; - } else { - return false; - } + RealTimePluginInstance *plugin = loadPluginFor(model); + if (plugin) { + QMutexLocker locker(&m_mutex); + m_synthMap[model] = plugin; + return true; } - NoteModel *nm = dynamic_cast<NoteModel *>(model); + return false; +} + +void +AudioGenerator::playPluginIdChanged(const Model *model, QString) +{ + if (m_synthMap.find(model) == m_synthMap.end()) return; + + RealTimePluginInstance *plugin = loadPluginFor(model); + if (plugin) { + QMutexLocker locker(&m_mutex); + delete m_synthMap[model]; + m_synthMap[model] = plugin; + } +} + +void +AudioGenerator::playPluginConfigurationChanged(const Model *model, + QString configurationXml) +{ + if (m_synthMap.find(model) == m_synthMap.end()) return; + + RealTimePluginInstance *plugin = m_synthMap[model]; + if (plugin) { + QMutexLocker locker(&m_mutex); + plugin->setParametersFromXml(configurationXml); + } +} + +QString +AudioGenerator::getDefaultPlayPluginId(const Model *model) +{ + const SparseOneDimensionalModel *sodm = + dynamic_cast<const SparseOneDimensionalModel *>(model); + if (sodm) { + return QString("dssi:%1:sample_player"). + arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); + } + + const NoteModel *nm = dynamic_cast<const NoteModel *>(model); if (nm) { - QString pluginId = QString("dssi:%1:sample_player"). - arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); - RealTimePluginInstance *plugin = loadPlugin(pluginId, "piano"); - if (plugin) { - QMutexLocker locker(&m_mutex); - m_synthMap[nm] = plugin; - return true; - } else { - return false; - } + return QString("dssi:%1:sample_player"). + arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); + } + + return ""; +} + +QString +AudioGenerator::getDefaultPlayPluginConfiguration(const Model *model) +{ + const SparseOneDimensionalModel *sodm = + dynamic_cast<const SparseOneDimensionalModel *>(model); + if (sodm) { + return "<plugin program=\"cowbell\"/>"; } - - return false; + const NoteModel *nm = dynamic_cast<const NoteModel *>(model); + if (nm) { + return "<plugin program=\"piano\"/>"; + } + + return ""; +} + +RealTimePluginInstance * +AudioGenerator::loadPluginFor(const Model *model) +{ + QString pluginId, configurationXml; + + PlayParameters *parameters = + PlayParameterRepository::instance()->getPlayParameters(model); + if (parameters) { + pluginId = parameters->getPlayPluginId(); + configurationXml = parameters->getPlayPluginConfiguration(); + } + + if (pluginId == "") { + pluginId = getDefaultPlayPluginId(model); + configurationXml = getDefaultPlayPluginConfiguration(model); + } + + if (pluginId == "") return 0; + + RealTimePluginInstance *plugin = loadPlugin(pluginId, ""); + if (configurationXml != "") { + plugin->setParametersFromXml(configurationXml); + } + + if (parameters) { + parameters->setPlayPluginId(pluginId); + parameters->setPlayPluginConfiguration(configurationXml); + } + + return plugin; } RealTimePluginInstance *
--- a/audioio/AudioGenerator.h Mon Mar 20 15:10:07 2006 +0000 +++ b/audioio/AudioGenerator.h Thu Mar 23 15:49:41 2006 +0000 @@ -23,13 +23,16 @@ class SparseOneDimensionalModel; class RealTimePluginInstance; +#include <QObject> #include <QMutex> #include <set> #include <map> -class AudioGenerator +class AudioGenerator : public QObject { + Q_OBJECT + public: AudioGenerator(ViewManager *); virtual ~AudioGenerator(); @@ -42,6 +45,9 @@ */ static bool canPlay(const Model *model); + static QString getDefaultPlayPluginId(const Model *model); + static QString getDefaultPlayPluginConfiguration(const Model *model); + /** * Add a data model to be played from and initialise any necessary * audio generation code. Returns true if the model will be @@ -85,6 +91,10 @@ virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount, float **buffer, size_t fadeIn = 0, size_t fadeOut = 0); +protected slots: + void playPluginIdChanged(const Model *, QString); + void playPluginConfigurationChanged(const Model *, QString); + protected: ViewManager *m_viewManager; size_t m_sourceSampleRate; @@ -102,15 +112,16 @@ }; }; - typedef std::map<Model *, RealTimePluginInstance *> PluginMap; + typedef std::map<const Model *, RealTimePluginInstance *> PluginMap; typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet; - typedef std::map<Model *, NoteOffSet> NoteOffMap; + typedef std::map<const Model *, NoteOffSet> NoteOffMap; QMutex m_mutex; PluginMap m_synthMap; NoteOffMap m_noteOffs; + virtual RealTimePluginInstance *loadPluginFor(const Model *model); virtual RealTimePluginInstance *loadPlugin(QString id, QString program); virtual size_t mixDenseTimeValueModel