From 5e76c32e96c1b9d2c88514ea28d9e39f2eefaa92 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Wed, 29 Dec 2021 11:21:44 -0600 Subject: [PATCH] trigger_ui: add a button to load a sample (TODO: refactor with triggerbox) --- gtk2_ardour/trigger_ui.cc | 73 ++++++++++++++++++++++++++++++++++++ gtk2_ardour/trigger_ui.h | 5 +++ gtk2_ardour/triggerbox_ui.cc | 16 ++++++++ 3 files changed, 94 insertions(+) diff --git a/gtk2_ardour/trigger_ui.cc b/gtk2_ardour/trigger_ui.cc index 8bd967e319..b6c529e7fd 100644 --- a/gtk2_ardour/trigger_ui.cc +++ b/gtk2_ardour/trigger_ui.cc @@ -25,6 +25,13 @@ #include "pbd/compose.h" #include "pbd/convert.h" +#include "pbd/basename.h" +#include "pbd/file_utils.h" +#include "pbd/pathexpand.h" +#include "pbd/search_path.h" + +#include "ardour/directory_names.h" +#include "ardour/filesystem_paths.h" #include "ardour/region.h" #include "ardour/triggerbox.h" @@ -250,6 +257,72 @@ TriggerUI::~TriggerUI () { } +void +TriggerUI::choose_sample () +{ + if (!_file_chooser) { + _file_chooser = new Gtk::FileChooserDialog (_("Select sample"), Gtk::FILE_CHOOSER_ACTION_OPEN); + _file_chooser->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + _file_chooser->add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK); + + /* for newbies, start in the bundled media folder */ + Searchpath spath (ardour_data_search_path ()); + spath.add_subdirectory_to_paths (media_dir_name); + for (auto const& f : spath) { + if (Glib::file_test (f, Glib::FILE_TEST_IS_DIR | Glib::FILE_TEST_EXISTS)) { + _file_chooser->set_current_folder (f); + } + } + + /* TODO: add various shortcut paths to user's media folders + + _file_chooser->add_shortcut_folder_uri(Glib::build_filename (user_config_directory (), media_dir_name); + + Searchpath cpath (Config->get_sample_lib_path ()); + for (auto const& f : cpath) { + _file_chooser->add_shortcut_folder_uri (f); + } + */ + +#ifdef __APPLE__ + try { + /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */ + _file_chooser->add_shortcut_folder_uri("file:///Library/GarageBand/Apple Loops"); + _file_chooser->add_shortcut_folder_uri("file:///Library/Audio/Apple Loops"); + _file_chooser->add_shortcut_folder_uri("file:///Library/Application Support/GarageBand/Instrument Library/Sampler/Sampler Files"); + } + catch (Glib::Error & e) { + std::cerr << "sfdb.add_shortcut_folder() threw Glib::Error " << e.what() << std::endl; + } +#endif + + } + + _file_chooser_connection.disconnect (); + _file_chooser_connection = _file_chooser->signal_response ().connect (sigc::mem_fun (*this, &TriggerUI::sample_chosen)); + + _file_chooser->present (); +} + +void +TriggerUI::sample_chosen (int response) +{ + _file_chooser->hide (); + + switch (response) { + case Gtk::RESPONSE_OK: + break; + default: + return; + } + + std::list paths = _file_chooser->get_filenames (); + + for (std::list::iterator s = paths.begin (); s != paths.end (); ++s) { + TriggerBox *box = (TriggerBox *) &tref.trigger()->box(); + box->set_from_path (trigger()->index(), *s); + } +} /* ****************************************************************************/ diff --git a/gtk2_ardour/trigger_ui.h b/gtk2_ardour/trigger_ui.h index 1da18c1219..cf280760f3 100644 --- a/gtk2_ardour/trigger_ui.h +++ b/gtk2_ardour/trigger_ui.h @@ -48,6 +48,8 @@ class TriggerUI : public Gtk::Table //, public sigc::trackable static std::string launch_style_to_string (ARDOUR::Trigger::LaunchStyle); private: + void choose_sample (); + void sample_chosen (int r); /* name editing */ bool namebox_button_press (GdkEventButton*); @@ -73,6 +75,9 @@ class TriggerUI : public Gtk::Table //, public sigc::trackable ArdourWidgets::Frame _name_frame; sigc::connection _file_chooser_connection; + Gtk::FileChooserDialog* _file_chooser; + ArdourWidgets::ArdourButton _load_button; + ArdourWidgets::ArdourButton _follow_action_button; Gtk::Adjustment _velocity_adjustment; diff --git a/gtk2_ardour/triggerbox_ui.cc b/gtk2_ardour/triggerbox_ui.cc index 452592b9a2..d62227e36a 100644 --- a/gtk2_ardour/triggerbox_ui.cc +++ b/gtk2_ardour/triggerbox_ui.cc @@ -27,6 +27,13 @@ #include "pbd/convert.h" #include "pbd/unwind.h" +#include "pbd/basename.h" +#include "pbd/file_utils.h" +#include "pbd/pathexpand.h" +#include "pbd/search_path.h" + +#include "ardour/directory_names.h" +#include "ardour/filesystem_paths.h" #include "ardour/region.h" #include "ardour/triggerbox.h" @@ -1047,6 +1054,15 @@ TriggerBoxUI::choose_sample (uint64_t n) _file_chooser->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); _file_chooser->add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK); _file_chooser->set_select_multiple (true); + + /* for newbies, start in the bundled media folder */ + Searchpath spath (ardour_data_search_path ()); + spath.add_subdirectory_to_paths (media_dir_name); + for (auto const& f : spath) { + if (Glib::file_test (f, Glib::FILE_TEST_IS_DIR | Glib::FILE_TEST_EXISTS)) { + _file_chooser->set_current_folder (f); + } + } } _file_chooser_connection.disconnect ();