# HG changeset patch # User matthiasm # Date 1371732456 -3600 # Node ID 8663a831838f566c315c84547d59e662f176afe1 # Parent 65b966394650c7b59ad454e530e7940587f5a84b# Parent 050404ae7799c4c4b92a08d60024f36f8273450f instrument is now "click" -- some other minor changes I don't remember diff -r 65b966394650 -r 8663a831838f layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Thu Jun 20 11:07:57 2013 +0100 +++ b/layer/FlexiNoteLayer.cpp Thu Jun 20 13:47:36 2013 +0100 @@ -61,7 +61,8 @@ m_editingCommand(0), m_verticalScale(AutoAlignScale), m_scaleMinimum(34), - m_scaleMaximum(77) + m_scaleMaximum(77), + m_intelligentActions(true) { } @@ -1019,10 +1020,10 @@ switch (m_editMode) { case LeftBoundary : { - // left - if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; + // left + if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; // right - if (dragFrame >= m_originalPoint.frame + m_originalPoint.duration) { + if (m_intelligentActions && dragFrame >= m_originalPoint.frame + m_originalPoint.duration) { dragFrame = m_originalPoint.frame + m_originalPoint.duration - 1; } m_editingPoint.frame = dragFrame; @@ -1031,16 +1032,16 @@ } case RightBoundary : { // left - if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; - if (dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1; + if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; + if (m_intelligentActions && dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1; m_editingPoint.duration = dragFrame - m_originalPoint.frame + 1; break; } case DragNote : { // left - if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; + if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; // right - if (dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { + if (m_intelligentActions && dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; } m_editingPoint.frame = dragFrame; @@ -1137,9 +1138,11 @@ FlexiNote newNote2(frame, note.value, note.duration - newNote1.duration, note.level, note.label); - - updateNoteValue(v,newNote1); - updateNoteValue(v,newNote2); + + if (m_intelligentActions) { + updateNoteValue(v,newNote1); + updateNoteValue(v,newNote2); + } FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand (m_model, tr("Edit Point")); @@ -1155,6 +1158,44 @@ } void +FlexiNoteLayer::addNote(View *v, QMouseEvent *e) +{ + std::cerr << "addNote" << std::endl; + if (!m_model) return; + + long duration = 10000; + + long frame = v->getFrameForX(e->x()); + float value = getValueForY(v, e->y()); + + if (m_intelligentActions) { + long smallestRightNeighbourFrame = 0; + for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); + i != m_model->getPoints().end(); ++i) { + FlexiNote currentNote = *i; + if (currentNote.frame > frame) { + smallestRightNeighbourFrame = currentNote.frame; + break; + } + } + + duration = std::min(smallestRightNeighbourFrame - frame + 1, duration); + duration = (duration > 0) ? duration : 0; + } + + if (!m_intelligentActions || + m_model->getPoints(frame).empty() && duration > 0) + { + FlexiNote newNote(frame, value, duration, 100, "new note"); + FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand + (m_model, tr("Add Point")); + command->addPoint(newNote); + finish(command); + } +} + + +void FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const { //GF: update the note value conforming the median of pitch values in the underlying note layer diff -r 65b966394650 -r 8663a831838f layer/FlexiNoteLayer.h --- a/layer/FlexiNoteLayer.h Thu Jun 20 11:07:57 2013 +0100 +++ b/layer/FlexiNoteLayer.h Thu Jun 20 13:47:36 2013 +0100 @@ -56,6 +56,8 @@ virtual void splitStart(View *v, QMouseEvent *); virtual void splitEnd(View *v, QMouseEvent *); + + virtual void addNote(View *v, QMouseEvent *e); virtual void mouseMoveEvent(View *v, QMouseEvent *); @@ -96,6 +98,8 @@ SplitNote, LeftBoundary }; + + void setIntelligentActions(bool on) { m_intelligentActions=on; } void setVerticalScale(VerticalScale scale); VerticalScale getVerticalScale() const { return m_verticalScale; } @@ -161,6 +165,7 @@ FlexiNoteModel *m_model; bool m_editing; + bool m_intelligentActions; int m_dragPointX; int m_dragPointY; int m_dragStartX; diff -r 65b966394650 -r 8663a831838f layer/Layer.h --- a/layer/Layer.h Thu Jun 20 11:07:57 2013 +0100 +++ b/layer/Layer.h Thu Jun 20 13:47:36 2013 +0100 @@ -231,6 +231,7 @@ virtual void splitStart(View *, QMouseEvent *) { } virtual void splitEnd(View *, QMouseEvent *) { } + virtual void addNote(View *v, QMouseEvent *e) { }; // Measurement rectangle (or equivalent). Unlike draw and edit, // the base Layer class can provide working implementations of diff -r 65b966394650 -r 8663a831838f view/Pane.cpp --- a/view/Pane.cpp Thu Jun 20 11:07:57 2013 +0100 +++ b/view/Pane.cpp Thu Jun 20 13:47:36 2013 +0100 @@ -2107,10 +2107,10 @@ if (mode == ViewManager::NavigateMode || mode == ViewManager::EditMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - if (layer->editOpen(this, e)) relocate = false; - } + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + if (layer->editOpen(this, e)) relocate = false; + } } else if (mode == ViewManager::MeasureMode) { @@ -2134,6 +2134,14 @@ m_dragStartMinValue = dmin; } } + + if (mode == ViewManager::NoteEditMode) { + std::cerr << "double click in note edit mode" << std::endl; + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->addNote(this, e); + } + } m_clickedInRange = false; // in case mouseReleaseEvent is not properly called }