X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftime_fx_dialog.cc;h=be2140d9d3559e8ddfe492293752940578f418bd;hb=dde13d288e22ba5dd8e23802c47fac288b089c57;hp=5d8bf57a3b296448052e071b8694c0f5a65f0163;hpb=52003be3695ab703b936163d7284e208790d5363;p=ardour.git diff --git a/gtk2_ardour/time_fx_dialog.cc b/gtk2_ardour/time_fx_dialog.cc index 5d8bf57a3b..be2140d9d3 100644 --- a/gtk2_ardour/time_fx_dialog.cc +++ b/gtk2_ardour/time_fx_dialog.cc @@ -17,7 +17,6 @@ */ -#include "time_fx_dialog.h" #include #include @@ -28,20 +27,25 @@ #include "pbd/error.h" #include "pbd/pthread_utils.h" #include "pbd/memento_command.h" +#include "pbd/unwind.h" +#include "pbd/stacktrace.h" #include +#include "audio_clock.h" #include "editor.h" #include "audio_time_axis.h" #include "audio_region_view.h" #include "region_selection.h" +#include "time_fx_dialog.h" +#include "timers.h" #ifdef USE_RUBBERBAND #include using namespace RubberBand; #endif -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; @@ -49,21 +53,27 @@ using namespace PBD; using namespace Gtk; using namespace Gtkmm2ext; -TimeFXDialog::TimeFXDialog (Editor& e, bool pitch) +TimeFXDialog::TimeFXDialog (Editor& e, bool pitch, framecnt_t oldlen, framecnt_t new_length, framepos_t position) : ArdourDialog (X_("time fx dialog")) , editor (e) , pitching (pitch) + , quick_button (_("Quick but Ugly")) + , antialias_button (_("Skip Anti-aliasing")) + , stretch_opts_label (_("Contents")) + , precise_button (_("Minimize time distortion")) + , preserve_formants_button(_("Preserve Formants")) + , original_length (oldlen) , 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) - , quick_button (_("Quick but Ugly")) - , antialias_button (_("Skip Anti-aliasing")) - , stretch_opts_label (_("Contents:")) - , precise_button (_("Minimize time distortion")) - , preserve_formants_button(_("Preserve Formants")) + , duration_adjustment (100.0, -1000.0, 1000.0, 1.0, 10.0) + , duration_clock (0) + , ignore_adjustment_change (false) + , ignore_clock_change (false) + , progress (0.0f) { set_modal (true); set_skip_taskbar_hint (true); @@ -123,31 +133,60 @@ TimeFXDialog::TimeFXDialog (Editor& e, bool pitch) upper_button_box.pack_start (*table, false, true); } else { - Table* table = manage (new Table (2, 3, false)); + Table* table = manage (new Table (4, 2, false)); + int row = 0; + table->set_row_spacings (6); - table->set_col_spacing (1, 6); - l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false )); - l->set_padding (8, 0); - table->attach (*l, 0, 1, 0, 2, Gtk::FILL, Gtk::FILL, 0, 0); + table->set_col_spacings (12); #ifdef USE_RUBBERBAND vector strings; + duration_clock = manage (new AudioClock (X_("stretch"), true, X_("stretch"), true, false, true, false, true)); + duration_clock->set_session (e.session()); + duration_clock->set (new_length, true); + duration_clock->set_mode (AudioClock::BBT); + duration_clock->set_bbt_reference (position); + + Gtk::Alignment* clock_align = manage (new Gtk::Alignment); + clock_align->add (*duration_clock); + clock_align->set (0.0, 0.5, 0.0, 1.0); + + l = manage (new Gtk::Label (_("Duration"))); + table->attach (*l, 0, 1, row, row+1, Gtk::FILL, Gtk::FILL, 0, 0); + table->attach (*clock_align, 1, 2, row, row+1, Gtk::AttachOptions (Gtk::EXPAND|Gtk::FILL), Gtk::FILL, 0, 0); + row++; - table->attach (stretch_opts_label, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0); + const double fract = ((double) new_length) / original_length; + /* note the *100.0 to convert fract into a percentage */ + duration_adjustment.set_value (fract*100.0); + Gtk::SpinButton* spinner = manage (new Gtk::SpinButton (duration_adjustment, 1.0, 3)); + + l = manage (new Gtk::Label (_("Percent"))); + table->attach (*l, 0, 1, row, row+1, Gtk::FILL, Gtk::FILL, 0, 0); + table->attach (*spinner, 1, 2, row, row+1, Gtk::FILL, Gtk::FILL, 0, 0); + row++; + + table->attach (stretch_opts_label, 0, 1, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0); set_popdown_strings (stretch_opts_selector, editor.rb_opt_strings); /* set default */ stretch_opts_selector.set_active_text (editor.rb_opt_strings[editor.rb_current_opt]); - table->attach (stretch_opts_selector, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0); + table->attach (stretch_opts_selector, 1, 2, row, row+1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0); + row++; - table->attach (precise_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0); + table->attach (precise_button, 0, 2, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0); + row++; + + 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)); #else quick_button.set_name (N_("TimeFXButton")); - table->attach (quick_button, 1, 3, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0); + table->attach (quick_button, 1, 3, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0); + row++; antialias_button.set_name (N_("TimeFXButton")); - table->attach (antialias_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0); + table->attach (antialias_button, 1, 3, row, row+1, Gtk::FILL, Gtk::EXPAND, 0, 0); #endif @@ -157,7 +196,7 @@ TimeFXDialog::TimeFXDialog (Editor& e, bool pitch) } set_default_response (Gtk::RESPONSE_ACCEPT); - + VBox* progress_box = manage (new VBox); progress_box->set_spacing (6); @@ -176,10 +215,31 @@ TimeFXDialog::TimeFXDialog (Editor& e, bool pitch) show_all_children (); } +void +TimeFXDialog::start_updates () +{ + update_connection = Timers::rapid_connect (sigc::mem_fun (*this, &TimeFXDialog::timer_update)); +} + void TimeFXDialog::update_progress_gui (float p) { - progress_bar.set_fraction (p); + /* 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. + */ + progress = p; +} + +void +TimeFXDialog::timer_update () +{ + progress_bar.set_fraction (progress); + + if (request.done || request.cancel) { + update_connection.disconnect (); + } } void @@ -199,3 +259,59 @@ TimeFXDialog::delete_in_progress (GdkEventAny*) return TRUE; } +float +TimeFXDialog::get_time_fraction () const +{ + if (pitching) { + return 1.0; + } + + return duration_adjustment.get_value() / 100.0; +} + +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); +} + +void +TimeFXDialog::duration_adjustment_changed () +{ + if (ignore_adjustment_change) { + return; + } + + PBD::Unwinder uw (ignore_clock_change, true); + + duration_clock->set ((framecnt_t) (original_length * (duration_adjustment.get_value()/ 100.0))); +} + +void +TimeFXDialog::duration_clock_changed () +{ + if (ignore_clock_change) { + return; + } + + PBD::Unwinder uw (ignore_adjustment_change, true); + + duration_adjustment.set_value (100.0 * (duration_clock->current_duration() / (double) original_length)); +}