void MatrixSelector::setContextHelpFor(const MatrixMouseEvent *e, bool ctrlPressed) { QSettings settings; settings.beginGroup( GeneralOptionsConfigGroup ); if (! qStrToBool( settings.value("toolcontexthelp", "true" ) ) ) { settings.endGroup(); return; } settings.endGroup(); MatrixElement *element = e->element; if (!element) { setContextHelp (tr("Click and drag to select; middle-click and drag to draw new note")); } else { // same logic as in handleLeftButtonPress float x = element->getLayoutX(); float width = element->getWidth(); float resizeStart = int(double(width) * 0.85) + x; // max size of 10 if ((x + width) - resizeStart > 10) resizeStart = x + width - 10; EventSelection *s = m_scene->getSelection(); if (e->sceneX > resizeStart) { if (s && s->getAddedEvents() > 1) { setContextHelp(tr("Click and drag to resize selected notes")); } else { setContextHelp(tr("Click and drag to resize note")); } } else { if (s && s->getAddedEvents() > 1) { if (!ctrlPressed) { setContextHelp(tr("Click and drag to move selected notes; hold Ctrl as well to copy")); } else { setContextHelp(tr("Click and drag to copy selected notes")); } } else { if (!ctrlPressed) { setContextHelp(tr("Click and drag to move note; hold Ctrl as well to copy")); } else { setContextHelp(tr("Click and drag to copy note")); } } } } }
MatrixResizer::FollowMode MatrixResizer::handleMouseMove(const MatrixMouseEvent *e) { if (!e) return NoFollow; setBasicContextHelp(); if (!m_currentElement || !m_currentViewSegment) return NoFollow; if (getSnapGrid()->getSnapSetting() != SnapGrid::NoSnap) { setContextHelp(tr("Hold Shift to avoid snapping to beat grid")); } else { clearContextHelp(); } // snap in the closest direction timeT snapTime = e->snappedLeftTime; if (e->snappedRightTime - e->time < e->time - e->snappedLeftTime) { snapTime = e->snappedRightTime; } timeT newDuration = snapTime - m_currentElement->getViewAbsoluteTime(); timeT durationDiff = newDuration - m_currentElement->getViewDuration(); EventSelection* selection = m_scene->getSelection(); if (!selection || selection->getAddedEvents() == 0) return NoFollow; EventSelection::eventcontainer::iterator it = selection->getSegmentEvents().begin(); for (; it != selection->getSegmentEvents().end(); ++it) { MatrixElement *element = 0; ViewElementList::iterator vi = m_currentViewSegment->findEvent(*it); if (vi != m_currentViewSegment->getViewElementList()->end()) { element = static_cast<MatrixElement *>(*vi); } if (!element) continue; timeT t = element->getViewAbsoluteTime(); timeT d = element->getViewDuration(); d = d + durationDiff; if (d < 0) { t = t + d; d = -d; } else if (d == 0) { d = getSnapGrid()->getSnapTime(t); } element->reconfigure(t, d); // m_currentStaff->positionElement(element); // } } // m_mParentView->canvas()->update(); return FollowHorizontal; }
/*!!! void MatrixResizer::slotMatrixScrolled(int newX, int newY) { QPoint newP1(newX, newY), oldP1(m_parentView->getCanvasView()->contentsX(), m_parentView->getCanvasView()->contentsY()); QPoint p(newX, newY); if (newP1.x() > oldP1.x()) { p.setX(newX + m_parentView->getCanvasView()->visibleWidth()); } p = m_mParentView->inverseMapPoint(p); int newTime = getSnapGrid()->snapX(p.x()); handleMouseMove(newTime, 0, 0); } */ void MatrixResizer::setBasicContextHelp() { EventSelection *selection = m_scene->getSelection(); if (selection && selection->getAddedEvents() > 1) { setContextHelp(tr("Click and drag to resize selected notes")); } else { setContextHelp(tr("Click and drag to resize a note")); } }
void MatrixMover::setBasicContextHelp(bool ctrlPressed) { EventSelection *selection = m_scene->getSelection(); if (!selection || selection->getAddedEvents() < 2) { if (!ctrlPressed) { setContextHelp(tr("Click and drag to move a note; hold Ctrl as well to copy it")); } else { setContextHelp(tr("Click and drag to copy a note")); } } else { if (!ctrlPressed) { setContextHelp(tr("Click and drag to move selected notes; hold Ctrl as well to copy")); } else { setContextHelp(tr("Click and drag to copy selected notes")); } } }
void MatrixMover::handleMouseRelease(const MatrixMouseEvent *e) { if (!e) return; MATRIX_DEBUG << "MatrixMover::handleMouseRelease() - newPitch = " << e->pitch << endl; if (!m_currentElement || !m_currentViewSegment) return; timeT newTime = m_currentElement->getViewAbsoluteTime() + (e->snappedLeftTime - m_clickSnappedLeftTime); int newPitch = e->pitch; if (newPitch > 127) newPitch = 127; if (newPitch < 0) newPitch = 0; // get a basic pitch difference calculation comparing the current element's // pitch to the pitch the mouse was released at (see note in // handleMouseMove) using BaseProperties::PITCH; timeT diffTime = newTime - m_currentElement->getViewAbsoluteTime(); int diffPitch = 0; if (m_currentElement->event()->has(PITCH)) { diffPitch = newPitch - m_currentElement->event()->get<Int>(PITCH); } EventSelection* selection = m_scene->getSelection(); // factor in transpose to adjust the height calculation long pitchOffset = selection->getSegment().getTranspose(); diffPitch += (pitchOffset * -1); if ((diffTime == 0 && diffPitch == 0) || selection->getAddedEvents() == 0) { for (size_t i = 0; i < m_duplicateElements.size(); ++i) { delete m_duplicateElements[i]->event(); delete m_duplicateElements[i]; } m_duplicateElements.clear(); m_currentElement = 0; return; } if (newPitch != m_lastPlayedPitch) { long velocity = m_widget->getCurrentVelocity(); m_currentElement->event()->get<Int>(BaseProperties::VELOCITY, velocity); m_scene->playNote(m_currentViewSegment->getSegment(), newPitch + (pitchOffset * -1), velocity); m_lastPlayedPitch = newPitch; } QString commandLabel; if (m_quickCopy) { if (selection->getAddedEvents() < 2) { commandLabel = tr("Copy and Move Event"); } else { commandLabel = tr("Copy and Move Events"); } } else { if (selection->getAddedEvents() < 2) { commandLabel = tr("Move Event"); } else { commandLabel = tr("Move Events"); } } MacroCommand *macro = new MacroCommand(commandLabel); EventSelection::eventcontainer::iterator it = selection->getSegmentEvents().begin(); Segment &segment = m_currentViewSegment->getSegment(); EventSelection *newSelection = new EventSelection(segment); timeT normalizeStart = selection->getStartTime(); timeT normalizeEnd = selection->getEndTime(); if (m_quickCopy) { for (size_t i = 0; i < m_duplicateElements.size(); ++i) { timeT time = m_duplicateElements[i]->getViewAbsoluteTime(); timeT endTime = time + m_duplicateElements[i]->getViewDuration(); if (time < normalizeStart) normalizeStart = time; if (endTime > normalizeEnd) normalizeEnd = endTime; macro->addCommand(new MatrixInsertionCommand (segment, time, endTime, m_duplicateElements[i]->event())); delete m_duplicateElements[i]->event(); delete m_duplicateElements[i]; } m_duplicateElements.clear(); m_quickCopy = false; } for (; it != selection->getSegmentEvents().end(); ++it) { timeT newTime = (*it)->getAbsoluteTime() + diffTime; int newPitch = 60; if ((*it)->has(PITCH)) { newPitch = (*it)->get<Int>(PITCH) + diffPitch; } Event *newEvent = 0; if (newTime < segment.getStartTime()) { newTime = segment.getStartTime(); } if (newTime + (*it)->getDuration() >= segment.getEndMarkerTime()) { timeT limit = getSnapGrid()->snapTime (segment.getEndMarkerTime() - 1, SnapGrid::SnapLeft); if (newTime > limit) newTime = limit; timeT newDuration = std::min ((*it)->getDuration(), segment.getEndMarkerTime() - newTime); newEvent = new Event(**it, newTime, newDuration); } else { newEvent = new Event(**it, newTime); } newEvent->set<Int>(BaseProperties::PITCH, newPitch); macro->addCommand(new MatrixModifyCommand(segment, (*it), newEvent, true, false)); newSelection->addEvent(newEvent); } normalizeStart = std::min(normalizeStart, newSelection->getStartTime()); normalizeEnd = std::max(normalizeEnd, newSelection->getEndTime()); macro->addCommand(new NormalizeRestsCommand(segment, normalizeStart, normalizeEnd)); m_scene->setSelection(0, false); CommandHistory::getInstance()->addCommand(macro); m_scene->setSelection(newSelection, false); // m_mParentView->canvas()->update(); m_currentElement = 0; setBasicContextHelp(); }
void MatrixResizer::handleMouseRelease(const MatrixMouseEvent *e) { if (!e || !m_currentElement || !m_currentViewSegment) return; // snap in the closest direction timeT snapTime = e->snappedLeftTime; if (e->snappedRightTime - e->time < e->time - e->snappedLeftTime) { snapTime = e->snappedRightTime; } timeT newDuration = snapTime - m_currentElement->getViewAbsoluteTime(); timeT durationDiff = newDuration - m_currentElement->getViewDuration(); EventSelection *selection = m_scene->getSelection(); if (!selection || selection->getAddedEvents() == 0) return; QString commandLabel = tr("Resize Event"); if (selection->getAddedEvents() > 1) commandLabel = tr("Resize Events"); MacroCommand *macro = new MacroCommand(commandLabel); EventSelection::eventcontainer::iterator it = selection->getSegmentEvents().begin(); Segment &segment = m_currentViewSegment->getSegment(); EventSelection *newSelection = new EventSelection(segment); timeT normalizeStart = selection->getStartTime(); timeT normalizeEnd = selection->getEndTime(); for (; it != selection->getSegmentEvents().end(); ++it) { timeT t = (*it)->getAbsoluteTime(); timeT d = (*it)->getDuration(); MATRIX_DEBUG << "MatrixResizer::handleMouseRelease - " << "Time = " << t << ", Duration = " << d << endl; d = d + durationDiff; if (d < 0) { t = t + d; d = -d; } else if (d == 0) { d = getSnapGrid()->getSnapTime(t); } if (t + d > segment.getEndMarkerTime()) { d = segment.getEndMarkerTime() - t; if (d <= 0) { d = segment.getEndMarkerTime(); t = d - getSnapGrid()->getSnapTime(t); } } Event *newEvent = new Event(**it, t, d); macro->addCommand(new MatrixModifyCommand(segment, *it, newEvent, false, false)); newSelection->addEvent(newEvent); } normalizeStart = std::min(normalizeStart, newSelection->getStartTime()); normalizeEnd = std::max(normalizeEnd, newSelection->getEndTime()); macro->addCommand(new NormalizeRestsCommand(segment, normalizeStart, normalizeEnd)); m_scene->setSelection(0, false); CommandHistory::getInstance()->addCommand(macro); m_scene->setSelection(newSelection, false); // m_mParentView->update(); m_currentElement = 0; setBasicContextHelp(); }