Renamed Insert to Processor and Redirect to IOProcessor.
[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 "canvas_impl.h"
53 #include "crossfade_view.h"
54 #include "enums.h"
55 #include "gui_thread.h"
56 #include "keyboard.h"
57 #include "playlist_selector.h"
58 #include "plugin_selector.h"
59 #include "plugin_ui.h"
60 #include "point_selection.h"
61 #include "prompter.h"
62 #include "public_editor.h"
63 #include "plugin_automation_line.h"
64 #include "processor_automation_time_axis.h"
65 #include "midi_controller_time_axis.h"
66 #include "region_view.h"
67 #include "rgb_macros.h"
68 #include "selection.h"
69 #include "simplerect.h"
70 #include "midi_streamview.h"
71 #include "utils.h"
72
73 #include <ardour/midi_track.h>
74
75 #include "i18n.h"
76
77 using namespace ARDOUR;
78 using namespace PBD;
79 using namespace Gtk;
80 using namespace Editing;
81
82
83 MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
84         : AxisView(sess), // FIXME: won't compile without this, why??
85         RouteTimeAxisView(ed, sess, rt, canvas)
86 {
87         subplugin_menu.set_name ("ArdourContextMenu");
88
89         _view = new MidiStreamView (*this);
90
91         ignore_toggle = false;
92
93         mute_button->set_active (false);
94         solo_button->set_active (false);
95         
96         if (is_midi_track())
97                 controls_ebox.set_name ("MidiTimeAxisViewControlsBaseUnselected");
98         else // bus
99                 controls_ebox.set_name ("MidiBusControlsBaseUnselected");
100
101         /* map current state of the route */
102
103         processors_changed ();
104
105         ensure_xml_node ();
106
107         set_state (*xml_node);
108         
109         _route->processors_changed.connect (mem_fun(*this, &MidiTimeAxisView::processors_changed));
110
111         if (is_track()) {
112
113                 controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
114                 controls_base_selected_name = "MidiTrackControlsBaseSelected";
115                 controls_base_unselected_name = "MidiTrackControlsBaseUnselected";
116
117                 /* ask for notifications of any new RegionViews */
118                 _view->RegionViewAdded.connect (mem_fun(*this, &MidiTimeAxisView::region_view_added));
119                 _view->attach ();
120
121         } /*else { // no MIDI busses yet
122
123                 controls_ebox.set_name ("MidiBusControlsBaseUnselected");
124                 controls_base_selected_name = "MidiBusControlsBaseSelected";
125                 controls_base_unselected_name = "MidiBusControlsBaseUnselected";
126         }*/
127 }
128
129 MidiTimeAxisView::~MidiTimeAxisView ()
130 {
131 }
132
133 guint32
134 MidiTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
135 {
136         ensure_xml_node ();
137         xml_node->add_property ("shown_editor", "yes");
138                 
139         return TimeAxisView::show_at (y, nth, parent);
140 }
141
142 void
143 MidiTimeAxisView::hide ()
144 {
145         ensure_xml_node ();
146         xml_node->add_property ("shown_editor", "no");
147
148         TimeAxisView::hide ();
149 }
150
151 void
152 MidiTimeAxisView::build_automation_action_menu ()
153 {
154         using namespace Menu_Helpers;
155
156         RouteTimeAxisView::build_automation_action_menu ();
157
158         MenuList& automation_items = automation_action_menu->items();
159         
160         automation_items.push_back (SeparatorElem());
161
162         automation_items.push_back (MenuElem (_("Controller..."), 
163                                                    mem_fun(*this, &MidiTimeAxisView::add_controller_track)));
164 }
165
166 /** Prompt for a controller with a dialog and add an automation track for it
167  */
168 void
169 MidiTimeAxisView::add_controller_track()
170 {
171         /* TODO: fancy controller selection dialog here... */
172
173         ParamID param(MidiCCAutomation, 7);
174         create_automation_child(param);
175 }
176
177 void
178 MidiTimeAxisView::create_automation_child (ParamID param)
179 {
180         if (param.type() == MidiCCAutomation) {
181         
182                 /* FIXME: this all probably leaks */
183
184                 ARDOUR::AutomationList* al = _route->automation_list(param);
185
186                 if (!al)
187                         al = new ARDOUR::AutomationList(param, 0, 127, 64);
188
189                 _route->add_automation_parameter(al);
190
191                 MidiControllerTimeAxisView* track = new MidiControllerTimeAxisView (_session,
192                                 _route,
193                                 editor,
194                                 *this,
195                                 parent_canvas,
196                                 _route->describe_parameter(param),
197                                 param,
198                                 *al);
199
200                 AutomationMidiCCLine* line = new AutomationMidiCCLine (param.to_string(),
201                                 *track,
202                                 *track->canvas_display,
203                                 *al);
204
205                 line->set_line_color (Config->canvasvar_AutomationLine.get());
206
207                 track->add_line(*line);
208
209                 add_automation_child(param, track);
210
211         } else {
212                 error << "MidiTimeAxisView: unknown automation child " << param.to_string() << endmsg;
213         }
214 }
215
216 void
217 MidiTimeAxisView::route_active_changed ()
218 {
219         RouteUI::route_active_changed ();
220
221         if (is_track()) {
222                 if (_route->active()) {
223                         controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
224                         controls_base_selected_name = "MidiTrackControlsBaseSelected";
225                         controls_base_unselected_name = "MidiTrackControlsBaseUnselected";
226                 } else {
227                         controls_ebox.set_name ("MidiTrackControlsBaseInactiveUnselected");
228                         controls_base_selected_name = "MidiTrackControlsBaseInactiveSelected";
229                         controls_base_unselected_name = "MidiTrackControlsBaseInactiveUnselected";
230                 }
231         } else {
232
233                 throw; // wha?
234                 
235                 if (_route->active()) {
236                         controls_ebox.set_name ("BusControlsBaseUnselected");
237                         controls_base_selected_name = "BusControlsBaseSelected";
238                         controls_base_unselected_name = "BusControlsBaseUnselected";
239                 } else {
240                         controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
241                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
242                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
243                 }
244         }
245 }
246