Add a Lua script snippet processing region data from the editor
[ardour.git] / gtk2_ardour / ardour_ui.cc
index 6c349260f77af6e6e99f5eba757bb4a34ab229fd..8c2ec7605387bee27aef65cdcac10367b4176711 100644 (file)
@@ -163,6 +163,7 @@ typedef uint64_t microseconds_t;
 #include "route_params_ui.h"
 #include "save_as_dialog.h"
 #include "script_selector.h"
+#include "session_archive_dialog.h"
 #include "session_dialog.h"
 #include "session_metadata_dialog.h"
 #include "session_option_editor.h"
@@ -1324,7 +1325,9 @@ If you still wish to quit, please use the\n\n\
        */
        save_ardour_state ();
 
-       key_editor->disconnect ();
+       if (key_editor.get (false)) {
+               key_editor->disconnect ();
+       }
 
        close_all_dialogs ();
 
@@ -2696,6 +2699,32 @@ ARDOUR_UI::save_session_as ()
        }
 }
 
+void
+ARDOUR_UI::archive_session ()
+{
+       if (!_session) {
+               return;
+       }
+
+       time_t n;
+       time (&n);
+       Glib::DateTime gdt (Glib::DateTime::create_now_local (n));
+
+       SessionArchiveDialog sad;
+       sad.set_name (_session->name() + gdt.format ("_%F_%H%M%S"));
+       int response = sad.run ();
+
+       if (response != Gtk::RESPONSE_OK) {
+               sad.hide ();
+               return;
+       }
+
+       if (_session->archive_session (sad.target_folder(), sad.name(), sad.encode_option (), sad.only_used_sources (), &sad)) {
+               MessageDialog msg (_("Session Archiving failed."));
+               msg.run ();
+       }
+}
+
 void
 ARDOUR_UI::quick_snapshot_session (bool switch_to_it)
 {
@@ -3096,7 +3125,19 @@ ARDOUR_UI::build_session_from_dialog (SessionDialog& sd, const std::string& sess
 void
 ARDOUR_UI::load_from_application_api (const std::string& path)
 {
+       /* OS X El Capitan (and probably later) now somehow passes the command
+          line arguments to an app via the openFile delegate protocol. Ardour 
+          already does its own command line processing, and having both
+          pathways active causes crashes. So, if the command line was already
+          set, do nothing here.
+       */
+
+       if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
+               return;
+       }
+
        ARDOUR_COMMAND_LINE::session_name = path;
+
        /* Cancel SessionDialog if it's visible to make OSX delegates work.
         *
         * ARDOUR_UI::starting connects app->ShouldLoad signal and then shows a SessionDialog
@@ -3579,7 +3620,9 @@ ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name,
        }
 
        catch (SessionException e) {
+               cerr << "Here are the errors associated with this failed session:\n";
                dump_errors (cerr);
+               cerr << "---------\n";
                MessageDialog msg (string_compose(_("Could not create session in \"%1\": %2"), path, e.what()));
                msg.set_title (_("Loading Error"));
                msg.set_position (Gtk::WIN_POS_CENTER);
@@ -3588,7 +3631,9 @@ ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name,
                return -1;
        }
        catch (...) {
+               cerr << "Here are the errors associated with this failed session:\n";
                dump_errors (cerr);
+               cerr << "---------\n";
                MessageDialog msg (string_compose(_("Could not create session in \"%1\""), path));
                msg.set_title (_("Loading Error"));
                msg.set_position (Gtk::WIN_POS_CENTER);
@@ -5529,15 +5574,15 @@ ARDOUR_UI::key_event_handler (GdkEventKey* ev, Gtk::Window* event_window)
 }
 
 static Gtkmm2ext::Bindings*
-get_bindings_from_widget_heirarchy (GtkWidget* w)
+get_bindings_from_widget_heirarchy (GtkWidget** w)
 {
        void* p = NULL;
 
-       while (w) {
-               if ((p = g_object_get_data (G_OBJECT(w), "ardour-bindings")) != 0) {
+       while (*w) {
+               if ((p = g_object_get_data (G_OBJECT(*w), "ardour-bindings")) != 0) {
                        break;
                }
-               w = gtk_widget_get_parent (w);
+               *w = gtk_widget_get_parent (*w);
        }
 
        return reinterpret_cast<Gtkmm2ext::Bindings*> (p);
@@ -5548,6 +5593,7 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
 {
        GtkWindow* win = window.gobj();
        GtkWidget* focus = gtk_window_get_focus (win);
+       GtkWidget* binding_widget = focus;
        bool special_handling_of_unmodified_accelerators = false;
        const guint mask = (Keyboard::RelevantModifierKeyMask & ~(Gdk::SHIFT_MASK|Gdk::LOCK_MASK));
 
@@ -5566,7 +5612,7 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
 
                } else {
 
-                       Gtkmm2ext::Bindings* focus_bindings = get_bindings_from_widget_heirarchy (focus);
+                       Gtkmm2ext::Bindings* focus_bindings = get_bindings_from_widget_heirarchy (&binding_widget);
                        if (focus_bindings) {
                                bindings = focus_bindings;
                                DEBUG_TRACE (DEBUG::Accelerators, string_compose ("Switch bindings based on focus widget, now using %1\n", bindings->name()));
@@ -5628,7 +5674,7 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
                DEBUG_TRACE (DEBUG::Accelerators, "\tsending to window\n");
                KeyboardKey k (ev->state, ev->keyval);
 
-               if (bindings) {
+               while (bindings) {
 
                        DEBUG_TRACE (DEBUG::Accelerators, string_compose ("\tusing Ardour bindings %1 @ %2 for this event\n", bindings->name(), bindings));
 
@@ -5636,6 +5682,17 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
                                DEBUG_TRACE (DEBUG::Accelerators, "\t\thandled\n");
                                return true;
                        }
+
+                       if (binding_widget) {
+                               binding_widget = gtk_widget_get_parent (binding_widget);
+                               if (binding_widget) {
+                                       bindings = get_bindings_from_widget_heirarchy (&binding_widget);
+                               } else {
+                                       bindings = 0;
+                               }
+                       } else {
+                               bindings = 0;
+                       }
                }
 
                DEBUG_TRACE (DEBUG::Accelerators, "\tnot yet handled, try global bindings\n");
@@ -5666,7 +5723,7 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
                DEBUG_TRACE (DEBUG::Accelerators, "\tpropagation didn't handle, so activate\n");
                KeyboardKey k (ev->state, ev->keyval);
 
-               if (bindings) {
+               while (bindings) {
 
                        DEBUG_TRACE (DEBUG::Accelerators, "\tusing Ardour bindings for this window\n");
 
@@ -5676,6 +5733,16 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
                                return true;
                        }
 
+                       if (binding_widget) {
+                               binding_widget = gtk_widget_get_parent (binding_widget);
+                               if (binding_widget) {
+                                       bindings = get_bindings_from_widget_heirarchy (&binding_widget);
+                               } else {
+                                       bindings = 0;
+                               }
+                       } else {
+                               bindings = 0;
+                       }
                }
 
                DEBUG_TRACE (DEBUG::Accelerators, "\tnot yet handled, try global bindings\n");