8b0f582ec93b000531b2d4f1398306c2e80d810d
[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 using namespace ARDOUR;
48
49 void
50 ARDOUR_UI::shutdown ()
51 {
52         if (session) {
53                 /* we're exiting cleanly, so remove any auto-save data */
54                 session->remove_pending_capture_state ();
55                 session = 0;
56         }
57
58         ui_config->save_state();
59 }
60
61 void
62 ARDOUR_UI::we_have_dependents ()
63 {
64         setup_keybindings ();
65         editor->UpdateAllTransportClocks.connect (mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
66 }
67
68 static void 
69 accel_map_changed (GtkAccelMap* map,
70                    gchar* path,
71                    guint  key,
72                    GdkModifierType mod,
73                    gpointer arg)
74 {
75         static_cast<ARDOUR_UI*>(arg)->save_keybindings ();
76 }
77
78 void
79 ARDOUR_UI::setup_keybindings ()
80 {
81         install_actions ();
82         RedirectBox::register_actions ();
83         
84         cerr << "loading bindings from " << keybindings_path << endl;
85
86         try {
87                 AccelMap::load (keybindings_path);
88         } catch (...) {
89                 error << string_compose (_("Ardour key bindings file not found at \"%1\" or contains errors."), keybindings_path)
90                       << endmsg;
91         }
92
93         /* catch changes */
94
95         GtkAccelMap* accelmap = gtk_accel_map_get();
96         g_signal_connect (accelmap, "changed", (GCallback) accel_map_changed, this);
97
98         
99
100 }
101
102 void
103 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
104 {
105         BootMessage (_("Setup Editor"));
106         editor->connect_to_session (s);
107         BootMessage (_("Setup Mixer"));
108         mixer->connect_to_session (s);
109
110         /* its safe to do this now */
111         
112         BootMessage (_("Reload Session History"));
113         s->restore_history ("");
114 }
115
116 static bool
117 _hide_splash (gpointer arg)
118 {
119         ((ARDOUR_UI*)arg)->hide_splash();
120         return false;
121 }
122
123 void
124 ARDOUR_UI::goto_editor_window ()
125 {
126         if (splash && splash->is_visible()) {
127                 // in 2 seconds, hide the splash screen 
128                 Glib::signal_timeout().connect (bind (sigc::ptr_fun (_hide_splash), this), 2000);
129         }
130
131         editor->show_window ();
132         editor->present();
133         flush_pending ();
134 }
135
136 void
137 ARDOUR_UI::goto_mixer_window ()
138 {
139         mixer->show_window ();
140         mixer->present();
141         flush_pending ();
142 }
143
144 gint
145 ARDOUR_UI::exit_on_main_window_close (GdkEventAny *ev)
146 {
147         finish();
148         return TRUE;
149 }