2 Copyright (C) 2001-2006 Paul Davis
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.
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.
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.
19 #ifndef __gtk_ardour_midi_region_view_h__
20 #define __gtk_ardour_midi_region_view_h__
24 #include <libgnomecanvasmm.h>
25 #include <libgnomecanvasmm/polygon.h>
26 #include <ardour/midi_region.h>
27 #include <ardour/midi_model.h>
28 #include <ardour/types.h>
30 #include "region_view.h"
31 #include "midi_time_axis.h"
32 #include "time_axis_view_item.h"
33 #include "automation_line.h"
36 #include "canvas-note.h"
37 #include "canvas-midi-event.h"
44 class MidiTimeAxisView;
46 class AutomationTimeAxisView;
48 class MidiRegionView : public RegionView
51 MidiRegionView (ArdourCanvas::Group *,
53 boost::shared_ptr<ARDOUR::MidiRegion>,
54 double initial_samples_per_unit,
55 Gdk::Color& basic_color);
59 virtual void init (Gdk::Color& basic_color, bool wfd);
61 inline const boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const
62 { return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region); }
64 inline MidiTimeAxisView* midi_view() const
65 { return dynamic_cast<MidiTimeAxisView*>(&trackview); }
67 inline MidiStreamView* midi_stream_view() const
68 { return midi_view()->midi_view(); }
70 inline uint8_t contents_note_range() const
71 { return midi_stream_view()->highest_note() - midi_stream_view()->lowest_note() + 1; }
73 inline double footer_height() const
74 { return name_highlight->property_y2() - name_highlight->property_y1(); }
76 inline double contents_height() const
77 { return (trackview.height - footer_height() - 5.0); }
79 inline double note_height() const
80 { return contents_height() / (double)contents_note_range(); }
82 inline double note_to_y(uint8_t note) const
83 { return trackview.height
84 - (contents_height() * (note - midi_stream_view()->lowest_note() + 1))
85 - footer_height() - 3.0; }
87 inline uint8_t y_to_note(double y) const
88 { return (uint8_t)floor((contents_height() - y)
89 / contents_height() * (double)contents_note_range()); }
91 void set_y_position_and_height (double, double);
93 void show_region_editor ();
95 GhostRegion* add_ghost (AutomationTimeAxisView&);
97 void add_event(const ARDOUR::MidiEvent& ev);
98 void add_note(const ARDOUR::MidiModel::Note& note);
102 void extend_active_notes();
104 void create_note_at(double x, double y);
106 void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
108 /* This stuff is a bit boilerplatey ATM. Work in progress. */
110 inline void start_remove_command() {
111 _command_mode = Remove;
113 _delta_command = _model->new_delta_command();
116 inline void start_delta_command() {
117 _command_mode = Delta;
119 _delta_command = _model->new_delta_command();
122 void command_remove_note(ArdourCanvas::CanvasMidiEvent* ev) {
123 if (_delta_command && ev->note()) {
124 _delta_command->remove(*ev->note());
129 void command_add_note(ARDOUR::MidiModel::Note& note) {
130 if (_delta_command) {
131 _delta_command->add(note);
135 void note_entered(ArdourCanvas::CanvasMidiEvent* ev) {
136 if (_command_mode == Remove && _delta_command && ev->note())
137 _delta_command->remove(*ev->note());
140 //ARDOUR::MidiModel::DeltaCommand* delta_command() { return _delta_command; }
142 void abort_command() {
143 delete _delta_command;
144 _delta_command = NULL;
145 _command_mode = None;
148 void apply_command() {
149 if (_delta_command) {
150 _model->apply_command(_delta_command);
151 _delta_command = NULL;
153 _command_mode = None;
158 /* this constructor allows derived types
159 to specify their visibility requirements
160 to the TimeAxisViewItem parent class
163 MidiRegionView (ArdourCanvas::Group *,
165 boost::shared_ptr<ARDOUR::MidiRegion>,
166 double samples_per_unit,
167 Gdk::Color& basic_color,
168 TimeAxisViewItem::Visibility);
170 void region_resized (ARDOUR::Change);
172 void set_flags (XMLNode *);
175 void reset_width_dependent_items (double pixel_width);
179 void redisplay_model();
182 bool canvas_event(GdkEvent* ev);
183 bool note_canvas_event(GdkEvent* ev);
185 boost::shared_ptr<ARDOUR::MidiModel> _model;
186 std::vector<ArdourCanvas::Item*> _events;
187 ArdourCanvas::CanvasNote** _active_notes;
188 ARDOUR::MidiModel::DeltaCommand* _delta_command;
190 enum CommandMode { None, Remove, Delta };
191 CommandMode _command_mode;
195 #endif /* __gtk_ardour_midi_region_view_h__ */