dab51b6349864f3eebbdf1db32d3ac7fdedc1c85
[ardour.git] / gtk2_ardour / ardour_ui_ed.cc
1 /*
2     Copyright (C) 20002-2004 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     $Id$
19 */
20
21 /* This file contains any ARDOUR_UI methods that require knowledge of
22    the editor, and exists so that no compilation dependency exists
23    between the main ARDOUR_UI modules and the PublicEditor class. This
24    is to cut down on the nasty compile times for both these classes.
25 */
26
27 #include <pbd/pathscanner.h>
28
29 #include "ardour_ui.h"
30 #include "public_editor.h"
31 #include "audio_clock.h"
32 #include "editor.h"
33
34 #include <ardour/session.h>
35
36 #include "i18n.h"
37
38 using namespace ARDOUR;
39 using namespace Gtk;
40 using namespace Gtkmmext;
41
42 int
43 ARDOUR_UI::create_editor ()
44
45 {
46         try {
47                 editor = new Editor (*engine);
48         }
49
50         catch (failed_constructor& err) {
51                 return -1;
52         }
53
54         editor->DisplayControlChanged.connect (slot (*this, &ARDOUR_UI::editor_display_control_changed));
55
56         return 0;
57 }
58
59 void
60 ARDOUR_UI::build_menu_bar ()
61
62 {
63         using namespace Menu_Helpers;
64
65         menu_bar.set_name ("MainMenuBar");
66
67         MenuList& items = menu_bar.items();
68
69         /* file menu */
70         
71         Menu *session_menu = manage (new Menu);
72         MenuList& session_items = session_menu->items();
73         session_menu->set_name ("ArdourContextMenu");
74
75         session_items.push_back (MenuElem (_("New"), bind (slot (*this, &ARDOUR_UI::new_session), false, string ())));
76         session_items.push_back (MenuElem (_("Open"), slot (*this, &ARDOUR_UI::open_session)));
77         session_items.push_back (MenuElem (_("Recent"), slot (*this, &ARDOUR_UI::open_recent_session)));
78         session_items.push_back (MenuElem (_("Close"), slot (*this, &ARDOUR_UI::close_session)));
79         close_item = session_items.back();
80         close_item->set_sensitive (false);
81
82         session_items.push_back (SeparatorElem());
83
84         session_items.push_back (MenuElem (_("Add Track/Bus"), slot (*this, &ARDOUR_UI::add_route)));
85         add_track_item = session_items.back ();
86         add_track_item->set_sensitive (false);
87
88         session_items.push_back (SeparatorElem());
89         
90         /* <CMT Additions> */
91
92         PathScanner scanner;
93         vector<string*>* results = scanner (getenv ("PATH"), "AniComp", false, false);
94
95         if (results && !results->empty()) {
96                 Menu* image_compositor_menu = manage(new Menu());
97                 MenuList& image_compositor_items = image_compositor_menu->items();
98                 image_compositor_menu->set_name ("ArdourContextMenu");
99                 image_compositor_items.push_back(MenuElem (_("Connect"), (slot (editor, &PublicEditor::connect_to_image_compositor)))) ;
100                 session_items.push_back(MenuElem (_("Image Compositor"), *image_compositor_menu)) ;
101                 image_compositor_item = session_items.back() ;
102                 image_compositor_item->set_sensitive(false) ;
103                 session_items.push_back (SeparatorElem());
104         } else {
105                 image_compositor_item = 0;
106         }
107
108         if (results) {
109                 delete results;
110         }
111
112         /* </CMT Additions> */
113
114         session_items.push_back (MenuElem (_("Save"), bind (slot (*this, &ARDOUR_UI::save_state), string(""))));
115         save_item = session_items.back();
116         save_item->set_sensitive (false);
117
118         session_items.push_back (MenuElem (_("Snapshot"), slot (*this, &ARDOUR_UI::snapshot_session)));
119         snapshot_item = session_items.back();
120         snapshot_item->set_sensitive (false);
121 /*
122         session_items.push_back (MenuElem (_("Save as...")));
123         save_as_item = session_items.back();
124         save_as_item->set_sensitive (false);
125 */
126         session_items.push_back (MenuElem (_("Save Template..."), slot (*this, &ARDOUR_UI::save_template)));
127         save_template_item = session_items.back();
128         save_template_item->set_sensitive (false);
129
130         Menu *export_menu = manage (new Menu);
131         MenuList& export_items = export_menu->items();
132         export_menu->set_name ("ArdourContextMenu");
133         export_items.push_back (MenuElem (_("Export session to audiofile..."), slot (*editor, &PublicEditor::export_session)));
134         export_items.push_back (MenuElem (_("Export range to audiofile..."), slot (*editor, &PublicEditor::export_selection)));
135         // export_items.back()->set_sensitive (false);
136
137         session_items.push_back (MenuElem (_("Export"), *export_menu));
138         export_item = session_items.back();
139         export_item->set_sensitive (false);
140
141         session_items.push_back (SeparatorElem());
142
143         Menu *cleanup_menu = manage (new Menu);
144         MenuList& cleanup_items = cleanup_menu->items();
145         cleanup_menu->set_name ("ArdourContextMenu");
146         cleanup_items.push_back (MenuElem (_("Cleanup unused sources"), slot (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup)));
147         cleanup_items.push_back (MenuElem (_("Flush wastebasket"), slot (*(ARDOUR_UI::instance()), &ARDOUR_UI::flush_trash)));
148
149         session_items.push_back (MenuElem (_("Cleanup"), *cleanup_menu));
150         cleanup_item = session_items.back ();
151         cleanup_item->set_sensitive (false);
152
153         session_items.push_back (SeparatorElem());
154
155         session_items.push_back (MenuElem (_("Quit"), slot (*(ARDOUR_UI::instance()), &ARDOUR_UI::finish)));
156
157         items.push_back (MenuElem (_("Session"), *session_menu));
158
159         /* edit menu; the editor is responsible for the contents */
160
161         Menu *edit_menu = manage (new Menu);
162         editor->set_edit_menu (*edit_menu);
163         items.push_back (MenuElem (_("Edit"), *edit_menu));
164         edit_menu->set_name ("ArdourContextMenu");
165         
166         /* JACK menu for controlling ... JACK */
167
168         Menu* jack_menu = manage (new Menu);
169         MenuList& jack_items = jack_menu->items();
170         jack_menu->set_name ("ArdourContextMenu");
171         
172         jack_items.push_back (MenuElem (_("Disconnect"), slot (*(ARDOUR_UI::instance()), &ARDOUR_UI::disconnect_from_jack)));
173         jack_disconnect_item = jack_items.back();
174         jack_disconnect_item->set_sensitive (false);
175         jack_items.push_back (MenuElem (_("Reconnect"), slot (*(ARDOUR_UI::instance()), &ARDOUR_UI::reconnect_to_jack)));
176         jack_reconnect_item = jack_items.back();
177         jack_reconnect_item->set_sensitive (false);
178
179         jack_bufsize_menu = manage (new Menu);
180         MenuList& jack_bufsize_items = jack_bufsize_menu->items();
181         jack_bufsize_menu->set_name ("ArdourContextMenu");
182
183         jack_bufsize_items.push_back (MenuElem (X_("32"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 32)));
184         jack_bufsize_items.push_back (MenuElem (X_("64"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 64)));
185         jack_bufsize_items.push_back (MenuElem (X_("128"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 128)));
186         jack_bufsize_items.push_back (MenuElem (X_("256"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 256)));
187         jack_bufsize_items.push_back (MenuElem (X_("512"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 512)));
188         jack_bufsize_items.push_back (MenuElem (X_("1024"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 1024)));
189         jack_bufsize_items.push_back (MenuElem (X_("2048"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 2048)));
190         jack_bufsize_items.push_back (MenuElem (X_("4096"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 4096)));
191         jack_bufsize_items.push_back (MenuElem (X_("8192"), bind (slot (*this, &ARDOUR_UI::set_jack_buffer_size), (jack_nframes_t) 8192)));
192
193         jack_items.push_back (MenuElem (_("Latency"), *jack_bufsize_menu));
194         jack_bufsize_menu->set_sensitive (false);
195
196         items.push_back (MenuElem (_("JACK"), *jack_menu));
197         
198         /* windows menu */
199
200         Menu *window_menu = new Menu();
201         MenuList& window_items = window_menu->items();
202         window_menu->set_name ("ArdourContextMenu");
203         
204         window_items.push_back (TearoffMenuElem());
205
206         window_items.push_back (MenuElem (_("Editor"), slot (*this, &ARDOUR_UI::goto_editor_window)));
207         window_items.push_back (MenuElem (_("Mixer"), slot (*this, &ARDOUR_UI::goto_mixer_window)));
208
209         window_items.push_back (SeparatorElem());
210
211         window_items.push_back 
212                 (CheckMenuElem 
213                  (_("Options Editor"),
214                   slot (*this, &ARDOUR_UI::toggle_options_window)));
215          options_window_check = dynamic_cast<CheckMenuItem*>(window_items.back());
216         // options_window_check->set_sensitive (false);
217
218         window_items.push_back
219                 (CheckMenuElem
220                  (_("Audio Library"),
221                   slot (*this, &ARDOUR_UI::toggle_sfdb_window)));
222         sfdb_check = dynamic_cast<CheckMenuItem*>(window_items.back());
223
224         window_items.push_back 
225                 (CheckMenuElem 
226                  (_("Track/Bus Inspector"),
227                   slot (*this, &ARDOUR_UI::toggle_route_params_window)));
228         route_params_check = dynamic_cast<CheckMenuItem*>(window_items.back());
229         route_params_check->set_sensitive (false);
230
231         window_items.push_back 
232                 (CheckMenuElem 
233                  (_("Connections"),
234                   slot (*this, &ARDOUR_UI::toggle_connection_editor)));
235         connection_editor_check = dynamic_cast<CheckMenuItem*>(window_items.back());
236         connection_editor_check->set_sensitive (false);
237
238 #if 0
239         window_items.push_back 
240                 (CheckMenuElem 
241                  (_("Meter Bridge"),
242                   slot (*this, &ARDOUR_UI::toggle_meter_bridge_window)));
243         meter_bridge_dialog_check = dynamic_cast<CheckMenuItem*>(window_items.back());
244         meter_bridge_dialog_check->set_sensitive (false);
245 #endif
246
247         window_items.push_back 
248                 (CheckMenuElem 
249                  (_("Locations"),
250                   slot (*this, &ARDOUR_UI::toggle_location_window)));
251         locations_dialog_check = dynamic_cast<CheckMenuItem*>(window_items.back());
252         locations_dialog_check->set_sensitive (false);
253
254         window_items.push_back 
255                 (CheckMenuElem 
256                  (_("Big Clock"),
257                   slot (*this, &ARDOUR_UI::toggle_big_clock_window)));
258         big_clock_check = dynamic_cast<CheckMenuItem*>(window_items.back());
259
260         window_items.push_back (SeparatorElem());
261
262         window_items.push_back (MenuElem (_("About"), slot (*this, &ARDOUR_UI::show_splash)));
263         
264         
265         items.push_back (MenuElem (_("Windows"), *window_menu));
266
267         wall_clock_box.add (wall_clock_label);
268         wall_clock_box.set_name ("WallClock");
269         wall_clock_label.set_name ("WallClock");
270
271         disk_space_box.add (disk_space_label);
272         disk_space_box.set_name ("WallClock");
273         disk_space_label.set_name ("WallClock");
274
275         cpu_load_box.add (cpu_load_label);
276         cpu_load_box.set_name ("CPULoad");
277         cpu_load_label.set_name ("CPULoad");
278
279         buffer_load_box.add (buffer_load_label);
280         buffer_load_box.set_name ("BufferLoad");
281         buffer_load_label.set_name ("BufferLoad");
282
283 //      disk_rate_box.add (disk_rate_label);
284 //      disk_rate_box.set_name ("DiskRate");
285 //      disk_rate_label.set_name ("DiskRate");
286
287         sample_rate_box.add (sample_rate_label);
288         sample_rate_box.set_name ("SampleRate");
289         sample_rate_label.set_name ("SampleRate");
290
291         menu_hbox.pack_start (menu_bar, true, true);
292         menu_hbox.pack_end (wall_clock_box, false, false, 10);
293         menu_hbox.pack_end (disk_space_box, false, false, 10);
294         menu_hbox.pack_end (cpu_load_box, false, false, 10);
295 //      menu_hbox.pack_end (disk_rate_box, false, false, 10);
296         menu_hbox.pack_end (buffer_load_box, false, false, 10);
297         menu_hbox.pack_end (sample_rate_box, false, false, 10);
298
299         menu_bar_base.set_name ("MainMenuBar");
300         menu_bar_base.add (menu_hbox);
301 }
302
303
304 void
305 ARDOUR_UI::editor_display_control_changed (Editing::DisplayControl c)
306 {
307         switch (c) {
308         case Editing::FollowPlayhead:
309                 follow_button.set_active (editor->follow_playhead ());
310                 break;
311         default:
312                 break;
313         }
314 }
315