diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index e1efaa268b..bccad1d72f 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4331,7 +4331,10 @@ Editor::apply_midi_note_edit_op_to_region (MidiOperator& op, MidiRegionView& mrv vector::Notes> v; v.push_back (selected); - return op (mrv.midi_region()->model(), v); + framepos_t pos_frames = mrv.midi_region()->position(); + double pos_beats = _session->tempo_map().framewalk_to_beats(0, pos_frames); + + return op (mrv.midi_region()->model(), pos_beats, v); } void diff --git a/libs/ardour/ardour/midi_operator.h b/libs/ardour/ardour/midi_operator.h index 31e412bafe..c5def76384 100644 --- a/libs/ardour/ardour/midi_operator.h +++ b/libs/ardour/ardour/midi_operator.h @@ -37,7 +37,9 @@ class MidiOperator { MidiOperator () {} virtual ~MidiOperator() {} - virtual Command* operator() (boost::shared_ptr, std::vector::Notes>&) = 0; + virtual Command* operator() (boost::shared_ptr, + double, + std::vector::Notes>&) = 0; virtual std::string name() const = 0; }; diff --git a/libs/ardour/ardour/quantize.h b/libs/ardour/ardour/quantize.h index bf046e6c50..e1ca2b2395 100644 --- a/libs/ardour/ardour/quantize.h +++ b/libs/ardour/ardour/quantize.h @@ -36,7 +36,9 @@ public: float strength, float swing, float threshold); ~Quantize (); - Command* operator() (boost::shared_ptr, std::vector::Notes>&); + Command* operator() (boost::shared_ptr, + double position, + std::vector::Notes>&); std::string name() const { return std::string ("quantize"); } private: diff --git a/libs/ardour/quantize.cc b/libs/ardour/quantize.cc index db2cbb1d21..7ede60b578 100644 --- a/libs/ardour/quantize.cc +++ b/libs/ardour/quantize.cc @@ -60,8 +60,17 @@ Quantize::~Quantize () } Command* -Quantize::operator () (boost::shared_ptr model, std::vector::Notes>& seqs) +Quantize::operator () (boost::shared_ptr model, + double position, + std::vector::Notes>& seqs) { + /* Calculate offset from start of model to next closest quantize step, + to quantize relative to actual session beats (etc.) rather than from the + start of the model. + */ + const double round_pos = ceil(position / _start_grid) * _start_grid; + const double offset = round_pos - position; + bool even; MidiModel::NoteDiffCommand* cmd = new MidiModel::NoteDiffCommand (model, "quantize"); @@ -71,9 +80,8 @@ Quantize::operator () (boost::shared_ptr model, std::vector::Notes::iterator i = (*s).begin(); i != (*s).end(); ++i) { - double new_start = round ((*i)->time() / _start_grid) * _start_grid; - double new_end = round ((*i)->end_time() / _end_grid) * _end_grid; - double delta; + double new_start = round ((*i)->time() / _start_grid) * _start_grid + offset; + double new_end = round ((*i)->end_time() / _end_grid) * _end_grid + offset; if (_swing > 0.0 && !even) { @@ -97,7 +105,7 @@ Quantize::operator () (boost::shared_ptr model, std::vectortime(); + double delta = new_start - (*i)->time(); if (fabs (delta) >= _threshold) { if (_snap_start) {