annotate layer/FlexiNoteLayer.cpp @ 654:f215fba963aa tonioni

bugfixes to compile on Linux again
author gyorgyf
date Tue, 18 Jun 2013 22:18:10 +0100
parents f073611b31d1
children c572a0705223
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@30 2
Chris@30 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@59 7 This file copyright 2006 Chris Cannam.
Chris@30 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@30 14 */
Chris@30 15
matthiasm@620 16 #include "FlexiNoteLayer.h"
Chris@30 17
Chris@128 18 #include "data/model/Model.h"
Chris@30 19 #include "base/RealTime.h"
Chris@30 20 #include "base/Profiler.h"
Chris@30 21 #include "base/Pitch.h"
Chris@197 22 #include "base/LogRange.h"
Chris@439 23 #include "base/RangeMapper.h"
Chris@376 24 #include "ColourDatabase.h"
Chris@128 25 #include "view/View.h"
Chris@30 26
matthiasm@620 27 #include "data/model/FlexiNoteModel.h"
Chris@30 28
Chris@70 29 #include "widgets/ItemEditDialog.h"
Chris@70 30
Chris@30 31 #include <QPainter>
Chris@30 32 #include <QPainterPath>
Chris@30 33 #include <QMouseEvent>
Chris@316 34 #include <QTextStream>
Chris@360 35 #include <QMessageBox>
Chris@30 36
Chris@30 37 #include <iostream>
Chris@30 38 #include <cmath>
Chris@551 39 #include <utility>
gyorgyf@654 40 #include <limits>
Chris@30 41
matthiasm@620 42 FlexiNoteLayer::FlexiNoteLayer() :
gyorgyf@646 43 SingleColourLayer(),
gyorgyf@625 44
gyorgyf@646 45 // m_model(0),
gyorgyf@646 46 // m_editing(false),
gyorgyf@646 47 // m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
gyorgyf@646 48 // m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
gyorgyf@646 49 // m_editingCommand(0),
gyorgyf@646 50 // m_verticalScale(AutoAlignScale),
gyorgyf@646 51 // m_scaleMinimum(0),
gyorgyf@646 52 // m_scaleMaximum(0)
gyorgyf@625 53
gyorgyf@627 54 m_model(0),
gyorgyf@628 55 m_editing(false),
gyorgyf@627 56 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
gyorgyf@627 57 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
gyorgyf@627 58 m_editingCommand(0),
matthiasm@634 59 m_verticalScale(AutoAlignScale),
gyorgyf@628 60 m_scaleMinimum(34),
gyorgyf@627 61 m_scaleMaximum(77)
Chris@30 62 {
Chris@30 63 }
Chris@30 64
Chris@30 65 void
gyorgyf@626 66 FlexiNoteLayer::setModel(FlexiNoteModel *model)
Chris@30 67 {
Chris@30 68 if (m_model == model) return;
Chris@30 69 m_model = model;
Chris@30 70
Chris@320 71 connectSignals(m_model);
Chris@30 72
gyorgyf@628 73 // m_scaleMinimum = 0;
gyorgyf@628 74 // m_scaleMaximum = 0;
Chris@439 75
Chris@30 76 emit modelReplaced();
Chris@30 77 }
Chris@30 78
Chris@30 79 Layer::PropertyList
matthiasm@620 80 FlexiNoteLayer::getProperties() const
Chris@30 81 {
Chris@287 82 PropertyList list = SingleColourLayer::getProperties();
Chris@87 83 list.push_back("Vertical Scale");
Chris@100 84 list.push_back("Scale Units");
Chris@30 85 return list;
Chris@30 86 }
Chris@30 87
Chris@87 88 QString
matthiasm@620 89 FlexiNoteLayer::getPropertyLabel(const PropertyName &name) const
Chris@87 90 {
Chris@87 91 if (name == "Vertical Scale") return tr("Vertical Scale");
Chris@116 92 if (name == "Scale Units") return tr("Scale Units");
Chris@287 93 return SingleColourLayer::getPropertyLabel(name);
Chris@87 94 }
Chris@87 95
Chris@30 96 Layer::PropertyType
matthiasm@620 97 FlexiNoteLayer::getPropertyType(const PropertyName &name) const
Chris@30 98 {
Chris@100 99 if (name == "Scale Units") return UnitsProperty;
Chris@287 100 if (name == "Vertical Scale") return ValueProperty;
Chris@287 101 return SingleColourLayer::getPropertyType(name);
Chris@30 102 }
Chris@30 103
Chris@198 104 QString
matthiasm@620 105 FlexiNoteLayer::getPropertyGroupName(const PropertyName &name) const
Chris@198 106 {
Chris@198 107 if (name == "Vertical Scale" || name == "Scale Units") {
Chris@198 108 return tr("Scale");
Chris@198 109 }
Chris@287 110 return SingleColourLayer::getPropertyGroupName(name);
Chris@198 111 }
Chris@198 112
Chris@30 113 int
matthiasm@620 114 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 115 int *min, int *max, int *deflt) const
Chris@30 116 {
Chris@216 117 int val = 0;
Chris@30 118
Chris@287 119 if (name == "Vertical Scale") {
gyorgyf@646 120
gyorgyf@646 121 if (min) *min = 0;
gyorgyf@646 122 if (max) *max = 3;
Chris@216 123 if (deflt) *deflt = int(AutoAlignScale);
gyorgyf@646 124
gyorgyf@646 125 val = int(m_verticalScale);
Chris@30 126
Chris@100 127 } else if (name == "Scale Units") {
Chris@100 128
Chris@216 129 if (deflt) *deflt = 0;
Chris@100 130 if (m_model) {
Chris@216 131 val = UnitDatabase::getInstance()->getUnitId
Chris@100 132 (m_model->getScaleUnits());
Chris@100 133 }
Chris@100 134
Chris@30 135 } else {
Chris@216 136
gyorgyf@646 137 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@30 138 }
Chris@30 139
Chris@216 140 return val;
Chris@30 141 }
Chris@30 142
Chris@30 143 QString
matthiasm@620 144 FlexiNoteLayer::getPropertyValueLabel(const PropertyName &name,
Chris@287 145 int value) const
Chris@30 146 {
Chris@287 147 if (name == "Vertical Scale") {
gyorgyf@646 148 switch (value) {
gyorgyf@646 149 default:
gyorgyf@646 150 case 0: return tr("Auto-Align");
gyorgyf@646 151 case 1: return tr("Linear");
gyorgyf@646 152 case 2: return tr("Log");
gyorgyf@646 153 case 3: return tr("MIDI Notes");
gyorgyf@646 154 }
Chris@30 155 }
Chris@287 156 return SingleColourLayer::getPropertyValueLabel(name, value);
Chris@30 157 }
Chris@30 158
Chris@30 159 void
matthiasm@620 160 FlexiNoteLayer::setProperty(const PropertyName &name, int value)
Chris@30 161 {
Chris@287 162 if (name == "Vertical Scale") {
gyorgyf@646 163 setVerticalScale(VerticalScale(value));
Chris@100 164 } else if (name == "Scale Units") {
Chris@100 165 if (m_model) {
Chris@100 166 m_model->setScaleUnits
Chris@100 167 (UnitDatabase::getInstance()->getUnitById(value));
Chris@100 168 emit modelChanged();
Chris@100 169 }
Chris@287 170 } else {
Chris@287 171 return SingleColourLayer::setProperty(name, value);
Chris@30 172 }
Chris@30 173 }
Chris@30 174
Chris@30 175 void
matthiasm@620 176 FlexiNoteLayer::setVerticalScale(VerticalScale scale)
Chris@30 177 {
Chris@30 178 if (m_verticalScale == scale) return;
Chris@30 179 m_verticalScale = scale;
Chris@30 180 emit layerParametersChanged();
Chris@30 181 }
Chris@30 182
Chris@30 183 bool
matthiasm@620 184 FlexiNoteLayer::isLayerScrollable(const View *v) const
Chris@30 185 {
Chris@30 186 QPoint discard;
Chris@44 187 return !v->shouldIlluminateLocalFeatures(this, discard);
Chris@30 188 }
Chris@30 189
Chris@79 190 bool
matthiasm@620 191 FlexiNoteLayer::shouldConvertMIDIToHz() const
Chris@101 192 {
Chris@101 193 QString unit = m_model->getScaleUnits();
Chris@101 194 return (unit != "Hz");
Chris@101 195 // if (unit == "" ||
Chris@101 196 // unit.startsWith("MIDI") ||
Chris@101 197 // unit.startsWith("midi")) return true;
Chris@101 198 // return false;
Chris@101 199 }
Chris@101 200
Chris@101 201 bool
matthiasm@620 202 FlexiNoteLayer::getValueExtents(float &min, float &max,
Chris@101 203 bool &logarithmic, QString &unit) const
Chris@79 204 {
Chris@79 205 if (!m_model) return false;
Chris@79 206 min = m_model->getValueMinimum();
Chris@79 207 max = m_model->getValueMaximum();
Chris@101 208
Chris@105 209 if (shouldConvertMIDIToHz()) {
Chris@105 210 unit = "Hz";
Chris@105 211 min = Pitch::getFrequencyForPitch(lrintf(min));
Chris@105 212 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
Chris@105 213 } else unit = m_model->getScaleUnits();
Chris@101 214
Chris@101 215 if (m_verticalScale == MIDIRangeScale ||
Chris@101 216 m_verticalScale == LogScale) logarithmic = true;
Chris@101 217
Chris@101 218 return true;
Chris@101 219 }
Chris@101 220
Chris@101 221 bool
matthiasm@620 222 FlexiNoteLayer::getDisplayExtents(float &min, float &max) const
Chris@101 223 {
matthiasm@623 224 if (!m_model || shouldAutoAlign()) {
gyorgyf@646 225 std::cerr << "No model or shouldAutoAlign()" << std::endl;
gyorgyf@646 226 return false;
gyorgyf@646 227 }
Chris@101 228
Chris@101 229 if (m_verticalScale == MIDIRangeScale) {
Chris@101 230 min = Pitch::getFrequencyForPitch(0);
matthiasm@634 231 max = Pitch::getFrequencyForPitch(127);
Chris@101 232 return true;
Chris@101 233 }
Chris@101 234
Chris@439 235 if (m_scaleMinimum == m_scaleMaximum) {
Chris@455 236 min = m_model->getValueMinimum();
Chris@455 237 max = m_model->getValueMaximum();
Chris@455 238 } else {
Chris@455 239 min = m_scaleMinimum;
Chris@455 240 max = m_scaleMaximum;
Chris@439 241 }
Chris@439 242
Chris@101 243 if (shouldConvertMIDIToHz()) {
Chris@101 244 min = Pitch::getFrequencyForPitch(lrintf(min));
Chris@101 245 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
Chris@101 246 }
Chris@101 247
Chris@79 248 return true;
Chris@79 249 }
Chris@79 250
Chris@439 251 bool
matthiasm@620 252 FlexiNoteLayer::setDisplayExtents(float min, float max)
Chris@439 253 {
Chris@439 254 if (!m_model) return false;
Chris@439 255
Chris@439 256 if (min == max) {
Chris@439 257 if (min == 0.f) {
Chris@439 258 max = 1.f;
Chris@439 259 } else {
Chris@439 260 max = min * 1.0001;
Chris@439 261 }
Chris@439 262 }
Chris@439 263
Chris@439 264 m_scaleMinimum = min;
Chris@439 265 m_scaleMaximum = max;
Chris@439 266
matthiasm@620 267 // SVDEBUG << "FlexiNoteLayer::setDisplayExtents: min = " << min << ", max = " << max << endl;
Chris@439 268
Chris@439 269 emit layerParametersChanged();
Chris@439 270 return true;
Chris@439 271 }
Chris@439 272
Chris@439 273 int
matthiasm@620 274 FlexiNoteLayer::getVerticalZoomSteps(int &defaultStep) const
Chris@439 275 {
Chris@439 276 if (shouldAutoAlign()) return 0;
Chris@439 277 if (!m_model) return 0;
Chris@439 278
Chris@439 279 defaultStep = 0;
Chris@439 280 return 100;
Chris@439 281 }
Chris@439 282
Chris@439 283 int
matthiasm@620 284 FlexiNoteLayer::getCurrentVerticalZoomStep() const
Chris@439 285 {
Chris@439 286 if (shouldAutoAlign()) return 0;
Chris@439 287 if (!m_model) return 0;
Chris@439 288
Chris@439 289 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
Chris@439 290 if (!mapper) return 0;
Chris@439 291
Chris@439 292 float dmin, dmax;
Chris@439 293 getDisplayExtents(dmin, dmax);
Chris@439 294
Chris@439 295 int nr = mapper->getPositionForValue(dmax - dmin);
Chris@439 296
Chris@439 297 delete mapper;
Chris@439 298
Chris@439 299 return 100 - nr;
Chris@439 300 }
Chris@439 301
Chris@439 302 //!!! lots of duplication with TimeValueLayer
Chris@439 303
Chris@439 304 void
matthiasm@620 305 FlexiNoteLayer::setVerticalZoomStep(int step)
Chris@439 306 {
Chris@439 307 if (shouldAutoAlign()) return;
Chris@439 308 if (!m_model) return;
Chris@439 309
Chris@439 310 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
Chris@439 311 if (!mapper) return;
Chris@439 312
Chris@439 313 float min, max;
Chris@439 314 bool logarithmic;
Chris@439 315 QString unit;
Chris@439 316 getValueExtents(min, max, logarithmic, unit);
Chris@439 317
Chris@439 318 float dmin, dmax;
Chris@439 319 getDisplayExtents(dmin, dmax);
Chris@439 320
Chris@439 321 float newdist = mapper->getValueForPosition(100 - step);
Chris@439 322
Chris@439 323 float newmin, newmax;
Chris@439 324
Chris@439 325 if (logarithmic) {
Chris@439 326
Chris@439 327 // see SpectrogramLayer::setVerticalZoomStep
Chris@439 328
Chris@439 329 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
Chris@439 330 newmin = newmax - newdist;
Chris@439 331
Chris@439 332 // std::cerr << "newmin = " << newmin << ", newmax = " << newmax << std::endl;
Chris@439 333
Chris@439 334 } else {
Chris@439 335 float dmid = (dmax + dmin) / 2;
Chris@439 336 newmin = dmid - newdist / 2;
Chris@439 337 newmax = dmid + newdist / 2;
Chris@439 338 }
Chris@439 339
Chris@439 340 if (newmin < min) {
Chris@439 341 newmax += (min - newmin);
Chris@439 342 newmin = min;
Chris@439 343 }
Chris@439 344 if (newmax > max) {
Chris@439 345 newmax = max;
Chris@439 346 }
Chris@439 347
matthiasm@620 348 SVDEBUG << "FlexiNoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl;
Chris@439 349
Chris@439 350 setDisplayExtents(newmin, newmax);
Chris@439 351 }
Chris@439 352
Chris@439 353 RangeMapper *
matthiasm@620 354 FlexiNoteLayer::getNewVerticalZoomRangeMapper() const
Chris@439 355 {
Chris@439 356 if (!m_model) return 0;
Chris@439 357
Chris@439 358 RangeMapper *mapper;
Chris@439 359
Chris@439 360 float min, max;
Chris@439 361 bool logarithmic;
Chris@439 362 QString unit;
Chris@439 363 getValueExtents(min, max, logarithmic, unit);
Chris@439 364
Chris@439 365 if (min == max) return 0;
Chris@439 366
Chris@439 367 if (logarithmic) {
Chris@439 368 mapper = new LogRangeMapper(0, 100, min, max, unit);
Chris@439 369 } else {
Chris@439 370 mapper = new LinearRangeMapper(0, 100, min, max, unit);
Chris@439 371 }
Chris@439 372
Chris@439 373 return mapper;
Chris@439 374 }
Chris@439 375
matthiasm@620 376 FlexiNoteModel::PointList
matthiasm@620 377 FlexiNoteLayer::getLocalPoints(View *v, int x) const
Chris@30 378 {
matthiasm@620 379 if (!m_model) return FlexiNoteModel::PointList();
Chris@30 380
Chris@44 381 long frame = v->getFrameForX(x);
Chris@30 382
matthiasm@620 383 FlexiNoteModel::PointList onPoints =
gyorgyf@646 384 m_model->getPoints(frame);
Chris@30 385
Chris@30 386 if (!onPoints.empty()) {
gyorgyf@646 387 return onPoints;
Chris@30 388 }
Chris@30 389
matthiasm@620 390 FlexiNoteModel::PointList prevPoints =
gyorgyf@646 391 m_model->getPreviousPoints(frame);
matthiasm@620 392 FlexiNoteModel::PointList nextPoints =
gyorgyf@646 393 m_model->getNextPoints(frame);
Chris@30 394
matthiasm@620 395 FlexiNoteModel::PointList usePoints = prevPoints;
Chris@30 396
Chris@30 397 if (prevPoints.empty()) {
gyorgyf@646 398 usePoints = nextPoints;
Chris@248 399 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
gyorgyf@646 400 !(nextPoints.begin()->frame > v->getEndFrame())) {
gyorgyf@646 401 usePoints = nextPoints;
Chris@248 402 } else if (long(nextPoints.begin()->frame) - frame <
gyorgyf@646 403 frame - long(prevPoints.begin()->frame)) {
gyorgyf@646 404 usePoints = nextPoints;
Chris@30 405 }
Chris@30 406
Chris@30 407 if (!usePoints.empty()) {
gyorgyf@646 408 int fuzz = 2;
gyorgyf@646 409 int px = v->getXForFrame(usePoints.begin()->frame);
gyorgyf@646 410 if ((px > x && px - x > fuzz) ||
gyorgyf@646 411 (px < x && x - px > fuzz + 1)) {
gyorgyf@646 412 usePoints.clear();
gyorgyf@646 413 }
Chris@30 414 }
Chris@30 415
Chris@30 416 return usePoints;
Chris@30 417 }
Chris@30 418
Chris@550 419 bool
matthiasm@622 420 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const
Chris@550 421 {
Chris@550 422 if (!m_model) return false;
Chris@550 423
Chris@550 424 long frame = v->getFrameForX(x);
Chris@550 425
matthiasm@620 426 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
Chris@550 427 if (onPoints.empty()) return false;
Chris@550 428
Chris@551 429 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
Chris@550 430
Chris@550 431 int nearestDistance = -1;
Chris@550 432
matthiasm@620 433 for (FlexiNoteModel::PointList::const_iterator i = onPoints.begin();
Chris@550 434 i != onPoints.end(); ++i) {
Chris@550 435
Chris@550 436 int distance = getYForValue(v, (*i).value) - y;
Chris@550 437 if (distance < 0) distance = -distance;
Chris@550 438 if (nearestDistance == -1 || distance < nearestDistance) {
Chris@550 439 nearestDistance = distance;
Chris@550 440 p = *i;
Chris@550 441 }
Chris@550 442 }
Chris@550 443
Chris@550 444 return true;
Chris@550 445 }
Chris@550 446
gyorgyf@646 447 bool
gyorgyf@646 448 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const
gyorgyf@646 449 {
gyorgyf@647 450 // GF: find the note that is closest to the cursor
gyorgyf@646 451 if (!m_model) return false;
gyorgyf@646 452
gyorgyf@646 453 long frame = v->getFrameForX(x);
gyorgyf@646 454
gyorgyf@646 455 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
gyorgyf@646 456 if (onPoints.empty()) return false;
gyorgyf@646 457
gyorgyf@646 458 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
gyorgyf@646 459
gyorgyf@646 460 int nearestDistance = -1;
gyorgyf@646 461
gyorgyf@646 462 for (FlexiNoteModel::PointList::const_iterator i = onPoints.begin();
gyorgyf@646 463 i != onPoints.end(); ++i) {
gyorgyf@646 464
gyorgyf@646 465 int distance = getYForValue(v, (*i).value) - y;
gyorgyf@646 466 if (distance < 0) distance = -distance;
gyorgyf@646 467 if (nearestDistance == -1 || distance < nearestDistance) {
gyorgyf@646 468 nearestDistance = distance;
gyorgyf@646 469 p = *i;
gyorgyf@646 470 }
gyorgyf@646 471 }
gyorgyf@646 472
gyorgyf@646 473 return true;
gyorgyf@646 474 }
gyorgyf@646 475
Chris@30 476 QString
matthiasm@620 477 FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const
Chris@30 478 {
Chris@30 479 int x = pos.x();
Chris@30 480
Chris@30 481 if (!m_model || !m_model->getSampleRate()) return "";
Chris@30 482
matthiasm@620 483 FlexiNoteModel::PointList points = getLocalPoints(v, x);
Chris@30 484
Chris@30 485 if (points.empty()) {
gyorgyf@653 486 if (!m_model->isReady()) {
gyorgyf@653 487 return tr("In progress");
gyorgyf@653 488 } else {
gyorgyf@653 489 return tr("No local points");
gyorgyf@653 490 }
Chris@30 491 }
Chris@30 492
matthiasm@620 493 FlexiNote note(0);
matthiasm@620 494 FlexiNoteModel::PointList::iterator i;
Chris@30 495
Chris@30 496 for (i = points.begin(); i != points.end(); ++i) {
Chris@30 497
gyorgyf@653 498 int y = getYForValue(v, i->value);
gyorgyf@653 499 int h = NOTE_HEIGHT; // GF: larger notes
Chris@30 500
gyorgyf@653 501 if (m_model->getValueQuantization() != 0.0) {
gyorgyf@653 502 h = y - getYForValue(v, i->value + m_model->getValueQuantization());
gyorgyf@653 503 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT;
gyorgyf@653 504 }
Chris@30 505
gyorgyf@647 506 // GF: this is not quite correct
gyorgyf@653 507 if (pos.y() >= y - 4 && pos.y() <= y + h) {
gyorgyf@653 508 note = *i;
gyorgyf@653 509 break;
gyorgyf@653 510 }
Chris@30 511 }
Chris@30 512
Chris@30 513 if (i == points.end()) return tr("No local points");
Chris@30 514
Chris@30 515 RealTime rt = RealTime::frame2RealTime(note.frame,
gyorgyf@653 516 m_model->getSampleRate());
Chris@30 517 RealTime rd = RealTime::frame2RealTime(note.duration,
gyorgyf@653 518 m_model->getSampleRate());
Chris@30 519
Chris@101 520 QString pitchText;
Chris@101 521
Chris@101 522 if (shouldConvertMIDIToHz()) {
Chris@101 523
Chris@101 524 int mnote = lrintf(note.value);
Chris@101 525 int cents = lrintf((note.value - mnote) * 100);
Chris@101 526 float freq = Pitch::getFrequencyForPitch(mnote, cents);
Chris@544 527 pitchText = tr("%1 (%2, %3 Hz)")
Chris@544 528 .arg(Pitch::getPitchLabel(mnote, cents))
Chris@544 529 .arg(mnote)
Chris@544 530 .arg(freq);
Chris@101 531
Chris@101 532 } else if (m_model->getScaleUnits() == "Hz") {
Chris@101 533
Chris@544 534 pitchText = tr("%1 Hz (%2, %3)")
Chris@101 535 .arg(note.value)
Chris@544 536 .arg(Pitch::getPitchLabelForFrequency(note.value))
Chris@544 537 .arg(Pitch::getPitchForFrequency(note.value));
Chris@101 538
Chris@101 539 } else {
Chris@234 540 pitchText = tr("%1 %2")
Chris@101 541 .arg(note.value).arg(m_model->getScaleUnits());
Chris@101 542 }
Chris@101 543
Chris@30 544 QString text;
Chris@30 545
Chris@30 546 if (note.label == "") {
gyorgyf@653 547 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label"))
gyorgyf@653 548 .arg(rt.toText(true).c_str())
gyorgyf@653 549 .arg(pitchText)
gyorgyf@653 550 .arg(rd.toText(true).c_str());
Chris@30 551 } else {
gyorgyf@653 552 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4"))
gyorgyf@653 553 .arg(rt.toText(true).c_str())
gyorgyf@653 554 .arg(pitchText)
gyorgyf@653 555 .arg(rd.toText(true).c_str())
gyorgyf@653 556 .arg(note.label);
Chris@30 557 }
Chris@30 558
Chris@44 559 pos = QPoint(v->getXForFrame(note.frame),
gyorgyf@653 560 getYForValue(v, note.value));
Chris@30 561 return text;
Chris@30 562 }
Chris@30 563
Chris@30 564 bool
matthiasm@620 565 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
gyorgyf@646 566 size_t &resolution,
gyorgyf@646 567 SnapType snap) const
Chris@30 568 {
Chris@30 569 if (!m_model) {
gyorgyf@646 570 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
Chris@30 571 }
Chris@30 572
Chris@30 573 resolution = m_model->getResolution();
matthiasm@620 574 FlexiNoteModel::PointList points;
Chris@30 575
Chris@30 576 if (snap == SnapNeighbouring) {
gyorgyf@646 577
gyorgyf@646 578 points = getLocalPoints(v, v->getXForFrame(frame));
gyorgyf@646 579 if (points.empty()) return false;
gyorgyf@646 580 frame = points.begin()->frame;
gyorgyf@646 581 return true;
Chris@30 582 }
Chris@30 583
Chris@30 584 points = m_model->getPoints(frame, frame);
Chris@30 585 int snapped = frame;
Chris@30 586 bool found = false;
Chris@30 587
matthiasm@620 588 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
gyorgyf@646 589 i != points.end(); ++i) {
Chris@30 590
gyorgyf@646 591 if (snap == SnapRight) {
Chris@30 592
gyorgyf@646 593 if (i->frame > frame) {
gyorgyf@646 594 snapped = i->frame;
gyorgyf@646 595 found = true;
gyorgyf@646 596 break;
gyorgyf@646 597 }
Chris@30 598
gyorgyf@646 599 } else if (snap == SnapLeft) {
Chris@30 600
gyorgyf@646 601 if (i->frame <= frame) {
gyorgyf@646 602 snapped = i->frame;
gyorgyf@646 603 found = true; // don't break, as the next may be better
gyorgyf@646 604 } else {
gyorgyf@646 605 break;
gyorgyf@646 606 }
Chris@30 607
gyorgyf@646 608 } else { // nearest
Chris@30 609
gyorgyf@646 610 FlexiNoteModel::PointList::const_iterator j = i;
gyorgyf@646 611 ++j;
Chris@30 612
gyorgyf@646 613 if (j == points.end()) {
Chris@30 614
gyorgyf@646 615 snapped = i->frame;
gyorgyf@646 616 found = true;
gyorgyf@646 617 break;
Chris@30 618
gyorgyf@646 619 } else if (j->frame >= frame) {
Chris@30 620
gyorgyf@646 621 if (j->frame - frame < frame - i->frame) {
gyorgyf@646 622 snapped = j->frame;
gyorgyf@646 623 } else {
gyorgyf@646 624 snapped = i->frame;
gyorgyf@646 625 }
gyorgyf@646 626 found = true;
gyorgyf@646 627 break;
gyorgyf@646 628 }
gyorgyf@646 629 }
Chris@30 630 }
Chris@30 631
Chris@30 632 frame = snapped;
Chris@30 633 return found;
Chris@30 634 }
Chris@30 635
Chris@101 636 void
matthiasm@620 637 FlexiNoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
Chris@30 638 {
Chris@101 639 min = 0.0;
Chris@101 640 max = 0.0;
Chris@101 641 log = false;
Chris@42 642
Chris@101 643 QString queryUnits;
Chris@101 644 if (shouldConvertMIDIToHz()) queryUnits = "Hz";
Chris@101 645 else queryUnits = m_model->getScaleUnits();
Chris@30 646
Chris@439 647 if (shouldAutoAlign()) {
Chris@30 648
Chris@101 649 if (!v->getValueExtents(queryUnits, min, max, log)) {
Chris@30 650
Chris@101 651 min = m_model->getValueMinimum();
Chris@101 652 max = m_model->getValueMaximum();
Chris@42 653
Chris@101 654 if (shouldConvertMIDIToHz()) {
Chris@101 655 min = Pitch::getFrequencyForPitch(lrintf(min));
Chris@101 656 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
Chris@101 657 }
Chris@42 658
gyorgyf@635 659 // std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl;
Chris@105 660
Chris@101 661 } else if (log) {
Chris@101 662
Chris@197 663 LogRange::mapRange(min, max);
Chris@105 664
gyorgyf@635 665 // std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl;
Chris@105 666
Chris@101 667 }
Chris@101 668
Chris@101 669 } else {
Chris@101 670
Chris@439 671 getDisplayExtents(min, max);
Chris@101 672
Chris@101 673 if (m_verticalScale == MIDIRangeScale) {
Chris@101 674 min = Pitch::getFrequencyForPitch(0);
matthiasm@623 675 max = Pitch::getFrequencyForPitch(70);
Chris@101 676 } else if (shouldConvertMIDIToHz()) {
Chris@101 677 min = Pitch::getFrequencyForPitch(lrintf(min));
Chris@101 678 max = Pitch::getFrequencyForPitch(lrintf(max + 1));
Chris@101 679 }
Chris@101 680
Chris@101 681 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) {
Chris@197 682 LogRange::mapRange(min, max);
Chris@101 683 log = true;
Chris@101 684 }
Chris@30 685 }
Chris@30 686
Chris@101 687 if (max == min) max = min + 1.0;
Chris@101 688 }
Chris@30 689
Chris@101 690 int
matthiasm@620 691 FlexiNoteLayer::getYForValue(View *v, float val) const
Chris@101 692 {
Chris@101 693 float min = 0.0, max = 0.0;
Chris@101 694 bool logarithmic = false;
Chris@101 695 int h = v->height();
Chris@101 696
Chris@101 697 getScaleExtents(v, min, max, logarithmic);
Chris@101 698
matthiasm@620 699 // std::cerr << "FlexiNoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl;
Chris@101 700
Chris@101 701 if (shouldConvertMIDIToHz()) {
Chris@101 702 val = Pitch::getFrequencyForPitch(lrintf(val),
Chris@101 703 lrintf((val - lrintf(val)) * 100));
Chris@101 704 // std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl;
Chris@101 705 }
Chris@101 706
Chris@101 707 if (logarithmic) {
Chris@197 708 val = LogRange::map(val);
Chris@101 709 // std::cerr << "logarithmic true, val now = " << val << std::endl;
Chris@101 710 }
Chris@101 711
Chris@101 712 int y = int(h - ((val - min) * h) / (max - min)) - 1;
Chris@101 713 // std::cerr << "y = " << y << std::endl;
Chris@101 714 return y;
Chris@30 715 }
Chris@30 716
Chris@30 717 float
matthiasm@620 718 FlexiNoteLayer::getValueForY(View *v, int y) const
Chris@30 719 {
Chris@101 720 float min = 0.0, max = 0.0;
Chris@101 721 bool logarithmic = false;
Chris@44 722 int h = v->height();
Chris@30 723
Chris@101 724 getScaleExtents(v, min, max, logarithmic);
Chris@101 725
Chris@101 726 float val = min + (float(h - y) * float(max - min)) / h;
Chris@101 727
Chris@101 728 if (logarithmic) {
Chris@197 729 val = powf(10.f, val);
Chris@101 730 }
Chris@101 731
Chris@101 732 if (shouldConvertMIDIToHz()) {
Chris@101 733 val = Pitch::getPitchForFrequency(val);
Chris@101 734 }
Chris@101 735
Chris@101 736 return val;
Chris@30 737 }
Chris@30 738
Chris@439 739 bool
matthiasm@620 740 FlexiNoteLayer::shouldAutoAlign() const
Chris@439 741 {
Chris@439 742 if (!m_model) return false;
Chris@439 743 return (m_verticalScale == AutoAlignScale);
Chris@439 744 }
Chris@439 745
Chris@30 746 void
matthiasm@620 747 FlexiNoteLayer::paint(View *v, QPainter &paint, QRect rect) const
Chris@30 748 {
Chris@30 749 if (!m_model || !m_model->isOK()) return;
Chris@30 750
Chris@30 751 int sampleRate = m_model->getSampleRate();
Chris@30 752 if (!sampleRate) return;
Chris@30 753
matthiasm@620 754 // Profiler profiler("FlexiNoteLayer::paint", true);
Chris@30 755
Chris@30 756 int x0 = rect.left(), x1 = rect.right();
Chris@44 757 long frame0 = v->getFrameForX(x0);
Chris@44 758 long frame1 = v->getFrameForX(x1);
Chris@30 759
matthiasm@620 760 FlexiNoteModel::PointList points(m_model->getPoints(frame0, frame1));
Chris@30 761 if (points.empty()) return;
Chris@30 762
Chris@287 763 paint.setPen(getBaseQColor());
Chris@30 764
Chris@287 765 QColor brushColour(getBaseQColor());
Chris@30 766 brushColour.setAlpha(80);
Chris@30 767
matthiasm@620 768 // SVDEBUG << "FlexiNoteLayer::paint: resolution is "
gyorgyf@646 769 // << m_model->getResolution() << " frames" << endl;
Chris@30 770
Chris@30 771 float min = m_model->getValueMinimum();
Chris@30 772 float max = m_model->getValueMaximum();
Chris@30 773 if (max == min) max = min + 1.0;
Chris@30 774
Chris@30 775 QPoint localPos;
matthiasm@620 776 FlexiNoteModel::Point illuminatePoint(0);
Chris@551 777 bool shouldIlluminate = false;
Chris@30 778
Chris@44 779 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
Chris@551 780 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(),
Chris@551 781 illuminatePoint);
Chris@30 782 }
Chris@30 783
Chris@30 784 paint.save();
Chris@30 785 paint.setRenderHint(QPainter::Antialiasing, false);
Chris@30 786
matthiasm@620 787 for (FlexiNoteModel::PointList::const_iterator i = points.begin();
gyorgyf@646 788 i != points.end(); ++i) {
Chris@30 789
gyorgyf@646 790 const FlexiNoteModel::Point &p(*i);
Chris@30 791
gyorgyf@646 792 int x = v->getXForFrame(p.frame);
gyorgyf@646 793 int y = getYForValue(v, p.value);
gyorgyf@646 794 int w = v->getXForFrame(p.frame + p.duration) - x;
gyorgyf@647 795 int h = NOTE_HEIGHT; //GF: larger notes
gyorgyf@646 796
gyorgyf@646 797 if (m_model->getValueQuantization() != 0.0) {
gyorgyf@646 798 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
gyorgyf@647 799 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT; //GF: larger notes
gyorgyf@646 800 }
Chris@30 801
gyorgyf@646 802 if (w < 1) w = 1;
gyorgyf@646 803 paint.setPen(getBaseQColor());
gyorgyf@646 804 paint.setBrush(brushColour);
Chris@30 805
matthiasm@651 806 // if (shouldIlluminate &&
matthiasm@651 807 // // "illuminatePoint == p"
matthiasm@651 808 // !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) &&
matthiasm@651 809 // !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) {
matthiasm@651 810 //
matthiasm@651 811 // paint.setPen(v->getForeground());
matthiasm@651 812 // paint.setBrush(v->getForeground());
matthiasm@651 813 //
matthiasm@651 814 // QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits());
matthiasm@651 815 // v->drawVisibleText(paint,
matthiasm@651 816 // x - paint.fontMetrics().width(vlabel) - 2,
matthiasm@651 817 // y + paint.fontMetrics().height()/2
matthiasm@651 818 // - paint.fontMetrics().descent(),
matthiasm@651 819 // vlabel, View::OutlinedText);
matthiasm@651 820 //
matthiasm@651 821 // QString hlabel = RealTime::frame2RealTime
matthiasm@651 822 // (p.frame, m_model->getSampleRate()).toText(true).c_str();
matthiasm@651 823 // v->drawVisibleText(paint,
matthiasm@651 824 // x,
matthiasm@651 825 // y - h/2 - paint.fontMetrics().descent() - 2,
matthiasm@651 826 // hlabel, View::OutlinedText);
matthiasm@651 827 // }
gyorgyf@646 828
gyorgyf@646 829 paint.drawRect(x, y - h/2, w, h);
Chris@30 830 }
Chris@30 831
Chris@30 832 paint.restore();
Chris@30 833 }
Chris@30 834
Chris@30 835 void
matthiasm@620 836 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e)
Chris@30 837 {
matthiasm@620 838 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
Chris@30 839
Chris@30 840 if (!m_model) return;
Chris@30 841
Chris@44 842 long frame = v->getFrameForX(e->x());
Chris@30 843 if (frame < 0) frame = 0;
Chris@30 844 frame = frame / m_model->getResolution() * m_model->getResolution();
Chris@30 845
Chris@44 846 float value = getValueForY(v, e->y());
Chris@30 847
matthiasm@620 848 m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
Chris@30 849 m_originalPoint = m_editingPoint;
Chris@30 850
Chris@376 851 if (m_editingCommand) finish(m_editingCommand);
matthiasm@620 852 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
gyorgyf@646 853 tr("Draw Point"));
Chris@30 854 m_editingCommand->addPoint(m_editingPoint);
Chris@30 855
Chris@30 856 m_editing = true;
Chris@30 857 }
Chris@30 858
Chris@30 859 void
matthiasm@620 860 FlexiNoteLayer::drawDrag(View *v, QMouseEvent *e)
Chris@30 861 {
matthiasm@620 862 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
Chris@30 863
Chris@30 864 if (!m_model || !m_editing) return;
Chris@30 865
Chris@44 866 long frame = v->getFrameForX(e->x());
Chris@30 867 if (frame < 0) frame = 0;
Chris@30 868 frame = frame / m_model->getResolution() * m_model->getResolution();
Chris@30 869
Chris@101 870 float newValue = getValueForY(v, e->y());
Chris@101 871
Chris@101 872 long newFrame = m_editingPoint.frame;
Chris@101 873 long newDuration = frame - newFrame;
Chris@101 874 if (newDuration < 0) {
Chris@101 875 newFrame = frame;
Chris@101 876 newDuration = -newDuration;
Chris@101 877 } else if (newDuration == 0) {
Chris@101 878 newDuration = 1;
Chris@101 879 }
Chris@30 880
Chris@30 881 m_editingCommand->deletePoint(m_editingPoint);
Chris@101 882 m_editingPoint.frame = newFrame;
Chris@101 883 m_editingPoint.value = newValue;
Chris@101 884 m_editingPoint.duration = newDuration;
Chris@30 885 m_editingCommand->addPoint(m_editingPoint);
Chris@30 886 }
Chris@30 887
Chris@30 888 void
matthiasm@620 889 FlexiNoteLayer::drawEnd(View *, QMouseEvent *)
Chris@30 890 {
matthiasm@620 891 // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl;
Chris@30 892 if (!m_model || !m_editing) return;
Chris@376 893 finish(m_editingCommand);
Chris@30 894 m_editingCommand = 0;
Chris@30 895 m_editing = false;
Chris@30 896 }
Chris@30 897
Chris@30 898 void
matthiasm@620 899 FlexiNoteLayer::eraseStart(View *v, QMouseEvent *e)
Chris@335 900 {
Chris@335 901 if (!m_model) return;
Chris@335 902
Chris@550 903 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
Chris@335 904
Chris@335 905 if (m_editingCommand) {
gyorgyf@646 906 finish(m_editingCommand);
gyorgyf@646 907 m_editingCommand = 0;
Chris@335 908 }
Chris@335 909
Chris@335 910 m_editing = true;
Chris@335 911 }
Chris@335 912
Chris@335 913 void
matthiasm@620 914 FlexiNoteLayer::eraseDrag(View *v, QMouseEvent *e)
Chris@335 915 {
Chris@335 916 }
Chris@335 917
Chris@335 918 void
matthiasm@620 919 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e)
Chris@335 920 {
Chris@335 921 if (!m_model || !m_editing) return;
Chris@335 922
Chris@335 923 m_editing = false;
Chris@335 924
matthiasm@620 925 FlexiNoteModel::Point p(0);
Chris@550 926 if (!getPointToDrag(v, e->x(), e->y(), p)) return;
Chris@550 927 if (p.frame != m_editingPoint.frame || p.value != m_editingPoint.value) return;
Chris@550 928
matthiasm@620 929 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, tr("Erase Point"));
Chris@335 930
Chris@335 931 m_editingCommand->deletePoint(m_editingPoint);
Chris@335 932
Chris@376 933 finish(m_editingCommand);
Chris@335 934 m_editingCommand = 0;
Chris@335 935 m_editing = false;
Chris@335 936 }
Chris@335 937
Chris@335 938 void
matthiasm@620 939 FlexiNoteLayer::editStart(View *v, QMouseEvent *e)
Chris@30 940 {
matthiasm@620 941 // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
gyorgyf@635 942 std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
Chris@30 943
Chris@30 944 if (!m_model) return;
Chris@30 945
Chris@550 946 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
matthiasm@651 947 m_originalPoint = FlexiNote(m_editingPoint);
gyorgyf@649 948
matthiasm@651 949 if (m_editMode == RightBoundary) {
matthiasm@651 950 m_dragPointX = v->getXForFrame(m_editingPoint.frame + m_editingPoint.duration);
gyorgyf@649 951 } else {
gyorgyf@649 952 m_dragPointX = v->getXForFrame(m_editingPoint.frame);
gyorgyf@649 953 }
Chris@551 954 m_dragPointY = getYForValue(v, m_editingPoint.value);
Chris@551 955
Chris@30 956 if (m_editingCommand) {
gyorgyf@646 957 finish(m_editingCommand);
gyorgyf@646 958 m_editingCommand = 0;
Chris@30 959 }
Chris@30 960
Chris@30 961 m_editing = true;
Chris@551 962 m_dragStartX = e->x();
Chris@551 963 m_dragStartY = e->y();
matthiasm@651 964
matthiasm@651 965 long onset = m_originalPoint.frame;
matthiasm@651 966 long offset = m_originalPoint.frame + m_originalPoint.duration - 1;
matthiasm@651 967
matthiasm@651 968 m_greatestLeftNeighbourFrame = -1;
matthiasm@651 969 m_smallestRightNeighbourFrame = std::numeric_limits<long>::max();
matthiasm@651 970
matthiasm@651 971 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
matthiasm@651 972 i != m_model->getPoints().end(); ++i) {
matthiasm@651 973 FlexiNote currentNote = *i;
matthiasm@651 974
matthiasm@651 975 // left boundary
matthiasm@651 976 if (currentNote.frame + currentNote.duration - 1 < onset) {
matthiasm@651 977 m_greatestLeftNeighbourFrame = currentNote.frame + currentNote.duration - 1;
matthiasm@651 978 }
matthiasm@651 979
matthiasm@651 980 // right boundary
matthiasm@651 981 if (currentNote.frame > offset) {
matthiasm@651 982 m_smallestRightNeighbourFrame = currentNote.frame;
matthiasm@651 983 break;
matthiasm@651 984 }
matthiasm@651 985 }
matthiasm@651 986 std::cerr << "note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl;
Chris@30 987 }
Chris@30 988
Chris@30 989 void
matthiasm@620 990 FlexiNoteLayer::editDrag(View *v, QMouseEvent *e)
Chris@30 991 {
matthiasm@620 992 // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
gyorgyf@635 993 std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
Chris@30 994
Chris@30 995 if (!m_model || !m_editing) return;
Chris@30 996
Chris@551 997 int xdist = e->x() - m_dragStartX;
Chris@551 998 int ydist = e->y() - m_dragStartY;
Chris@551 999 int newx = m_dragPointX + xdist;
Chris@551 1000 int newy = m_dragPointY + ydist;
Chris@551 1001
Chris@551 1002 long frame = v->getFrameForX(newx);
Chris@30 1003 if (frame < 0) frame = 0;
Chris@30 1004 frame = frame / m_model->getResolution() * m_model->getResolution();
matthiasm@651 1005
Chris@551 1006 float value = getValueForY(v, newy);
Chris@30 1007
Chris@30 1008 if (!m_editingCommand) {
gyorgyf@646 1009 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
gyorgyf@646 1010 tr("Drag Point"));
Chris@30 1011 }
Chris@30 1012
Chris@30 1013 m_editingCommand->deletePoint(m_editingPoint);
matthiasm@651 1014
matthiasm@651 1015 std::cerr << "edit mode: " << m_editMode << std::endl;
matthiasm@651 1016 switch (m_editMode) {
matthiasm@651 1017 case LeftBoundary : {
matthiasm@651 1018 if ((frame > m_greatestLeftNeighbourFrame)
matthiasm@651 1019 && (frame < m_originalPoint.frame + m_originalPoint.duration - 1)
matthiasm@651 1020 && (frame < m_smallestRightNeighbourFrame)) {
matthiasm@651 1021 m_editingPoint.duration = m_editingPoint.frame + m_editingPoint.duration - frame + 1;
matthiasm@651 1022 m_editingPoint.frame = frame;
matthiasm@651 1023 }
matthiasm@651 1024 break;
matthiasm@651 1025 }
matthiasm@651 1026 case RightBoundary : {
matthiasm@651 1027 long tempDuration = frame - m_originalPoint.frame;
matthiasm@651 1028 if (tempDuration > 0 && m_originalPoint.frame + tempDuration - 1 < m_smallestRightNeighbourFrame) {
matthiasm@651 1029 m_editingPoint.duration = tempDuration;
matthiasm@651 1030 }
matthiasm@651 1031 break;
matthiasm@651 1032 }
matthiasm@651 1033 case DragNote : {
matthiasm@651 1034 if (frame <= m_smallestRightNeighbourFrame - m_editingPoint.duration
matthiasm@651 1035 && frame > m_greatestLeftNeighbourFrame) {
matthiasm@651 1036 m_editingPoint.frame = frame; // only move if it doesn't overlap with right note or left note
matthiasm@651 1037 }
matthiasm@651 1038 m_editingPoint.value = value;
matthiasm@651 1039 break;
matthiasm@651 1040 }
gyorgyf@649 1041 }
Chris@30 1042 m_editingCommand->addPoint(m_editingPoint);
gyorgyf@649 1043 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl;
gyorgyf@649 1044
Chris@30 1045 }
Chris@30 1046
Chris@30 1047 void
gyorgyf@635 1048 FlexiNoteLayer::editEnd(View *v, QMouseEvent *e)
Chris@30 1049 {
matthiasm@620 1050 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
gyorgyf@635 1051 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
gyorgyf@635 1052
Chris@30 1053 if (!m_model || !m_editing) return;
Chris@30 1054
Chris@30 1055 if (m_editingCommand) {
Chris@30 1056
gyorgyf@646 1057 QString newName = m_editingCommand->getName();
Chris@30 1058
gyorgyf@646 1059 if (m_editingPoint.frame != m_originalPoint.frame) {
gyorgyf@646 1060 if (m_editingPoint.value != m_originalPoint.value) {
gyorgyf@646 1061 newName = tr("Edit Point");
gyorgyf@646 1062 } else {
gyorgyf@646 1063 newName = tr("Relocate Point");
gyorgyf@646 1064 }
gyorgyf@646 1065 } else {
gyorgyf@646 1066 newName = tr("Change Point Value");
gyorgyf@646 1067 }
Chris@30 1068
gyorgyf@646 1069 m_editingCommand->setName(newName);
gyorgyf@646 1070 finish(m_editingCommand);
Chris@30 1071 }
Chris@30 1072
Chris@30 1073 m_editingCommand = 0;
Chris@30 1074 m_editing = false;
Chris@30 1075 }
Chris@30 1076
gyorgyf@635 1077 void
gyorgyf@635 1078 FlexiNoteLayer::splitStart(View *v, QMouseEvent *e)
gyorgyf@635 1079 {
gyorgyf@646 1080 // GF: note splitting starts (!! remove printing soon)
gyorgyf@646 1081 std::cerr << "splitStart" << std::endl;
gyorgyf@646 1082 if (!m_model) return;
gyorgyf@635 1083
gyorgyf@635 1084 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
gyorgyf@635 1085 // m_originalPoint = m_editingPoint;
gyorgyf@635 1086 //
gyorgyf@635 1087 // m_dragPointX = v->getXForFrame(m_editingPoint.frame);
gyorgyf@635 1088 // m_dragPointY = getYForValue(v, m_editingPoint.value);
gyorgyf@635 1089
gyorgyf@635 1090 if (m_editingCommand) {
gyorgyf@646 1091 finish(m_editingCommand);
gyorgyf@646 1092 m_editingCommand = 0;
gyorgyf@635 1093 }
gyorgyf@635 1094
gyorgyf@635 1095 m_editing = true;
gyorgyf@635 1096 m_dragStartX = e->x();
gyorgyf@635 1097 m_dragStartY = e->y();
gyorgyf@635 1098
gyorgyf@635 1099 }
gyorgyf@635 1100
gyorgyf@635 1101 void
gyorgyf@635 1102 FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e)
gyorgyf@635 1103 {
gyorgyf@646 1104 // GF: note splitting ends. (!! remove printing soon)
gyorgyf@646 1105 std::cerr << "splitEnd" << std::endl;
matthiasm@651 1106 if (!m_model || !m_editing || m_editMode != SplitNote) return;
gyorgyf@635 1107
gyorgyf@635 1108 int xdist = e->x() - m_dragStartX;
gyorgyf@635 1109 int ydist = e->y() - m_dragStartY;
gyorgyf@635 1110 if (xdist != 0 || ydist != 0) {
gyorgyf@646 1111 std::cerr << "mouse moved" << std::endl;
gyorgyf@635 1112 return;
gyorgyf@635 1113 }
gyorgyf@635 1114
gyorgyf@649 1115 // MM: simpler declaration
matthiasm@648 1116 FlexiNote note(0);
gyorgyf@635 1117 if (!getPointToDrag(v, e->x(), e->y(), note)) return;
gyorgyf@635 1118
gyorgyf@635 1119 long frame = v->getFrameForX(e->x());
gyorgyf@635 1120
matthiasm@648 1121 int gap = 0; // MM: I prefer a gap of 0, but we can decide later
matthiasm@648 1122
gyorgyf@649 1123 // MM: changed this a bit, to make it slightly clearer (// GF: nice changes!)
matthiasm@648 1124 FlexiNote newNote1(note.frame, note.value,
matthiasm@648 1125 frame - note.frame - gap,
matthiasm@648 1126 note.level, note.label);
matthiasm@648 1127
matthiasm@648 1128 FlexiNote newNote2(frame, note.value,
matthiasm@648 1129 note.duration - newNote1.duration,
matthiasm@648 1130 note.level, note.label);
gyorgyf@635 1131
gyorgyf@635 1132 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
gyorgyf@635 1133 (m_model, tr("Edit Point"));
gyorgyf@635 1134 command->deletePoint(note);
gyorgyf@649 1135 if ((e->modifiers() & Qt::ShiftModifier)) {
gyorgyf@649 1136 finish(command);
gyorgyf@649 1137 return;
gyorgyf@649 1138 }
gyorgyf@635 1139 command->addPoint(newNote1);
gyorgyf@635 1140 command->addPoint(newNote2);
gyorgyf@635 1141 finish(command);
gyorgyf@646 1142
gyorgyf@646 1143 }
gyorgyf@646 1144
gyorgyf@646 1145 void
gyorgyf@646 1146 FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e)
gyorgyf@646 1147 {
gyorgyf@646 1148 // GF: context sensitive cursors
gyorgyf@646 1149 // v->setCursor(Qt::ArrowCursor);
gyorgyf@646 1150 FlexiNoteModel::Point note(0);
gyorgyf@646 1151 if (!getNoteToEdit(v, e->x(), e->y(), note)) {
gyorgyf@646 1152 // v->setCursor(Qt::UpArrowCursor);
gyorgyf@646 1153 return;
gyorgyf@646 1154 }
gyorgyf@646 1155
gyorgyf@646 1156 bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false;
gyorgyf@646 1157 getRelativeMousePosition(v, note, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom);
gyorgyf@646 1158 // if (!closeToLeft) return;
gyorgyf@646 1159 // if (closeToTop) v->setCursor(Qt::SizeVerCursor);
gyorgyf@649 1160
matthiasm@651 1161 if (closeToLeft) { v->setCursor(Qt::SizeHorCursor); m_editMode = LeftBoundary; return; }
matthiasm@651 1162 if (closeToRight) { v->setCursor(Qt::SizeHorCursor); m_editMode = RightBoundary; return; }
matthiasm@651 1163 if (closeToTop) { v->setCursor(Qt::CrossCursor); m_editMode = DragNote; return; }
matthiasm@651 1164 if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); m_editMode = SplitNote; return; }
gyorgyf@649 1165
gyorgyf@646 1166 v->setCursor(Qt::ArrowCursor);
gyorgyf@646 1167
gyorgyf@649 1168 // std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl;
gyorgyf@646 1169 // v->setCursor(Qt::SizeHorCursor);
gyorgyf@646 1170
gyorgyf@646 1171 }
gyorgyf@646 1172
gyorgyf@646 1173 void
gyorgyf@646 1174 FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const
gyorgyf@646 1175 {
gyorgyf@649 1176 // GF: TODO: consoloidate the tolerance values
gyorgyf@646 1177 if (!m_model) return;
gyorgyf@646 1178
matthiasm@651 1179 int ctol = 0;
gyorgyf@646 1180 int noteStartX = v->getXForFrame(note.frame);
gyorgyf@646 1181 int noteEndX = v->getXForFrame(note.frame + note.duration);
gyorgyf@646 1182 int noteValueY = getYForValue(v,note.value);
gyorgyf@646 1183 int noteStartY = noteValueY - (NOTE_HEIGHT / 2);
gyorgyf@646 1184 int noteEndY = noteValueY + (NOTE_HEIGHT / 2);
gyorgyf@646 1185
gyorgyf@646 1186 bool closeToNote = false;
gyorgyf@646 1187
gyorgyf@646 1188 if (y >= noteStartY-ctol && y <= noteEndY+ctol && x >= noteStartX-ctol && x <= noteEndX+ctol) closeToNote = true;
gyorgyf@646 1189 if (!closeToNote) return;
gyorgyf@646 1190
matthiasm@651 1191 int tol = NOTE_HEIGHT / 2;
gyorgyf@646 1192
gyorgyf@646 1193 if (x >= noteStartX - tol && x <= noteStartX + tol) closeToLeft = true;
gyorgyf@646 1194 if (x >= noteEndX - tol && x <= noteEndX + tol) closeToRight = true;
gyorgyf@646 1195 if (y >= noteStartY - tol && y <= noteStartY + tol) closeToTop = true;
gyorgyf@646 1196 if (y >= noteEndY - tol && y <= noteEndY + tol) closeToBottom = true;
gyorgyf@646 1197
gyorgyf@635 1198 }
gyorgyf@635 1199
gyorgyf@635 1200
Chris@255 1201 bool
matthiasm@620 1202 FlexiNoteLayer::editOpen(View *v, QMouseEvent *e)
Chris@70 1203 {
gyorgyf@633 1204 std::cerr << "Opening note editor dialog" << std::endl;
Chris@255 1205 if (!m_model) return false;
Chris@70 1206
matthiasm@620 1207 FlexiNoteModel::Point note(0);
Chris@550 1208 if (!getPointToDrag(v, e->x(), e->y(), note)) return false;
Chris@550 1209
matthiasm@620 1210 // FlexiNoteModel::Point note = *points.begin();
Chris@70 1211
Chris@70 1212 ItemEditDialog *dialog = new ItemEditDialog
Chris@70 1213 (m_model->getSampleRate(),
Chris@70 1214 ItemEditDialog::ShowTime |
Chris@70 1215 ItemEditDialog::ShowDuration |
Chris@70 1216 ItemEditDialog::ShowValue |
Chris@100 1217 ItemEditDialog::ShowText,
Chris@100 1218 m_model->getScaleUnits());
Chris@70 1219
Chris@70 1220 dialog->setFrameTime(note.frame);
Chris@70 1221 dialog->setValue(note.value);
Chris@70 1222 dialog->setFrameDuration(note.duration);
Chris@70 1223 dialog->setText(note.label);
Chris@70 1224
Chris@70 1225 if (dialog->exec() == QDialog::Accepted) {
Chris@70 1226
matthiasm@620 1227 FlexiNoteModel::Point newNote = note;
Chris@70 1228 newNote.frame = dialog->getFrameTime();
Chris@70 1229 newNote.value = dialog->getValue();
Chris@70 1230 newNote.duration = dialog->getFrameDuration();
Chris@70 1231 newNote.label = dialog->getText();
Chris@70 1232
matthiasm@620 1233 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
Chris@70 1234 (m_model, tr("Edit Point"));
Chris@70 1235 command->deletePoint(note);
Chris@70 1236 command->addPoint(newNote);
Chris@376 1237 finish(command);
Chris@70 1238 }
Chris@70 1239
Chris@70 1240 delete dialog;
Chris@255 1241 return true;
Chris@70 1242 }
Chris@70 1243
Chris@70 1244 void
matthiasm@620 1245 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame)
Chris@43 1246 {
Chris@99 1247 if (!m_model) return;
Chris@99 1248
matthiasm@620 1249 FlexiNoteModel::EditCommand *command =
gyorgyf@646 1250 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection"));
Chris@43 1251
matthiasm@620 1252 FlexiNoteModel::PointList points =
gyorgyf@646 1253 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
Chris@43 1254
matthiasm@620 1255 for (FlexiNoteModel::PointList::iterator i = points.begin();
gyorgyf@646 1256 i != points.end(); ++i) {
Chris@43 1257
gyorgyf@646 1258 if (s.contains(i->frame)) {
gyorgyf@646 1259 FlexiNoteModel::Point newPoint(*i);
gyorgyf@646 1260 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
gyorgyf@646 1261 command->deletePoint(*i);
gyorgyf@646 1262 command->addPoint(newPoint);
gyorgyf@646 1263 }
Chris@43 1264 }
Chris@43 1265
Chris@376 1266 finish(command);
Chris@43 1267 }
Chris@43 1268
Chris@43 1269 void
matthiasm@620 1270 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize)
Chris@43 1271 {
Chris@99 1272 if (!m_model) return;
Chris@99 1273
matthiasm@620 1274 FlexiNoteModel::EditCommand *command =
gyorgyf@646 1275 new FlexiNoteModel::EditCommand(m_model, tr("Resize Selection"));
Chris@43 1276
matthiasm@620 1277 FlexiNoteModel::PointList points =
gyorgyf@646 1278 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
Chris@43 1279
Chris@43 1280 double ratio =
gyorgyf@646 1281 double(newSize.getEndFrame() - newSize.getStartFrame()) /
gyorgyf@646 1282 double(s.getEndFrame() - s.getStartFrame());
Chris@43 1283
matthiasm@620 1284 for (FlexiNoteModel::PointList::iterator i = points.begin();
gyorgyf@646 1285 i != points.end(); ++i) {
Chris@43 1286
gyorgyf@646 1287 if (s.contains(i->frame)) {
Chris@43 1288
gyorgyf@646 1289 double targetStart = i->frame;
gyorgyf@646 1290 targetStart = newSize.getStartFrame() +
gyorgyf@646 1291 double(targetStart - s.getStartFrame()) * ratio;
Chris@43 1292
gyorgyf@646 1293 double targetEnd = i->frame + i->duration;
gyorgyf@646 1294 targetEnd = newSize.getStartFrame() +
gyorgyf@646 1295 double(targetEnd - s.getStartFrame()) * ratio;
Chris@43 1296
gyorgyf@646 1297 FlexiNoteModel::Point newPoint(*i);
gyorgyf@646 1298 newPoint.frame = lrint(targetStart);
gyorgyf@646 1299 newPoint.duration = lrint(targetEnd - targetStart);
gyorgyf@646 1300 command->deletePoint(*i);
gyorgyf@646 1301 command->addPoint(newPoint);
gyorgyf@646 1302 }
Chris@43 1303 }
Chris@43 1304
Chris@376 1305 finish(command);
Chris@43 1306 }
Chris@43 1307
Chris@76 1308 void
matthiasm@620 1309 FlexiNoteLayer::deleteSelection(Selection s)
Chris@76 1310 {
Chris@99 1311 if (!m_model) return;
Chris@99 1312
matthiasm@620 1313 FlexiNoteModel::EditCommand *command =
gyorgyf@646 1314 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points"));
Chris@76 1315
matthiasm@620 1316 FlexiNoteModel::PointList points =
gyorgyf@646 1317 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
Chris@76 1318
matthiasm@620 1319 for (FlexiNoteModel::PointList::iterator i = points.begin();
gyorgyf@646 1320 i != points.end(); ++i) {
Chris@76 1321
Chris@76 1322 if (s.contains(i->frame)) {
Chris@76 1323 command->deletePoint(*i);
Chris@76 1324 }
Chris@76 1325 }
Chris@76 1326
Chris@376 1327 finish(command);
Chris@76 1328 }
Chris@76 1329
Chris@76 1330 void
matthiasm@620 1331 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to)
Chris@76 1332 {
Chris@99 1333 if (!m_model) return;
Chris@99 1334
matthiasm@620 1335 FlexiNoteModel::PointList points =
gyorgyf@646 1336 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
Chris@76 1337
matthiasm@620 1338 for (FlexiNoteModel::PointList::iterator i = points.begin();
gyorgyf@646 1339 i != points.end(); ++i) {
gyorgyf@646 1340 if (s.contains(i->frame)) {
Chris@335 1341 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label);
Chris@360 1342 point.setReferenceFrame(alignToReference(v, i->frame));
Chris@76 1343 to.addPoint(point);
Chris@76 1344 }
Chris@76 1345 }
Chris@76 1346 }
Chris@76 1347
Chris@125 1348 bool
matthiasm@620 1349 FlexiNoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
Chris@76 1350 {
Chris@125 1351 if (!m_model) return false;
Chris@99 1352
Chris@76 1353 const Clipboard::PointList &points = from.getPoints();
Chris@76 1354
Chris@360 1355 bool realign = false;
Chris@360 1356
Chris@360 1357 if (clipboardHasDifferentAlignment(v, from)) {
Chris@360 1358
Chris@360 1359 QMessageBox::StandardButton button =
Chris@360 1360 QMessageBox::question(v, tr("Re-align pasted items?"),
Chris@360 1361 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
Chris@360 1362 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@360 1363 QMessageBox::Yes);
Chris@360 1364
Chris@360 1365 if (button == QMessageBox::Cancel) {
Chris@360 1366 return false;
Chris@360 1367 }
Chris@360 1368
Chris@360 1369 if (button == QMessageBox::Yes) {
Chris@360 1370 realign = true;
Chris@360 1371 }
Chris@360 1372 }
Chris@360 1373
matthiasm@620 1374 FlexiNoteModel::EditCommand *command =
gyorgyf@646 1375 new FlexiNoteModel::EditCommand(m_model, tr("Paste"));
Chris@76 1376
Chris@76 1377 for (Clipboard::PointList::const_iterator i = points.begin();
Chris@76 1378 i != points.end(); ++i) {
Chris@76 1379
Chris@76 1380 if (!i->haveFrame()) continue;
Chris@76 1381 size_t frame = 0;
Chris@360 1382
Chris@360 1383 if (!realign) {
Chris@360 1384
Chris@360 1385 frame = i->getFrame();
Chris@360 1386
Chris@360 1387 } else {
Chris@360 1388
Chris@360 1389 if (i->haveReferenceFrame()) {
Chris@360 1390 frame = i->getReferenceFrame();
Chris@360 1391 frame = alignFromReference(v, frame);
Chris@360 1392 } else {
Chris@360 1393 frame = i->getFrame();
Chris@360 1394 }
Chris@76 1395 }
Chris@360 1396
matthiasm@620 1397 FlexiNoteModel::Point newPoint(frame);
Chris@76 1398
Chris@76 1399 if (i->haveLabel()) newPoint.label = i->getLabel();
Chris@76 1400 if (i->haveValue()) newPoint.value = i->getValue();
Chris@76 1401 else newPoint.value = (m_model->getValueMinimum() +
Chris@76 1402 m_model->getValueMaximum()) / 2;
Chris@335 1403 if (i->haveLevel()) newPoint.level = i->getLevel();
Chris@76 1404 if (i->haveDuration()) newPoint.duration = i->getDuration();
Chris@125 1405 else {
Chris@125 1406 size_t nextFrame = frame;
Chris@125 1407 Clipboard::PointList::const_iterator j = i;
Chris@125 1408 for (; j != points.end(); ++j) {
Chris@125 1409 if (!j->haveFrame()) continue;
Chris@125 1410 if (j != i) break;
Chris@125 1411 }
Chris@125 1412 if (j != points.end()) {
Chris@125 1413 nextFrame = j->getFrame();
Chris@125 1414 }
Chris@125 1415 if (nextFrame == frame) {
Chris@125 1416 newPoint.duration = m_model->getResolution();
Chris@125 1417 } else {
Chris@125 1418 newPoint.duration = nextFrame - frame;
Chris@125 1419 }
Chris@125 1420 }
Chris@76 1421
Chris@76 1422 command->addPoint(newPoint);
Chris@76 1423 }
Chris@76 1424
Chris@376 1425 finish(command);
Chris@125 1426 return true;
Chris@76 1427 }
Chris@76 1428
Chris@507 1429 void
matthiasm@620 1430 FlexiNoteLayer::addNoteOn(long frame, int pitch, int velocity)
Chris@507 1431 {
matthiasm@620 1432 m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, ""));
Chris@507 1433 }
Chris@507 1434
Chris@507 1435 void
matthiasm@620 1436 FlexiNoteLayer::addNoteOff(long frame, int pitch)
Chris@507 1437 {
matthiasm@620 1438 for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin();
Chris@507 1439 i != m_pendingNoteOns.end(); ++i) {
Chris@507 1440 if (lrintf((*i).value) == pitch) {
matthiasm@620 1441 FlexiNote note(*i);
Chris@507 1442 m_pendingNoteOns.erase(i);
Chris@507 1443 note.duration = frame - note.frame;
Chris@507 1444 if (m_model) {
matthiasm@620 1445 FlexiNoteModel::AddPointCommand *c = new FlexiNoteModel::AddPointCommand
matthiasm@620 1446 (m_model, note, tr("Record FlexiNote"));
Chris@507 1447 // execute and bundle:
Chris@507 1448 CommandHistory::getInstance()->addCommand(c, true, true);
Chris@507 1449 }
Chris@507 1450 break;
Chris@507 1451 }
Chris@507 1452 }
Chris@507 1453 }
Chris@507 1454
Chris@507 1455 void
matthiasm@620 1456 FlexiNoteLayer::abandonNoteOns()
Chris@507 1457 {
Chris@507 1458 m_pendingNoteOns.clear();
Chris@507 1459 }
Chris@507 1460
Chris@287 1461 int
matthiasm@620 1462 FlexiNoteLayer::getDefaultColourHint(bool darkbg, bool &impose)
Chris@287 1463 {
Chris@287 1464 impose = false;
Chris@287 1465 return ColourDatabase::getInstance()->getColourIndex
Chris@287 1466 (QString(darkbg ? "White" : "Black"));
Chris@287 1467 }
Chris@287 1468
Chris@316 1469 void
matthiasm@620 1470 FlexiNoteLayer::toXml(QTextStream &stream,
Chris@316 1471 QString indent, QString extraAttributes) const
Chris@30 1472 {
Chris@316 1473 SingleColourLayer::toXml(stream, indent, extraAttributes +
Chris@445 1474 QString(" verticalScale=\"%1\" scaleMinimum=\"%2\" scaleMaximum=\"%3\" ")
Chris@445 1475 .arg(m_verticalScale)
Chris@445 1476 .arg(m_scaleMinimum)
Chris@445 1477 .arg(m_scaleMaximum));
Chris@30 1478 }
Chris@30 1479
Chris@30 1480 void
matthiasm@620 1481 FlexiNoteLayer::setProperties(const QXmlAttributes &attributes)
Chris@30 1482 {
Chris@287 1483 SingleColourLayer::setProperties(attributes);
Chris@30 1484
Chris@445 1485 bool ok, alsoOk;
Chris@30 1486 VerticalScale scale = (VerticalScale)
gyorgyf@646 1487 attributes.value("verticalScale").toInt(&ok);
Chris@30 1488 if (ok) setVerticalScale(scale);
Chris@445 1489
Chris@445 1490 float min = attributes.value("scaleMinimum").toFloat(&ok);
Chris@445 1491 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
Chris@445 1492 if (ok && alsoOk) setDisplayExtents(min, max);
Chris@30 1493 }
Chris@30 1494
matthiasm@651 1495 void
matthiasm@651 1496 FlexiNoteLayer::setVerticalRangeToNoteRange()
matthiasm@651 1497 {
matthiasm@651 1498 float minf = std::numeric_limits<float>::max();;
matthiasm@651 1499 float maxf = 0;
matthiasm@651 1500 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
matthiasm@651 1501 i != m_model->getPoints().end(); ++i) {
matthiasm@651 1502 FlexiNote note = *i;
matthiasm@651 1503 if (note.value < minf) minf = note.value;
matthiasm@651 1504 else if (note.value > maxf) maxf = note.value;
matthiasm@651 1505 std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl;
matthiasm@651 1506 }
matthiasm@651 1507
matthiasm@651 1508 if (this) {
matthiasm@651 1509 setDisplayExtents(minf,maxf);
matthiasm@651 1510 }
matthiasm@651 1511 }
Chris@30 1512
matthiasm@651 1513