comparison layer/FlexiNoteLayer.cpp @ 647:87fe9e05e076 tonioni

getFeatureDescription now supports larger notes
author gyorgyf
date Sat, 15 Jun 2013 17:43:04 +0100
parents ba76130ed7e5
children f61a54364d1d
comparison
equal deleted inserted replaced
646:ba76130ed7e5 647:87fe9e05e076
444 } 444 }
445 445
446 bool 446 bool
447 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const 447 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const
448 { 448 {
449 // GF: find the note that is closest to the cursor
449 if (!m_model) return false; 450 if (!m_model) return false;
450 451
451 long frame = v->getFrameForX(x); 452 long frame = v->getFrameForX(x);
452 453
453 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); 454 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
479 if (!m_model || !m_model->getSampleRate()) return ""; 480 if (!m_model || !m_model->getSampleRate()) return "";
480 481
481 FlexiNoteModel::PointList points = getLocalPoints(v, x); 482 FlexiNoteModel::PointList points = getLocalPoints(v, x);
482 483
483 if (points.empty()) { 484 if (points.empty()) {
484 if (!m_model->isReady()) { 485 if (!m_model->isReady()) {
485 return tr("In progress"); 486 return tr("In progress");
486 } else { 487 } else {
487 return tr("No local points"); 488 return tr("No local points");
488 } 489 }
489 } 490 }
490 491
491 FlexiNote note(0); 492 FlexiNote note(0);
492 FlexiNoteModel::PointList::iterator i; 493 FlexiNoteModel::PointList::iterator i;
493 494
494 for (i = points.begin(); i != points.end(); ++i) { 495 for (i = points.begin(); i != points.end(); ++i) {
495 496
496 int y = getYForValue(v, i->value); 497 int y = getYForValue(v, i->value);
497 int h = 3; 498 int h = NOTE_HEIGHT; // GF: larger notes
498 499
499 if (m_model->getValueQuantization() != 0.0) { 500 if (m_model->getValueQuantization() != 0.0) {
500 h = y - getYForValue(v, i->value + m_model->getValueQuantization()); 501 h = y - getYForValue(v, i->value + m_model->getValueQuantization());
501 if (h < 3) h = 3; 502 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT;
502 } 503 }
503 504
504 if (pos.y() >= y - h && pos.y() <= y) { 505 // GF: this is not quite correct
505 note = *i; 506 if (pos.y() >= y - 4 && pos.y() <= y + h) {
506 break; 507 note = *i;
507 } 508 break;
509 }
508 } 510 }
509 511
510 if (i == points.end()) return tr("No local points"); 512 if (i == points.end()) return tr("No local points");
511 513
512 RealTime rt = RealTime::frame2RealTime(note.frame, 514 RealTime rt = RealTime::frame2RealTime(note.frame,
513 m_model->getSampleRate()); 515 m_model->getSampleRate());
514 RealTime rd = RealTime::frame2RealTime(note.duration, 516 RealTime rd = RealTime::frame2RealTime(note.duration,
515 m_model->getSampleRate()); 517 m_model->getSampleRate());
516 518
517 QString pitchText; 519 QString pitchText;
518 520
519 if (shouldConvertMIDIToHz()) { 521 if (shouldConvertMIDIToHz()) {
520 522
539 } 541 }
540 542
541 QString text; 543 QString text;
542 544
543 if (note.label == "") { 545 if (note.label == "") {
544 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label")) 546 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nNo label"))
545 .arg(rt.toText(true).c_str()) 547 .arg(rt.toText(true).c_str())
546 .arg(pitchText) 548 .arg(pitchText)
547 .arg(rd.toText(true).c_str()); 549 .arg(rd.toText(true).c_str());
548 } else { 550 } else {
549 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4")) 551 text = QString(tr("Time:\t%1\nPitch:\t%2\nDuration:\t%3\nLabel:\t%4"))
550 .arg(rt.toText(true).c_str()) 552 .arg(rt.toText(true).c_str())
551 .arg(pitchText) 553 .arg(pitchText)
552 .arg(rd.toText(true).c_str()) 554 .arg(rd.toText(true).c_str())
553 .arg(note.label); 555 .arg(note.label);
554 } 556 }
555 557
556 pos = QPoint(v->getXForFrame(note.frame), 558 pos = QPoint(v->getXForFrame(note.frame),
557 getYForValue(v, note.value)); 559 getYForValue(v, note.value));
558 return text; 560 return text;
559 } 561 }
560 562
561 bool 563 bool
562 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame, 564 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
787 const FlexiNoteModel::Point &p(*i); 789 const FlexiNoteModel::Point &p(*i);
788 790
789 int x = v->getXForFrame(p.frame); 791 int x = v->getXForFrame(p.frame);
790 int y = getYForValue(v, p.value); 792 int y = getYForValue(v, p.value);
791 int w = v->getXForFrame(p.frame + p.duration) - x; 793 int w = v->getXForFrame(p.frame + p.duration) - x;
792 int h = 8; //GF: larger notes 794 int h = NOTE_HEIGHT; //GF: larger notes
793 795
794 if (m_model->getValueQuantization() != 0.0) { 796 if (m_model->getValueQuantization() != 0.0) {
795 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); 797 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
796 if (h < 3) h = 8; //GF: larger notes 798 if (h < NOTE_HEIGHT) h = NOTE_HEIGHT; //GF: larger notes
797 } 799 }
798 800
799 if (w < 1) w = 1; 801 if (w < 1) w = 1;
800 paint.setPen(getBaseQColor()); 802 paint.setPen(getBaseQColor());
801 paint.setBrush(brushColour); 803 paint.setBrush(brushColour);