From b4462b3d22f57f3fe7f4e933b2df0e2c89148e78 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 17 Jan 2014 00:20:58 +0100 Subject: add seeking to sfdb auditioner --- gtk2_ardour/sfdb_ui.cc | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- gtk2_ardour/sfdb_ui.h | 11 ++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 9b3d78e86d..54faae5654 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -120,7 +120,9 @@ SoundFileBox::SoundFileBox (bool persistent) length_clock ("sfboxLengthClock", !persistent, "", false, false, true, false), timecode_clock ("sfboxTimecodeClock", !persistent, "", false, false, false, false), main_box (false, 6), - autoplay_btn (_("Auto-play")) + autoplay_btn (_("Auto-play")), + seek_slider(0,1000,1), + _seeking(false) { set_name (X_("SoundFileBox")); @@ -198,9 +200,18 @@ SoundFileBox::SoundFileBox (bool persistent) bottom_box.pack_start(stop_btn, true, true); bottom_box.pack_start(autoplay_btn, false, false); + seek_slider.set_draw_value(false); + + seek_slider.add_events(Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK); + seek_slider.signal_button_press_event().connect(sigc::mem_fun(*this, &SoundFileBox::seek_button_press), false); + seek_slider.signal_button_release_event().connect(sigc::mem_fun(*this, &SoundFileBox::seek_button_release), false); + main_box.pack_start (seek_slider, false, false); + play_btn.signal_clicked().connect (sigc::mem_fun (*this, &SoundFileBox::audition)); stop_btn.signal_clicked().connect (sigc::mem_fun (*this, &SoundFileBox::stop_audition)); + stop_btn.set_sensitive (false); + channels_value.set_alignment (0.0f, 0.5f); samplerate_value.set_alignment (0.0f, 0.5f); } @@ -216,9 +227,45 @@ SoundFileBox::set_session(Session* s) if (!_session) { play_btn.set_sensitive (false); stop_btn.set_sensitive (false); + auditioner_connections.drop_connections(); + } else { + auditioner_connections.drop_connections(); + _session->AuditionActive.connect(auditioner_connections, invalidator (*this), boost::bind (&SoundFileBox::audition_active, this, _1), gui_context()); + _session->the_auditioner()->AuditionProgress.connect(auditioner_connections, invalidator (*this), boost::bind (&SoundFileBox::audition_progress, this, _1, _2), gui_context()); + } +} + +void +SoundFileBox::audition_active(bool active) { + stop_btn.set_sensitive (active); + seek_slider.set_sensitive (active); + if (!active) { + seek_slider.set_value(0); + } +} + +void +SoundFileBox::audition_progress(ARDOUR::framecnt_t pos, ARDOUR::framecnt_t len) { + if (!_seeking) { + seek_slider.set_value( 1000.0 * pos / len); + seek_slider.set_sensitive (true); } } +bool +SoundFileBox::seek_button_press(GdkEventButton*) { + _seeking = true; + return false; // pass on to slider +} + +bool +SoundFileBox::seek_button_release(GdkEventButton*) { + _seeking = false; + _session->the_auditioner()->seek_to_percent(seek_slider.get_value() / 10.0); + seek_slider.set_sensitive (false); + return false; // pass on to slider +} + bool SoundFileBox::setup_labels (const string& filename) { diff --git a/gtk2_ardour/sfdb_ui.h b/gtk2_ardour/sfdb_ui.h index 5d8decddf4..ccfd3799be 100644 --- a/gtk2_ardour/sfdb_ui.h +++ b/gtk2_ardour/sfdb_ui.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,7 @@ namespace ARDOUR { class GainMeter; class Mootcher; -class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr +class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList { public: SoundFileBox (bool persistent); @@ -103,11 +104,19 @@ class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr Gtk::Button stop_btn; Gtk::CheckButton autoplay_btn; Gtk::Button apply_btn; + Gtk::HScale seek_slider; + + PBD::ScopedConnectionList auditioner_connections; + void audition_active(bool); + void audition_progress(ARDOUR::framecnt_t, ARDOUR::framecnt_t); bool tags_entry_left (GdkEventFocus* event); void tags_changed (); void save_tags (const std::vector&); void stop_audition (); + bool seek_button_press(GdkEventButton*); + bool seek_button_release(GdkEventButton*); + bool _seeking; }; class SoundFileBrowser : public ArdourWindow -- cgit v1.2.3