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_track.h>
27 #include <ardour/midi_region.h>
28 #include <ardour/midi_model.h>
29 #include <ardour/diskstream.h>
30 #include <ardour/types.h>
32 #include "region_view.h"
33 #include "midi_time_axis.h"
34 #include "time_axis_view_item.h"
35 #include "automation_line.h"
38 #include "canvas-note.h"
39 #include "canvas-midi-event.h"
46 class MidiTimeAxisView;
48 class AutomationTimeAxisView;
50 class MidiRegionView : public RegionView
53 MidiRegionView (ArdourCanvas::Group *,
55 boost::shared_ptr<ARDOUR::MidiRegion>,
56 double initial_samples_per_unit,
57 Gdk::Color& basic_color);
61 virtual void init (Gdk::Color& basic_color, bool wfd);
63 inline const boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const
64 { return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region); }
66 inline MidiTimeAxisView* midi_view() const
67 { return dynamic_cast<MidiTimeAxisView*>(&trackview); }
69 inline MidiStreamView* midi_stream_view() const
70 { return midi_view()->midi_view(); }
72 void set_y_position_and_height (double, double);
74 void redisplay_model();
76 GhostRegion* add_ghost (AutomationTimeAxisView&);
78 void add_event(const ARDOUR::MidiEvent& ev);
79 void add_note(const ARDOUR::MidiModel::Note& note);
83 void extend_active_notes();
85 void create_note_at(double x, double y, double dur);
87 void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
89 /* This stuff is a bit boilerplatey ATM. Work in progress. */
91 inline void start_remove_command() {
93 _delta_command = _model->new_delta_command();
96 inline void start_delta_command() {
98 _delta_command = _model->new_delta_command();
101 void command_add_note(ARDOUR::MidiModel::Note& note) {
103 _delta_command->add(note);
106 void command_remove_note(ArdourCanvas::CanvasMidiEvent* ev) {
107 if (_delta_command && ev->note()) {
108 _delta_command->remove(*ev->note());
113 void abort_command() {
114 delete _delta_command;
115 _delta_command = NULL;
119 void apply_command() {
120 if (_delta_command) {
121 _model->apply_command(_delta_command);
122 _delta_command = NULL;
124 midi_view()->midi_track()->diskstream()->playlist_modified();
127 void note_entered(ArdourCanvas::CanvasMidiEvent* ev);
128 void unique_select(ArdourCanvas::CanvasMidiEvent* ev);
129 void note_selected(ArdourCanvas::CanvasMidiEvent* ev, bool add);
130 void note_deselected(ArdourCanvas::CanvasMidiEvent* ev, bool add);
131 void delete_selection();
132 size_t selection_size() { return _selection.size(); }
134 void move_selection(double dx, double dy);
135 void note_dropped(ArdourCanvas::CanvasMidiEvent* ev, double dt, uint8_t dnote);
137 enum MouseState { None, Pressed, SelectTouchDragging, SelectRectDragging, AddDragging, EraseTouchDragging };
138 MouseState mouse_state() const { return _mouse_state; }
142 /* this constructor allows derived types
143 to specify their visibility requirements
144 to the TimeAxisViewItem parent class
147 MidiRegionView (ArdourCanvas::Group *,
149 boost::shared_ptr<ARDOUR::MidiRegion>,
150 double samples_per_unit,
151 Gdk::Color& basic_color,
152 TimeAxisViewItem::Visibility);
154 void region_resized (ARDOUR::Change);
156 void set_flags (XMLNode *);
159 void reset_width_dependent_items (double pixel_width);
165 bool canvas_event(GdkEvent* ev);
166 bool note_canvas_event(GdkEvent* ev);
168 void clear_selection_except(ArdourCanvas::CanvasMidiEvent* ev);
169 void clear_selection() { clear_selection_except(NULL); }
170 void update_drag_selection(double last_x, double x, double last_y, double y);
172 double _default_note_length;
174 boost::shared_ptr<ARDOUR::MidiModel> _model;
175 std::vector<ArdourCanvas::CanvasMidiEvent*> _events;
176 ArdourCanvas::CanvasNote** _active_notes;
177 ArdourCanvas::Group* _note_group;
178 ARDOUR::MidiModel::DeltaCommand* _delta_command;
180 MouseState _mouse_state;
183 typedef std::set<ArdourCanvas::CanvasMidiEvent*> Selection;
184 Selection _selection;
187 #endif /* __gtk_ardour_midi_region_view_h__ */