Mercurial > hg > svapp
diff audioio/AudioGenerator.cpp @ 30:f38b8abd3540
* Pull out temporary directory management into its own class
* Make sure playback plugins get a default sample path in their original
play parameters configuration
* Save play parameters to .sv file (we aren't reloading yet though)
author | Chris Cannam |
---|---|
date | Tue, 25 Apr 2006 22:14:43 +0000 |
parents | dd2084d32652 |
children | b1112948724f |
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp Mon Apr 10 13:52:32 2006 +0000 +++ b/audioio/AudioGenerator.cpp Tue Apr 25 22:14:43 2006 +0000 @@ -15,7 +15,7 @@ #include "AudioGenerator.h" -#include "base/ViewManager.h" +#include "base/TempDirectory.h" #include "base/PlayParameters.h" #include "base/PlayParameterRepository.h" @@ -38,10 +38,12 @@ const size_t AudioGenerator::m_pluginBlockSize = 2048; +QString +AudioGenerator::m_sampleDir = ""; + //#define DEBUG_AUDIO_GENERATOR 1 -AudioGenerator::AudioGenerator(ViewManager *manager) : - m_viewManager(manager), +AudioGenerator::AudioGenerator() : m_sourceSampleRate(0), m_targetChannelCount(1) { @@ -147,18 +149,27 @@ QString AudioGenerator::getDefaultPlayPluginConfiguration(const Model *model) { + QString program = ""; + const SparseOneDimensionalModel *sodm = dynamic_cast<const SparseOneDimensionalModel *>(model); if (sodm) { - return "<plugin program=\"cowbell\"/>"; + program = "cowbell"; } const NoteModel *nm = dynamic_cast<const NoteModel *>(model); if (nm) { - return "<plugin program=\"piano\"/>"; - } - - return ""; + program = "piano"; + } + + if (program == "") return ""; + + return + QString("<plugin configuration=\"%1\" program=\"%2\"/>") + .arg(XmlExportable::encodeEntities + (QString("samplepath=%1") + .arg(PluginXml::encodeConfigurationChars(getSamplePath())))) + .arg(XmlExportable::encodeEntities(program)); } QString @@ -166,16 +177,15 @@ { if (m_sampleDir != "") return m_sampleDir; - QString tmppath = m_viewManager->getTemporaryDirectory(); - - QDir tmpdir(tmppath); - if (!tmpdir.mkdir("samples")) { + try { + m_sampleDir = TempDirectory::instance()->getSubDirectoryPath("samples"); + } catch (TempDirectory::DirectoryCreationFailed f) { std::cerr << "WARNING: AudioGenerator::getSampleDir: Failed to create " - << "directory " << tmpdir.filePath("samples").toStdString() << std::endl; + << "temporary sample directory" << std::endl; + m_sampleDir = ""; + return ""; } - m_sampleDir = tmpdir.filePath("samples"); - QDir sampleResourceDir(":/samples", "*.wav"); for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) { @@ -194,8 +204,8 @@ return m_sampleDir; } -void -AudioGenerator::setSamplePath(RealTimePluginInstance *plugin) +QString +AudioGenerator::getSamplePath() { QString samplePath = QString("%1:%2%3%4%5%6") .arg(getSampleDir()) @@ -204,8 +214,13 @@ .arg(".sv") .arg(QDir::separator()) .arg("samples"); + return samplePath; +} - plugin->configure("samplepath", samplePath.toStdString()); +void +AudioGenerator::setSamplePath(RealTimePluginInstance *plugin) +{ + plugin->configure("samplepath", getSamplePath().toStdString()); } RealTimePluginInstance *