# HG changeset patch # User gyorgyf # Date 1371626784 -3600 # Node ID c572a070522359e2c001973d0258ebad782cb190 # Parent f215fba963aa4075bc7f467dee765e1ea221d250 funky note value re-estimation using underlying pitch median value diff -r f215fba963aa -r c572a0705223 layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Tue Jun 18 22:18:10 2013 +0100 +++ b/layer/FlexiNoteLayer.cpp Wed Jun 19 08:26:24 2013 +0100 @@ -16,6 +16,7 @@ #include "FlexiNoteLayer.h" #include "data/model/Model.h" +#include "data/model/SparseTimeValueModel.h" #include "base/RealTime.h" #include "base/Profiler.h" #include "base/Pitch.h" @@ -37,7 +38,9 @@ #include #include #include -#include +#include // GF: included to compile std::numerical_limits on linux +#include + FlexiNoteLayer::FlexiNoteLayer() : SingleColourLayer(), @@ -1129,6 +1132,9 @@ note.duration - newNote1.duration, note.level, note.label); + updateNoteValue(v,newNote1); + updateNoteValue(v,newNote2); + FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand (m_model, tr("Edit Point")); command->deletePoint(note); @@ -1142,6 +1148,43 @@ } +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 + Layer *layer = v->getLayer(1); // GF: !!! gross assumption about correct layer order + SparseTimeValueModel *model = 0; + if (layer && layer->getModel()) + model = dynamic_cast(layer->getModel()); + + if (!model) return; + + std::cerr << model->getTypeName() << std::endl; + + SparseModel::PointList dataPoints = model->getPoints(note.frame, note.frame + note.duration); + if (dataPoints.empty()) return; + + // std::cerr << "frame " << note.frame << ": " << dataPoints.size() << " candidate points" << std::endl; + + std::vector pitchValues; + + for (SparseModel::PointList::const_iterator i = dataPoints.begin(); + i != dataPoints.end(); ++i) { + pitchValues.push_back((*i).value); + } + sort(pitchValues.begin(), pitchValues.end()); + size_t size = pitchValues.size(); + double median; + + if (size % 2 == 0) { + median = (pitchValues[size/2 - 1] + pitchValues[size/2]) / 2; + } else { + median = pitchValues[size/2]; + } + + note.value = median; +} + void FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e) { diff -r f215fba963aa -r c572a0705223 layer/FlexiNoteLayer.h --- a/layer/FlexiNoteLayer.h Tue Jun 18 22:18:10 2013 +0100 +++ b/layer/FlexiNoteLayer.h Wed Jun 19 08:26:24 2013 +0100 @@ -157,6 +157,7 @@ bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const; bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const; void getRelativeMousePosition(View *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const; + void updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const; FlexiNoteModel *m_model; bool m_editing;