08501e746a68c487888195c133b85f6541e5bf9d
[ardour.git] / gtk2_ardour / ardour_ui_dialogs.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 contains any ARDOUR_UI methods that require knowledge of
21    the various dialog boxes, and exists so that no compilation dependency 
22    exists between the main ARDOUR_UI modules and their respective classes.
23    This is to cut down on the compile times.  It also helps with my sanity.
24 */
25
26 #include <ardour/session.h>
27
28 #include "actions.h"
29 #include "ardour_ui.h"
30 #include "connection_editor.h"
31 #include "location_ui.h"
32 #include "mixer_ui.h"
33 #include "option_editor.h"
34 #include "public_editor.h"
35 #include "route_params_ui.h"
36 #include "sfdb_ui.h"
37 #include "color_manager.h"
38
39 #include "i18n.h"
40
41 using namespace ARDOUR;
42 using namespace Glib;
43 using namespace Gtk;
44 using namespace Gtkmm2ext;
45
46 void
47 ARDOUR_UI::connect_to_session (Session *s)
48 {
49         session = s;
50
51         session->HaltOnXrun.connect (mem_fun(*this, &ARDOUR_UI::halt_on_xrun_message));
52
53         /* sensitize menu bar options that are now valid */
54
55         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
56
57         rec_button.set_sensitive (true);
58         shuttle_box.set_sensitive (true);
59         
60         if (session->n_diskstreams() == 0) {
61                 session->DiskStreamAdded.connect (mem_fun(*this, &ARDOUR_UI::diskstream_added));
62         }
63
64         if (connection_editor) {
65                 connection_editor->set_session (s);
66         }
67
68         if (location_ui) {
69                 location_ui->set_session(s);
70         }
71
72         if (route_params) {
73                 route_params->set_session (s);
74         }
75
76         if (option_editor) {
77                 option_editor->set_session (s);
78         }
79
80         if (sfdb) {
81                 sfdb->set_session (s);
82         }
83
84         setup_options ();
85
86         Blink.connect (mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
87         Blink.connect (mem_fun(*this, &ARDOUR_UI::solo_blink));
88         Blink.connect (mem_fun(*this, &ARDOUR_UI::audition_blink));
89
90         /* these are all need to be handled in an RT-safe and MT way, so don't
91            do any GUI work, just queue it for handling by the GUI thread.
92         */
93
94         session->TransportStateChange.connect (mem_fun(*this, &ARDOUR_UI::queue_transport_change));
95
96         /* alert the user to these things happening */
97
98         session->AuditionActive.connect (mem_fun(*this, &ARDOUR_UI::auditioning_changed));
99         session->SoloActive.connect (mem_fun(*this, &ARDOUR_UI::soloing_changed));
100
101         solo_alert_button.set_active (session->soloing());
102
103         /* can't be auditioning here */
104
105         primary_clock.set_session (s);
106         secondary_clock.set_session (s);
107         big_clock.set_session (s);
108         preroll_clock.set_session (s);
109         postroll_clock.set_session (s);
110
111         /* Clocks are on by default after we are connected to a session, so show that here.
112         */
113         
114         connect_dependents_to_session (s);
115
116         start_clocking ();
117         start_blinking ();
118
119         if (editor) {
120                 editor->present();
121         }
122
123         transport_stopped ();
124
125         second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_second), 1000);
126         point_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
127         point_zero_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
128 }
129
130 int
131 ARDOUR_UI::unload_session ()
132 {
133         if (session && session->dirty()) {
134                 switch (ask_about_saving_session (_("close session"))) {
135                 case -1:
136                         return 1;
137                         
138                 case 1:
139                         session->save_state ("");
140                         break;
141                 }
142         }
143
144         second_connection.disconnect ();
145         point_one_second_connection.disconnect ();
146         point_zero_one_second_connection.disconnect();
147
148         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
149         
150         rec_button.set_sensitive (false);
151         shuttle_box.set_sensitive (false);
152
153         stop_blinking ();
154         stop_clocking ();
155
156         /* drop everything attached to the blink signal */
157
158         Blink.clear ();
159
160         primary_clock.set_session (0);
161         secondary_clock.set_session (0);
162         big_clock.set_session (0);
163         preroll_clock.set_session (0);
164         postroll_clock.set_session (0);
165
166         if (option_editor) {
167                 option_editor->set_session (0);
168         }
169
170         if (mixer) {
171                 mixer->hide_all ();
172         }
173
174         delete session;
175         session = 0;
176
177         update_buffer_load ();
178         // update_disk_rate ();
179
180         return 0;
181 }
182
183 int
184 ARDOUR_UI::create_connection_editor ()
185 {
186 #if 0
187         if (connection_editor == 0) {
188                 connection_editor = new ConnectionEditor ();
189                 connection_editor->signal_unmap().connect (sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleConnections")));
190         }
191
192         if (session) {
193                 connection_editor->set_session (session);
194         }
195 #endif
196
197         return 0;
198 }
199
200 void
201 ARDOUR_UI::toggle_connection_editor ()
202 {
203         if (create_connection_editor()) {
204                 return;
205         }
206
207 #if 0
208         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleConnections"));
209         if (act) {
210                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
211         
212                 if (tact->get_active()) {
213                         connection_editor->show_all ();
214                         connection_editor->present ();
215                 } else {
216                         connection_editor->hide ();
217                 } 
218         }
219 #endif
220 }
221
222 void
223 ARDOUR_UI::toggle_big_clock_window ()
224 {
225         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
226         if (act) {
227                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
228         
229                 if (tact->get_active()) {
230                         big_clock_window->show_all ();
231                         big_clock_window->present ();
232                 } else {
233                         big_clock_window->hide ();
234                 } 
235         }
236 }
237
238 void
239 ARDOUR_UI::toggle_options_window ()
240 {
241         if (option_editor == 0) {
242                 option_editor = new OptionEditor (*this, *editor, *mixer);
243                 option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleOptionsEditor")));
244                 option_editor->set_session (session);
245         } 
246
247         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleOptionsEditor"));
248         if (act) {
249                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
250         
251                 if (tact->get_active()) {
252                         option_editor->show_all ();
253                         option_editor->present ();
254                 } else {
255                         option_editor->hide ();
256                 } 
257         }
258 }
259
260 int
261 ARDOUR_UI::create_location_ui ()
262 {
263         if (location_ui == 0) {
264                 location_ui = new LocationUI ();
265                 location_ui->set_session (session);
266                 location_ui->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
267         }
268         return 0;
269 }
270
271 void
272 ARDOUR_UI::toggle_location_window ()
273 {
274         if (create_location_ui()) {
275                 return;
276         }
277
278         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
279         if (act) {
280                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
281         
282                 if (tact->get_active()) {
283                         location_ui->show_all ();
284                         location_ui->present ();
285                 } else {
286                         location_ui->hide ();
287                 } 
288         }
289 }
290
291 void
292 ARDOUR_UI::toggle_color_manager ()
293 {
294         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleColorManager"));
295         if (act) {
296                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
297         
298                 if (tact->get_active()) {
299                         color_manager->show_all ();
300                         color_manager->present ();
301                 } else {
302                         color_manager->hide ();
303                 } 
304         }
305 }
306
307 int
308 ARDOUR_UI::create_route_params ()
309 {
310         if (route_params == 0) {
311                 route_params = new RouteParams_UI (*engine);
312                 route_params->set_session (session);
313                 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
314         }
315         return 0;
316 }
317
318 void
319 ARDOUR_UI::toggle_route_params_window ()
320 {
321         if (create_route_params ()) {
322                 return;
323         }
324
325         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
326         if (act) {
327                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
328         
329                 if (tact->get_active()) {
330                         route_params->show_all ();
331                         route_params->present ();
332                 } else {
333                         route_params->hide ();
334                 } 
335         }
336 }
337
338 int
339 ARDOUR_UI::create_sound_file_browser ()
340 {
341         if (sfdb == 0) {
342                 sfdb = new SoundFileBrowser (_("Sound File Browser"));
343                 sfdb->set_session (session);
344                 sfdb->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSoundFileBrowser")));
345         }
346         return 0;
347 }
348         
349 void
350 ARDOUR_UI::toggle_sound_file_browser ()
351 {
352         if (create_sound_file_browser()) {
353                 return;
354         }
355
356         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSoundFileBrowser"));
357         if (act) {
358                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
359         
360                 if (tact->get_active()) {
361                         sfdb->show_all();
362                         sfdb->present();
363                 } else {
364                         sfdb->hide ();
365                 }
366         }
367 }
368