Mercurial > hg > svapp
comparison 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 |
comparison
equal
deleted
inserted
replaced
29:dd2084d32652 | 30:f38b8abd3540 |
---|---|
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "AudioGenerator.h" | 16 #include "AudioGenerator.h" |
17 | 17 |
18 #include "base/ViewManager.h" | 18 #include "base/TempDirectory.h" |
19 #include "base/PlayParameters.h" | 19 #include "base/PlayParameters.h" |
20 #include "base/PlayParameterRepository.h" | 20 #include "base/PlayParameterRepository.h" |
21 | 21 |
22 #include "model/NoteModel.h" | 22 #include "model/NoteModel.h" |
23 #include "model/DenseTimeValueModel.h" | 23 #include "model/DenseTimeValueModel.h" |
36 #include <QFile> | 36 #include <QFile> |
37 | 37 |
38 const size_t | 38 const size_t |
39 AudioGenerator::m_pluginBlockSize = 2048; | 39 AudioGenerator::m_pluginBlockSize = 2048; |
40 | 40 |
41 QString | |
42 AudioGenerator::m_sampleDir = ""; | |
43 | |
41 //#define DEBUG_AUDIO_GENERATOR 1 | 44 //#define DEBUG_AUDIO_GENERATOR 1 |
42 | 45 |
43 AudioGenerator::AudioGenerator(ViewManager *manager) : | 46 AudioGenerator::AudioGenerator() : |
44 m_viewManager(manager), | |
45 m_sourceSampleRate(0), | 47 m_sourceSampleRate(0), |
46 m_targetChannelCount(1) | 48 m_targetChannelCount(1) |
47 { | 49 { |
48 connect(PlayParameterRepository::instance(), | 50 connect(PlayParameterRepository::instance(), |
49 SIGNAL(playPluginIdChanged(const Model *, QString)), | 51 SIGNAL(playPluginIdChanged(const Model *, QString)), |
145 } | 147 } |
146 | 148 |
147 QString | 149 QString |
148 AudioGenerator::getDefaultPlayPluginConfiguration(const Model *model) | 150 AudioGenerator::getDefaultPlayPluginConfiguration(const Model *model) |
149 { | 151 { |
152 QString program = ""; | |
153 | |
150 const SparseOneDimensionalModel *sodm = | 154 const SparseOneDimensionalModel *sodm = |
151 dynamic_cast<const SparseOneDimensionalModel *>(model); | 155 dynamic_cast<const SparseOneDimensionalModel *>(model); |
152 if (sodm) { | 156 if (sodm) { |
153 return "<plugin program=\"cowbell\"/>"; | 157 program = "cowbell"; |
154 } | 158 } |
155 | 159 |
156 const NoteModel *nm = dynamic_cast<const NoteModel *>(model); | 160 const NoteModel *nm = dynamic_cast<const NoteModel *>(model); |
157 if (nm) { | 161 if (nm) { |
158 return "<plugin program=\"piano\"/>"; | 162 program = "piano"; |
159 } | 163 } |
160 | 164 |
161 return ""; | 165 if (program == "") return ""; |
166 | |
167 return | |
168 QString("<plugin configuration=\"%1\" program=\"%2\"/>") | |
169 .arg(XmlExportable::encodeEntities | |
170 (QString("samplepath=%1") | |
171 .arg(PluginXml::encodeConfigurationChars(getSamplePath())))) | |
172 .arg(XmlExportable::encodeEntities(program)); | |
162 } | 173 } |
163 | 174 |
164 QString | 175 QString |
165 AudioGenerator::getSampleDir() | 176 AudioGenerator::getSampleDir() |
166 { | 177 { |
167 if (m_sampleDir != "") return m_sampleDir; | 178 if (m_sampleDir != "") return m_sampleDir; |
168 | 179 |
169 QString tmppath = m_viewManager->getTemporaryDirectory(); | 180 try { |
170 | 181 m_sampleDir = TempDirectory::instance()->getSubDirectoryPath("samples"); |
171 QDir tmpdir(tmppath); | 182 } catch (TempDirectory::DirectoryCreationFailed f) { |
172 if (!tmpdir.mkdir("samples")) { | |
173 std::cerr << "WARNING: AudioGenerator::getSampleDir: Failed to create " | 183 std::cerr << "WARNING: AudioGenerator::getSampleDir: Failed to create " |
174 << "directory " << tmpdir.filePath("samples").toStdString() << std::endl; | 184 << "temporary sample directory" << std::endl; |
175 } | 185 m_sampleDir = ""; |
176 | 186 return ""; |
177 m_sampleDir = tmpdir.filePath("samples"); | 187 } |
178 | 188 |
179 QDir sampleResourceDir(":/samples", "*.wav"); | 189 QDir sampleResourceDir(":/samples", "*.wav"); |
180 | 190 |
181 for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) { | 191 for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) { |
182 | 192 |
183 QString fileName(sampleResourceDir[i]); | 193 QString fileName(sampleResourceDir[i]); |
192 } | 202 } |
193 | 203 |
194 return m_sampleDir; | 204 return m_sampleDir; |
195 } | 205 } |
196 | 206 |
197 void | 207 QString |
198 AudioGenerator::setSamplePath(RealTimePluginInstance *plugin) | 208 AudioGenerator::getSamplePath() |
199 { | 209 { |
200 QString samplePath = QString("%1:%2%3%4%5%6") | 210 QString samplePath = QString("%1:%2%3%4%5%6") |
201 .arg(getSampleDir()) | 211 .arg(getSampleDir()) |
202 .arg(QDir::homePath()) | 212 .arg(QDir::homePath()) |
203 .arg(QDir::separator()) | 213 .arg(QDir::separator()) |
204 .arg(".sv") | 214 .arg(".sv") |
205 .arg(QDir::separator()) | 215 .arg(QDir::separator()) |
206 .arg("samples"); | 216 .arg("samples"); |
207 | 217 return samplePath; |
208 plugin->configure("samplepath", samplePath.toStdString()); | 218 } |
219 | |
220 void | |
221 AudioGenerator::setSamplePath(RealTimePluginInstance *plugin) | |
222 { | |
223 plugin->configure("samplepath", getSamplePath().toStdString()); | |
209 } | 224 } |
210 | 225 |
211 RealTimePluginInstance * | 226 RealTimePluginInstance * |
212 AudioGenerator::loadPluginFor(const Model *model) | 227 AudioGenerator::loadPluginFor(const Model *model) |
213 { | 228 { |