comparison layer/FlexiNoteLayer.cpp @ 620:fde7e2fae256 tonioni

updated names in FlexiNote source -- will need to make new FlexiNoteModel source
author matthiasm
date Tue, 26 Mar 2013 14:15:42 +0000
parents aa141d619142
children 765bb3774c4f
comparison
equal deleted inserted replaced
619:aa141d619142 620:fde7e2fae256
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "NoteLayer.h" 16 #include "FlexiNoteLayer.h"
17 17
18 #include "data/model/Model.h" 18 #include "data/model/Model.h"
19 #include "base/RealTime.h" 19 #include "base/RealTime.h"
20 #include "base/Profiler.h" 20 #include "base/Profiler.h"
21 #include "base/Pitch.h" 21 #include "base/Pitch.h"
22 #include "base/LogRange.h" 22 #include "base/LogRange.h"
23 #include "base/RangeMapper.h" 23 #include "base/RangeMapper.h"
24 #include "ColourDatabase.h" 24 #include "ColourDatabase.h"
25 #include "view/View.h" 25 #include "view/View.h"
26 26
27 #include "data/model/NoteModel.h" 27 #include "data/model/FlexiNoteModel.h"
28 28
29 #include "widgets/ItemEditDialog.h" 29 #include "widgets/ItemEditDialog.h"
30 30
31 #include <QPainter> 31 #include <QPainter>
32 #include <QPainterPath> 32 #include <QPainterPath>
36 36
37 #include <iostream> 37 #include <iostream>
38 #include <cmath> 38 #include <cmath>
39 #include <utility> 39 #include <utility>
40 40
41 NoteLayer::NoteLayer() : 41 FlexiNoteLayer::FlexiNoteLayer() :
42 SingleColourLayer(), 42 SingleColourLayer(),
43 m_model(0), 43 m_model(0),
44 m_editing(false), 44 m_editing(false),
45 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), 45 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
46 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), 46 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
51 { 51 {
52 52
53 } 53 }
54 54
55 void 55 void
56 NoteLayer::setModel(NoteModel *model) 56 FlexiNoteLayer::setModel(FlexiNoteModel *model)
57 { 57 {
58 if (m_model == model) return; 58 if (m_model == model) return;
59 m_model = model; 59 m_model = model;
60 60
61 connectSignals(m_model); 61 connectSignals(m_model);
62 62
63 // SVDEBUG << "NoteLayer::setModel(" << model << ")" << endl; 63 // SVDEBUG << "FlexiNoteLayer::setModel(" << model << ")" << endl;
64 64
65 m_scaleMinimum = 0; 65 m_scaleMinimum = 0;
66 m_scaleMaximum = 0; 66 m_scaleMaximum = 0;
67 67
68 emit modelReplaced(); 68 emit modelReplaced();
69 } 69 }
70 70
71 Layer::PropertyList 71 Layer::PropertyList
72 NoteLayer::getProperties() const 72 FlexiNoteLayer::getProperties() const
73 { 73 {
74 PropertyList list = SingleColourLayer::getProperties(); 74 PropertyList list = SingleColourLayer::getProperties();
75 list.push_back("Vertical Scale"); 75 list.push_back("Vertical Scale");
76 list.push_back("Scale Units"); 76 list.push_back("Scale Units");
77 return list; 77 return list;
78 } 78 }
79 79
80 QString 80 QString
81 NoteLayer::getPropertyLabel(const PropertyName &name) const 81 FlexiNoteLayer::getPropertyLabel(const PropertyName &name) const
82 { 82 {
83 if (name == "Vertical Scale") return tr("Vertical Scale"); 83 if (name == "Vertical Scale") return tr("Vertical Scale");
84 if (name == "Scale Units") return tr("Scale Units"); 84 if (name == "Scale Units") return tr("Scale Units");
85 return SingleColourLayer::getPropertyLabel(name); 85 return SingleColourLayer::getPropertyLabel(name);
86 } 86 }
87 87
88 Layer::PropertyType 88 Layer::PropertyType
89 NoteLayer::getPropertyType(const PropertyName &name) const 89 FlexiNoteLayer::getPropertyType(const PropertyName &name) const
90 { 90 {
91 if (name == "Scale Units") return UnitsProperty; 91 if (name == "Scale Units") return UnitsProperty;
92 if (name == "Vertical Scale") return ValueProperty; 92 if (name == "Vertical Scale") return ValueProperty;
93 return SingleColourLayer::getPropertyType(name); 93 return SingleColourLayer::getPropertyType(name);
94 } 94 }
95 95
96 QString 96 QString
97 NoteLayer::getPropertyGroupName(const PropertyName &name) const 97 FlexiNoteLayer::getPropertyGroupName(const PropertyName &name) const
98 { 98 {
99 if (name == "Vertical Scale" || name == "Scale Units") { 99 if (name == "Vertical Scale" || name == "Scale Units") {
100 return tr("Scale"); 100 return tr("Scale");
101 } 101 }
102 return SingleColourLayer::getPropertyGroupName(name); 102 return SingleColourLayer::getPropertyGroupName(name);
103 } 103 }
104 104
105 int 105 int
106 NoteLayer::getPropertyRangeAndValue(const PropertyName &name, 106 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name,
107 int *min, int *max, int *deflt) const 107 int *min, int *max, int *deflt) const
108 { 108 {
109 int val = 0; 109 int val = 0;
110 110
111 if (name == "Vertical Scale") { 111 if (name == "Vertical Scale") {
131 131
132 return val; 132 return val;
133 } 133 }
134 134
135 QString 135 QString
136 NoteLayer::getPropertyValueLabel(const PropertyName &name, 136 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name,
137 int value) const 137 int value) const
138 { 138 {
139 if (name == "Vertical Scale") { 139 if (name == "Vertical Scale") {
140 switch (value) { 140 switch (value) {
141 default: 141 default:
147 } 147 }
148 return SingleColourLayer::getPropertyValueLabel(name, value); 148 return SingleColourLayer::getPropertyValueLabel(name, value);
149 } 149 }
150 150
151 void 151 void
152 NoteLayer::setProperty(const PropertyName &name, int value) 152 FlexiNoteLayer::setProperty(const PropertyName &name, int value)
153 { 153 {
154 if (name == "Vertical Scale") { 154 if (name == "Vertical Scale") {
155 setVerticalScale(VerticalScale(value)); 155 setVerticalScale(VerticalScale(value));
156 } else if (name == "Scale Units") { 156 } else if (name == "Scale Units") {
157 if (m_model) { 157 if (m_model) {
163 return SingleColourLayer::setProperty(name, value); 163 return SingleColourLayer::setProperty(name, value);
164 } 164 }
165 } 165 }
166 166
167 void 167 void
168 NoteLayer::setVerticalScale(VerticalScale scale) 168 FlexiNoteLayer::setVerticalScale(VerticalScale scale)
169 { 169 {
170 if (m_verticalScale == scale) return; 170 if (m_verticalScale == scale) return;
171 m_verticalScale = scale; 171 m_verticalScale = scale;
172 emit layerParametersChanged(); 172 emit layerParametersChanged();
173 } 173 }
174 174
175 bool 175 bool
176 NoteLayer::isLayerScrollable(const View *v) const 176 FlexiNoteLayer::isLayerScrollable(const View *v) const
177 { 177 {
178 QPoint discard; 178 QPoint discard;
179 return !v->shouldIlluminateLocalFeatures(this, discard); 179 return !v->shouldIlluminateLocalFeatures(this, discard);
180 } 180 }
181 181
182 bool 182 bool
183 NoteLayer::shouldConvertMIDIToHz() const 183 FlexiNoteLayer::shouldConvertMIDIToHz() const
184 { 184 {
185 QString unit = m_model->getScaleUnits(); 185 QString unit = m_model->getScaleUnits();
186 return (unit != "Hz"); 186 return (unit != "Hz");
187 // if (unit == "" || 187 // if (unit == "" ||
188 // unit.startsWith("MIDI") || 188 // unit.startsWith("MIDI") ||
189 // unit.startsWith("midi")) return true; 189 // unit.startsWith("midi")) return true;
190 // return false; 190 // return false;
191 } 191 }
192 192
193 bool 193 bool
194 NoteLayer::getValueExtents(float &min, float &max, 194 FlexiNoteLayer::getValueExtents(float &min, float &max,
195 bool &logarithmic, QString &unit) const 195 bool &logarithmic, QString &unit) const
196 { 196 {
197 if (!m_model) return false; 197 if (!m_model) return false;
198 min = m_model->getValueMinimum(); 198 min = m_model->getValueMinimum();
199 max = m_model->getValueMaximum(); 199 max = m_model->getValueMaximum();
209 209
210 return true; 210 return true;
211 } 211 }
212 212
213 bool 213 bool
214 NoteLayer::getDisplayExtents(float &min, float &max) const 214 FlexiNoteLayer::getDisplayExtents(float &min, float &max) const
215 { 215 {
216 if (!m_model || shouldAutoAlign()) return false; 216 if (!m_model || shouldAutoAlign()) return false;
217 217
218 if (m_verticalScale == MIDIRangeScale) { 218 if (m_verticalScale == MIDIRangeScale) {
219 min = Pitch::getFrequencyForPitch(0); 219 min = Pitch::getFrequencyForPitch(0);
236 236
237 return true; 237 return true;
238 } 238 }
239 239
240 bool 240 bool
241 NoteLayer::setDisplayExtents(float min, float max) 241 FlexiNoteLayer::setDisplayExtents(float min, float max)
242 { 242 {
243 if (!m_model) return false; 243 if (!m_model) return false;
244 244
245 if (min == max) { 245 if (min == max) {
246 if (min == 0.f) { 246 if (min == 0.f) {
251 } 251 }
252 252
253 m_scaleMinimum = min; 253 m_scaleMinimum = min;
254 m_scaleMaximum = max; 254 m_scaleMaximum = max;
255 255
256 // SVDEBUG << "NoteLayer::setDisplayExtents: min = " << min << ", max = " << max << endl; 256 // SVDEBUG << "FlexiNoteLayer::setDisplayExtents: min = " << min << ", max = " << max << endl;
257 257
258 emit layerParametersChanged(); 258 emit layerParametersChanged();
259 return true; 259 return true;
260 } 260 }
261 261
262 int 262 int
263 NoteLayer::getVerticalZoomSteps(int &defaultStep) const 263 FlexiNoteLayer::getVerticalZoomSteps(int &defaultStep) const
264 { 264 {
265 if (shouldAutoAlign()) return 0; 265 if (shouldAutoAlign()) return 0;
266 if (!m_model) return 0; 266 if (!m_model) return 0;
267 267
268 defaultStep = 0; 268 defaultStep = 0;
269 return 100; 269 return 100;
270 } 270 }
271 271
272 int 272 int
273 NoteLayer::getCurrentVerticalZoomStep() const 273 FlexiNoteLayer::getCurrentVerticalZoomStep() const
274 { 274 {
275 if (shouldAutoAlign()) return 0; 275 if (shouldAutoAlign()) return 0;
276 if (!m_model) return 0; 276 if (!m_model) return 0;
277 277
278 RangeMapper *mapper = getNewVerticalZoomRangeMapper(); 278 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
289 } 289 }
290 290
291 //!!! lots of duplication with TimeValueLayer 291 //!!! lots of duplication with TimeValueLayer
292 292
293 void 293 void
294 NoteLayer::setVerticalZoomStep(int step) 294 FlexiNoteLayer::setVerticalZoomStep(int step)
295 { 295 {
296 if (shouldAutoAlign()) return; 296 if (shouldAutoAlign()) return;
297 if (!m_model) return; 297 if (!m_model) return;
298 298
299 RangeMapper *mapper = getNewVerticalZoomRangeMapper(); 299 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
332 } 332 }
333 if (newmax > max) { 333 if (newmax > max) {
334 newmax = max; 334 newmax = max;
335 } 335 }
336 336
337 SVDEBUG << "NoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; 337 SVDEBUG << "FlexiNoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl;
338 338
339 setDisplayExtents(newmin, newmax); 339 setDisplayExtents(newmin, newmax);
340 } 340 }
341 341
342 RangeMapper * 342 RangeMapper *
343 NoteLayer::getNewVerticalZoomRangeMapper() const 343 FlexiNoteLayer::getNewVerticalZoomRangeMapper() const
344 { 344 {
345 if (!m_model) return 0; 345 if (!m_model) return 0;
346 346
347 RangeMapper *mapper; 347 RangeMapper *mapper;
348 348
360 } 360 }
361 361
362 return mapper; 362 return mapper;
363 } 363 }
364 364
365 NoteModel::PointList 365 FlexiNoteModel::PointList
366 NoteLayer::getLocalPoints(View *v, int x) const 366 FlexiNoteLayer::getLocalPoints(View *v, int x) const
367 { 367 {
368 if (!m_model) return NoteModel::PointList(); 368 if (!m_model) return FlexiNoteModel::PointList();
369 369
370 long frame = v->getFrameForX(x); 370 long frame = v->getFrameForX(x);
371 371
372 NoteModel::PointList onPoints = 372 FlexiNoteModel::PointList onPoints =
373 m_model->getPoints(frame); 373 m_model->getPoints(frame);
374 374
375 if (!onPoints.empty()) { 375 if (!onPoints.empty()) {
376 return onPoints; 376 return onPoints;
377 } 377 }
378 378
379 NoteModel::PointList prevPoints = 379 FlexiNoteModel::PointList prevPoints =
380 m_model->getPreviousPoints(frame); 380 m_model->getPreviousPoints(frame);
381 NoteModel::PointList nextPoints = 381 FlexiNoteModel::PointList nextPoints =
382 m_model->getNextPoints(frame); 382 m_model->getNextPoints(frame);
383 383
384 NoteModel::PointList usePoints = prevPoints; 384 FlexiNoteModel::PointList usePoints = prevPoints;
385 385
386 if (prevPoints.empty()) { 386 if (prevPoints.empty()) {
387 usePoints = nextPoints; 387 usePoints = nextPoints;
388 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && 388 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
389 !(nextPoints.begin()->frame > v->getEndFrame())) { 389 !(nextPoints.begin()->frame > v->getEndFrame())) {
404 404
405 return usePoints; 405 return usePoints;
406 } 406 }
407 407
408 bool 408 bool
409 NoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const 409 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const
410 { 410 {
411 if (!m_model) return false; 411 if (!m_model) return false;
412 412
413 long frame = v->getFrameForX(x); 413 long frame = v->getFrameForX(x);
414 414
415 NoteModel::PointList onPoints = m_model->getPoints(frame); 415 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
416 if (onPoints.empty()) return false; 416 if (onPoints.empty()) return false;
417 417
418 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl; 418 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
419 419
420 int nearestDistance = -1; 420 int nearestDistance = -1;
421 421
422 for (NoteModel::PointList::const_iterator i = onPoints.begin(); 422 for (FlexiNoteModel::PointList::const_iterator i = onPoints.begin();
423 i != onPoints.end(); ++i) { 423 i != onPoints.end(); ++i) {
424 424
425 int distance = getYForValue(v, (*i).value) - y; 425 int distance = getYForValue(v, (*i).value) - y;
426 if (distance < 0) distance = -distance; 426 if (distance < 0) distance = -distance;
427 if (nearestDistance == -1 || distance < nearestDistance) { 427 if (nearestDistance == -1 || distance < nearestDistance) {
432 432
433 return true; 433 return true;
434 } 434 }
435 435
436 QString 436 QString
437 NoteLayer::getFeatureDescription(View *v, QPoint &pos) const 437 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const
438 { 438 {
439 int x = pos.x(); 439 int x = pos.x();
440 440
441 if (!m_model || !m_model->getSampleRate()) return ""; 441 if (!m_model || !m_model->getSampleRate()) return "";
442 442
443 NoteModel::PointList points = getLocalPoints(v, x); 443 FlexiNoteModel::PointList points = getLocalPoints(v, x);
444 444
445 if (points.empty()) { 445 if (points.empty()) {
446 if (!m_model->isReady()) { 446 if (!m_model->isReady()) {
447 return tr("In progress"); 447 return tr("In progress");
448 } else { 448 } else {
449 return tr("No local points"); 449 return tr("No local points");
450 } 450 }
451 } 451 }
452 452
453 Note note(0); 453 FlexiNote note(0);
454 NoteModel::PointList::iterator i; 454 FlexiNoteModel::PointList::iterator i;
455 455
456 for (i = points.begin(); i != points.end(); ++i) { 456 for (i = points.begin(); i != points.end(); ++i) {
457 457
458 int y = getYForValue(v, i->value); 458 int y = getYForValue(v, i->value);
459 int h = 3; 459 int h = 3;
519 getYForValue(v, note.value)); 519 getYForValue(v, note.value));
520 return text; 520 return text;
521 } 521 }
522 522
523 bool 523 bool
524 NoteLayer::snapToFeatureFrame(View *v, int &frame, 524 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
525 size_t &resolution, 525 size_t &resolution,
526 SnapType snap) const 526 SnapType snap) const
527 { 527 {
528 if (!m_model) { 528 if (!m_model) {
529 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 529 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
530 } 530 }
531 531
532 resolution = m_model->getResolution(); 532 resolution = m_model->getResolution();
533 NoteModel::PointList points; 533 FlexiNoteModel::PointList points;
534 534
535 if (snap == SnapNeighbouring) { 535 if (snap == SnapNeighbouring) {
536 536
537 points = getLocalPoints(v, v->getXForFrame(frame)); 537 points = getLocalPoints(v, v->getXForFrame(frame));
538 if (points.empty()) return false; 538 if (points.empty()) return false;
542 542
543 points = m_model->getPoints(frame, frame); 543 points = m_model->getPoints(frame, frame);
544 int snapped = frame; 544 int snapped = frame;
545 bool found = false; 545 bool found = false;
546 546
547 for (NoteModel::PointList::const_iterator i = points.begin(); 547 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
548 i != points.end(); ++i) { 548 i != points.end(); ++i) {
549 549
550 if (snap == SnapRight) { 550 if (snap == SnapRight) {
551 551
552 if (i->frame > frame) { 552 if (i->frame > frame) {
564 break; 564 break;
565 } 565 }
566 566
567 } else { // nearest 567 } else { // nearest
568 568
569 NoteModel::PointList::const_iterator j = i; 569 FlexiNoteModel::PointList::const_iterator j = i;
570 ++j; 570 ++j;
571 571
572 if (j == points.end()) { 572 if (j == points.end()) {
573 573
574 snapped = i->frame; 574 snapped = i->frame;
591 frame = snapped; 591 frame = snapped;
592 return found; 592 return found;
593 } 593 }
594 594
595 void 595 void
596 NoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const 596 FlexiNoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
597 { 597 {
598 min = 0.0; 598 min = 0.0;
599 max = 0.0; 599 max = 0.0;
600 log = false; 600 log = false;
601 601
613 if (shouldConvertMIDIToHz()) { 613 if (shouldConvertMIDIToHz()) {
614 min = Pitch::getFrequencyForPitch(lrintf(min)); 614 min = Pitch::getFrequencyForPitch(lrintf(min));
615 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); 615 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
616 } 616 }
617 617
618 std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; 618 std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl;
619 619
620 } else if (log) { 620 } else if (log) {
621 621
622 LogRange::mapRange(min, max); 622 LogRange::mapRange(min, max);
623 623
624 std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; 624 std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl;
625 625
626 } 626 }
627 627
628 } else { 628 } else {
629 629
645 645
646 if (max == min) max = min + 1.0; 646 if (max == min) max = min + 1.0;
647 } 647 }
648 648
649 int 649 int
650 NoteLayer::getYForValue(View *v, float val) const 650 FlexiNoteLayer::getYForValue(View *v, float val) const
651 { 651 {
652 float min = 0.0, max = 0.0; 652 float min = 0.0, max = 0.0;
653 bool logarithmic = false; 653 bool logarithmic = false;
654 int h = v->height(); 654 int h = v->height();
655 655
656 getScaleExtents(v, min, max, logarithmic); 656 getScaleExtents(v, min, max, logarithmic);
657 657
658 // std::cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; 658 // std::cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl;
659 659
660 if (shouldConvertMIDIToHz()) { 660 if (shouldConvertMIDIToHz()) {
661 val = Pitch::getFrequencyForPitch(lrintf(val), 661 val = Pitch::getFrequencyForPitch(lrintf(val),
662 lrintf((val - lrintf(val)) * 100)); 662 lrintf((val - lrintf(val)) * 100));
663 // std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl; 663 // std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl;
672 // std::cerr << "y = " << y << std::endl; 672 // std::cerr << "y = " << y << std::endl;
673 return y; 673 return y;
674 } 674 }
675 675
676 float 676 float
677 NoteLayer::getValueForY(View *v, int y) const 677 FlexiNoteLayer::getValueForY(View *v, int y) const
678 { 678 {
679 float min = 0.0, max = 0.0; 679 float min = 0.0, max = 0.0;
680 bool logarithmic = false; 680 bool logarithmic = false;
681 int h = v->height(); 681 int h = v->height();
682 682
694 694
695 return val; 695 return val;
696 } 696 }
697 697
698 bool 698 bool
699 NoteLayer::shouldAutoAlign() const 699 FlexiNoteLayer::shouldAutoAlign() const
700 { 700 {
701 if (!m_model) return false; 701 if (!m_model) return false;
702 return (m_verticalScale == AutoAlignScale); 702 return (m_verticalScale == AutoAlignScale);
703 } 703 }
704 704
705 void 705 void
706 NoteLayer::paint(View *v, QPainter &paint, QRect rect) const 706 FlexiNoteLayer::paint(View *v, QPainter &paint, QRect rect) const
707 { 707 {
708 if (!m_model || !m_model->isOK()) return; 708 if (!m_model || !m_model->isOK()) return;
709 709
710 int sampleRate = m_model->getSampleRate(); 710 int sampleRate = m_model->getSampleRate();
711 if (!sampleRate) return; 711 if (!sampleRate) return;
712 712
713 // Profiler profiler("NoteLayer::paint", true); 713 // Profiler profiler("FlexiNoteLayer::paint", true);
714 714
715 int x0 = rect.left(), x1 = rect.right(); 715 int x0 = rect.left(), x1 = rect.right();
716 long frame0 = v->getFrameForX(x0); 716 long frame0 = v->getFrameForX(x0);
717 long frame1 = v->getFrameForX(x1); 717 long frame1 = v->getFrameForX(x1);
718 718
719 NoteModel::PointList points(m_model->getPoints(frame0, frame1)); 719 FlexiNoteModel::PointList points(m_model->getPoints(frame0, frame1));
720 if (points.empty()) return; 720 if (points.empty()) return;
721 721
722 paint.setPen(getBaseQColor()); 722 paint.setPen(getBaseQColor());
723 723
724 QColor brushColour(getBaseQColor()); 724 QColor brushColour(getBaseQColor());
725 brushColour.setAlpha(80); 725 brushColour.setAlpha(80);
726 726
727 // SVDEBUG << "NoteLayer::paint: resolution is " 727 // SVDEBUG << "FlexiNoteLayer::paint: resolution is "
728 // << m_model->getResolution() << " frames" << endl; 728 // << m_model->getResolution() << " frames" << endl;
729 729
730 float min = m_model->getValueMinimum(); 730 float min = m_model->getValueMinimum();
731 float max = m_model->getValueMaximum(); 731 float max = m_model->getValueMaximum();
732 if (max == min) max = min + 1.0; 732 if (max == min) max = min + 1.0;
733 733
734 QPoint localPos; 734 QPoint localPos;
735 NoteModel::Point illuminatePoint(0); 735 FlexiNoteModel::Point illuminatePoint(0);
736 bool shouldIlluminate = false; 736 bool shouldIlluminate = false;
737 737
738 if (v->shouldIlluminateLocalFeatures(this, localPos)) { 738 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
739 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), 739 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(),
740 illuminatePoint); 740 illuminatePoint);
741 } 741 }
742 742
743 paint.save(); 743 paint.save();
744 paint.setRenderHint(QPainter::Antialiasing, false); 744 paint.setRenderHint(QPainter::Antialiasing, false);
745 745
746 for (NoteModel::PointList::const_iterator i = points.begin(); 746 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
747 i != points.end(); ++i) { 747 i != points.end(); ++i) {
748 748
749 const NoteModel::Point &p(*i); 749 const FlexiNoteModel::Point &p(*i);
750 750
751 int x = v->getXForFrame(p.frame); 751 int x = v->getXForFrame(p.frame);
752 int y = getYForValue(v, p.value); 752 int y = getYForValue(v, p.value);
753 int w = v->getXForFrame(p.frame + p.duration) - x; 753 int w = v->getXForFrame(p.frame + p.duration) - x;
754 int h = 3; 754 int h = 3;
762 paint.setPen(getBaseQColor()); 762 paint.setPen(getBaseQColor());
763 paint.setBrush(brushColour); 763 paint.setBrush(brushColour);
764 764
765 if (shouldIlluminate && 765 if (shouldIlluminate &&
766 // "illuminatePoint == p" 766 // "illuminatePoint == p"
767 !NoteModel::Point::Comparator()(illuminatePoint, p) && 767 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) &&
768 !NoteModel::Point::Comparator()(p, illuminatePoint)) { 768 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) {
769 769
770 paint.setPen(v->getForeground()); 770 paint.setPen(v->getForeground());
771 paint.setBrush(v->getForeground()); 771 paint.setBrush(v->getForeground());
772 772
773 QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); 773 QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits());
790 790
791 paint.restore(); 791 paint.restore();
792 } 792 }
793 793
794 void 794 void
795 NoteLayer::drawStart(View *v, QMouseEvent *e) 795 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e)
796 { 796 {
797 // SVDEBUG << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; 797 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
798 798
799 if (!m_model) return; 799 if (!m_model) return;
800 800
801 long frame = v->getFrameForX(e->x()); 801 long frame = v->getFrameForX(e->x());
802 if (frame < 0) frame = 0; 802 if (frame < 0) frame = 0;
803 frame = frame / m_model->getResolution() * m_model->getResolution(); 803 frame = frame / m_model->getResolution() * m_model->getResolution();
804 804
805 float value = getValueForY(v, e->y()); 805 float value = getValueForY(v, e->y());
806 806
807 m_editingPoint = NoteModel::Point(frame, value, 0, 0.8, tr("New Point")); 807 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
808 m_originalPoint = m_editingPoint; 808 m_originalPoint = m_editingPoint;
809 809
810 if (m_editingCommand) finish(m_editingCommand); 810 if (m_editingCommand) finish(m_editingCommand);
811 m_editingCommand = new NoteModel::EditCommand(m_model, 811 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
812 tr("Draw Point")); 812 tr("Draw Point"));
813 m_editingCommand->addPoint(m_editingPoint); 813 m_editingCommand->addPoint(m_editingPoint);
814 814
815 m_editing = true; 815 m_editing = true;
816 } 816 }
817 817
818 void 818 void
819 NoteLayer::drawDrag(View *v, QMouseEvent *e) 819 FlexiNoteLayer::drawDrag(View *v, QMouseEvent *e)
820 { 820 {
821 // SVDEBUG << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; 821 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
822 822
823 if (!m_model || !m_editing) return; 823 if (!m_model || !m_editing) return;
824 824
825 long frame = v->getFrameForX(e->x()); 825 long frame = v->getFrameForX(e->x());
826 if (frame < 0) frame = 0; 826 if (frame < 0) frame = 0;
843 m_editingPoint.duration = newDuration; 843 m_editingPoint.duration = newDuration;
844 m_editingCommand->addPoint(m_editingPoint); 844 m_editingCommand->addPoint(m_editingPoint);
845 } 845 }
846 846
847 void 847 void
848 NoteLayer::drawEnd(View *, QMouseEvent *) 848 FlexiNoteLayer::drawEnd(View *, QMouseEvent *)
849 { 849 {
850 // SVDEBUG << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; 850 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl;
851 if (!m_model || !m_editing) return; 851 if (!m_model || !m_editing) return;
852 finish(m_editingCommand); 852 finish(m_editingCommand);
853 m_editingCommand = 0; 853 m_editingCommand = 0;
854 m_editing = false; 854 m_editing = false;
855 } 855 }
856 856
857 void 857 void
858 NoteLayer::eraseStart(View *v, QMouseEvent *e) 858 FlexiNoteLayer::eraseStart(View *v, QMouseEvent *e)
859 { 859 {
860 if (!m_model) return; 860 if (!m_model) return;
861 861
862 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 862 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
863 863
868 868
869 m_editing = true; 869 m_editing = true;
870 } 870 }
871 871
872 void 872 void
873 NoteLayer::eraseDrag(View *v, QMouseEvent *e) 873 FlexiNoteLayer::eraseDrag(View *v, QMouseEvent *e)
874 { 874 {
875 } 875 }
876 876
877 void 877 void
878 NoteLayer::eraseEnd(View *v, QMouseEvent *e) 878 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e)
879 { 879 {
880 if (!m_model || !m_editing) return; 880 if (!m_model || !m_editing) return;
881 881
882 m_editing = false; 882 m_editing = false;
883 883
884 NoteModel::Point p(0); 884 FlexiNoteModel::Point p(0);
885 if (!getPointToDrag(v, e->x(), e->y(), p)) return; 885 if (!getPointToDrag(v, e->x(), e->y(), p)) return;
886 if (p.frame != m_editingPoint.frame || p.value != m_editingPoint.value) return; 886 if (p.frame != m_editingPoint.frame || p.value != m_editingPoint.value) return;
887 887
888 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Erase Point")); 888 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, tr("Erase Point"));
889 889
890 m_editingCommand->deletePoint(m_editingPoint); 890 m_editingCommand->deletePoint(m_editingPoint);
891 891
892 finish(m_editingCommand); 892 finish(m_editingCommand);
893 m_editingCommand = 0; 893 m_editingCommand = 0;
894 m_editing = false; 894 m_editing = false;
895 } 895 }
896 896
897 void 897 void
898 NoteLayer::editStart(View *v, QMouseEvent *e) 898 FlexiNoteLayer::editStart(View *v, QMouseEvent *e)
899 { 899 {
900 // SVDEBUG << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; 900 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
901 901
902 if (!m_model) return; 902 if (!m_model) return;
903 903
904 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 904 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
905 m_originalPoint = m_editingPoint; 905 m_originalPoint = m_editingPoint;
916 m_dragStartX = e->x(); 916 m_dragStartX = e->x();
917 m_dragStartY = e->y(); 917 m_dragStartY = e->y();
918 } 918 }
919 919
920 void 920 void
921 NoteLayer::editDrag(View *v, QMouseEvent *e) 921 FlexiNoteLayer::editDrag(View *v, QMouseEvent *e)
922 { 922 {
923 // SVDEBUG << "NoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; 923 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
924 924
925 if (!m_model || !m_editing) return; 925 if (!m_model || !m_editing) return;
926 926
927 int xdist = e->x() - m_dragStartX; 927 int xdist = e->x() - m_dragStartX;
928 int ydist = e->y() - m_dragStartY; 928 int ydist = e->y() - m_dragStartY;
934 frame = frame / m_model->getResolution() * m_model->getResolution(); 934 frame = frame / m_model->getResolution() * m_model->getResolution();
935 935
936 float value = getValueForY(v, newy); 936 float value = getValueForY(v, newy);
937 937
938 if (!m_editingCommand) { 938 if (!m_editingCommand) {
939 m_editingCommand = new NoteModel::EditCommand(m_model, 939 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
940 tr("Drag Point")); 940 tr("Drag Point"));
941 } 941 }
942 942
943 m_editingCommand->deletePoint(m_editingPoint); 943 m_editingCommand->deletePoint(m_editingPoint);
944 m_editingPoint.frame = frame; 944 m_editingPoint.frame = frame;
945 m_editingPoint.value = value; 945 m_editingPoint.value = value;
946 m_editingCommand->addPoint(m_editingPoint); 946 m_editingCommand->addPoint(m_editingPoint);
947 } 947 }
948 948
949 void 949 void
950 NoteLayer::editEnd(View *, QMouseEvent *) 950 FlexiNoteLayer::editEnd(View *, QMouseEvent *)
951 { 951 {
952 // SVDEBUG << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; 952 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
953 if (!m_model || !m_editing) return; 953 if (!m_model || !m_editing) return;
954 954
955 if (m_editingCommand) { 955 if (m_editingCommand) {
956 956
957 QString newName = m_editingCommand->getName(); 957 QString newName = m_editingCommand->getName();
973 m_editingCommand = 0; 973 m_editingCommand = 0;
974 m_editing = false; 974 m_editing = false;
975 } 975 }
976 976
977 bool 977 bool
978 NoteLayer::editOpen(View *v, QMouseEvent *e) 978 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e)
979 { 979 {
980 if (!m_model) return false; 980 if (!m_model) return false;
981 981
982 NoteModel::Point note(0); 982 FlexiNoteModel::Point note(0);
983 if (!getPointToDrag(v, e->x(), e->y(), note)) return false; 983 if (!getPointToDrag(v, e->x(), e->y(), note)) return false;
984 984
985 // NoteModel::Point note = *points.begin(); 985 // FlexiNoteModel::Point note = *points.begin();
986 986
987 ItemEditDialog *dialog = new ItemEditDialog 987 ItemEditDialog *dialog = new ItemEditDialog
988 (m_model->getSampleRate(), 988 (m_model->getSampleRate(),
989 ItemEditDialog::ShowTime | 989 ItemEditDialog::ShowTime |
990 ItemEditDialog::ShowDuration | 990 ItemEditDialog::ShowDuration |
997 dialog->setFrameDuration(note.duration); 997 dialog->setFrameDuration(note.duration);
998 dialog->setText(note.label); 998 dialog->setText(note.label);
999 999
1000 if (dialog->exec() == QDialog::Accepted) { 1000 if (dialog->exec() == QDialog::Accepted) {
1001 1001
1002 NoteModel::Point newNote = note; 1002 FlexiNoteModel::Point newNote = note;
1003 newNote.frame = dialog->getFrameTime(); 1003 newNote.frame = dialog->getFrameTime();
1004 newNote.value = dialog->getValue(); 1004 newNote.value = dialog->getValue();
1005 newNote.duration = dialog->getFrameDuration(); 1005 newNote.duration = dialog->getFrameDuration();
1006 newNote.label = dialog->getText(); 1006 newNote.label = dialog->getText();
1007 1007
1008 NoteModel::EditCommand *command = new NoteModel::EditCommand 1008 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
1009 (m_model, tr("Edit Point")); 1009 (m_model, tr("Edit Point"));
1010 command->deletePoint(note); 1010 command->deletePoint(note);
1011 command->addPoint(newNote); 1011 command->addPoint(newNote);
1012 finish(command); 1012 finish(command);
1013 } 1013 }
1015 delete dialog; 1015 delete dialog;
1016 return true; 1016 return true;
1017 } 1017 }
1018 1018
1019 void 1019 void
1020 NoteLayer::moveSelection(Selection s, size_t newStartFrame) 1020 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame)
1021 { 1021 {
1022 if (!m_model) return; 1022 if (!m_model) return;
1023 1023
1024 NoteModel::EditCommand *command = 1024 FlexiNoteModel::EditCommand *command =
1025 new NoteModel::EditCommand(m_model, tr("Drag Selection")); 1025 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection"));
1026 1026
1027 NoteModel::PointList points = 1027 FlexiNoteModel::PointList points =
1028 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1028 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1029 1029
1030 for (NoteModel::PointList::iterator i = points.begin(); 1030 for (FlexiNoteModel::PointList::iterator i = points.begin();
1031 i != points.end(); ++i) { 1031 i != points.end(); ++i) {
1032 1032
1033 if (s.contains(i->frame)) { 1033 if (s.contains(i->frame)) {
1034 NoteModel::Point newPoint(*i); 1034 FlexiNoteModel::Point newPoint(*i);
1035 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); 1035 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
1036 command->deletePoint(*i); 1036 command->deletePoint(*i);
1037 command->addPoint(newPoint); 1037 command->addPoint(newPoint);
1038 } 1038 }
1039 } 1039 }
1040 1040
1041 finish(command); 1041 finish(command);
1042 } 1042 }
1043 1043
1044 void 1044 void
1045 NoteLayer::resizeSelection(Selection s, Selection newSize) 1045 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize)
1046 { 1046 {
1047 if (!m_model) return; 1047 if (!m_model) return;
1048 1048
1049 NoteModel::EditCommand *command = 1049 FlexiNoteModel::EditCommand *command =
1050 new NoteModel::EditCommand(m_model, tr("Resize Selection")); 1050 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection"));
1051 1051
1052 NoteModel::PointList points = 1052 FlexiNoteModel::PointList points =
1053 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1053 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1054 1054
1055 double ratio = 1055 double ratio =
1056 double(newSize.getEndFrame() - newSize.getStartFrame()) / 1056 double(newSize.getEndFrame() - newSize.getStartFrame()) /
1057 double(s.getEndFrame() - s.getStartFrame()); 1057 double(s.getEndFrame() - s.getStartFrame());
1058 1058
1059 for (NoteModel::PointList::iterator i = points.begin(); 1059 for (FlexiNoteModel::PointList::iterator i = points.begin();
1060 i != points.end(); ++i) { 1060 i != points.end(); ++i) {
1061 1061
1062 if (s.contains(i->frame)) { 1062 if (s.contains(i->frame)) {
1063 1063
1064 double targetStart = i->frame; 1064 double targetStart = i->frame;
1067 1067
1068 double targetEnd = i->frame + i->duration; 1068 double targetEnd = i->frame + i->duration;
1069 targetEnd = newSize.getStartFrame() + 1069 targetEnd = newSize.getStartFrame() +
1070 double(targetEnd - s.getStartFrame()) * ratio; 1070 double(targetEnd - s.getStartFrame()) * ratio;
1071 1071
1072 NoteModel::Point newPoint(*i); 1072 FlexiNoteModel::Point newPoint(*i);
1073 newPoint.frame = lrint(targetStart); 1073 newPoint.frame = lrint(targetStart);
1074 newPoint.duration = lrint(targetEnd - targetStart); 1074 newPoint.duration = lrint(targetEnd - targetStart);
1075 command->deletePoint(*i); 1075 command->deletePoint(*i);
1076 command->addPoint(newPoint); 1076 command->addPoint(newPoint);
1077 } 1077 }
1079 1079
1080 finish(command); 1080 finish(command);
1081 } 1081 }
1082 1082
1083 void 1083 void
1084 NoteLayer::deleteSelection(Selection s) 1084 FlexiNoteLayer::deleteSelection(Selection s)
1085 { 1085 {
1086 if (!m_model) return; 1086 if (!m_model) return;
1087 1087
1088 NoteModel::EditCommand *command = 1088 FlexiNoteModel::EditCommand *command =
1089 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); 1089 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points"));
1090 1090
1091 NoteModel::PointList points = 1091 FlexiNoteModel::PointList points =
1092 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1092 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1093 1093
1094 for (NoteModel::PointList::iterator i = points.begin(); 1094 for (FlexiNoteModel::PointList::iterator i = points.begin();
1095 i != points.end(); ++i) { 1095 i != points.end(); ++i) {
1096 1096
1097 if (s.contains(i->frame)) { 1097 if (s.contains(i->frame)) {
1098 command->deletePoint(*i); 1098 command->deletePoint(*i);
1099 } 1099 }
1101 1101
1102 finish(command); 1102 finish(command);
1103 } 1103 }
1104 1104
1105 void 1105 void
1106 NoteLayer::copy(View *v, Selection s, Clipboard &to) 1106 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to)
1107 { 1107 {
1108 if (!m_model) return; 1108 if (!m_model) return;
1109 1109
1110 NoteModel::PointList points = 1110 FlexiNoteModel::PointList points =
1111 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1111 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1112 1112
1113 for (NoteModel::PointList::iterator i = points.begin(); 1113 for (FlexiNoteModel::PointList::iterator i = points.begin();
1114 i != points.end(); ++i) { 1114 i != points.end(); ++i) {
1115 if (s.contains(i->frame)) { 1115 if (s.contains(i->frame)) {
1116 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label); 1116 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label);
1117 point.setReferenceFrame(alignToReference(v, i->frame)); 1117 point.setReferenceFrame(alignToReference(v, i->frame));
1118 to.addPoint(point); 1118 to.addPoint(point);
1119 } 1119 }
1120 } 1120 }
1121 } 1121 }
1122 1122
1123 bool 1123 bool
1124 NoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */) 1124 FlexiNoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
1125 { 1125 {
1126 if (!m_model) return false; 1126 if (!m_model) return false;
1127 1127
1128 const Clipboard::PointList &points = from.getPoints(); 1128 const Clipboard::PointList &points = from.getPoints();
1129 1129
1144 if (button == QMessageBox::Yes) { 1144 if (button == QMessageBox::Yes) {
1145 realign = true; 1145 realign = true;
1146 } 1146 }
1147 } 1147 }
1148 1148
1149 NoteModel::EditCommand *command = 1149 FlexiNoteModel::EditCommand *command =
1150 new NoteModel::EditCommand(m_model, tr("Paste")); 1150 new FlexiNoteModel::EditCommand(m_model, tr("Paste"));
1151 1151
1152 for (Clipboard::PointList::const_iterator i = points.begin(); 1152 for (Clipboard::PointList::const_iterator i = points.begin();
1153 i != points.end(); ++i) { 1153 i != points.end(); ++i) {
1154 1154
1155 if (!i->haveFrame()) continue; 1155 if (!i->haveFrame()) continue;
1167 } else { 1167 } else {
1168 frame = i->getFrame(); 1168 frame = i->getFrame();
1169 } 1169 }
1170 } 1170 }
1171 1171
1172 NoteModel::Point newPoint(frame); 1172 FlexiNoteModel::Point newPoint(frame);
1173 1173
1174 if (i->haveLabel()) newPoint.label = i->getLabel(); 1174 if (i->haveLabel()) newPoint.label = i->getLabel();
1175 if (i->haveValue()) newPoint.value = i->getValue(); 1175 if (i->haveValue()) newPoint.value = i->getValue();
1176 else newPoint.value = (m_model->getValueMinimum() + 1176 else newPoint.value = (m_model->getValueMinimum() +
1177 m_model->getValueMaximum()) / 2; 1177 m_model->getValueMaximum()) / 2;
1200 finish(command); 1200 finish(command);
1201 return true; 1201 return true;
1202 } 1202 }
1203 1203
1204 void 1204 void
1205 NoteLayer::addNoteOn(long frame, int pitch, int velocity) 1205 FlexiNoteLayer::addNoteOn(long frame, int pitch, int velocity)
1206 { 1206 {
1207 m_pendingNoteOns.insert(Note(frame, pitch, 0, float(velocity) / 127.0, "")); 1207 m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, ""));
1208 } 1208 }
1209 1209
1210 void 1210 void
1211 NoteLayer::addNoteOff(long frame, int pitch) 1211 FlexiNoteLayer::addNoteOff(long frame, int pitch)
1212 { 1212 {
1213 for (NoteSet::iterator i = m_pendingNoteOns.begin(); 1213 for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin();
1214 i != m_pendingNoteOns.end(); ++i) { 1214 i != m_pendingNoteOns.end(); ++i) {
1215 if (lrintf((*i).value) == pitch) { 1215 if (lrintf((*i).value) == pitch) {
1216 Note note(*i); 1216 FlexiNote note(*i);
1217 m_pendingNoteOns.erase(i); 1217 m_pendingNoteOns.erase(i);
1218 note.duration = frame - note.frame; 1218 note.duration = frame - note.frame;
1219 if (m_model) { 1219 if (m_model) {
1220 NoteModel::AddPointCommand *c = new NoteModel::AddPointCommand 1220 FlexiNoteModel::AddPointCommand *c = new FlexiNoteModel::AddPointCommand
1221 (m_model, note, tr("Record Note")); 1221 (m_model, note, tr("Record FlexiNote"));
1222 // execute and bundle: 1222 // execute and bundle:
1223 CommandHistory::getInstance()->addCommand(c, true, true); 1223 CommandHistory::getInstance()->addCommand(c, true, true);
1224 } 1224 }
1225 break; 1225 break;
1226 } 1226 }
1227 } 1227 }
1228 } 1228 }
1229 1229
1230 void 1230 void
1231 NoteLayer::abandonNoteOns() 1231 FlexiNoteLayer::abandonNoteOns()
1232 { 1232 {
1233 m_pendingNoteOns.clear(); 1233 m_pendingNoteOns.clear();
1234 } 1234 }
1235 1235
1236 int 1236 int
1237 NoteLayer::getDefaultColourHint(bool darkbg, bool &impose) 1237 FlexiNoteLayer::getDefaultColourHint(bool darkbg, bool &impose)
1238 { 1238 {
1239 impose = false; 1239 impose = false;
1240 return ColourDatabase::getInstance()->getColourIndex 1240 return ColourDatabase::getInstance()->getColourIndex
1241 (QString(darkbg ? "White" : "Black")); 1241 (QString(darkbg ? "White" : "Black"));
1242 } 1242 }
1243 1243
1244 void 1244 void
1245 NoteLayer::toXml(QTextStream &stream, 1245 FlexiNoteLayer::toXml(QTextStream &stream,
1246 QString indent, QString extraAttributes) const 1246 QString indent, QString extraAttributes) const
1247 { 1247 {
1248 SingleColourLayer::toXml(stream, indent, extraAttributes + 1248 SingleColourLayer::toXml(stream, indent, extraAttributes +
1249 QString(" verticalScale=\"%1\" scaleMinimum=\"%2\" scaleMaximum=\"%3\" ") 1249 QString(" verticalScale=\"%1\" scaleMinimum=\"%2\" scaleMaximum=\"%3\" ")
1250 .arg(m_verticalScale) 1250 .arg(m_verticalScale)
1251 .arg(m_scaleMinimum) 1251 .arg(m_scaleMinimum)
1252 .arg(m_scaleMaximum)); 1252 .arg(m_scaleMaximum));
1253 } 1253 }
1254 1254
1255 void 1255 void
1256 NoteLayer::setProperties(const QXmlAttributes &attributes) 1256 FlexiNoteLayer::setProperties(const QXmlAttributes &attributes)
1257 { 1257 {
1258 SingleColourLayer::setProperties(attributes); 1258 SingleColourLayer::setProperties(attributes);
1259 1259
1260 bool ok, alsoOk; 1260 bool ok, alsoOk;
1261 VerticalScale scale = (VerticalScale) 1261 VerticalScale scale = (VerticalScale)