# HG changeset patch # User Chris Cannam # Date 1396383511 -3600 # Node ID 09e2677e34e7156a1091fc37c4d24db6b83f5604 # Parent f428bd8525801b07835037682572e91287ac0409 Fix fancy note-editing mode (was not working in new multi-layer world, and shift-click delete was broken) diff -r f428bd852580 -r 09e2677e34e7 layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Tue Apr 01 16:20:55 2014 +0100 +++ b/layer/FlexiNoteLayer.cpp Tue Apr 01 21:18:31 2014 +0100 @@ -1043,7 +1043,7 @@ m_originalPoint = FlexiNote(m_editingPoint); if (m_editMode == RightBoundary) { - m_dragPointX = v->getXForFrame(m_editingPoint.frame + m_editingPoint.duration); + m_dragPointX = v->getXForFrame(m_editingPoint.frame + m_editingPoint.duration); } else { m_dragPointX = v->getXForFrame(m_editingPoint.frame); } @@ -1079,7 +1079,7 @@ break; } } - std::cerr << "note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl; + std::cerr << "editStart: mode is " << m_editMode << ", note frame: " << onset << ", left boundary: " << m_greatestLeftNeighbourFrame << ", right boundary: " << m_smallestRightNeighbourFrame << std::endl; } void @@ -1216,41 +1216,50 @@ long frame = v->getFrameForX(e->x()); - splitNotesAt(v, frame); + splitNotesAt(v, frame, e); } void FlexiNoteLayer::splitNotesAt(View *v, int frame) { + splitNotesAt(v, frame, 0); +} + +void +FlexiNoteLayer::splitNotesAt(View *v, int frame, QMouseEvent *e) +{ FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); if (onPoints.empty()) return; FlexiNote note(*onPoints.begin()); - int gap = 0; // MM: I prefer a gap of 0, but we can decide later - - FlexiNote newNote1(note.frame, note.value, - frame - note.frame - gap, - note.level, note.label); - - FlexiNote newNote2(frame, note.value, - note.duration - newNote1.duration, - note.level, note.label); - FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand (m_model, tr("Edit Point")); command->deletePoint(note); + + if (!e || !(e->modifiers() & Qt::ShiftModifier)) { + + int gap = 0; // MM: I prefer a gap of 0, but we can decide later + + FlexiNote newNote1(note.frame, note.value, + frame - note.frame - gap, + note.level, note.label); + + FlexiNote newNote2(frame, note.value, + note.duration - newNote1.duration, + note.level, note.label); - if (m_intelligentActions) { - if (updateNoteValue(v, newNote1)) { + if (m_intelligentActions) { + if (updateNoteValue(v, newNote1)) { + command->addPoint(newNote1); + } + if (updateNoteValue(v, newNote2)) { + command->addPoint(newNote2); + } + } else { command->addPoint(newNote1); - } - if (updateNoteValue(v, newNote2)) { command->addPoint(newNote2); } - } else { - command->addPoint(newNote1); - command->addPoint(newNote2); } finish(command); diff -r f428bd852580 -r 09e2677e34e7 layer/FlexiNoteLayer.h --- a/layer/FlexiNoteLayer.h Tue Apr 01 16:20:55 2014 +0100 +++ b/layer/FlexiNoteLayer.h Tue Apr 01 21:18:31 2014 +0100 @@ -175,6 +175,7 @@ void getRelativeMousePosition(View *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const; SparseTimeValueModel *getAssociatedPitchModel(View *v) const; bool updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const; + void splitNotesAt(View *v, int frame, QMouseEvent *e); FlexiNoteModel *m_model; bool m_editing; diff -r f428bd852580 -r 09e2677e34e7 view/Pane.cpp --- a/view/Pane.cpp Tue Apr 01 16:20:55 2014 +0100 +++ b/view/Pane.cpp Tue Apr 01 21:18:31 2014 +0100 @@ -344,10 +344,10 @@ } if (layer == getSelectedLayer() && - !shouldIlluminateLocalSelection(discard, b0, b1)) { - - pos = m_identifyPoint; - return m_identifyFeatures; + !shouldIlluminateLocalSelection(discard, b0, b1)) { + + pos = m_identifyPoint; + return m_identifyFeatures; } return false; @@ -364,17 +364,17 @@ !m_manager->getSelections().empty() && !selectionIsBeingEdited()) { - Selection s(getSelectionAt(m_identifyPoint.x(), - closeToLeft, closeToRight)); - - if (!s.isEmpty()) { - if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { - - pos = m_identifyPoint; - return true; + Selection s(getSelectionAt(m_identifyPoint.x(), + closeToLeft, closeToRight)); + + if (!s.isEmpty()) { + if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { + + pos = m_identifyPoint; + return true; + } } } - } return false; } @@ -1276,6 +1276,18 @@ tr("Shift-click left button and drag to zoom to a rectangular area")); } +Layer * +Pane::getTopFlexiNoteLayer() +{ + for (int i = int(m_layers.size()) - 1; i >= 0; --i) { + if (LayerFactory::getInstance()->getLayerType(m_layers[i]) == + LayerFactory::FlexiNotes) { + return m_layers[i]; + } + } + return 0; +} + void Pane::mousePressEvent(QMouseEvent *e) { @@ -1387,8 +1399,8 @@ } else if (mode == ViewManager::NoteEditMode) { std::cerr << "mouse pressed in note edit mode" << std::endl; - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { + Layer *layer = getTopFlexiNoteLayer(); + if (layer) { layer->splitStart(this, e); } @@ -1502,11 +1514,22 @@ } else if (mode == ViewManager::NoteEditMode) { //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later) - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { + Layer *layer = getTopFlexiNoteLayer(); + + if (layer) { layer->splitEnd(this, e); - update(); } - + update(); + + if (m_editing) { + if (!editSelectionEnd(e)) { + layer->editEnd(this, e); + update(); + } + } + } + + } else if (mode == ViewManager::EditMode) { + if (m_editing) { if (!editSelectionEnd(e)) { Layer *layer = getSelectedLayer(); @@ -1517,19 +1540,6 @@ } } - } else if (mode == ViewManager::EditMode) { - - // GF: edited this previously, but restored to original state - if (m_editing) { - if (!editSelectionEnd(e)) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->editEnd(this, e); - update(); - } - } - } - } else if (mode == ViewManager::MeasureMode) { Layer *layer = getTopLayer(); @@ -1580,10 +1590,12 @@ // GF: handle mouse move for context sensitive cursor switching in NoteEditMode. // GF: Propagate the event to FlexiNoteLayer. I somehow feel it's best handeled there rather than here, but perhaps not if this will be needed elsewhere too. - if (mode == ViewManager::NoteEditMode && LayerFactory::getInstance()->getLayerType(getTopLayer()) == LayerFactory::FlexiNotes) { - - dynamic_cast(getTopLayer())->mouseMoveEvent(this, e); - + if (mode == ViewManager::NoteEditMode) { + FlexiNoteLayer *layer = qobject_cast(getTopFlexiNoteLayer()); + if (layer) { + layer->mouseMoveEvent(this, e); //!!! ew + return; + } } if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) { @@ -1692,8 +1704,8 @@ e->modifiers()); if (!editSelectionStart(&clickEvent)) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { + Layer *layer = getTopFlexiNoteLayer(); + if (layer) { std::cerr << "calling edit start" << std::endl; layer->editStart(this, &clickEvent); } diff -r f428bd852580 -r 09e2677e34e7 view/Pane.h --- a/view/Pane.h Tue Apr 01 16:20:55 2014 +0100 +++ b/view/Pane.h Tue Apr 01 21:18:31 2014 +0100 @@ -136,6 +136,8 @@ void updateContextHelp(const QPoint *pos); void edgeScrollMaybe(int x); + Layer *getTopFlexiNoteLayer(); + bool m_identifyFeatures; QPoint m_identifyPoint; QPoint m_clickPos;