comparison transform/RealTimeEffectModelTransformer.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents fde8c497373f
children 70e172e6cc59
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
45 m_outputNo = 45 m_outputNo =
46 (transform.getOutput() == "A") ? -1 : transform.getOutput().toInt(); 46 (transform.getOutput() == "A") ? -1 : transform.getOutput().toInt();
47 47
48 QString pluginId = transform.getPluginIdentifier(); 48 QString pluginId = transform.getPluginIdentifier();
49 49
50 // SVDEBUG << "RealTimeEffectModelTransformer::RealTimeEffectModelTransformer: plugin " << pluginId << ", output " << output << endl; 50 SVDEBUG << "RealTimeEffectModelTransformer::RealTimeEffectModelTransformer: plugin " << pluginId << ", output " << transform.getOutput() << endl;
51 51
52 RealTimePluginFactory *factory = 52 RealTimePluginFactory *factory =
53 RealTimePluginFactory::instanceFor(pluginId); 53 RealTimePluginFactory::instanceFor(pluginId);
54 54
55 if (!factory) { 55 if (!factory) {
56 cerr << "RealTimeEffectModelTransformer: No factory available for plugin id \"" 56 SVCERR << "RealTimeEffectModelTransformer: No factory available for plugin id \""
57 << pluginId << "\"" << endl; 57 << pluginId << "\"" << endl;
58 return; 58 return;
59 } 59 }
60 60
61 DenseTimeValueModel *input = getConformingInput(); 61 DenseTimeValueModel *input = getConformingInput();
62 if (!input) return; 62 if (!input) return;
63 63
65 input->getSampleRate(), 65 input->getSampleRate(),
66 transform.getBlockSize(), 66 transform.getBlockSize(),
67 input->getChannelCount()); 67 input->getChannelCount());
68 68
69 if (!m_plugin) { 69 if (!m_plugin) {
70 cerr << "RealTimeEffectModelTransformer: Failed to instantiate plugin \"" 70 SVCERR << "RealTimeEffectModelTransformer: Failed to instantiate plugin \""
71 << pluginId << "\"" << endl; 71 << pluginId << "\"" << endl;
72 return; 72 return;
73 } 73 }
74 74
75 TransformFactory::getInstance()->setPluginParameters(transform, m_plugin); 75 TransformFactory::getInstance()->setPluginParameters(transform, m_plugin);
76 76
77 if (m_outputNo >= 0 && 77 if (m_outputNo >= 0 &&
91 (input->getSampleRate(), outputChannels); 91 (input->getSampleRate(), outputChannels);
92 92
93 m_outputs.push_back(model); 93 m_outputs.push_back(model);
94 94
95 } else { 95 } else {
96 96
97 SparseTimeValueModel *model = new SparseTimeValueModel 97 SparseTimeValueModel *model = new SparseTimeValueModel
98 (input->getSampleRate(), transform.getBlockSize(), 0.0, 0.0, false); 98 (input->getSampleRate(), transform.getBlockSize(), 0.0, 0.0, false);
99 99
100 if (m_units != "") model->setScaleUnits(m_units); 100 if (m_units != "") model->setScaleUnits(m_units);
101 101
110 110
111 DenseTimeValueModel * 111 DenseTimeValueModel *
112 RealTimeEffectModelTransformer::getConformingInput() 112 RealTimeEffectModelTransformer::getConformingInput()
113 { 113 {
114 DenseTimeValueModel *dtvm = 114 DenseTimeValueModel *dtvm =
115 dynamic_cast<DenseTimeValueModel *>(getInputModel()); 115 dynamic_cast<DenseTimeValueModel *>(getInputModel());
116 if (!dtvm) { 116 if (!dtvm) {
117 SVDEBUG << "RealTimeEffectModelTransformer::getConformingInput: WARNING: Input model is not conformable to DenseTimeValueModel" << endl; 117 SVDEBUG << "RealTimeEffectModelTransformer::getConformingInput: WARNING: Input model is not conformable to DenseTimeValueModel" << endl;
118 } 118 }
119 return dtvm; 119 return dtvm;
120 } 120 }
121 121
122 void 122 void
127 127
128 while (!input->isReady() && !m_abandoned) { 128 while (!input->isReady() && !m_abandoned) {
129 SVDEBUG << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << endl; 129 SVDEBUG << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << endl;
130 usleep(500000); 130 usleep(500000);
131 } 131 }
132 if (m_abandoned) return; 132 if (m_abandoned) {
133 133 return;
134 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>(m_outputs[0]); 134 }
135 WritableWaveFileModel *wwfm = dynamic_cast<WritableWaveFileModel *>(m_outputs[0]); 135 if (m_outputs.empty()) {
136 if (!stvm && !wwfm) return; 136 return;
137 137 }
138 if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) return; 138
139 SparseTimeValueModel *stvm =
140 dynamic_cast<SparseTimeValueModel *>(m_outputs[0]);
141 WritableWaveFileModel *wwfm =
142 dynamic_cast<WritableWaveFileModel *>(m_outputs[0]);
143
144 if (!stvm && !wwfm) {
145 return;
146 }
147
148 if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) {
149 return;
150 }
139 151
140 sv_samplerate_t sampleRate = input->getSampleRate(); 152 sv_samplerate_t sampleRate = input->getSampleRate();
141 int channelCount = input->getChannelCount(); 153 int channelCount = input->getChannelCount();
142 if (!wwfm && m_input.getChannel() != -1) channelCount = 1; 154 if (!wwfm && m_input.getChannel() != -1) channelCount = 1;
143 155
181 sv_frame_t latency = m_plugin->getLatency(); 193 sv_frame_t latency = m_plugin->getLatency();
182 194
183 while (blockFrame < contextStart + contextDuration + latency && 195 while (blockFrame < contextStart + contextDuration + latency &&
184 !m_abandoned) { 196 !m_abandoned) {
185 197
186 int completion = int 198 int completion = int
187 ((((blockFrame - contextStart) / blockSize) * 99) / 199 ((((blockFrame - contextStart) / blockSize) * 99) /
188 (1 + ((contextDuration) / blockSize))); 200 (1 + ((contextDuration) / blockSize)));
189 201
190 sv_frame_t got = 0; 202 sv_frame_t got = 0;
191 203
192 if (channelCount == 1) { 204 if (channelCount == 1) {
193 if (inbufs && inbufs[0]) { 205 if (inbufs && inbufs[0]) {
194 auto data = input->getData 206 auto data = input->getData
195 (m_input.getChannel(), blockFrame, blockSize); 207 (m_input.getChannel(), blockFrame, blockSize);
196 got = data.size(); 208 got = data.size();
197 for (sv_frame_t i = 0; i < got; ++i) { 209 for (sv_frame_t i = 0; i < got; ++i) {
204 for (sv_frame_t i = 0; i < blockSize; ++i) { 216 for (sv_frame_t i = 0; i < blockSize; ++i) {
205 inbufs[ch][i] = inbufs[0][i]; 217 inbufs[ch][i] = inbufs[0][i];
206 } 218 }
207 } 219 }
208 } 220 }
209 } else { 221 } else {
210 if (inbufs && inbufs[0]) { 222 if (inbufs && inbufs[0]) {
211 auto data = input->getMultiChannelData 223 auto data = input->getMultiChannelData
212 (0, channelCount - 1, blockFrame, blockSize); 224 (0, channelCount - 1, blockFrame, blockSize);
213 if (!data.empty()) got = data[0].size(); 225 if (!data.empty()) got = data[0].size();
214 for (int ch = 0; ch < channelCount; ++ch) { 226 for (int ch = 0; ch < channelCount; ++ch) {
226 for (sv_frame_t i = 0; i < blockSize; ++i) { 238 for (sv_frame_t i = 0; i < blockSize; ++i) {
227 inbufs[ch][i] = inbufs[ch % channelCount][i]; 239 inbufs[ch][i] = inbufs[ch % channelCount][i];
228 } 240 }
229 } 241 }
230 } 242 }
231 } 243 }
232 244
233 /* 245 /*
234 cerr << "Input for plugin: " << m_plugin->getAudioInputCount() << " channels "<< endl; 246 cerr << "Input for plugin: " << m_plugin->getAudioInputCount() << " channels "<< endl;
235 247
236 for (int ch = 0; ch < m_plugin->getAudioInputCount(); ++ch) { 248 for (int ch = 0; ch < m_plugin->getAudioInputCount(); ++ch) {
279 delete[] tmp; 291 delete[] tmp;
280 } 292 }
281 } 293 }
282 } 294 }
283 295
284 if (blockFrame == contextStart || completion > prevCompletion) { 296 if (blockFrame == contextStart || completion > prevCompletion) {
285 // This setCompletion is probably misusing the completion 297 // This setCompletion is probably misusing the completion
286 // terminology, just as it was for WritableWaveFileModel 298 // terminology, just as it was for WritableWaveFileModel
287 if (stvm) stvm->setCompletion(completion); 299 if (stvm) stvm->setCompletion(completion);
288 if (wwfm) wwfm->setWriteProportion(completion); 300 if (wwfm) wwfm->setWriteProportion(completion);
289 prevCompletion = completion; 301 prevCompletion = completion;
290 } 302 }
291 303
292 blockFrame += blockSize; 304 blockFrame += blockSize;
293 } 305 }
294 306
295 if (m_abandoned) return; 307 if (m_abandoned) return;
296 308
297 if (stvm) stvm->setCompletion(100); 309 if (stvm) stvm->setCompletion(100);