Mercurial > hg > svcore
comparison plugin/transform/RealTimeEffectModelTransformer.cpp @ 350:d7c41483af8f
* Merge from transforms branch -- switch over to using Transform object
properly
author | Chris Cannam |
---|---|
date | Fri, 07 Dec 2007 16:47:31 +0000 |
parents | f620ce48c950 |
children | 876a79afd376 |
comparison
equal
deleted
inserted
replaced
348:edda24bb85fc | 350:d7c41483af8f |
---|---|
23 #include "data/model/SparseTimeValueModel.h" | 23 #include "data/model/SparseTimeValueModel.h" |
24 #include "data/model/DenseTimeValueModel.h" | 24 #include "data/model/DenseTimeValueModel.h" |
25 #include "data/model/WritableWaveFileModel.h" | 25 #include "data/model/WritableWaveFileModel.h" |
26 #include "data/model/WaveFileModel.h" | 26 #include "data/model/WaveFileModel.h" |
27 | 27 |
28 #include "TransformFactory.h" | |
29 | |
28 #include <iostream> | 30 #include <iostream> |
29 | 31 |
30 RealTimeEffectModelTransformer::RealTimeEffectModelTransformer(Model *inputModel, | 32 RealTimeEffectModelTransformer::RealTimeEffectModelTransformer(Input in, |
31 QString pluginId, | 33 const Transform &transform) : |
32 const ExecutionContext &context, | 34 ModelTransformer(in, transform), |
33 QString configurationXml, | 35 m_plugin(0) |
34 QString units, | 36 { |
35 int output) : | 37 m_units = TransformFactory::getInstance()->getTransformUnits |
36 PluginTransformer(inputModel, context), | 38 (transform.getIdentifier()); |
37 m_pluginId(pluginId), | 39 m_outputNo = |
38 m_configurationXml(configurationXml), | 40 (transform.getOutput() == "A") ? -1 : transform.getOutput().toInt(); |
39 m_units(units), | 41 |
40 m_plugin(0), | 42 QString pluginId = transform.getPluginIdentifier(); |
41 m_outputNo(output) | 43 |
42 { | 44 if (!m_transform.getBlockSize()) m_transform.setBlockSize(1024); |
43 if (!m_context.blockSize) m_context.blockSize = 1024; | |
44 | 45 |
45 // std::cerr << "RealTimeEffectModelTransformer::RealTimeEffectModelTransformer: plugin " << pluginId.toStdString() << ", output " << output << std::endl; | 46 // std::cerr << "RealTimeEffectModelTransformer::RealTimeEffectModelTransformer: plugin " << pluginId.toStdString() << ", output " << output << std::endl; |
46 | 47 |
47 RealTimePluginFactory *factory = | 48 RealTimePluginFactory *factory = |
48 RealTimePluginFactory::instanceFor(pluginId); | 49 RealTimePluginFactory::instanceFor(pluginId); |
51 std::cerr << "RealTimeEffectModelTransformer: No factory available for plugin id \"" | 52 std::cerr << "RealTimeEffectModelTransformer: No factory available for plugin id \"" |
52 << pluginId.toStdString() << "\"" << std::endl; | 53 << pluginId.toStdString() << "\"" << std::endl; |
53 return; | 54 return; |
54 } | 55 } |
55 | 56 |
56 DenseTimeValueModel *input = getInput(); | 57 DenseTimeValueModel *input = getConformingInput(); |
57 if (!input) return; | 58 if (!input) return; |
58 | 59 |
59 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, | 60 m_plugin = factory->instantiatePlugin(pluginId, 0, 0, |
60 m_input->getSampleRate(), | 61 input->getSampleRate(), |
61 m_context.blockSize, | 62 m_transform.getBlockSize(), |
62 input->getChannelCount()); | 63 input->getChannelCount()); |
63 | 64 |
64 if (!m_plugin) { | 65 if (!m_plugin) { |
65 std::cerr << "RealTimeEffectModelTransformer: Failed to instantiate plugin \"" | 66 std::cerr << "RealTimeEffectModelTransformer: Failed to instantiate plugin \"" |
66 << pluginId.toStdString() << "\"" << std::endl; | 67 << pluginId.toStdString() << "\"" << std::endl; |
67 return; | 68 return; |
68 } | 69 } |
69 | 70 |
70 if (configurationXml != "") { | 71 TransformFactory::getInstance()->setPluginParameters(m_transform, m_plugin); |
71 PluginXml(m_plugin).setParametersFromXml(configurationXml); | |
72 } | |
73 | 72 |
74 if (m_outputNo >= 0 && | 73 if (m_outputNo >= 0 && |
75 m_outputNo >= int(m_plugin->getControlOutputCount())) { | 74 m_outputNo >= int(m_plugin->getControlOutputCount())) { |
76 std::cerr << "RealTimeEffectModelTransformer: Plugin has fewer than desired " << m_outputNo << " control outputs" << std::endl; | 75 std::cerr << "RealTimeEffectModelTransformer: Plugin has fewer than desired " << m_outputNo << " control outputs" << std::endl; |
77 return; | 76 return; |
90 m_output = model; | 89 m_output = model; |
91 | 90 |
92 } else { | 91 } else { |
93 | 92 |
94 SparseTimeValueModel *model = new SparseTimeValueModel | 93 SparseTimeValueModel *model = new SparseTimeValueModel |
95 (input->getSampleRate(), m_context.blockSize, 0.0, 0.0, false); | 94 (input->getSampleRate(), m_transform.getBlockSize(), 0.0, 0.0, false); |
96 | 95 |
97 if (units != "") model->setScaleUnits(units); | 96 if (m_units != "") model->setScaleUnits(m_units); |
98 | 97 |
99 m_output = model; | 98 m_output = model; |
100 } | 99 } |
101 } | 100 } |
102 | 101 |
104 { | 103 { |
105 delete m_plugin; | 104 delete m_plugin; |
106 } | 105 } |
107 | 106 |
108 DenseTimeValueModel * | 107 DenseTimeValueModel * |
109 RealTimeEffectModelTransformer::getInput() | 108 RealTimeEffectModelTransformer::getConformingInput() |
110 { | 109 { |
111 DenseTimeValueModel *dtvm = | 110 DenseTimeValueModel *dtvm = |
112 dynamic_cast<DenseTimeValueModel *>(getInputModel()); | 111 dynamic_cast<DenseTimeValueModel *>(getInputModel()); |
113 if (!dtvm) { | 112 if (!dtvm) { |
114 std::cerr << "RealTimeEffectModelTransformer::getInput: WARNING: Input model is not conformable to DenseTimeValueModel" << std::endl; | 113 std::cerr << "RealTimeEffectModelTransformer::getConformingInput: WARNING: Input model is not conformable to DenseTimeValueModel" << std::endl; |
115 } | 114 } |
116 return dtvm; | 115 return dtvm; |
117 } | 116 } |
118 | 117 |
119 void | 118 void |
120 RealTimeEffectModelTransformer::run() | 119 RealTimeEffectModelTransformer::run() |
121 { | 120 { |
122 DenseTimeValueModel *input = getInput(); | 121 DenseTimeValueModel *input = getConformingInput(); |
123 if (!input) return; | 122 if (!input) return; |
124 | 123 |
125 while (!input->isReady()) { | 124 while (!input->isReady()) { |
126 if (dynamic_cast<WaveFileModel *>(input)) break; // no need to wait | 125 if (dynamic_cast<WaveFileModel *>(input)) break; // no need to wait |
127 std::cerr << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << std::endl; | 126 std::cerr << "RealTimeEffectModelTransformer::run: Waiting for input model to be ready..." << std::endl; |
134 | 133 |
135 if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) return; | 134 if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) return; |
136 | 135 |
137 size_t sampleRate = input->getSampleRate(); | 136 size_t sampleRate = input->getSampleRate(); |
138 size_t channelCount = input->getChannelCount(); | 137 size_t channelCount = input->getChannelCount(); |
139 if (!wwfm && m_context.channel != -1) channelCount = 1; | 138 if (!wwfm && m_input.getChannel() != -1) channelCount = 1; |
140 | 139 |
141 long blockSize = m_plugin->getBufferSize(); | 140 long blockSize = m_plugin->getBufferSize(); |
142 | 141 |
143 float **inbufs = m_plugin->getAudioInputBuffers(); | 142 float **inbufs = m_plugin->getAudioInputBuffers(); |
144 | 143 |
145 long startFrame = m_input->getStartFrame(); | 144 long startFrame = m_input.getModel()->getStartFrame(); |
146 long endFrame = m_input->getEndFrame(); | 145 long endFrame = m_input.getModel()->getEndFrame(); |
147 | 146 |
148 long contextStart = m_context.startFrame; | 147 RealTime contextStartRT = m_transform.getStartTime(); |
149 long contextDuration = m_context.duration; | 148 RealTime contextDurationRT = m_transform.getDuration(); |
149 | |
150 long contextStart = | |
151 RealTime::realTime2Frame(contextStartRT, sampleRate); | |
152 | |
153 long contextDuration = | |
154 RealTime::realTime2Frame(contextDurationRT, sampleRate); | |
150 | 155 |
151 if (contextStart == 0 || contextStart < startFrame) { | 156 if (contextStart == 0 || contextStart < startFrame) { |
152 contextStart = startFrame; | 157 contextStart = startFrame; |
153 } | 158 } |
154 | 159 |
177 long got = 0; | 182 long got = 0; |
178 | 183 |
179 if (channelCount == 1) { | 184 if (channelCount == 1) { |
180 if (inbufs && inbufs[0]) { | 185 if (inbufs && inbufs[0]) { |
181 got = input->getData | 186 got = input->getData |
182 (m_context.channel, blockFrame, blockSize, inbufs[0]); | 187 (m_input.getChannel(), blockFrame, blockSize, inbufs[0]); |
183 while (got < blockSize) { | 188 while (got < blockSize) { |
184 inbufs[0][got++] = 0.0; | 189 inbufs[0][got++] = 0.0; |
185 } | 190 } |
186 } | 191 } |
187 for (size_t ch = 1; ch < m_plugin->getAudioInputCount(); ++ch) { | 192 for (size_t ch = 1; ch < m_plugin->getAudioInputCount(); ++ch) { |