fix timefx to use ratio_t from the beginning of the operation

This commit is contained in:
Paul Davis 2020-12-27 17:47:08 -07:00
parent 968da60e90
commit 06f93e65b2
3 changed files with 13 additions and 9 deletions

View file

@ -2134,7 +2134,7 @@ private:
static void* timefx_thread (void* arg); static void* timefx_thread (void* arg);
void do_timefx (); void do_timefx ();
int time_stretch (RegionSelection&, float fraction); int time_stretch (RegionSelection&, Temporal::ratio_t const & fraction);
int pitch_shift (RegionSelection&, float cents); int pitch_shift (RegionSelection&, float cents);
void pitch_shift_region (); void pitch_shift_region ();

View file

@ -5543,7 +5543,7 @@ TimeFXDrag::finished (GdkEvent* event, bool movement_occurred)
parameters for the timestretch. parameters for the timestretch.
*/ */
ratio_t fraction (1, 1); ratio_t ratio (1, 1);
if (movement_occurred) { if (movement_occurred) {
@ -5560,12 +5560,17 @@ TimeFXDrag::finished (GdkEvent* event, bool movement_occurred)
timecnt_t newlen = _primary->region()->position().distance (adjusted_pos); timecnt_t newlen = _primary->region()->position().distance (adjusted_pos);
fraction = newlen / _primary->region()->length(); if (_primary->region()->length().time_domain() == Temporal::BeatTime) {
ratio = ratio_t (newlen.ticks(), _primary->region()->length().ticks());
} else {
ratio = ratio_t (newlen.samples(), _primary->region()->length().samples());
}
#ifndef USE_RUBBERBAND #ifndef USE_RUBBERBAND
// Soundtouch uses fraction / 100 instead of normal (/ 1) // Soundtouch uses fraction / 100 instead of normal (/ 1)
#warning NUTEMPO timefx request now uses a rational type so this needs revisiting
if (_primary->region()->data_type() == DataType::AUDIO) { if (_primary->region()->data_type() == DataType::AUDIO) {
fraction = ((newlen - _primary->region()->length()) / newlen) * 100; ratio = ((newlen - _primary->region()->length()) / newlen) * 100;
} }
#endif #endif
} }
@ -5577,7 +5582,7 @@ TimeFXDrag::finished (GdkEvent* event, bool movement_occurred)
selection. selection.
*/ */
if (_editor->time_stretch (_editor->get_selection().regions, fraction) == -1) { if (_editor->time_stretch (_editor->get_selection().regions, ratio) == -1) {
error << _("An error occurred while executing time stretch operation") << endmsg; error << _("An error occurred while executing time stretch operation") << endmsg;
} }
} }
@ -6966,7 +6971,6 @@ void
NoteCreateDrag::motion (GdkEvent* event, bool) NoteCreateDrag::motion (GdkEvent* event, bool)
{ {
const timepos_t pos = _drags->current_pointer_time (); const timepos_t pos = _drags->current_pointer_time ();
const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
Temporal::Beats aligned_beats = grid_aligned_beats (pos, event); Temporal::Beats aligned_beats = grid_aligned_beats (pos, event);
if (_editor->snap_mode() != SnapOff) { if (_editor->snap_mode() != SnapOff) {

View file

@ -66,7 +66,7 @@ using namespace Gtkmm2ext;
/** @return -1 in case of error, 1 if operation was cancelled by the user, 0 if everything went ok */ /** @return -1 in case of error, 1 if operation was cancelled by the user, 0 if everything went ok */
int int
Editor::time_stretch (RegionSelection& regions, float fraction) Editor::time_stretch (RegionSelection& regions, Temporal::ratio_t const & ratio)
{ {
RegionList audio; RegionList audio;
RegionList midi; RegionList midi;
@ -81,7 +81,7 @@ Editor::time_stretch (RegionSelection& regions, float fraction)
} }
} }
int aret = time_fx (audio, fraction, false); int aret = time_fx (audio, ratio, false);
if (aret < 0) { if (aret < 0) {
abort_reversible_command (); abort_reversible_command ();
return aret; return aret;
@ -99,7 +99,7 @@ Editor::time_stretch (RegionSelection& regions, float fraction)
} }
ARDOUR::TimeFXRequest request; ARDOUR::TimeFXRequest request;
request.time_fraction = fraction; request.time_fraction = ratio;
for (RegionList::iterator i = midi.begin(); i != midi.end(); ++i) { for (RegionList::iterator i = midi.begin(); i != midi.end(); ++i) {
boost::shared_ptr<Playlist> playlist = (*i)->playlist(); boost::shared_ptr<Playlist> playlist = (*i)->playlist();