Mercurial > hg > svgui
diff layer/FlexiNoteLayer.cpp @ 660:8663a831838f tonioni
instrument is now "click" -- some other minor changes I don't remember
author | matthiasm |
---|---|
date | Thu, 20 Jun 2013 13:47:36 +0100 |
parents | 65b966394650 050404ae7799 |
children | 123ebecd12e6 |
line wrap: on
line diff
--- 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