annotate layer/FlexiNoteLayer.cpp @ 650:12d570c27d85 tonioni

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