2009-02-26 20:20:25 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2009-02-26 20:20:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
|
|
|
#include <string>
|
|
|
|
|
2017-07-16 21:48:18 -04:00
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
|
2009-02-26 20:20:25 -05:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/pthread_utils.h"
|
|
|
|
#include "pbd/memento_command.h"
|
2016-02-22 10:17:09 -05:00
|
|
|
#include "pbd/unwind.h"
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2017-07-16 21:48:18 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2016-02-21 16:28:44 -05:00
|
|
|
#include "audio_clock.h"
|
2009-02-26 20:20:25 -05:00
|
|
|
#include "editor.h"
|
|
|
|
#include "audio_time_axis.h"
|
|
|
|
#include "audio_region_view.h"
|
|
|
|
#include "region_selection.h"
|
2016-02-21 16:28:44 -05:00
|
|
|
#include "time_fx_dialog.h"
|
2016-02-22 10:17:09 -05:00
|
|
|
#include "timers.h"
|
2009-02-26 20:20:25 -05:00
|
|
|
|
|
|
|
#ifdef USE_RUBBERBAND
|
2013-10-26 10:58:14 -04:00
|
|
|
#include <rubberband/RubberBandStretcher.h>
|
2009-02-26 20:20:25 -05:00
|
|
|
using namespace RubberBand;
|
|
|
|
#endif
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2009-02-26 20:20:25 -05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
|
2023-06-08 17:33:14 -04:00
|
|
|
TimeFXDialog::TimeFXDialog (Editor& e, bool pitch, timecnt_t const & oldlen, timecnt_t const & new_length, Temporal::ratio_t const & ratio, timepos_t const & position, bool fixed_end)
|
2009-02-26 20:20:25 -05:00
|
|
|
: ArdourDialog (X_("time fx dialog"))
|
|
|
|
, editor (e)
|
|
|
|
, pitching (pitch)
|
2016-02-21 16:28:44 -05:00
|
|
|
, quick_button (_("Quick but Ugly"))
|
|
|
|
, antialias_button (_("Skip Anti-aliasing"))
|
2016-02-22 10:17:09 -05:00
|
|
|
, stretch_opts_label (_("Contents"))
|
2016-02-21 16:28:44 -05:00
|
|
|
, precise_button (_("Minimize time distortion"))
|
|
|
|
, preserve_formants_button(_("Preserve Formants"))
|
2023-06-08 17:33:14 -04:00
|
|
|
, fixed_end (fixed_end)
|
2016-02-21 16:28:44 -05:00
|
|
|
, original_length (oldlen)
|
2009-02-26 20:20:25 -05:00
|
|
|
, pitch_octave_adjustment (0.0, -4.0, 4.0, 1, 2.0)
|
|
|
|
, pitch_semitone_adjustment (0.0, -12.0, 12.0, 1.0, 4.0)
|
|
|
|
, pitch_cent_adjustment (0.0, -499.0, 500.0, 5.0, 15.0)
|
|
|
|
, pitch_octave_spinner (pitch_octave_adjustment)
|
|
|
|
, pitch_semitone_spinner (pitch_semitone_adjustment)
|
|
|
|
, pitch_cent_spinner (pitch_cent_adjustment)
|
2022-05-31 14:36:49 -04:00
|
|
|
, duration_ratio (ratio)
|
2016-02-22 10:17:09 -05:00
|
|
|
, duration_adjustment (100.0, -1000.0, 1000.0, 1.0, 10.0)
|
2016-02-21 16:28:44 -05:00
|
|
|
, duration_clock (0)
|
2016-02-22 10:17:09 -05:00
|
|
|
, ignore_adjustment_change (false)
|
|
|
|
, ignore_clock_change (false)
|
|
|
|
, progress (0.0f)
|
2009-02-26 20:20:25 -05:00
|
|
|
{
|
|
|
|
set_modal (true);
|
2009-06-27 07:29:54 -04:00
|
|
|
set_skip_taskbar_hint (true);
|
|
|
|
set_resizable (false);
|
2009-02-26 20:20:25 -05:00
|
|
|
set_name (N_("TimeFXDialog"));
|
|
|
|
|
|
|
|
if (pitching) {
|
2011-04-05 22:04:37 -04:00
|
|
|
set_title (_("Pitch Shift Audio"));
|
2009-02-26 20:20:25 -05:00
|
|
|
} else {
|
2011-04-05 22:04:37 -04:00
|
|
|
set_title (_("Time Stretch Audio"));
|
2009-02-26 20:20:25 -05:00
|
|
|
}
|
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
VBox* vbox = manage (new VBox);
|
|
|
|
Gtk::Label* l;
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
get_vbox()->set_spacing (4);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
vbox->set_spacing (18);
|
|
|
|
vbox->set_border_width (5);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
upper_button_box.set_spacing (6);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2022-01-26 16:19:32 -05:00
|
|
|
l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false ));
|
2009-06-27 07:29:54 -04:00
|
|
|
l->set_use_markup ();
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
upper_button_box.pack_start (*l, false, false);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2022-05-31 14:36:49 -04:00
|
|
|
/* if the ratio is already set, do not allow adjustment */
|
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
if (pitching) {
|
|
|
|
Table* table = manage (new Table (4, 3, false));
|
|
|
|
table->set_row_spacings (6);
|
|
|
|
table->set_col_spacing (1, 6);
|
2022-01-26 16:19:32 -05:00
|
|
|
l = manage (new Label ("", Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false )); //Common gnome way for padding
|
2009-06-27 07:29:54 -04:00
|
|
|
l->set_padding (8, 0);
|
|
|
|
table->attach (*l, 0, 1, 0, 4, Gtk::FILL, Gtk::FILL, 0, 0);
|
|
|
|
|
2022-01-26 16:19:32 -05:00
|
|
|
l = manage (new Label (_("Octaves:"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false));
|
2009-06-27 07:29:54 -04:00
|
|
|
table->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
|
|
|
table->attach (pitch_octave_spinner, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
|
2011-11-14 08:43:56 -05:00
|
|
|
pitch_octave_spinner.set_activates_default ();
|
2009-06-27 07:29:54 -04:00
|
|
|
|
2022-01-26 16:19:32 -05:00
|
|
|
l = manage (new Label (_("Semitones:"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false));
|
2009-06-27 07:29:54 -04:00
|
|
|
table->attach (*l, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
|
|
|
table->attach (pitch_semitone_spinner, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
|
2011-11-14 08:43:56 -05:00
|
|
|
pitch_semitone_spinner.set_activates_default ();
|
2009-06-27 07:29:54 -04:00
|
|
|
|
2022-01-26 16:19:32 -05:00
|
|
|
l = manage (new Label (_("Cents:"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false));
|
2009-02-26 20:20:25 -05:00
|
|
|
pitch_cent_spinner.set_digits (1);
|
2009-06-27 07:29:54 -04:00
|
|
|
table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
|
|
|
table->attach (pitch_cent_spinner, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
|
2011-11-14 08:43:56 -05:00
|
|
|
pitch_cent_spinner.set_activates_default ();
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
table->attach (preserve_formants_button, 1, 3, 3, 4, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2011-11-28 14:46:30 -05:00
|
|
|
add_button (S_("Time|Shift"), Gtk::RESPONSE_ACCEPT);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
upper_button_box.pack_start (*table, false, true);
|
2009-02-26 20:20:25 -05:00
|
|
|
} else {
|
2016-02-21 16:28:44 -05:00
|
|
|
Table* table = manage (new Table (4, 2, false));
|
|
|
|
int row = 0;
|
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
table->set_row_spacings (6);
|
2016-02-22 10:17:09 -05:00
|
|
|
table->set_col_spacings (12);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
|
|
|
#ifdef USE_RUBBERBAND
|
|
|
|
vector<string> strings;
|
2016-02-22 10:17:09 -05:00
|
|
|
duration_clock = manage (new AudioClock (X_("stretch"), true, X_("stretch"), true, false, true, false, true));
|
2016-02-21 16:28:44 -05:00
|
|
|
duration_clock->set_session (e.session());
|
|
|
|
duration_clock->set_mode (AudioClock::BBT);
|
2023-02-08 18:35:27 -05:00
|
|
|
duration_clock->set_duration (timecnt_t (new_length, position), true);
|
2016-02-21 16:28:44 -05:00
|
|
|
|
|
|
|
Gtk::Alignment* clock_align = manage (new Gtk::Alignment);
|
|
|
|
clock_align->add (*duration_clock);
|
|
|
|
clock_align->set (0.0, 0.5, 0.0, 1.0);
|
|
|
|
|
2016-02-22 10:17:09 -05:00
|
|
|
l = manage (new Gtk::Label (_("Duration")));
|
|
|
|
table->attach (*l, 0, 1, row, row+1, Gtk::FILL, Gtk::FILL, 0, 0);
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (*clock_align, 1, 2, row, row+1, Gtk::AttachOptions (Gtk::EXPAND|Gtk::FILL), Gtk::FILL, 0, 0);
|
|
|
|
row++;
|
|
|
|
|
|
|
|
/* note the *100.0 to convert fract into a percentage */
|
2022-05-31 14:36:49 -04:00
|
|
|
duration_adjustment.set_value (duration_ratio.to_double() * 100.0);
|
|
|
|
|
2016-02-22 10:17:09 -05:00
|
|
|
Gtk::SpinButton* spinner = manage (new Gtk::SpinButton (duration_adjustment, 1.0, 3));
|
2016-02-21 16:28:44 -05:00
|
|
|
|
2022-05-31 14:36:49 -04:00
|
|
|
if (duration_ratio != Temporal::ratio_t (1, 1)) {
|
|
|
|
spinner->set_sensitive (false);
|
|
|
|
}
|
|
|
|
|
2016-02-22 10:17:09 -05:00
|
|
|
l = manage (new Gtk::Label (_("Percent")));
|
|
|
|
table->attach (*l, 0, 1, row, row+1, Gtk::FILL, Gtk::FILL, 0, 0);
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (*spinner, 1, 2, row, row+1, Gtk::FILL, Gtk::FILL, 0, 0);
|
|
|
|
row++;
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (stretch_opts_label, 0, 1, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
2009-06-27 07:29:54 -04:00
|
|
|
|
2009-02-26 20:20:25 -05:00
|
|
|
set_popdown_strings (stretch_opts_selector, editor.rb_opt_strings);
|
|
|
|
/* set default */
|
2010-08-13 12:50:29 -04:00
|
|
|
stretch_opts_selector.set_active_text (editor.rb_opt_strings[editor.rb_current_opt]);
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (stretch_opts_selector, 1, 2, row, row+1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
|
|
|
|
row++;
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (precise_button, 0, 2, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
|
|
|
row++;
|
2016-02-22 10:17:09 -05:00
|
|
|
|
|
|
|
duration_clock->ValueChanged.connect (sigc::mem_fun (*this, &TimeFXDialog::duration_clock_changed));
|
|
|
|
duration_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &TimeFXDialog::duration_adjustment_changed));
|
|
|
|
|
2009-02-26 20:20:25 -05:00
|
|
|
#else
|
|
|
|
quick_button.set_name (N_("TimeFXButton"));
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (quick_button, 1, 3, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
|
|
|
row++;
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
antialias_button.set_name (N_("TimeFXButton"));
|
2016-02-21 16:28:44 -05:00
|
|
|
table->attach (antialias_button, 1, 3, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
#endif
|
2009-06-27 07:29:54 -04:00
|
|
|
|
2009-02-26 20:20:25 -05:00
|
|
|
add_button (_("Stretch/Shrink"), Gtk::RESPONSE_ACCEPT);
|
2009-06-27 07:29:54 -04:00
|
|
|
|
|
|
|
upper_button_box.pack_start (*table, false, true);
|
2009-02-26 20:20:25 -05:00
|
|
|
}
|
|
|
|
|
2011-11-14 08:43:56 -05:00
|
|
|
set_default_response (Gtk::RESPONSE_ACCEPT);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
VBox* progress_box = manage (new VBox);
|
|
|
|
progress_box->set_spacing (6);
|
|
|
|
|
2022-01-26 16:19:32 -05:00
|
|
|
l = manage (new Label (_("<b>Progress</b>"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false));
|
2009-06-27 07:29:54 -04:00
|
|
|
l->set_use_markup ();
|
2009-02-26 20:20:25 -05:00
|
|
|
|
2009-06-27 07:29:54 -04:00
|
|
|
progress_box->pack_start (*l, false, false);
|
|
|
|
progress_box->pack_start (progress_bar, false, true);
|
|
|
|
|
|
|
|
|
|
|
|
vbox->pack_start (upper_button_box, false, true);
|
|
|
|
vbox->pack_start (*progress_box, false, true);
|
|
|
|
|
|
|
|
get_vbox()->pack_start (*vbox, false, false);
|
2009-02-26 20:20:25 -05:00
|
|
|
|
|
|
|
show_all_children ();
|
|
|
|
}
|
|
|
|
|
2016-02-22 10:17:09 -05:00
|
|
|
void
|
|
|
|
TimeFXDialog::start_updates ()
|
|
|
|
{
|
|
|
|
update_connection = Timers::rapid_connect (sigc::mem_fun (*this, &TimeFXDialog::timer_update));
|
|
|
|
}
|
|
|
|
|
2012-01-24 12:04:15 -05:00
|
|
|
void
|
|
|
|
TimeFXDialog::update_progress_gui (float p)
|
2009-02-26 20:20:25 -05:00
|
|
|
{
|
2016-02-22 10:28:49 -05:00
|
|
|
/* time/pitch FX are applied in a dedicated thread, so we cannot just
|
|
|
|
update the GUI when notified about progress. That is deferred to a
|
|
|
|
timer-driven callback which will ensure that the visual progress
|
|
|
|
indicator is updated.
|
|
|
|
*/
|
2016-02-22 10:17:09 -05:00
|
|
|
progress = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimeFXDialog::timer_update ()
|
|
|
|
{
|
|
|
|
progress_bar.set_fraction (progress);
|
|
|
|
|
|
|
|
if (request.done || request.cancel) {
|
|
|
|
update_connection.disconnect ();
|
|
|
|
}
|
2009-02-26 20:20:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimeFXDialog::cancel_in_progress ()
|
|
|
|
{
|
|
|
|
request.cancel = true;
|
|
|
|
first_cancel.disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2009-07-21 11:55:17 -04:00
|
|
|
TimeFXDialog::delete_in_progress (GdkEventAny*)
|
2009-02-26 20:20:25 -05:00
|
|
|
{
|
|
|
|
request.cancel = true;
|
|
|
|
first_delete.disconnect();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-03-19 19:23:41 -04:00
|
|
|
Temporal::ratio_t
|
2016-02-21 16:28:44 -05:00
|
|
|
TimeFXDialog::get_time_fraction () const
|
|
|
|
{
|
|
|
|
if (pitching) {
|
2021-03-19 19:23:41 -04:00
|
|
|
return Temporal::ratio_t (1, 1);
|
2016-02-21 16:28:44 -05:00
|
|
|
}
|
|
|
|
|
2022-05-31 14:36:49 -04:00
|
|
|
if (duration_ratio != Temporal::ratio_t (1, 1)) {
|
|
|
|
return duration_ratio;
|
|
|
|
}
|
|
|
|
|
2021-03-19 19:23:41 -04:00
|
|
|
return Temporal::ratio_t (duration_adjustment.get_value(), 100);
|
2016-02-21 16:28:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
TimeFXDialog::get_pitch_fraction () const
|
|
|
|
{
|
|
|
|
if (!pitching) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float cents = pitch_octave_adjustment.get_value() * 1200.0;
|
|
|
|
|
|
|
|
cents += pitch_semitone_adjustment.get_value() * 100.0;
|
|
|
|
cents += pitch_cent_adjustment.get_value();
|
|
|
|
|
|
|
|
if (cents == 0.0) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// one octave == 1200 cents
|
|
|
|
// adding one octave doubles the frequency
|
|
|
|
// ratio is 2^^octaves
|
|
|
|
|
|
|
|
return pow(2, cents/1200);
|
|
|
|
}
|
2016-02-22 10:17:09 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
TimeFXDialog::duration_adjustment_changed ()
|
|
|
|
{
|
|
|
|
if (ignore_adjustment_change) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-31 15:15:36 -04:00
|
|
|
if (duration_adjustment.get_value() == 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-22 10:17:09 -05:00
|
|
|
PBD::Unwinder<bool> uw (ignore_clock_change, true);
|
2022-05-31 15:15:36 -04:00
|
|
|
timecnt_t dur = original_length.scale (Temporal::ratio_t (duration_adjustment.get_value(), 100.0));
|
2016-02-22 10:17:09 -05:00
|
|
|
|
2022-05-31 15:15:36 -04:00
|
|
|
duration_clock->set_duration (dur);
|
2016-02-22 10:17:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimeFXDialog::duration_clock_changed ()
|
|
|
|
{
|
|
|
|
if (ignore_clock_change) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBD::Unwinder<bool> uw (ignore_adjustment_change, true);
|
|
|
|
|
2022-05-26 12:34:48 -04:00
|
|
|
duration_adjustment.set_value (100.0 * (duration_clock->current_duration() / original_length).to_double());
|
2016-02-22 10:17:09 -05:00
|
|
|
}
|