comparison layer/SpectrogramLayer.cpp @ 87:4b98bda7e94d

* Add property labels to property containers (so i18n() won't affect file format)
author Chris Cannam
date Wed, 03 May 2006 16:48:03 +0000
parents 93a7efc75fb7
children 6b864e6864cb
comparison
equal deleted inserted replaced
86:93a7efc75fb7 87:4b98bda7e94d
139 139
140 Layer::PropertyList 140 Layer::PropertyList
141 SpectrogramLayer::getProperties() const 141 SpectrogramLayer::getProperties() const
142 { 142 {
143 PropertyList list; 143 PropertyList list;
144 list.push_back(tr("Colour")); 144 list.push_back("Colour");
145 list.push_back(tr("Colour Scale")); 145 list.push_back("Colour Scale");
146 list.push_back(tr("Window Type")); 146 list.push_back("Window Type");
147 list.push_back(tr("Window Size")); 147 list.push_back("Window Size");
148 list.push_back(tr("Window Overlap")); 148 list.push_back("Window Overlap");
149 list.push_back(tr("Normalize Columns")); 149 list.push_back("Normalize Columns");
150 list.push_back(tr("Bin Display")); 150 list.push_back("Bin Display");
151 list.push_back(tr("Threshold")); 151 list.push_back("Threshold");
152 list.push_back(tr("Gain")); 152 list.push_back("Gain");
153 list.push_back(tr("Colour Rotation")); 153 list.push_back("Colour Rotation");
154 list.push_back(tr("Min Frequency")); 154 list.push_back("Min Frequency");
155 list.push_back(tr("Max Frequency")); 155 list.push_back("Max Frequency");
156 list.push_back(tr("Frequency Scale")); 156 list.push_back("Frequency Scale");
157 return list; 157 return list;
158 }
159
160 QString
161 SpectrogramLayer::getPropertyLabel(const PropertyName &name) const
162 {
163 if (name == "Colour") return tr("Colour");
164 if (name == "Colour Scale") return tr("Colour Scale");
165 if (name == "Window Type") return tr("Window Type");
166 if (name == "Window Size") return tr("Window Size");
167 if (name == "Window Overlap") return tr("Window Overlap");
168 if (name == "Normalize Columns") return tr("Normalize Columns");
169 if (name == "Bin Display") return tr("Bin Display");
170 if (name == "Threshold") return tr("Threshold");
171 if (name == "Gain") return tr("Gain");
172 if (name == "Colour Rotation") return tr("Colour Rotation");
173 if (name == "Min Frequency") return tr("Min Frequency");
174 if (name == "Max Frequency") return tr("Max Frequency");
175 if (name == "Frequency Scale") return tr("Frequency Scale");
176 return "";
158 } 177 }
159 178
160 Layer::PropertyType 179 Layer::PropertyType
161 SpectrogramLayer::getPropertyType(const PropertyName &name) const 180 SpectrogramLayer::getPropertyType(const PropertyName &name) const
162 { 181 {
163 if (name == tr("Gain")) return RangeProperty; 182 if (name == "Gain") return RangeProperty;
164 if (name == tr("Colour Rotation")) return RangeProperty; 183 if (name == "Colour Rotation") return RangeProperty;
165 if (name == tr("Normalize Columns")) return ToggleProperty; 184 if (name == "Normalize Columns") return ToggleProperty;
166 if (name == tr("Threshold")) return RangeProperty; 185 if (name == "Threshold") return RangeProperty;
167 return ValueProperty; 186 return ValueProperty;
168 } 187 }
169 188
170 QString 189 QString
171 SpectrogramLayer::getPropertyGroupName(const PropertyName &name) const 190 SpectrogramLayer::getPropertyGroupName(const PropertyName &name) const
172 { 191 {
173 if (name == tr("Window Size") || 192 if (name == "Window Size" ||
174 name == tr("Window Type") || 193 name == "Window Type" ||
175 name == tr("Window Overlap")) return tr("Window"); 194 name == "Window Overlap") return tr("Window");
176 if (name == tr("Colour") || 195 if (name == "Colour" ||
177 name == tr("Gain") || 196 name == "Gain" ||
178 name == tr("Threshold") || 197 name == "Threshold" ||
179 name == tr("Colour Rotation")) return tr("Colour"); 198 name == "Colour Rotation") return tr("Colour");
180 if (name == tr("Normalize Columns") || 199 if (name == "Normalize Columns" ||
181 name == tr("Bin Display") || 200 name == "Bin Display" ||
182 name == tr("Colour Scale")) return tr("Scale"); 201 name == "Colour Scale") return tr("Scale");
183 if (name == tr("Max Frequency") || 202 if (name == "Max Frequency" ||
184 name == tr("Min Frequency") || 203 name == "Min Frequency" ||
185 name == tr("Frequency Scale") || 204 name == "Frequency Scale" ||
186 name == tr("Frequency Adjustment")) return tr("Range"); 205 name == "Frequency Adjustment") return tr("Range");
187 return QString(); 206 return QString();
188 } 207 }
189 208
190 int 209 int
191 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name, 210 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name,
195 214
196 int garbage0, garbage1; 215 int garbage0, garbage1;
197 if (!min) min = &garbage0; 216 if (!min) min = &garbage0;
198 if (!max) max = &garbage1; 217 if (!max) max = &garbage1;
199 218
200 if (name == tr("Gain")) { 219 if (name == "Gain") {
201 220
202 *min = -50; 221 *min = -50;
203 *max = 50; 222 *max = 50;
204 223
205 deft = lrint(log10(m_gain) * 20.0); 224 deft = lrint(log10(m_gain) * 20.0);
206 if (deft < *min) deft = *min; 225 if (deft < *min) deft = *min;
207 if (deft > *max) deft = *max; 226 if (deft > *max) deft = *max;
208 227
209 } else if (name == tr("Threshold")) { 228 } else if (name == "Threshold") {
210 229
211 *min = -50; 230 *min = -50;
212 *max = 0; 231 *max = 0;
213 232
214 deft = lrintf(AudioLevel::multiplier_to_dB(m_threshold)); 233 deft = lrintf(AudioLevel::multiplier_to_dB(m_threshold));
215 if (deft < *min) deft = *min; 234 if (deft < *min) deft = *min;
216 if (deft > *max) deft = *max; 235 if (deft > *max) deft = *max;
217 236
218 } else if (name == tr("Colour Rotation")) { 237 } else if (name == "Colour Rotation") {
219 238
220 *min = 0; 239 *min = 0;
221 *max = 256; 240 *max = 256;
222 241
223 deft = m_colourRotation; 242 deft = m_colourRotation;
224 243
225 } else if (name == tr("Colour Scale")) { 244 } else if (name == "Colour Scale") {
226 245
227 *min = 0; 246 *min = 0;
228 *max = 3; 247 *max = 3;
229 248
230 deft = (int)m_colourScale; 249 deft = (int)m_colourScale;
231 250
232 } else if (name == tr("Colour")) { 251 } else if (name == "Colour") {
233 252
234 *min = 0; 253 *min = 0;
235 *max = 6; 254 *max = 6;
236 255
237 deft = (int)m_colourScheme; 256 deft = (int)m_colourScheme;
238 257
239 } else if (name == tr("Window Type")) { 258 } else if (name == "Window Type") {
240 259
241 *min = 0; 260 *min = 0;
242 *max = 6; 261 *max = 6;
243 262
244 deft = (int)m_windowType; 263 deft = (int)m_windowType;
245 264
246 } else if (name == tr("Window Size")) { 265 } else if (name == "Window Size") {
247 266
248 *min = 0; 267 *min = 0;
249 *max = 10; 268 *max = 10;
250 269
251 deft = 0; 270 deft = 0;
252 int ws = m_windowSize; 271 int ws = m_windowSize;
253 while (ws > 32) { ws >>= 1; deft ++; } 272 while (ws > 32) { ws >>= 1; deft ++; }
254 273
255 } else if (name == tr("Window Overlap")) { 274 } else if (name == "Window Overlap") {
256 275
257 *min = 0; 276 *min = 0;
258 *max = 4; 277 *max = 4;
259 278
260 deft = m_windowOverlap / 25; 279 deft = m_windowOverlap / 25;
261 if (m_windowOverlap == 90) deft = 4; 280 if (m_windowOverlap == 90) deft = 4;
262 281
263 } else if (name == tr("Min Frequency")) { 282 } else if (name == "Min Frequency") {
264 283
265 *min = 0; 284 *min = 0;
266 *max = 9; 285 *max = 9;
267 286
268 switch (m_minFrequency) { 287 switch (m_minFrequency) {
276 case 1000: deft = 7; break; 295 case 1000: deft = 7; break;
277 case 4000: deft = 8; break; 296 case 4000: deft = 8; break;
278 case 10000: deft = 9; break; 297 case 10000: deft = 9; break;
279 } 298 }
280 299
281 } else if (name == tr("Max Frequency")) { 300 } else if (name == "Max Frequency") {
282 301
283 *min = 0; 302 *min = 0;
284 *max = 9; 303 *max = 9;
285 304
286 switch (m_maxFrequency) { 305 switch (m_maxFrequency) {
294 case 12000: deft = 7; break; 313 case 12000: deft = 7; break;
295 case 16000: deft = 8; break; 314 case 16000: deft = 8; break;
296 default: deft = 9; break; 315 default: deft = 9; break;
297 } 316 }
298 317
299 } else if (name == tr("Frequency Scale")) { 318 } else if (name == "Frequency Scale") {
300 319
301 *min = 0; 320 *min = 0;
302 *max = 1; 321 *max = 1;
303 deft = (int)m_frequencyScale; 322 deft = (int)m_frequencyScale;
304 323
305 } else if (name == tr("Bin Display")) { 324 } else if (name == "Bin Display") {
306 325
307 *min = 0; 326 *min = 0;
308 *max = 2; 327 *max = 2;
309 deft = (int)m_binDisplay; 328 deft = (int)m_binDisplay;
310 329
311 } else if (name == tr("Normalize Columns")) { 330 } else if (name == "Normalize Columns") {
312 331
313 deft = (m_normalizeColumns ? 1 : 0); 332 deft = (m_normalizeColumns ? 1 : 0);
314 333
315 } else { 334 } else {
316 deft = Layer::getPropertyRangeAndValue(name, min, max); 335 deft = Layer::getPropertyRangeAndValue(name, min, max);
321 340
322 QString 341 QString
323 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name, 342 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name,
324 int value) const 343 int value) const
325 { 344 {
326 if (name == tr("Colour")) { 345 if (name == "Colour") {
327 switch (value) { 346 switch (value) {
328 default: 347 default:
329 case 0: return tr("Default"); 348 case 0: return tr("Default");
330 case 1: return tr("White on Black"); 349 case 1: return tr("White on Black");
331 case 2: return tr("Black on White"); 350 case 2: return tr("Black on White");
333 case 4: return tr("Yellow on Black"); 352 case 4: return tr("Yellow on Black");
334 case 5: return tr("Blue on Black"); 353 case 5: return tr("Blue on Black");
335 case 6: return tr("Fruit Salad"); 354 case 6: return tr("Fruit Salad");
336 } 355 }
337 } 356 }
338 if (name == tr("Colour Scale")) { 357 if (name == "Colour Scale") {
339 switch (value) { 358 switch (value) {
340 default: 359 default:
341 case 0: return tr("Linear"); 360 case 0: return tr("Linear");
342 case 1: return tr("Meter"); 361 case 1: return tr("Meter");
343 case 2: return tr("dB"); 362 case 2: return tr("dB");
344 case 3: return tr("Phase"); 363 case 3: return tr("Phase");
345 } 364 }
346 } 365 }
347 if (name == tr("Window Type")) { 366 if (name == "Window Type") {
348 switch ((WindowType)value) { 367 switch ((WindowType)value) {
349 default: 368 default:
350 case RectangularWindow: return tr("Rectangle"); 369 case RectangularWindow: return tr("Rectangle");
351 case BartlettWindow: return tr("Bartlett"); 370 case BartlettWindow: return tr("Bartlett");
352 case HammingWindow: return tr("Hamming"); 371 case HammingWindow: return tr("Hamming");
354 case BlackmanWindow: return tr("Blackman"); 373 case BlackmanWindow: return tr("Blackman");
355 case GaussianWindow: return tr("Gaussian"); 374 case GaussianWindow: return tr("Gaussian");
356 case ParzenWindow: return tr("Parzen"); 375 case ParzenWindow: return tr("Parzen");
357 } 376 }
358 } 377 }
359 if (name == tr("Window Size")) { 378 if (name == "Window Size") {
360 return QString("%1").arg(32 << value); 379 return QString("%1").arg(32 << value);
361 } 380 }
362 if (name == tr("Window Overlap")) { 381 if (name == "Window Overlap") {
363 switch (value) { 382 switch (value) {
364 default: 383 default:
365 case 0: return tr("0%"); 384 case 0: return tr("0%");
366 case 1: return tr("25%"); 385 case 1: return tr("25%");
367 case 2: return tr("50%"); 386 case 2: return tr("50%");
368 case 3: return tr("75%"); 387 case 3: return tr("75%");
369 case 4: return tr("90%"); 388 case 4: return tr("90%");
370 } 389 }
371 } 390 }
372 if (name == tr("Min Frequency")) { 391 if (name == "Min Frequency") {
373 switch (value) { 392 switch (value) {
374 default: 393 default:
375 case 0: return tr("No min"); 394 case 0: return tr("No min");
376 case 1: return tr("10 Hz"); 395 case 1: return tr("10 Hz");
377 case 2: return tr("20 Hz"); 396 case 2: return tr("20 Hz");
382 case 7: return tr("1 KHz"); 401 case 7: return tr("1 KHz");
383 case 8: return tr("4 KHz"); 402 case 8: return tr("4 KHz");
384 case 9: return tr("10 KHz"); 403 case 9: return tr("10 KHz");
385 } 404 }
386 } 405 }
387 if (name == tr("Max Frequency")) { 406 if (name == "Max Frequency") {
388 switch (value) { 407 switch (value) {
389 default: 408 default:
390 case 0: return tr("500 Hz"); 409 case 0: return tr("500 Hz");
391 case 1: return tr("1 KHz"); 410 case 1: return tr("1 KHz");
392 case 2: return tr("1.5 KHz"); 411 case 2: return tr("1.5 KHz");
397 case 7: return tr("12 KHz"); 416 case 7: return tr("12 KHz");
398 case 8: return tr("16 KHz"); 417 case 8: return tr("16 KHz");
399 case 9: return tr("No max"); 418 case 9: return tr("No max");
400 } 419 }
401 } 420 }
402 if (name == tr("Frequency Scale")) { 421 if (name == "Frequency Scale") {
403 switch (value) { 422 switch (value) {
404 default: 423 default:
405 case 0: return tr("Linear"); 424 case 0: return tr("Linear");
406 case 1: return tr("Log"); 425 case 1: return tr("Log");
407 } 426 }
408 } 427 }
409 if (name == tr("Bin Display")) { 428 if (name == "Bin Display") {
410 switch (value) { 429 switch (value) {
411 default: 430 default:
412 case 0: return tr("All Bins"); 431 case 0: return tr("All Bins");
413 case 1: return tr("Peak Bins"); 432 case 1: return tr("Peak Bins");
414 case 2: return tr("Frequencies"); 433 case 2: return tr("Frequencies");
418 } 437 }
419 438
420 void 439 void
421 SpectrogramLayer::setProperty(const PropertyName &name, int value) 440 SpectrogramLayer::setProperty(const PropertyName &name, int value)
422 { 441 {
423 if (name == tr("Gain")) { 442 if (name == "Gain") {
424 setGain(pow(10, float(value)/20.0)); 443 setGain(pow(10, float(value)/20.0));
425 } else if (name == tr("Threshold")) { 444 } else if (name == "Threshold") {
426 if (value == -50) setThreshold(0.0); 445 if (value == -50) setThreshold(0.0);
427 else setThreshold(AudioLevel::dB_to_multiplier(value)); 446 else setThreshold(AudioLevel::dB_to_multiplier(value));
428 } else if (name == tr("Colour Rotation")) { 447 } else if (name == "Colour Rotation") {
429 setColourRotation(value); 448 setColourRotation(value);
430 } else if (name == tr("Colour")) { 449 } else if (name == "Colour") {
431 switch (value) { 450 switch (value) {
432 default: 451 default:
433 case 0: setColourScheme(DefaultColours); break; 452 case 0: setColourScheme(DefaultColours); break;
434 case 1: setColourScheme(WhiteOnBlack); break; 453 case 1: setColourScheme(WhiteOnBlack); break;
435 case 2: setColourScheme(BlackOnWhite); break; 454 case 2: setColourScheme(BlackOnWhite); break;
436 case 3: setColourScheme(RedOnBlue); break; 455 case 3: setColourScheme(RedOnBlue); break;
437 case 4: setColourScheme(YellowOnBlack); break; 456 case 4: setColourScheme(YellowOnBlack); break;
438 case 5: setColourScheme(BlueOnBlack); break; 457 case 5: setColourScheme(BlueOnBlack); break;
439 case 6: setColourScheme(Rainbow); break; 458 case 6: setColourScheme(Rainbow); break;
440 } 459 }
441 } else if (name == tr("Window Type")) { 460 } else if (name == "Window Type") {
442 setWindowType(WindowType(value)); 461 setWindowType(WindowType(value));
443 } else if (name == tr("Window Size")) { 462 } else if (name == "Window Size") {
444 setWindowSize(32 << value); 463 setWindowSize(32 << value);
445 } else if (name == tr("Window Overlap")) { 464 } else if (name == "Window Overlap") {
446 if (value == 4) setWindowOverlap(90); 465 if (value == 4) setWindowOverlap(90);
447 else setWindowOverlap(25 * value); 466 else setWindowOverlap(25 * value);
448 } else if (name == tr("Min Frequency")) { 467 } else if (name == "Min Frequency") {
449 switch (value) { 468 switch (value) {
450 default: 469 default:
451 case 0: setMinFrequency(0); break; 470 case 0: setMinFrequency(0); break;
452 case 1: setMinFrequency(10); break; 471 case 1: setMinFrequency(10); break;
453 case 2: setMinFrequency(20); break; 472 case 2: setMinFrequency(20); break;
457 case 6: setMinFrequency(500); break; 476 case 6: setMinFrequency(500); break;
458 case 7: setMinFrequency(1000); break; 477 case 7: setMinFrequency(1000); break;
459 case 8: setMinFrequency(4000); break; 478 case 8: setMinFrequency(4000); break;
460 case 9: setMinFrequency(10000); break; 479 case 9: setMinFrequency(10000); break;
461 } 480 }
462 } else if (name == tr("Max Frequency")) { 481 } else if (name == "Max Frequency") {
463 switch (value) { 482 switch (value) {
464 case 0: setMaxFrequency(500); break; 483 case 0: setMaxFrequency(500); break;
465 case 1: setMaxFrequency(1000); break; 484 case 1: setMaxFrequency(1000); break;
466 case 2: setMaxFrequency(1500); break; 485 case 2: setMaxFrequency(1500); break;
467 case 3: setMaxFrequency(2000); break; 486 case 3: setMaxFrequency(2000); break;
471 case 7: setMaxFrequency(12000); break; 490 case 7: setMaxFrequency(12000); break;
472 case 8: setMaxFrequency(16000); break; 491 case 8: setMaxFrequency(16000); break;
473 default: 492 default:
474 case 9: setMaxFrequency(0); break; 493 case 9: setMaxFrequency(0); break;
475 } 494 }
476 } else if (name == tr("Colour Scale")) { 495 } else if (name == "Colour Scale") {
477 switch (value) { 496 switch (value) {
478 default: 497 default:
479 case 0: setColourScale(LinearColourScale); break; 498 case 0: setColourScale(LinearColourScale); break;
480 case 1: setColourScale(MeterColourScale); break; 499 case 1: setColourScale(MeterColourScale); break;
481 case 2: setColourScale(dBColourScale); break; 500 case 2: setColourScale(dBColourScale); break;
482 case 3: setColourScale(PhaseColourScale); break; 501 case 3: setColourScale(PhaseColourScale); break;
483 } 502 }
484 } else if (name == tr("Frequency Scale")) { 503 } else if (name == "Frequency Scale") {
485 switch (value) { 504 switch (value) {
486 default: 505 default:
487 case 0: setFrequencyScale(LinearFrequencyScale); break; 506 case 0: setFrequencyScale(LinearFrequencyScale); break;
488 case 1: setFrequencyScale(LogFrequencyScale); break; 507 case 1: setFrequencyScale(LogFrequencyScale); break;
489 } 508 }
490 } else if (name == tr("Bin Display")) { 509 } else if (name == "Bin Display") {
491 switch (value) { 510 switch (value) {
492 default: 511 default:
493 case 0: setBinDisplay(AllBins); break; 512 case 0: setBinDisplay(AllBins); break;
494 case 1: setBinDisplay(PeakBins); break; 513 case 1: setBinDisplay(PeakBins); break;
495 case 2: setBinDisplay(PeakFrequencies); break; 514 case 2: setBinDisplay(PeakFrequencies); break;
1323 1342
1324 if (!plan) { 1343 if (!plan) {
1325 std::cerr << "WARNING: fftw_plan_dft_r2c_1d(" << windowSize << ") failed!" << std::endl; 1344 std::cerr << "WARNING: fftw_plan_dft_r2c_1d(" << windowSize << ") failed!" << std::endl;
1326 fftw_free(input); 1345 fftw_free(input);
1327 fftw_free(output); 1346 fftw_free(output);
1347 fftw_free(workbuffer);
1328 m_layer.m_mutex.lock(); 1348 m_layer.m_mutex.lock();
1329 continue; 1349 continue;
1330 } 1350 }
1331 1351
1332 int counter = 0; 1352 int counter = 0;