new ArdourButton class, to start to provide more control over how our buttons work...
[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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 /* this file exists solely to break compilation dependencies that
25    would connect changes to the mixer or editor objects.
26 */
27
28 #include <cstdio>
29
30 #include "pbd/error.h"
31
32 #include "ardour/session.h"
33
34 #include "ardour_ui.h"
35 #include "public_editor.h"
36 #include "mixer_ui.h"
37 #include "keyboard.h"
38 #include "splash.h"
39 #include "route_params_ui.h"
40 #include "opts.h"
41 #include "i18n.h"
42
43 using namespace Gtk;
44 using namespace PBD;
45
46 namespace ARDOUR {
47         class Session;
48         class Route;
49 }
50
51 using namespace ARDOUR;
52
53 void
54 ARDOUR_UI::shutdown ()
55 {
56         if (ui_config->dirty()) {
57                 ui_config->save_state();
58         }
59 }
60
61 void
62 ARDOUR_UI::we_have_dependents ()
63 {
64         install_actions ();
65         ProcessorBox::register_actions ();
66         keyboard->setup_keybindings ();
67         editor->setup_tooltips ();
68         editor->UpdateAllTransportClocks.connect (sigc::mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
69 }
70
71 void
72 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
73 {
74         BootMessage (_("Setup Editor"));
75         editor->set_session (s);
76         BootMessage (_("Setup Mixer"));
77         mixer->set_session (s);
78
79         /* its safe to do this now */
80
81         BootMessage (_("Reload Session History"));
82         s->restore_history ("");
83 }
84
85 static bool
86 _hide_splash (gpointer arg)
87 {
88         ((ARDOUR_UI*)arg)->hide_splash();
89         return false;
90 }
91
92 void
93 ARDOUR_UI::goto_editor_window ()
94 {
95         if (splash && splash->is_visible()) {
96                 // in 2 seconds, hide the splash screen
97                 Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (_hide_splash), this), 2000);
98         }
99
100         editor->show_window ();
101         editor->present ();
102         flush_pending ();
103 }
104
105 void
106 ARDOUR_UI::goto_mixer_window ()
107 {
108         mixer->show_window ();
109         mixer->present ();
110         flush_pending ();
111 }
112
113 void
114 ARDOUR_UI::toggle_mixer_window ()
115 {
116         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-mixer"));
117         if (!act) {
118                 return;
119         }
120
121         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
122
123         if (tact->get_active()) {
124                 goto_mixer_window ();
125         } else {
126                 mixer->hide ();
127         }
128 }
129
130 void
131 ARDOUR_UI::toggle_mixer_on_top ()
132 {
133         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-mixer-on-top"));
134         if (!act) {
135                 return;
136         }
137
138         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
139
140         if (tact->get_active()) {
141
142                 /* Toggle the mixer to `visible' if required */
143                 act = ActionManager::get_action (X_("Common"), X_("toggle-mixer"));
144                 if (act) {
145                         tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
146
147                         if (!tact->get_active()) {
148                                 tact->set_active ();
149                         }
150                 }
151
152                 goto_mixer_window ();
153         } else {
154                 goto_editor_window ();
155         }
156 }
157
158 /** The main editor window has been closed */
159 gint
160 ARDOUR_UI::exit_on_main_window_close (GdkEventAny * /*ev*/)
161 {
162 #ifdef TOP_MENUBAR
163         /* just hide the window, and return - the top menu stays up */
164         editor->hide ();
165         return TRUE;
166 #else
167         /* time to get out of here */
168         finish();
169         return TRUE;
170 #endif
171 }
172