Mercurial > hg > svapp
changeset 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 |
files | audioio/AudioCallbackPlaySource.cpp audioio/AudioGenerator.cpp audioio/AudioGenerator.h |
diffstat | 3 files changed, 39 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp Mon Apr 10 13:52:32 2006 +0000 +++ b/audioio/AudioCallbackPlaySource.cpp Tue Apr 25 22:14:43 2006 +0000 @@ -35,7 +35,7 @@ AudioCallbackPlaySource::AudioCallbackPlaySource(ViewManager *manager) : m_viewManager(manager), - m_audioGenerator(new AudioGenerator(manager)), + m_audioGenerator(new AudioGenerator()), m_readBuffers(0), m_writeBuffers(0), m_readBufferFill(0),
--- 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 *
--- a/audioio/AudioGenerator.h Mon Apr 10 13:52:32 2006 +0000 +++ b/audioio/AudioGenerator.h Tue Apr 25 22:14:43 2006 +0000 @@ -17,7 +17,6 @@ #define _AUDIO_GENERATOR_H_ class Model; -class ViewManager; class NoteModel; class DenseTimeValueModel; class SparseOneDimensionalModel; @@ -34,7 +33,7 @@ Q_OBJECT public: - AudioGenerator(ViewManager *); + AudioGenerator(); virtual ~AudioGenerator(); /** @@ -96,7 +95,6 @@ void playPluginConfigurationChanged(const Model *, QString); protected: - ViewManager *m_viewManager; size_t m_sourceSampleRate; size_t m_targetChannelCount; @@ -120,12 +118,13 @@ QMutex m_mutex; PluginMap m_synthMap; NoteOffMap m_noteOffs; - QString m_sampleDir; + static QString m_sampleDir; virtual RealTimePluginInstance *loadPluginFor(const Model *model); virtual RealTimePluginInstance *loadPlugin(QString id, QString program); - QString getSampleDir(); - void setSamplePath(RealTimePluginInstance *plugin); + static QString getSampleDir(); + static QString getSamplePath(); + static void setSamplePath(RealTimePluginInstance *plugin); virtual size_t mixDenseTimeValueModel (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,