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