13
0

Consolidate Varispeed dialog

* localize speed changes into varispeed dialog
* make speed-changes idempotent
* remember window position (do not overlap with button)
  ideally the window would show up below the "Vari" button
This commit is contained in:
Robin Gareus 2021-07-19 01:59:33 +02:00
parent 0ca77db96d
commit 9a66bd6163
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 22 additions and 14 deletions

View File

@ -199,12 +199,9 @@ ShuttleControl::~ShuttleControl ()
void
ShuttleControl::varispeed_button_clicked ()
{
_vari_dialog.set_session(_session);
if (_session->default_play_speed()==1.0) {
_vari_dialog.show_all ();
_vari_dialog.apply_speed ();
if (_session->default_play_speed() == 1.0) {
_vari_dialog.show ();
} else {
_session->set_default_play_speed(1.0);
_vari_dialog.hide ();
}
}
@ -226,12 +223,14 @@ void
ShuttleControl::set_session (Session *s)
{
SessionHandlePtr::set_session (s);
_vari_dialog.set_session (_session);
if (_session) {
set_sensitive (true);
_session->add_controllable (_controllable);
_info_button.set_session (s);
} else {
_vari_dialog.hide ();
set_sensitive (false);
}
}

View File

@ -28,14 +28,12 @@
using namespace Gtk;
VarispeedDialog::VarispeedDialog ()
: ArdourDialog (_("Varispeed"))
: ArdourDialog (_("Varispeed"), false)
, _semitones_adjustment (0.0, -12.0, 12.0, 1.0, 4.0)
, _cents_adjustment (0.0, -100.0, 100.0, 1.0, 10.0)
, _semitones_spinner (_semitones_adjustment)
, _cents_spinner (_cents_adjustment)
{
set_modal (false);
Table* t = manage (new Table (3, 2));
t->set_row_spacings (6);
t->set_col_spacings (6);
@ -82,16 +80,26 @@ VarispeedDialog::apply_speed ()
{
int cents = _semitones_spinner.get_value () * 100 + _cents_spinner.get_value ();
double speed = pow (2.0, ((double)cents / (double)1200.0));
double speed = pow (2.0, ((double)cents / 1200.0));
if (_session) {
if (_session && _session->default_play_speed () != speed) {
_session->set_default_play_speed (speed);
}
}
void
VarispeedDialog::on_show ()
{
apply_speed ();
ArdourDialog::on_show ();
set_position (Gtk::WIN_POS_NONE); // remember position from now on
}
void
VarispeedDialog::on_hide ()
{
_session->set_default_play_speed (1.0);
if (_session && _session->default_play_speed () != 1.0) {
_session->set_default_play_speed (1.0);
}
ArdourDialog::on_hide ();
}

View File

@ -32,13 +32,14 @@ class VarispeedDialog : public ArdourDialog
public:
VarispeedDialog ();
void reset ();
private:
void apply_speed ();
void on_hide ();
void reset ();
void on_show ();
void on_hide ();
bool on_key_press_event (GdkEventKey*);
private:
Gtk::Adjustment _semitones_adjustment;
Gtk::Adjustment _cents_adjustment;
Gtk::SpinButton _semitones_spinner;