MIDI metering.
[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/insert.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 "canvas_impl.h"
52 #include "crossfade_view.h"
53 #include "enums.h"
54 #include "gui_thread.h"
55 #include "keyboard.h"
56 #include "playlist_selector.h"
57 #include "plugin_selector.h"
58 #include "plugin_ui.h"
59 #include "point_selection.h"
60 #include "prompter.h"
61 #include "public_editor.h"
62 #include "redirect_automation_line.h"
63 #include "redirect_automation_time_axis.h"
64 #include "region_view.h"
65 #include "rgb_macros.h"
66 #include "selection.h"
67 #include "simplerect.h"
68 #include "midi_streamview.h"
69 #include "utils.h"
70
71 #include <ardour/midi_track.h>
72
73 #include "i18n.h"
74
75 using namespace ARDOUR;
76 using namespace PBD;
77 using namespace Gtk;
78 using namespace Editing;
79
80
81 MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
82         : AxisView(sess), // FIXME: won't compile without this, why??
83         RouteTimeAxisView(ed, sess, rt, canvas)
84 {
85         subplugin_menu.set_name ("ArdourContextMenu");
86
87         _view = new MidiStreamView (*this);
88
89         ignore_toggle = false;
90
91         mute_button->set_active (false);
92         solo_button->set_active (false);
93         
94         if (is_midi_track())
95                 controls_ebox.set_name ("MidiTimeAxisViewControlsBaseUnselected");
96         else // bus
97                 controls_ebox.set_name ("MidiBusControlsBaseUnselected");
98
99         /* map current state of the route */
100
101         redirects_changed (0);
102
103         ensure_xml_node ();
104
105         set_state (*xml_node);
106         
107         _route->redirects_changed.connect (mem_fun(*this, &MidiTimeAxisView::redirects_changed));
108
109         if (is_track()) {
110
111                 controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
112                 controls_base_selected_name = "MidiTrackControlsBaseSelected";
113                 controls_base_unselected_name = "MidiTrackControlsBaseUnselected";
114
115                 /* ask for notifications of any new RegionViews */
116                 _view->RegionViewAdded.connect (mem_fun(*this, &MidiTimeAxisView::region_view_added));
117                 _view->attach ();
118
119         } else { /* bus */
120
121                 throw; // what the?
122                 controls_ebox.set_name ("MidiBusControlsBaseUnselected");
123                 controls_base_selected_name = "MidiBusControlsBaseSelected";
124                 controls_base_unselected_name = "MidiBusControlsBaseUnselected";
125         }
126 }
127
128 MidiTimeAxisView::~MidiTimeAxisView ()
129 {
130 }
131
132 guint32
133 MidiTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
134 {
135         ensure_xml_node ();
136         xml_node->add_property ("shown_editor", "yes");
137                 
138         return TimeAxisView::show_at (y, nth, parent);
139 }
140
141 void
142 MidiTimeAxisView::hide ()
143 {
144         ensure_xml_node ();
145         xml_node->add_property ("shown_editor", "no");
146
147         TimeAxisView::hide ();
148 }
149
150 void
151 MidiTimeAxisView::set_state (const XMLNode& node)
152 {
153         const XMLProperty *prop;
154         
155         TimeAxisView::set_state (node);
156         
157         if ((prop = node.property ("shown_editor")) != 0) {
158                 if (prop->value() == "no") {
159                         _marked_for_display = false;
160                 } else {
161                         _marked_for_display = true;
162                 }
163         } else {
164                 _marked_for_display = true;
165         }
166         
167         XMLNodeList nlist = node.children();
168         XMLNodeConstIterator niter;
169         XMLNode *child_node;
170         
171         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
172                 child_node = *niter;
173                 
174                 // uh... do stuff..
175         }
176 }
177
178 // FIXME: duplicated in audio_time_axis.cc
179 /*static string 
180 legalize_for_xml_node (string str)
181 {
182         string::size_type pos;
183         string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
184         string legal;
185
186         legal = str;
187         pos = 0;
188
189         while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
190                 legal.replace (pos, 1, "_");
191                 pos += 1;
192         }
193
194         return legal;
195 }*/
196
197 void
198 MidiTimeAxisView::route_active_changed ()
199 {
200         RouteUI::route_active_changed ();
201
202         if (is_track()) {
203                 if (_route->active()) {
204                         controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
205                         controls_base_selected_name = "MidiTrackControlsBaseSelected";
206                         controls_base_unselected_name = "MidiTrackControlsBaseUnselected";
207                 } else {
208                         controls_ebox.set_name ("MidiTrackControlsBaseInactiveUnselected");
209                         controls_base_selected_name = "MidiTrackControlsBaseInactiveSelected";
210                         controls_base_unselected_name = "MidiTrackControlsBaseInactiveUnselected";
211                 }
212         } else {
213
214                 throw; // wha?
215                 
216                 if (_route->active()) {
217                         controls_ebox.set_name ("BusControlsBaseUnselected");
218                         controls_base_selected_name = "BusControlsBaseSelected";
219                         controls_base_unselected_name = "BusControlsBaseUnselected";
220                 } else {
221                         controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
222                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
223                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
224                 }
225         }
226 }
227
228 XMLNode* 
229 MidiTimeAxisView::get_child_xml_node (const string & childname)
230 {
231         return RouteUI::get_child_xml_node (childname);
232 }
233