X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fquantize.cc;h=7ede60b578540e73472f4f342819804108810a67;hb=00ddd099ed5cd6e0d77448670381d13d88b96218;hp=db2cbb1d21f722ab0c50e6b61791c0fb5f239ef9;hpb=5c23faaa0d86b2d1b18d4f03565bad55c410fb7a;p=ardour.git 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) {