X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fquantize.cc;h=7da1edaaa18732695a64ab7d678f9e3f5ce917ac;hb=3020b224fa2d6e1b6b8a576e8e8e211e0585f2a2;hp=563b7bf4e761eb0629c16fa86da83d1fe38f5c26;hpb=77be4a2742b593e74e6b0ca79a6aa990bacf3233;p=ardour.git diff --git a/libs/ardour/quantize.cc b/libs/ardour/quantize.cc index 563b7bf4e7..7da1edaaa1 100644 --- a/libs/ardour/quantize.cc +++ b/libs/ardour/quantize.cc @@ -20,13 +20,8 @@ #include "pbd/basename.h" -#include "ardour/types.h" #include "ardour/quantize.h" -#include "ardour/session.h" -#include "ardour/smf_source.h" #include "ardour/midi_model.h" -#include "ardour/midi_region.h" -#include "ardour/tempo.h" #include "i18n.h" @@ -67,7 +62,7 @@ Quantize::operator () (boost::shared_ptr model, 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 round_pos = round(position / _start_grid) * _start_grid; const double offset = round_pos - position; bool even; @@ -77,10 +72,13 @@ Quantize::operator () (boost::shared_ptr model, even = false; + /* TODO 'swing' probably requires a 2nd iteration: + * first quantize notes to the grid, then apply beat shift + */ for (Evoral::Sequence::Notes::iterator i = (*s).begin(); i != (*s).end(); ++i) { - double new_start = round ((*i)->time() / _start_grid) * _start_grid + offset; - double new_end = round ((*i)->end_time() / _end_grid) * _end_grid + offset; + double new_start = round (((*i)->time() - offset) / _start_grid) * _start_grid + offset; + double new_end = round (((*i)->end_time() - offset) / _end_grid) * _end_grid + offset; if (_swing > 0.0 && !even) { @@ -91,6 +89,7 @@ Quantize::operator () (boost::shared_ptr model, */ new_start = new_start + (2.0/3.0 * _swing * (next_grid - new_start)); + new_end = new_end + (2.0/3.0 * _swing * (next_grid - new_start)); } else if (_swing < 0.0 && !even) { @@ -101,6 +100,7 @@ Quantize::operator () (boost::shared_ptr model, */ new_start = new_start - (2.0/3.0 * _swing * (new_start - prev_grid)); + new_end = new_end - (2.0/3.0 * _swing * (new_start - prev_grid)); }