Mercurial > hg > svapp
changeset 108:e25e8f5d785b
* Fix #1628781 changes to layer visibility and mute should use a command
* Also use a command for changes to layer playback pan, gain, plugin settings
* Refactor PlayParameterRepository to remove dependency on audioio from base
* Fix failure to save play parameters for main model in session file
author | Chris Cannam |
---|---|
date | Thu, 13 Mar 2008 14:06:03 +0000 |
parents | 52af71802ffd |
children | 2dd30a7cd21a |
files | audioio/AudioGenerator.cpp audioio/AudioGenerator.h framework/Document.cpp framework/MainWindowBase.cpp |
diffstat | 4 files changed, 86 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp Thu Mar 13 10:12:14 2008 +0000 +++ b/audioio/AudioGenerator.cpp Thu Mar 13 14:06:03 2008 +0000 @@ -50,30 +50,51 @@ m_targetChannelCount(1), m_soloing(false) { - connect(PlayParameterRepository::getInstance(), - SIGNAL(playPluginIdChanged(const Model *, QString)), - this, - SLOT(playPluginIdChanged(const Model *, QString))); + initialiseSampleDir(); connect(PlayParameterRepository::getInstance(), - SIGNAL(playPluginConfigurationChanged(const Model *, QString)), + SIGNAL(playPluginIdChanged(const Playable *, QString)), this, - SLOT(playPluginConfigurationChanged(const Model *, QString))); + SLOT(playPluginIdChanged(const Playable *, QString))); + + connect(PlayParameterRepository::getInstance(), + SIGNAL(playPluginConfigurationChanged(const Playable *, QString)), + this, + SLOT(playPluginConfigurationChanged(const Playable *, QString))); } AudioGenerator::~AudioGenerator() { } -bool -AudioGenerator::canPlay(const Model *model) +void +AudioGenerator::initialiseSampleDir() { - if (dynamic_cast<const DenseTimeValueModel *>(model) || - dynamic_cast<const SparseOneDimensionalModel *>(model) || - dynamic_cast<const NoteModel *>(model)) { - return true; - } else { - return false; + if (m_sampleDir != "") return; + + try { + m_sampleDir = TempDirectory::getInstance()->getSubDirectoryPath("samples"); + } catch (DirectoryCreationFailed f) { + std::cerr << "WARNING: AudioGenerator::initialiseSampleDir:" + << " Failed to create temporary sample directory" + << std::endl; + m_sampleDir = ""; + return; + } + + QDir sampleResourceDir(":/samples", "*.wav"); + + for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) { + + QString fileName(sampleResourceDir[i]); + QFile file(sampleResourceDir.filePath(fileName)); + + if (!file.copy(QDir(m_sampleDir).filePath(fileName))) { + std::cerr << "WARNING: AudioGenerator::getSampleDir: " + << "Unable to copy " << fileName.toStdString() + << " into temporary directory \"" + << m_sampleDir.toStdString() << "\"" << std::endl; + } } } @@ -106,8 +127,16 @@ } void -AudioGenerator::playPluginIdChanged(const Model *model, QString) +AudioGenerator::playPluginIdChanged(const Playable *playable, QString) { + const Model *model = dynamic_cast<const Model *>(playable); + if (!model) { + std::cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " + << playable << " is not a supported model type" + << std::endl; + return; + } + if (m_synthMap.find(model) == m_synthMap.end()) return; RealTimePluginInstance *plugin = loadPluginFor(model); @@ -119,11 +148,19 @@ } void -AudioGenerator::playPluginConfigurationChanged(const Model *model, +AudioGenerator::playPluginConfigurationChanged(const Playable *playable, QString configurationXml) { // std::cerr << "AudioGenerator::playPluginConfigurationChanged" << std::endl; + const Model *model = dynamic_cast<const Model *>(playable); + if (!model) { + std::cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " + << playable << " is not a supported model type" + << std::endl; + return; + } + if (m_synthMap.find(model) == m_synthMap.end()) { std::cerr << "AudioGenerator::playPluginConfigurationChanged: We don't know about this plugin" << std::endl; return; @@ -135,87 +172,12 @@ } } -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) { - return QString("dssi:%1:sample_player"). - arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); - } - - return ""; -} - -QString -AudioGenerator::getDefaultPlayPluginConfiguration(const Model *model) -{ - QString program = ""; - - const SparseOneDimensionalModel *sodm = - dynamic_cast<const SparseOneDimensionalModel *>(model); - if (sodm) { - program = "tap"; - } - - const NoteModel *nm = dynamic_cast<const NoteModel *>(model); - if (nm) { - program = "piano"; - } - - if (program == "") return ""; - - return - QString("<plugin configuration=\"%1\" program=\"%2\"/>") - .arg(XmlExportable::encodeEntities - (QString("sampledir=%1") - .arg(PluginXml::encodeConfigurationChars(getSampleDir())))) - .arg(XmlExportable::encodeEntities(program)); -} - -QString -AudioGenerator::getSampleDir() -{ - if (m_sampleDir != "") return m_sampleDir; - - try { - m_sampleDir = TempDirectory::getInstance()->getSubDirectoryPath("samples"); - } catch (DirectoryCreationFailed f) { - std::cerr << "WARNING: AudioGenerator::getSampleDir: Failed to create " - << "temporary sample directory" << std::endl; - m_sampleDir = ""; - return ""; - } - - QDir sampleResourceDir(":/samples", "*.wav"); - - for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) { - - QString fileName(sampleResourceDir[i]); - QFile file(sampleResourceDir.filePath(fileName)); - - if (!file.copy(QDir(m_sampleDir).filePath(fileName))) { - std::cerr << "WARNING: AudioGenerator::getSampleDir: " - << "Unable to copy " << fileName.toStdString() - << " into temporary directory \"" - << m_sampleDir.toStdString() << "\"" << std::endl; - } - } - - return m_sampleDir; -} - void AudioGenerator::setSampleDir(RealTimePluginInstance *plugin) { - plugin->configure("sampledir", getSampleDir().toStdString()); + if (m_sampleDir != "") { + plugin->configure("sampledir", m_sampleDir.toStdString()); + } } RealTimePluginInstance * @@ -223,18 +185,16 @@ { QString pluginId, configurationXml; + const Playable *playable = model; + if (!playable || !playable->canPlay()) return 0; + PlayParameters *parameters = - PlayParameterRepository::getInstance()->getPlayParameters(model); + PlayParameterRepository::getInstance()->getPlayParameters(playable); if (parameters) { pluginId = parameters->getPlayPluginId(); configurationXml = parameters->getPlayPluginConfiguration(); } - if (pluginId == "") { - pluginId = getDefaultPlayPluginId(model); - configurationXml = getDefaultPlayPluginConfiguration(model); - } - if (pluginId == "") return 0; RealTimePluginInstance *plugin = loadPlugin(pluginId, ""); @@ -244,6 +204,8 @@ PluginXml(plugin).setParametersFromXml(configurationXml); } + configurationXml = PluginXml(plugin).toXmlString(); + if (parameters) { parameters->setPlayPluginId(pluginId); parameters->setPlayPluginConfiguration(configurationXml); @@ -382,8 +344,11 @@ QMutexLocker locker(&m_mutex); + Playable *playable = model; + if (!playable || !playable->canPlay()) return frameCount; + PlayParameters *parameters = - PlayParameterRepository::getInstance()->getPlayParameters(model); + PlayParameterRepository::getInstance()->getPlayParameters(playable); if (!parameters) return frameCount; bool playing = !parameters->isPlayMuted();
--- a/audioio/AudioGenerator.h Thu Mar 13 10:12:14 2008 +0000 +++ b/audioio/AudioGenerator.h Thu Mar 13 14:06:03 2008 +0000 @@ -21,6 +21,7 @@ class DenseTimeValueModel; class SparseOneDimensionalModel; class RealTimePluginInstance; +class Playable; #include <QObject> #include <QMutex> @@ -37,22 +38,10 @@ virtual ~AudioGenerator(); /** - * Return true if the given model is of a type that we generally - * know how to play. This doesn't guarantee that a specific - * AudioGenerator will actually produce sounds for it (for - * example, it may turn out that a vital plugin is missing). - */ - 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 - * played. (The return value test here is stricter than that for - * canPlay, above.) The model will be added regardless of the - * return value. + * played. The model will be added regardless of the return + * value. */ virtual bool addModel(Model *model); @@ -102,8 +91,8 @@ virtual void clearSoloModelSet(); protected slots: - void playPluginIdChanged(const Model *, QString); - void playPluginConfigurationChanged(const Model *, QString); + void playPluginIdChanged(const Playable *, QString); + void playPluginConfigurationChanged(const Playable *, QString); protected: size_t m_sourceSampleRate; @@ -136,7 +125,7 @@ virtual RealTimePluginInstance *loadPluginFor(const Model *model); virtual RealTimePluginInstance *loadPlugin(QString id, QString program); - static QString getSampleDir(); + static void initialiseSampleDir(); static void setSampleDir(RealTimePluginInstance *plugin); virtual size_t mixDenseTimeValueModel
--- a/framework/Document.cpp Thu Mar 13 10:12:14 2008 +0000 +++ b/framework/Document.cpp Thu Mar 13 14:06:03 2008 +0000 @@ -993,7 +993,17 @@ .arg(extraAttributes == "" ? "" : " ").arg(extraAttributes); if (m_mainModel) { + m_mainModel->toXml(out, indent + " ", "mainModel=\"true\""); + + PlayParameters *playParameters = + PlayParameterRepository::getInstance()->getPlayParameters(m_mainModel); + if (playParameters) { + playParameters->toXml + (out, indent + " ", + QString("model=\"%1\"") + .arg(XmlExportable::getObjectExportId(m_mainModel))); + } } // Models that are not used in a layer that is in a view should
--- a/framework/MainWindowBase.cpp Thu Mar 13 10:12:14 2008 +0000 +++ b/framework/MainWindowBase.cpp Thu Mar 13 14:06:03 2008 +0000 @@ -780,7 +780,8 @@ sodm->getSampleRate()) .toText(false).c_str())); - command->finish(); + Command *c = command->finish(); + if (c) CommandHistory::getInstance()->addCommand(c, false); } } } @@ -931,9 +932,9 @@ Model *prevMain = getMainModel(); if (prevMain) { m_playSource->removeModel(prevMain); - PlayParameterRepository::getInstance()->removeModel(prevMain); + PlayParameterRepository::getInstance()->removePlayable(prevMain); } - PlayParameterRepository::getInstance()->addModel(newModel); + PlayParameterRepository::getInstance()->addPlayable(newModel); m_document->setMainModel(newModel);