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 void set_y_position_and_height (double, double);
72 void redisplay_model();
74 GhostRegion* add_ghost (AutomationTimeAxisView&);
76 void add_event(const ARDOUR::MidiEvent& ev);
77 void add_note(const ARDOUR::MidiModel::Note& note);
81 void extend_active_notes();
83 void create_note_at(double x, double y, double dur);
85 void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
87 /* This stuff is a bit boilerplatey ATM. Work in progress. */
89 inline void start_remove_command() {
90 _command_mode = Remove;
92 _delta_command = _model->new_delta_command();
95 inline void start_delta_command() {
96 _command_mode = Delta;
98 _delta_command = _model->new_delta_command();
101 void command_remove_note(ArdourCanvas::CanvasMidiEvent* ev) {
102 if (_delta_command && ev->note()) {
103 _delta_command->remove(*ev->note());
108 void command_add_note(ARDOUR::MidiModel::Note& note) {
109 if (_delta_command) {
110 _delta_command->add(note);
114 void note_entered(ArdourCanvas::CanvasMidiEvent* ev) {
115 if (_command_mode == Remove && _delta_command && ev->note()) {
117 _delta_command->remove(*ev->note());
121 //ARDOUR::MidiModel::DeltaCommand* delta_command() { return _delta_command; }
123 void abort_command() {
124 delete _delta_command;
125 _delta_command = NULL;
126 _command_mode = None;
130 void apply_command() {
131 if (_delta_command) {
132 _model->apply_command(_delta_command);
133 _delta_command = NULL;
135 _command_mode = None;
138 void unique_select(ArdourCanvas::CanvasMidiEvent* ev);
139 void note_selected(ArdourCanvas::CanvasMidiEvent* ev, bool add);
140 void note_deselected(ArdourCanvas::CanvasMidiEvent* ev, bool add);
141 void delete_selection();
142 size_t selection_size() { return _selection.size(); }
146 /* this constructor allows derived types
147 to specify their visibility requirements
148 to the TimeAxisViewItem parent class
151 MidiRegionView (ArdourCanvas::Group *,
153 boost::shared_ptr<ARDOUR::MidiRegion>,
154 double samples_per_unit,
155 Gdk::Color& basic_color,
156 TimeAxisViewItem::Visibility);
158 void region_resized (ARDOUR::Change);
160 void set_flags (XMLNode *);
163 void reset_width_dependent_items (double pixel_width);
169 bool canvas_event(GdkEvent* ev);
170 bool note_canvas_event(GdkEvent* ev);
172 void clear_selection_except(ArdourCanvas::CanvasMidiEvent* ev);
173 void clear_selection() { clear_selection_except(NULL); }
175 double _default_note_length;
177 boost::shared_ptr<ARDOUR::MidiModel> _model;
178 std::vector<ArdourCanvas::Item*> _events;
179 ArdourCanvas::CanvasNote** _active_notes;
180 ARDOUR::MidiModel::DeltaCommand* _delta_command;
182 typedef std::set<ArdourCanvas::CanvasMidiEvent*> Selection;
183 Selection _selection;
185 enum CommandMode { None, Remove, Delta };
186 CommandMode _command_mode;
189 #endif /* __gtk_ardour_midi_region_view_h__ */