comparison layer/NoteLayer.cpp @ 42:1bdf285c4eac

* Add "Export Audio File" option * Make note layer align in frequency with any spectrogram layer on the same view (if it's set to frequency mode) * Start to implement mouse editing for ranges of points by dragging the selection * First scrappy attempt at a vertical scale for time value layer
author Chris Cannam
date Mon, 27 Feb 2006 17:34:41 +0000
parents ea6fe8cfcdd5
children 78515b1e29eb
comparison
equal deleted inserted replaced
41:f2c416cbdaa9 42:1bdf285c4eac
14 #include "base/Profiler.h" 14 #include "base/Profiler.h"
15 #include "base/Pitch.h" 15 #include "base/Pitch.h"
16 #include "base/View.h" 16 #include "base/View.h"
17 17
18 #include "model/NoteModel.h" 18 #include "model/NoteModel.h"
19
20 #include "SpectrogramLayer.h" // for optional frequency alignment
19 21
20 #include <QPainter> 22 #include <QPainter>
21 #include <QPainterPath> 23 #include <QPainterPath>
22 #include <QMouseEvent> 24 #include <QMouseEvent>
23 25
351 353
352 int 354 int
353 NoteLayer::getYForValue(float value) const 355 NoteLayer::getYForValue(float value) const
354 { 356 {
355 float min, max, h = m_view->height(); 357 float min, max, h = m_view->height();
356 358
357 switch (m_verticalScale) { 359 switch (m_verticalScale) {
358 360
359 case MIDIRangeScale: 361 case MIDIRangeScale:
360 min = 0.0; 362 min = 0.0;
361 max = 127.0; 363 max = 127.0;
365 min = m_model->getValueMinimum(); 367 min = m_model->getValueMinimum();
366 max = m_model->getValueMaximum(); 368 max = m_model->getValueMaximum();
367 break; 369 break;
368 370
369 case FrequencyScale: 371 case FrequencyScale:
372
373 value = Pitch::getFrequencyForPitch(lrintf(value),
374 value - lrintf(value));
375
376 // If we have a spectrogram layer on the same view as us, align
377 // ourselves with it...
378 for (int i = 0; i < m_view->getLayerCount(); ++i) {
379 SpectrogramLayer *spectrogram = dynamic_cast<SpectrogramLayer *>
380 (m_view->getLayer(i));
381 if (spectrogram) {
382 return spectrogram->getYForFrequency(value);
383 }
384 }
385
386 // ...otherwise just interpolate
370 std::cerr << "FrequencyScale: value in = " << value << std::endl; 387 std::cerr << "FrequencyScale: value in = " << value << std::endl;
371 min = m_model->getValueMinimum(); 388 min = m_model->getValueMinimum();
372 min = Pitch::getFrequencyForPitch(lrintf(min), min - lrintf(min)); 389 min = Pitch::getFrequencyForPitch(lrintf(min), min - lrintf(min));
373 max = m_model->getValueMaximum(); 390 max = m_model->getValueMaximum();
374 max = Pitch::getFrequencyForPitch(lrintf(max), max - lrintf(max)); 391 max = Pitch::getFrequencyForPitch(lrintf(max), max - lrintf(max));
375 value = Pitch::getFrequencyForPitch(lrintf(value), value - lrintf(value));
376 std::cerr << "FrequencyScale: min = " << min << ", max = " << max << ", value = " << value << std::endl; 392 std::cerr << "FrequencyScale: min = " << min << ", max = " << max << ", value = " << value << std::endl;
377 break; 393 break;
378 } 394 }
379 395
380 if (max < min) max = min; 396 if (max < min) max = min;