Mercurial > hg > svgui
comparison layer/NoteLayer.cpp @ 678:26c5f7fd4807 imaf_enc
Merge from the default branch
author | Chris Cannam |
---|---|
date | Mon, 04 Nov 2013 17:12:32 +0000 |
parents | 2727bc3aab59 |
children | 47735c9518e7 1a0dfcbffaf1 |
comparison
equal
deleted
inserted
replaced
677:5e5ab4e8d64b | 678:26c5f7fd4807 |
---|---|
36 | 36 |
37 #include <iostream> | 37 #include <iostream> |
38 #include <cmath> | 38 #include <cmath> |
39 #include <utility> | 39 #include <utility> |
40 | 40 |
41 //#define DEBUG_NOTE_LAYER 1 | |
42 | |
41 NoteLayer::NoteLayer() : | 43 NoteLayer::NoteLayer() : |
42 SingleColourLayer(), | 44 SingleColourLayer(), |
43 m_model(0), | 45 m_model(0), |
44 m_editing(false), | 46 m_editing(false), |
45 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), | 47 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), |
232 if (shouldConvertMIDIToHz()) { | 234 if (shouldConvertMIDIToHz()) { |
233 min = Pitch::getFrequencyForPitch(lrintf(min)); | 235 min = Pitch::getFrequencyForPitch(lrintf(min)); |
234 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); | 236 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); |
235 } | 237 } |
236 | 238 |
239 #ifdef DEBUG_NOTE_LAYER | |
240 std::cerr << "NoteLayer::getDisplayExtents: min = " << min << ", max = " << max << " (m_scaleMinimum = " << m_scaleMinimum << ", m_scaleMaximum = " << m_scaleMaximum << ")" << std::endl; | |
241 #endif | |
242 | |
237 return true; | 243 return true; |
238 } | 244 } |
239 | 245 |
240 bool | 246 bool |
241 NoteLayer::setDisplayExtents(float min, float max) | 247 NoteLayer::setDisplayExtents(float min, float max) |
251 } | 257 } |
252 | 258 |
253 m_scaleMinimum = min; | 259 m_scaleMinimum = min; |
254 m_scaleMaximum = max; | 260 m_scaleMaximum = max; |
255 | 261 |
256 // SVDEBUG << "NoteLayer::setDisplayExtents: min = " << min << ", max = " << max << endl; | 262 #ifdef DEBUG_NOTE_LAYER |
263 std::cerr << "NoteLayer::setDisplayExtents: min = " << min << ", max = " << max << std::endl; | |
264 #endif | |
257 | 265 |
258 emit layerParametersChanged(); | 266 emit layerParametersChanged(); |
259 return true; | 267 return true; |
260 } | 268 } |
261 | 269 |
332 } | 340 } |
333 if (newmax > max) { | 341 if (newmax > max) { |
334 newmax = max; | 342 newmax = max; |
335 } | 343 } |
336 | 344 |
337 SVDEBUG << "NoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; | 345 #ifdef DEBUG_NOTE_LAYER |
346 std::cerr << "NoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << std::endl; | |
347 #endif | |
338 | 348 |
339 setDisplayExtents(newmin, newmax); | 349 setDisplayExtents(newmin, newmax); |
340 } | 350 } |
341 | 351 |
342 RangeMapper * | 352 RangeMapper * |
613 if (shouldConvertMIDIToHz()) { | 623 if (shouldConvertMIDIToHz()) { |
614 min = Pitch::getFrequencyForPitch(lrintf(min)); | 624 min = Pitch::getFrequencyForPitch(lrintf(min)); |
615 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); | 625 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); |
616 } | 626 } |
617 | 627 |
628 #ifdef DEBUG_NOTE_LAYER | |
618 std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; | 629 std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; |
630 #endif | |
619 | 631 |
620 } else if (log) { | 632 } else if (log) { |
621 | 633 |
622 LogRange::mapRange(min, max); | 634 LogRange::mapRange(min, max); |
623 | 635 |
636 #ifdef DEBUG_NOTE_LAYER | |
624 std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; | 637 std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; |
638 #endif | |
625 | 639 |
626 } | 640 } |
627 | 641 |
628 } else { | 642 } else { |
629 | 643 |
653 bool logarithmic = false; | 667 bool logarithmic = false; |
654 int h = v->height(); | 668 int h = v->height(); |
655 | 669 |
656 getScaleExtents(v, min, max, logarithmic); | 670 getScaleExtents(v, min, max, logarithmic); |
657 | 671 |
658 // std::cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; | 672 #ifdef DEBUG_NOTE_LAYER |
673 std::cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; | |
674 #endif | |
659 | 675 |
660 if (shouldConvertMIDIToHz()) { | 676 if (shouldConvertMIDIToHz()) { |
661 val = Pitch::getFrequencyForPitch(lrintf(val), | 677 val = Pitch::getFrequencyForPitch(lrintf(val), |
662 lrintf((val - lrintf(val)) * 100)); | 678 lrintf((val - lrintf(val)) * 100)); |
663 // std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl; | 679 #ifdef DEBUG_NOTE_LAYER |
680 std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl; | |
681 #endif | |
664 } | 682 } |
665 | 683 |
666 if (logarithmic) { | 684 if (logarithmic) { |
667 val = LogRange::map(val); | 685 val = LogRange::map(val); |
668 // std::cerr << "logarithmic true, val now = " << val << std::endl; | 686 #ifdef DEBUG_NOTE_LAYER |
687 std::cerr << "logarithmic true, val now = " << val << std::endl; | |
688 #endif | |
669 } | 689 } |
670 | 690 |
671 int y = int(h - ((val - min) * h) / (max - min)) - 1; | 691 int y = int(h - ((val - min) * h) / (max - min)) - 1; |
672 // std::cerr << "y = " << y << std::endl; | 692 #ifdef DEBUG_NOTE_LAYER |
693 std::cerr << "y = " << y << std::endl; | |
694 #endif | |
673 return y; | 695 return y; |
674 } | 696 } |
675 | 697 |
676 float | 698 float |
677 NoteLayer::getValueForY(View *v, int y) const | 699 NoteLayer::getValueForY(View *v, int y) const |
1262 attributes.value("verticalScale").toInt(&ok); | 1284 attributes.value("verticalScale").toInt(&ok); |
1263 if (ok) setVerticalScale(scale); | 1285 if (ok) setVerticalScale(scale); |
1264 | 1286 |
1265 float min = attributes.value("scaleMinimum").toFloat(&ok); | 1287 float min = attributes.value("scaleMinimum").toFloat(&ok); |
1266 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); | 1288 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); |
1267 if (ok && alsoOk) setDisplayExtents(min, max); | 1289 if (ok && alsoOk && min != max) setDisplayExtents(min, max); |
1268 } | 1290 } |
1269 | 1291 |
1270 | 1292 |