5f6459c041acd952e25fd3810d74db2a8c77af02
[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
38 #include "i18n.h"
39
40 using namespace ARDOUR;
41 using namespace Gtk;
42 using namespace Gtkmm2ext;
43
44 void
45 ARDOUR_UI::connect_to_session (Session *s)
46 {
47         session = s;
48
49         session->HaltOnXrun.connect (mem_fun(*this, &ARDOUR_UI::halt_on_xrun_message));
50
51         /* sensitize menu bar options that are now valid */
52
53         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
54
55         rec_button.set_sensitive (true);
56         shuttle_box.set_sensitive (true);
57         
58         if (session->n_diskstreams() == 0) {
59                 session->DiskStreamAdded.connect (mem_fun(*this, &ARDOUR_UI::diskstream_added));
60         }
61
62         if (connection_editor) {
63                 connection_editor->set_session (s);
64         }
65
66         if (location_ui) {
67                 location_ui->set_session(s);
68         }
69
70         if (route_params) {
71                 route_params->set_session (s);
72         }
73
74         if (option_editor) {
75                 option_editor->set_session (s);
76         }
77
78
79         Blink.connect (mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
80         Blink.connect (mem_fun(*this, &ARDOUR_UI::solo_blink));
81         Blink.connect (mem_fun(*this, &ARDOUR_UI::audition_blink));
82
83         /* these are all need to be handled in an RT-safe and MT way, so don't
84            do any GUI work, just queue it for handling by the GUI thread.
85         */
86
87         session->TransportStateChange.connect (mem_fun(*this, &ARDOUR_UI::queue_transport_change));
88         session->ControlChanged.connect (mem_fun(*this, &ARDOUR_UI::queue_map_control_change));
89
90         /* alert the user to these things happening */
91
92         session->AuditionActive.connect (mem_fun(*this, &ARDOUR_UI::auditioning_changed));
93         session->SoloActive.connect (mem_fun(*this, &ARDOUR_UI::soloing_changed));
94
95         solo_alert_button.set_active (session->soloing());
96
97         /* can't be auditioning here */
98
99         primary_clock.set_session (s);
100         secondary_clock.set_session (s);
101         big_clock.set_session (s);
102         preroll_clock.set_session (s);
103         postroll_clock.set_session (s);
104
105         /* Clocks are on by default after we are connected to a session, so show that here.
106         */
107         
108         map_button_state ();
109
110         connect_dependents_to_session (s);
111         
112         start_clocking ();
113         start_blinking ();
114
115         if (editor) {
116                 editor->present();
117         }
118
119         transport_stopped ();
120
121         second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_second), 1000);
122         point_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
123         point_zero_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
124 }
125
126 int
127 ARDOUR_UI::unload_session ()
128 {
129         if (session && session->dirty()) {
130                 switch (ask_about_saving_session (_("close session"))) {
131                 case -1:
132                         return 1;
133                         
134                 case 1:
135                         session->save_state ("");
136                         break;
137                 }
138         }
139
140         second_connection.disconnect ();
141         point_one_second_connection.disconnect ();
142         point_zero_one_second_connection.disconnect();
143
144         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
145         
146         rec_button.set_sensitive (false);
147         shuttle_box.set_sensitive (false);
148
149         stop_blinking ();
150         stop_clocking ();
151
152         /* drop everything attached to the blink signal */
153
154         Blink.clear ();
155
156         primary_clock.set_session (0);
157         secondary_clock.set_session (0);
158         big_clock.set_session (0);
159         preroll_clock.set_session (0);
160         postroll_clock.set_session (0);
161
162         if (option_editor) {
163                 option_editor->set_session (0);
164         }
165
166         if (mixer) {
167                 mixer->hide_all ();
168         }
169
170         delete session;
171         session = 0;
172
173         update_buffer_load ();
174         // update_disk_rate ();
175
176         return 0;
177 }
178
179 int
180 ARDOUR_UI::create_connection_editor ()
181 {
182         if (connection_editor == 0) {
183 //              connection_editor = new ConnectionEditor ();
184 //              connection_editor->signal_unmap().connect (sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleConnections")));
185         }
186
187         if (session) {
188 //              connection_editor->set_session (session);
189         }
190
191         return 0;
192 }
193
194 void
195 ARDOUR_UI::toggle_connection_editor ()
196 {
197         if (create_connection_editor()) {
198                 return;
199         }
200
201         //GTK2FIX
202 #if 0
203
204         if (connection_editor_check->get_active()){
205                 connection_editor->present();
206         } else {
207                 connection_editor->hide_all();
208         }
209 #endif
210 }
211
212 void
213 ARDOUR_UI::toggle_big_clock_window ()
214 {
215         if (big_clock_window->is_visible()) {
216                 big_clock_window->hide ();
217         } else {
218                 big_clock_window->show_all ();
219                 big_clock_window->present ();
220         }
221 }
222
223 void
224 ARDOUR_UI::toggle_options_window ()
225 {
226         if (option_editor == 0) {
227                 option_editor = new OptionEditor (*this, *editor, *mixer);
228                 option_editor->signal_unmap().connect(sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleOptionsWindow")));
229                 option_editor->set_session (session);
230         } 
231
232         if (option_editor->is_visible()) {
233                 option_editor->hide ();
234         } else {
235                 option_editor->present ();
236         }
237 }
238
239 void
240 ARDOUR_UI::toggle_auto_input ()
241
242 {
243         toggle_some_session_state (auto_input_button,
244                                    &Session::get_auto_input,
245                                    &Session::set_auto_input);
246 }
247
248 int
249 ARDOUR_UI::create_location_ui ()
250 {
251         if (location_ui == 0) {
252                 location_ui = new LocationUI ();
253                 location_ui->set_session (session);
254                 location_ui->signal_unmap().connect (sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
255         }
256         return 0;
257 }
258
259 void
260 ARDOUR_UI::toggle_location_window ()
261 {
262         if (create_location_ui()) {
263                 return;
264         }
265
266         if (location_ui->is_visible()) {
267                 location_ui->hide();
268         } else {
269                 location_ui->present();
270         }
271 }
272
273 int
274 ARDOUR_UI::create_route_params ()
275 {
276         if (route_params == 0) {
277                 route_params = new RouteParams_UI (*engine);
278                 route_params->set_session (session);
279                 route_params->signal_unmap().connect (sigc::bind(ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
280         }
281         return 0;
282 }
283
284 void
285 ARDOUR_UI::toggle_route_params_window ()
286 {
287         if (create_route_params ()) {
288                 return;
289         }
290
291         if (route_params->is_visible ()) {
292                 route_params->hide ();
293         } else {
294                 route_params->present ();
295         }
296 }
297         
298 void
299 ARDOUR_UI::toggle_sound_file_browser ()
300 {
301         using namespace Glib;
302
303         SoundFileBrowser sfdb(_("Sound File Browser"));
304         sfdb.run();
305
306         ActionManager::uncheck_toggleaction(X_("<Actions>/Common/ToggleSoundFileBrowser"));
307 }