Heavy-duty abstraction work to split type-specific classes into
[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                         break;
160                 }
161         }
162         editor->hide ();
163         second_connection.disconnect ();
164         point_one_second_connection.disconnect ();
165         point_zero_one_second_connection.disconnect();
166
167         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
168         
169         rec_button.set_sensitive (false);
170         shuttle_box.set_sensitive (false);
171
172         stop_blinking ();
173         stop_clocking ();
174
175         /* drop everything attached to the blink signal */
176
177         Blink.clear ();
178
179         primary_clock.set_session (0);
180         secondary_clock.set_session (0);
181         big_clock.set_session (0);
182         preroll_clock.set_session (0);
183         postroll_clock.set_session (0);
184
185         if (option_editor) {
186                 option_editor->set_session (0);
187         }
188
189         if (mixer) {
190                 mixer->hide_all ();
191         }
192
193         delete session;
194         session = 0;
195
196         update_buffer_load ();
197
198         return 0;
199 }
200
201 int
202 ARDOUR_UI::create_connection_editor ()
203 {
204 #if 0
205         if (connection_editor == 0) {
206                 connection_editor = new ConnectionEditor ();
207                 connection_editor->signal_unmap().connect (sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleConnections")));
208         }
209
210         if (session) {
211                 connection_editor->set_session (session);
212         }
213 #endif
214
215         return 0;
216 }
217
218 void
219 ARDOUR_UI::toggle_connection_editor ()
220 {
221         if (create_connection_editor()) {
222                 return;
223         }
224
225 #if 0
226         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleConnections"));
227         if (act) {
228                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
229         
230                 if (tact->get_active()) {
231                         connection_editor->show_all ();
232                         connection_editor->present ();
233                 } else {
234                         connection_editor->hide ();
235                 } 
236         }
237 #endif
238 }
239
240 void
241 ARDOUR_UI::toggle_big_clock_window ()
242 {
243         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
244         if (act) {
245                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
246         
247                 if (tact->get_active()) {
248                         big_clock_window->show_all ();
249                         big_clock_window->present ();
250                 } else {
251                         big_clock_window->hide ();
252                 } 
253         }
254 }
255
256 void
257 ARDOUR_UI::toggle_options_window ()
258 {
259         if (option_editor == 0) {
260                 option_editor = new OptionEditor (*this, *editor, *mixer);
261                 option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleOptionsEditor")));
262                 option_editor->set_session (session);
263         } 
264
265         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleOptionsEditor"));
266         if (act) {
267                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
268         
269                 if (tact->get_active()) {
270                         option_editor->show_all ();
271                         option_editor->present ();
272                 } else {
273                         option_editor->hide ();
274                 } 
275         }
276 }
277
278 int
279 ARDOUR_UI::create_location_ui ()
280 {
281         if (location_ui == 0) {
282                 location_ui = new LocationUI ();
283                 location_ui->set_session (session);
284                 location_ui->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
285         }
286         return 0;
287 }
288
289 void
290 ARDOUR_UI::toggle_location_window ()
291 {
292         if (create_location_ui()) {
293                 return;
294         }
295
296         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
297         if (act) {
298                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
299         
300                 if (tact->get_active()) {
301                         location_ui->show_all ();
302                         location_ui->present ();
303                 } else {
304                         location_ui->hide ();
305                 } 
306         }
307 }
308
309 void
310 ARDOUR_UI::toggle_color_manager ()
311 {
312         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleColorManager"));
313         if (act) {
314                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
315         
316                 if (tact->get_active()) {
317                         color_manager->show_all ();
318                         color_manager->present ();
319                 } else {
320                         color_manager->hide ();
321                 } 
322         }
323 }
324
325 int
326 ARDOUR_UI::create_route_params ()
327 {
328         if (route_params == 0) {
329                 route_params = new RouteParams_UI (*engine);
330                 route_params->set_session (session);
331                 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
332         }
333         return 0;
334 }
335
336 void
337 ARDOUR_UI::toggle_route_params_window ()
338 {
339         if (create_route_params ()) {
340                 return;
341         }
342
343         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
344         if (act) {
345                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
346         
347                 if (tact->get_active()) {
348                         route_params->show_all ();
349                         route_params->present ();
350                 } else {
351                         route_params->hide ();
352                 } 
353         }
354 }
355
356 int
357 ARDOUR_UI::create_sound_file_browser ()
358 {
359         if (sfdb == 0) {
360                 sfdb = new SoundFileBrowser (_("Sound File Browser"), session);
361                 sfdb->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSoundFileBrowser")));
362         }
363         return 0;
364 }
365         
366 void
367 ARDOUR_UI::toggle_sound_file_browser ()
368 {
369         if (create_sound_file_browser()) {
370                 return;
371         }
372
373         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSoundFileBrowser"));
374         if (act) {
375                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
376         
377                 if (tact->get_active()) {
378                         sfdb->show_all();
379                         sfdb->present();
380                 } else {
381                         sfdb->hide ();
382                 }
383         }
384 }
385
386 void
387 ARDOUR_UI::handle_locations_change (Location* ignored)
388 {
389         if (session) {
390                 if (session->locations()->num_range_markers()) {
391                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
392                 } else {
393                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
394                 }
395         }
396 }