comparison audioio/AudioGenerator.cpp @ 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
comparison
equal deleted inserted replaced
21:ebe07d3560e6 22:7f32bb07629a
39 AudioGenerator::AudioGenerator(ViewManager *manager) : 39 AudioGenerator::AudioGenerator(ViewManager *manager) :
40 m_viewManager(manager), 40 m_viewManager(manager),
41 m_sourceSampleRate(0), 41 m_sourceSampleRate(0),
42 m_targetChannelCount(1) 42 m_targetChannelCount(1)
43 { 43 {
44 connect(PlayParameterRepository::instance(),
45 SIGNAL(playPluginIdChanged(const Model *, QString)),
46 this,
47 SLOT(playPluginIdChanged(const Model *, QString)));
48
49 connect(PlayParameterRepository::instance(),
50 SIGNAL(playPluginConfigurationChanged(const Model *, QString)),
51 this,
52 SLOT(playPluginConfigurationChanged(const Model *, QString)));
44 } 53 }
45 54
46 AudioGenerator::~AudioGenerator() 55 AudioGenerator::~AudioGenerator()
47 { 56 {
48 } 57 }
75 m_sourceSampleRate = model->getSampleRate(); 84 m_sourceSampleRate = model->getSampleRate();
76 return true; 85 return true;
77 } 86 }
78 } 87 }
79 88
80 SparseOneDimensionalModel *sodm = 89 RealTimePluginInstance *plugin = loadPluginFor(model);
81 dynamic_cast<SparseOneDimensionalModel *>(model); 90 if (plugin) {
91 QMutexLocker locker(&m_mutex);
92 m_synthMap[model] = plugin;
93 return true;
94 }
95
96 return false;
97 }
98
99 void
100 AudioGenerator::playPluginIdChanged(const Model *model, QString)
101 {
102 if (m_synthMap.find(model) == m_synthMap.end()) return;
103
104 RealTimePluginInstance *plugin = loadPluginFor(model);
105 if (plugin) {
106 QMutexLocker locker(&m_mutex);
107 delete m_synthMap[model];
108 m_synthMap[model] = plugin;
109 }
110 }
111
112 void
113 AudioGenerator::playPluginConfigurationChanged(const Model *model,
114 QString configurationXml)
115 {
116 if (m_synthMap.find(model) == m_synthMap.end()) return;
117
118 RealTimePluginInstance *plugin = m_synthMap[model];
119 if (plugin) {
120 QMutexLocker locker(&m_mutex);
121 plugin->setParametersFromXml(configurationXml);
122 }
123 }
124
125 QString
126 AudioGenerator::getDefaultPlayPluginId(const Model *model)
127 {
128 const SparseOneDimensionalModel *sodm =
129 dynamic_cast<const SparseOneDimensionalModel *>(model);
82 if (sodm) { 130 if (sodm) {
83 QString pluginId = QString("dssi:%1:sample_player"). 131 return QString("dssi:%1:sample_player").
84 arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); 132 arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME);
85 RealTimePluginInstance *plugin = loadPlugin(pluginId, "cowbell"); 133 }
86 if (plugin) { 134
87 QMutexLocker locker(&m_mutex); 135 const NoteModel *nm = dynamic_cast<const NoteModel *>(model);
88 m_synthMap[sodm] = plugin;
89 return true;
90 } else {
91 return false;
92 }
93 }
94
95 NoteModel *nm = dynamic_cast<NoteModel *>(model);
96 if (nm) { 136 if (nm) {
97 QString pluginId = QString("dssi:%1:sample_player"). 137 return QString("dssi:%1:sample_player").
98 arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME); 138 arg(PluginIdentifier::BUILTIN_PLUGIN_SONAME);
99 RealTimePluginInstance *plugin = loadPlugin(pluginId, "piano"); 139 }
100 if (plugin) { 140
101 QMutexLocker locker(&m_mutex); 141 return "";
102 m_synthMap[nm] = plugin; 142 }
103 return true; 143
104 } else { 144 QString
105 return false; 145 AudioGenerator::getDefaultPlayPluginConfiguration(const Model *model)
106 } 146 {
107 } 147 const SparseOneDimensionalModel *sodm =
108 148 dynamic_cast<const SparseOneDimensionalModel *>(model);
109 149 if (sodm) {
110 return false; 150 return "<plugin program=\"cowbell\"/>";
151 }
152
153 const NoteModel *nm = dynamic_cast<const NoteModel *>(model);
154 if (nm) {
155 return "<plugin program=\"piano\"/>";
156 }
157
158 return "";
159 }
160
161 RealTimePluginInstance *
162 AudioGenerator::loadPluginFor(const Model *model)
163 {
164 QString pluginId, configurationXml;
165
166 PlayParameters *parameters =
167 PlayParameterRepository::instance()->getPlayParameters(model);
168 if (parameters) {
169 pluginId = parameters->getPlayPluginId();
170 configurationXml = parameters->getPlayPluginConfiguration();
171 }
172
173 if (pluginId == "") {
174 pluginId = getDefaultPlayPluginId(model);
175 configurationXml = getDefaultPlayPluginConfiguration(model);
176 }
177
178 if (pluginId == "") return 0;
179
180 RealTimePluginInstance *plugin = loadPlugin(pluginId, "");
181 if (configurationXml != "") {
182 plugin->setParametersFromXml(configurationXml);
183 }
184
185 if (parameters) {
186 parameters->setPlayPluginId(pluginId);
187 parameters->setPlayPluginConfiguration(configurationXml);
188 }
189
190 return plugin;
111 } 191 }
112 192
113 RealTimePluginInstance * 193 RealTimePluginInstance *
114 AudioGenerator::loadPlugin(QString pluginId, QString program) 194 AudioGenerator::loadPlugin(QString pluginId, QString program)
115 { 195 {