comparison framework/TransformUserConfigurator.cpp @ 595:b23bebfdfaba

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents 36aa947ec962
children e2715204feaa
comparison
equal deleted inserted replaced
594:72b4870f0e6b 595:b23bebfdfaba
38 parentWidget = w; 38 parentWidget = w;
39 } 39 }
40 40
41 bool 41 bool
42 TransformUserConfigurator::getChannelRange(TransformId identifier, 42 TransformUserConfigurator::getChannelRange(TransformId identifier,
43 Vamp::PluginBase *plugin, 43 Vamp::PluginBase *plugin,
44 int &minChannels, int &maxChannels) 44 int &minChannels, int &maxChannels)
45 { 45 {
46 if (plugin && plugin->getType() == "Feature Extraction Plugin") { 46 if (plugin && plugin->getType() == "Feature Extraction Plugin") {
47 Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin); 47 Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin);
48 SVDEBUG << "TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl; 48 SVDEBUG << "TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl;
49 minChannels = int(vp->getMinChannelCount()); 49 minChannels = int(vp->getMinChannelCount());
50 maxChannels = int(vp->getMaxChannelCount()); 50 maxChannels = int(vp->getMaxChannelCount());
51 return true; 51 return true;
52 } else { 52 } else {
53 SVDEBUG << "TransformUserConfigurator::getChannelRange: is not a Vamp plugin" << endl; 53 SVDEBUG << "TransformUserConfigurator::getChannelRange: is not a Vamp plugin" << endl;
54 return TransformFactory::getInstance()-> 54 return TransformFactory::getInstance()->
55 getTransformChannelRange(identifier, minChannels, maxChannels); 55 getTransformChannelRange(identifier, minChannels, maxChannels);
56 } 56 }
57 } 57 }
58 58
59 bool 59 bool
60 TransformUserConfigurator::configure(ModelTransformer::Input &input, 60 TransformUserConfigurator::configure(ModelTransformer::Input &input,
61 Transform &transform, 61 Transform &transform,
62 Vamp::PluginBase *plugin, 62 Vamp::PluginBase *plugin,
63 Model *&inputModel, 63 Model *&inputModel,
64 AudioPlaySource *source, 64 AudioPlaySource *source,
65 sv_frame_t startFrame, 65 sv_frame_t startFrame,
66 sv_frame_t duration, 66 sv_frame_t duration,
67 const QMap<QString, Model *> &modelMap, 67 const QMap<QString, Model *> &modelMap,
68 QStringList candidateModelNames, 68 QStringList candidateModelNames,
69 QString defaultModelName) 69 QString defaultModelName)
70 { 70 {
71 bool ok = false; 71 bool ok = false;
72 QString id = transform.getPluginIdentifier(); 72 QString id = transform.getPluginIdentifier();
73 QString output = transform.getOutput(); 73 QString output = transform.getOutput();
74 QString outputLabel = ""; 74 QString outputLabel = "";
106 106
107 RealTimePluginInstance *rtp = 107 RealTimePluginInstance *rtp =
108 static_cast<RealTimePluginInstance *>(plugin); 108 static_cast<RealTimePluginInstance *>(plugin);
109 109
110 if (effect && source) { 110 if (effect && source) {
111 SVDEBUG << "Setting auditioning effect" << endl; 111 SVDEBUG << "Setting auditioning effect" << endl;
112 source->setAuditioningEffect(rtp); 112 source->setAuditioningEffect(rtp);
113 } 113 }
114 114
115 } else { 115 } else {
116 116
117 Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin); 117 Vamp::Plugin *vp = static_cast<Vamp::Plugin *>(plugin);
118 118
119 frequency = (vp->getInputDomain() == Vamp::Plugin::FrequencyDomain); 119 frequency = (vp->getInputDomain() == Vamp::Plugin::FrequencyDomain);
120 120
121 std::vector<Vamp::Plugin::OutputDescriptor> od = 121 std::vector<Vamp::Plugin::OutputDescriptor> od =
122 vp->getOutputDescriptors(); 122 vp->getOutputDescriptors();
123 123
124 // cerr << "configure: looking for output: " << output << endl; 124 // cerr << "configure: looking for output: " << output << endl;
125 125
126 if (od.size() > 1) { 126 if (od.size() > 1) {
127 for (size_t i = 0; i < od.size(); ++i) { 127 for (size_t i = 0; i < od.size(); ++i) {
128 if (od[i].identifier == output.toStdString()) { 128 if (od[i].identifier == output.toStdString()) {
129 outputLabel = od[i].name.c_str(); 129 outputLabel = od[i].name.c_str();
130 outputDescription = od[i].description.c_str(); 130 outputDescription = od[i].description.c_str();
131 break; 131 break;
132 } 132 }
133 } 133 }
134 } 134 }
135 } 135 }
136 136
137 int sourceChannels = 1; 137 int sourceChannels = 1;
138 if (dynamic_cast<DenseTimeValueModel *>(inputModel)) { 138 if (dynamic_cast<DenseTimeValueModel *>(inputModel)) {
139 sourceChannels = dynamic_cast<DenseTimeValueModel *>(inputModel) 139 sourceChannels = dynamic_cast<DenseTimeValueModel *>(inputModel)
140 ->getChannelCount(); 140 ->getChannelCount();
141 } 141 }
142 142
143 int minChannels = 1, maxChannels = sourceChannels; 143 int minChannels = 1, maxChannels = sourceChannels;
144 getChannelRange(transform.getIdentifier(), plugin, 144 getChannelRange(transform.getIdentifier(), plugin,
145 minChannels, maxChannels); 145 minChannels, maxChannels);
146 146
147 int targetChannels = sourceChannels; 147 int targetChannels = sourceChannels;
148 if (!effect) { 148 if (!effect) {
149 if (sourceChannels < minChannels) targetChannels = minChannels; 149 if (sourceChannels < minChannels) targetChannels = minChannels;
150 if (sourceChannels > maxChannels) targetChannels = maxChannels; 150 if (sourceChannels > maxChannels) targetChannels = maxChannels;
151 } 151 }
152 152
153 int defaultChannel = -1; //!!! no longer saved! [was context.channel] 153 int defaultChannel = -1; //!!! no longer saved! [was context.channel]
154 154
155 PluginParameterDialog *dialog = new PluginParameterDialog 155 PluginParameterDialog *dialog = new PluginParameterDialog
156 (plugin, parentWidget); 156 (plugin, parentWidget);
157 157
158 dialog->setMoreInfoUrl(TransformFactory::getInstance()-> 158 dialog->setMoreInfoUrl(TransformFactory::getInstance()->
159 getTransformInfoUrl(transform.getIdentifier())); 159 getTransformInfoUrl(transform.getIdentifier()));
160 160
161 if (candidateModelNames.size() > 1 && !generator) { 161 if (candidateModelNames.size() > 1 && !generator) {
162 dialog->setCandidateInputModels(candidateModelNames, 162 dialog->setCandidateInputModels(candidateModelNames,
163 defaultModelName); 163 defaultModelName);
164 } 164 }
165 165
166 if (startFrame != 0 || duration != 0) { 166 if (startFrame != 0 || duration != 0) {
167 dialog->setShowSelectionOnlyOption(true); 167 dialog->setShowSelectionOnlyOption(true);
168 } 168 }
169 169
170 if (targetChannels > 0) { 170 if (targetChannels > 0) {
171 dialog->setChannelArrangement(sourceChannels, targetChannels, 171 dialog->setChannelArrangement(sourceChannels, targetChannels,
172 defaultChannel); 172 defaultChannel);
173 } 173 }
174 174
175 dialog->setOutputLabel(outputLabel, outputDescription); 175 dialog->setOutputLabel(outputLabel, outputDescription);
176 176
177 dialog->setShowProcessingOptions(true, frequency); 177 dialog->setShowProcessingOptions(true, frequency);
178 178
179 if (dialog->exec() == QDialog::Accepted) { 179 if (dialog->exec() == QDialog::Accepted) {
180 ok = true; 180 ok = true;
181 } 181 }
182 182
183 QString selectedInput = dialog->getInputModel(); 183 QString selectedInput = dialog->getInputModel();
184 if (selectedInput != "") { 184 if (selectedInput != "") {
185 if (modelMap.contains(selectedInput)) { 185 if (modelMap.contains(selectedInput)) {
186 inputModel = modelMap.value(selectedInput); 186 inputModel = modelMap.value(selectedInput);
187 SVDEBUG << "Found selected input \"" << selectedInput << "\" in model map, result is " << inputModel << endl; 187 SVDEBUG << "Found selected input \"" << selectedInput << "\" in model map, result is " << inputModel << endl;
188 } else { 188 } else {
189 SVDEBUG << "Failed to find selected input \"" << selectedInput << "\" in model map" << endl; 189 SVDEBUG << "Failed to find selected input \"" << selectedInput << "\" in model map" << endl;
190 } 190 }
191 } else { 191 } else {
192 SVDEBUG << "Selected input empty: \"" << selectedInput << "\"" << endl; 192 SVDEBUG << "Selected input empty: \"" << selectedInput << "\"" << endl;
193 } 193 }
194 194
195 // Write parameters back to transform object 195 // Write parameters back to transform object
196 TransformFactory::getInstance()-> 196 TransformFactory::getInstance()->
197 setParametersFromPlugin(transform, plugin); 197 setParametersFromPlugin(transform, plugin);
198 198
199 input.setChannel(dialog->getChannel()); 199 input.setChannel(dialog->getChannel());
200 200
201 //!!! The dialog ought to be taking & returning transform 201 //!!! The dialog ought to be taking & returning transform
202 //objects and input objects and stuff rather than passing 202 //objects and input objects and stuff rather than passing
203 //around all this misc stuff, but that's for tomorrow 203 //around all this misc stuff, but that's for tomorrow
204 //(whenever that may be) 204 //(whenever that may be)
205 205
206 if (startFrame != 0 || duration != 0) { 206 if (startFrame != 0 || duration != 0) {
207 if (dialog->getSelectionOnly()) { 207 if (dialog->getSelectionOnly()) {
208 transform.setStartTime(RealTime::frame2RealTime 208 transform.setStartTime(RealTime::frame2RealTime
209 (startFrame, inputModel->getSampleRate())); 209 (startFrame, inputModel->getSampleRate()));
210 transform.setDuration(RealTime::frame2RealTime 210 transform.setDuration(RealTime::frame2RealTime
211 (duration, inputModel->getSampleRate())); 211 (duration, inputModel->getSampleRate()));
212 } 212 }
213 } 213 }
214 214
215 int stepSize = 0, blockSize = 0; 215 int stepSize = 0, blockSize = 0;
216 WindowType windowType = HanningWindow; 216 WindowType windowType = HanningWindow;
217 217
218 dialog->getProcessingParameters(stepSize, 218 dialog->getProcessingParameters(stepSize,
219 blockSize, 219 blockSize,
220 windowType); 220 windowType);
221 221
222 transform.setStepSize(stepSize); 222 transform.setStepSize(stepSize);
223 transform.setBlockSize(blockSize); 223 transform.setBlockSize(blockSize);
224 transform.setWindowType(windowType); 224 transform.setWindowType(windowType);
225 225
226 delete dialog; 226 delete dialog;
227 227
228 if (effect && source) { 228 if (effect && source) {
229 source->setAuditioningEffect(0); 229 source->setAuditioningEffect(0);
230 } 230 }
231 231
232 return ok; 232 return ok;
233 } 233 }
234 234