diff options
author | David Robillard <d@drobilla.net> | 2011-05-31 02:59:48 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-05-31 02:59:48 +0000 |
commit | fd33fa896f787470d3c12708e02f9c7af63259c8 (patch) | |
tree | 2eb361f7bf4847e769b031e4b0dd14b4ec056069 /libs/ardour/quantize.cc | |
parent | a0d09e81d4b304b2474b3be9f1bd6a04b3779489 (diff) |
Quantize notes to session tempo time, not relative to start of region (fix issue #4069).
git-svn-id: svn://localhost/ardour2/branches/3.0@9640 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/quantize.cc')
-rw-r--r-- | libs/ardour/quantize.cc | 18 |
1 files changed, 13 insertions, 5 deletions
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<MidiModel> model, std::vector<Evoral::Sequence<Evoral::MusicalTime>::Notes>& seqs) +Quantize::operator () (boost::shared_ptr<MidiModel> model, + double position, + std::vector<Evoral::Sequence<Evoral::MusicalTime>::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<MidiModel> model, std::vector<Evoral::S for (Evoral::Sequence<MidiModel::TimeType>::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<MidiModel> model, std::vector<Evoral::S } - delta = new_start - (*i)->time(); + double delta = new_start - (*i)->time(); if (fabs (delta) >= _threshold) { if (_snap_start) { |