Merge with 2.0-ongoing R2988
[ardour.git] / gtk2_ardour / ardour_ui_dependents.cc
1 /*
2     Copyright (C) 2000 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /* this file exists solely to break compilation dependencies that
21    would connect changes to the mixer or editor objects.
22 */
23
24 #include <cstdio>
25
26 #include <gtkmm/accelmap.h>
27
28 #include <pbd/error.h>
29
30 #include "ardour_ui.h"
31 #include "public_editor.h"
32 #include "mixer_ui.h"
33 #include "keyboard.h"
34 #include "splash.h"
35 #include "route_params_ui.h"
36 #include "i18n.h"
37
38 using namespace sigc;
39 using namespace Gtk;
40 using namespace PBD;
41
42 namespace ARDOUR {
43         class Session;
44         class Route;
45 }
46
47 void
48 ARDOUR_UI::shutdown ()
49 {
50         if (session) {
51                 /* we're exiting cleanly, so remove any auto-save data */
52                 session->remove_pending_capture_state ();
53                 session = 0;
54         }
55
56         ui_config->save_state();
57 }
58
59 void
60 ARDOUR_UI::we_have_dependents ()
61 {
62         setup_keybindings ();
63         editor->UpdateAllTransportClocks.connect (mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
64 }
65
66 static void 
67 accel_map_changed (GtkAccelMap* map,
68                    gchar* path,
69                    guint  key,
70                    GdkModifierType mod,
71                    gpointer arg)
72 {
73         static_cast<ARDOUR_UI*>(arg)->save_keybindings ();
74 }
75
76 void
77 ARDOUR_UI::setup_keybindings ()
78 {
79         install_actions ();
80         ProcessorBox::register_actions ();
81         
82         cerr << "loading bindings from " << keybindings_path << endl;
83
84         try {
85                 AccelMap::load (keybindings_path);
86         } catch (...) {
87                 error << string_compose (_("Ardour key bindings file not found at \"%1\" or contains errors."), keybindings_path)
88                       << endmsg;
89         }
90
91         /* catch changes */
92
93         GtkAccelMap* accelmap = gtk_accel_map_get();
94         g_signal_connect (accelmap, "changed", (GCallback) accel_map_changed, this);
95
96         
97
98 }
99
100 void
101 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
102 {
103         editor->connect_to_session (s);
104         mixer->connect_to_session (s);
105
106         /* its safe to do this now */
107         
108         s->restore_history ("");
109 }
110
111 static bool
112 _hide_splash (gpointer arg)
113 {
114         ((ARDOUR_UI*)arg)->hide_splash();
115         return false;
116 }
117
118 void
119 ARDOUR_UI::goto_editor_window ()
120 {
121         if (splash && splash->is_visible()) {
122                 // in 2 seconds, hide the splash screen 
123                 Glib::signal_timeout().connect (bind (sigc::ptr_fun (_hide_splash), this), 2000);
124         }
125
126         editor->show_window ();
127         editor->present ();
128         flush_pending ();
129 }
130
131 void
132 ARDOUR_UI::goto_mixer_window ()
133 {
134         mixer->show_window ();
135         mixer->present ();
136         flush_pending ();
137 }
138
139 gint
140 ARDOUR_UI::exit_on_main_window_close (GdkEventAny *ev)
141 {
142         finish();
143         return TRUE;
144 }