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