Moved canvas colors and theme file selection into new ui specific config system
[ardour.git] / gtk2_ardour / midi_time_axis.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 #include <cstdlib>
20 #include <cmath>
21
22 #include <algorithm>
23 #include <string>
24 #include <vector>
25
26 #include <sigc++/bind.h>
27
28 #include <pbd/error.h>
29 #include <pbd/stl_delete.h>
30 #include <pbd/whitespace.h>
31
32 #include <gtkmm2ext/gtk_ui.h>
33 #include <gtkmm2ext/selector.h>
34 #include <gtkmm2ext/stop_signal.h>
35 #include <gtkmm2ext/bindable_button.h>
36 #include <gtkmm2ext/utils.h>
37
38 #include <ardour/midi_playlist.h>
39 #include <ardour/midi_diskstream.h>
40 #include <ardour/processor.h>
41 #include <ardour/ladspa_plugin.h>
42 #include <ardour/location.h>
43 #include <ardour/playlist.h>
44 #include <ardour/session.h>
45 #include <ardour/session_playlist.h>
46 #include <ardour/utils.h>
47
48 #include "ardour_ui.h"
49 #include "midi_time_axis.h"
50 #include "automation_time_axis.h"
51 #include "automation_midi_cc_line.h"
52 #include "add_midi_cc_track_dialog.h"
53 #include "canvas_impl.h"
54 #include "crossfade_view.h"
55 #include "enums.h"
56 #include "gui_thread.h"
57 #include "keyboard.h"
58 #include "playlist_selector.h"
59 #include "plugin_selector.h"
60 #include "plugin_ui.h"
61 #include "point_selection.h"
62 #include "prompter.h"
63 #include "public_editor.h"
64 #include "processor_automation_line.h"
65 #include "processor_automation_time_axis.h"
66 #include "midi_controller_time_axis.h"
67 #include "region_view.h"
68 #include "rgb_macros.h"
69 #include "selection.h"
70 #include "simplerect.h"
71 #include "midi_streamview.h"
72 #include "utils.h"
73
74 #include <ardour/midi_track.h>
75
76 #include "i18n.h"
77
78 using namespace ARDOUR;
79 using namespace PBD;
80 using namespace Gtk;
81 using namespace Editing;
82
83
84 MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
85         : AxisView(sess), // FIXME: won't compile without this, why??
86         RouteTimeAxisView(ed, sess, rt, canvas)
87 {
88         subplugin_menu.set_name ("ArdourContextMenu");
89
90         _view = new MidiStreamView (*this);
91
92         ignore_toggle = false;
93
94         mute_button->set_active (false);
95         solo_button->set_active (false);
96         
97         if (is_midi_track())
98                 controls_ebox.set_name ("MidiTimeAxisViewControlsBaseUnselected");
99         else // bus
100                 controls_ebox.set_name ("MidiBusControlsBaseUnselected");
101
102         /* map current state of the route */
103
104         processors_changed ();
105
106         ensure_xml_node ();
107
108         set_state (*xml_node);
109         
110         _route->processors_changed.connect (mem_fun(*this, &MidiTimeAxisView::processors_changed));
111
112         if (is_track()) {
113
114                 controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
115                 controls_base_selected_name = "MidiTrackControlsBaseSelected";
116                 controls_base_unselected_name = "MidiTrackControlsBaseUnselected";
117
118                 /* ask for notifications of any new RegionViews */
119                 _view->RegionViewAdded.connect (mem_fun(*this, &MidiTimeAxisView::region_view_added));
120                 _view->attach ();
121
122         } /*else { // no MIDI busses yet
123
124                 controls_ebox.set_name ("MidiBusControlsBaseUnselected");
125                 controls_base_selected_name = "MidiBusControlsBaseSelected";
126                 controls_base_unselected_name = "MidiBusControlsBaseUnselected";
127         }*/
128 }
129
130 MidiTimeAxisView::~MidiTimeAxisView ()
131 {
132 }
133
134 guint32
135 MidiTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
136 {
137         ensure_xml_node ();
138         xml_node->add_property ("shown_editor", "yes");
139                 
140         return TimeAxisView::show_at (y, nth, parent);
141 }
142
143 void
144 MidiTimeAxisView::hide ()
145 {
146         ensure_xml_node ();
147         xml_node->add_property ("shown_editor", "no");
148
149         TimeAxisView::hide ();
150 }
151
152 void
153 MidiTimeAxisView::build_automation_action_menu ()
154 {
155         using namespace Menu_Helpers;
156
157         RouteTimeAxisView::build_automation_action_menu ();
158
159         MenuList& automation_items = automation_action_menu->items();
160         
161         automation_items.push_back (SeparatorElem());
162
163         automation_items.push_back (MenuElem (_("Controller..."), 
164                                                    mem_fun(*this, &MidiTimeAxisView::add_controller_track)));
165 }
166
167 /** Prompt for a controller with a dialog and add an automation track for it
168  */
169 void
170 MidiTimeAxisView::add_controller_track()
171 {
172         AddMidiCCTrackDialog dialog;
173         dialog.set_transient_for(editor);
174         int response = dialog.run();
175         if (response == Gtk::RESPONSE_ACCEPT) {
176                 ParamID param = dialog.parameter();
177                 create_automation_child(param);
178         }
179 }
180
181 void
182 MidiTimeAxisView::create_automation_child (ParamID param)
183 {
184         if (param.type() == MidiCCAutomation) {
185         
186                 /* FIXME: this all probably leaks */
187
188                 boost::shared_ptr<AutomationControl> c =_route->control(param);
189
190                 if (!c) {
191                         boost::shared_ptr<AutomationList> al(new ARDOUR::AutomationList(param, 0, 127, 64));
192                         c = boost::shared_ptr<AutomationControl>(new AutomationControl(_session, al));
193                         _route->add_control(c);
194                 }
195
196                 MidiControllerTimeAxisView* track = new MidiControllerTimeAxisView (_session,
197                                 _route,
198                                 editor,
199                                 *this,
200                                 parent_canvas,
201                                 _route->describe_parameter(param),
202                                 c);
203
204                 AutomationMidiCCLine* line = new AutomationMidiCCLine (param.to_string(),
205                                 *track,
206                                 *track->canvas_display,
207                                 c->list());
208
209                 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
210
211                 track->add_line(*line);
212
213                 add_automation_child(param, track);
214
215         } else {
216                 error << "MidiTimeAxisView: unknown automation child " << param.to_string() << endmsg;
217         }
218 }
219
220 void
221 MidiTimeAxisView::route_active_changed ()
222 {
223         RouteUI::route_active_changed ();
224
225         if (is_track()) {
226                 if (_route->active()) {
227                         controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
228                         controls_base_selected_name = "MidiTrackControlsBaseSelected";
229                         controls_base_unselected_name = "MidiTrackControlsBaseUnselected";
230                 } else {
231                         controls_ebox.set_name ("MidiTrackControlsBaseInactiveUnselected");
232                         controls_base_selected_name = "MidiTrackControlsBaseInactiveSelected";
233                         controls_base_unselected_name = "MidiTrackControlsBaseInactiveUnselected";
234                 }
235         } else {
236
237                 throw; // wha?
238                 
239                 if (_route->active()) {
240                         controls_ebox.set_name ("BusControlsBaseUnselected");
241                         controls_base_selected_name = "BusControlsBaseSelected";
242                         controls_base_unselected_name = "BusControlsBaseUnselected";
243                 } else {
244                         controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
245                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
246                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
247                 }
248         }
249 }
250