2 Copyright (C) 2001-2007 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;
49 class AutomationRegionView;
51 class MidiRegionView : public RegionView
54 MidiRegionView (ArdourCanvas::Group *,
56 boost::shared_ptr<ARDOUR::MidiRegion>,
57 double initial_samples_per_unit,
58 Gdk::Color& basic_color);
62 virtual void init (Gdk::Color& basic_color, bool wfd);
64 inline const boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const
65 { return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region); }
67 inline MidiTimeAxisView* midi_view() const
68 { return dynamic_cast<MidiTimeAxisView*>(&trackview); }
70 inline MidiStreamView* midi_stream_view() const
71 { return midi_view()->midi_view(); }
73 void set_y_position_and_height (double, double);
75 void set_frame_color();
77 void redisplay_model();
79 GhostRegion* add_ghost (TimeAxisView&);
81 void add_note(const boost::shared_ptr<ARDOUR::Note> note);
82 void resolve_note(uint8_t note_num, double end_time);
86 void extend_active_notes();
88 void create_note_at(double x, double y, double dur);
90 void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
92 /* This stuff is a bit boilerplatey ATM. Work in progress. */
94 inline void start_delta_command() {
96 _delta_command = _model->new_delta_command();
99 void command_add_note(const boost::shared_ptr<ARDOUR::Note> note) {
101 _delta_command->add(note);
104 void command_remove_note(ArdourCanvas::CanvasMidiEvent* ev) {
105 if (_delta_command && ev->note()) {
106 _delta_command->remove(ev->note());
111 void abort_command() {
112 delete _delta_command;
113 _delta_command = NULL;
117 void apply_command() {
118 if (_delta_command) {
119 _model->apply_command(_delta_command);
120 _delta_command = NULL;
122 midi_view()->midi_track()->diskstream()->playlist_modified();
125 void note_entered(ArdourCanvas::CanvasMidiEvent* ev);
126 void unique_select(ArdourCanvas::CanvasMidiEvent* ev);
127 void note_selected(ArdourCanvas::CanvasMidiEvent* ev, bool add);
128 void note_deselected(ArdourCanvas::CanvasMidiEvent* ev, bool add);
129 void delete_selection();
130 size_t selection_size() { return _selection.size(); }
132 void move_selection(double dx, double dy);
133 void note_dropped(ArdourCanvas::CanvasMidiEvent* ev, double dt, uint8_t dnote);
136 * This function is needed to subtract the region start in pixels
137 * from world coordinates submitted by the mouse
139 double get_position_pixels(void);
142 * This function is called by CanvasMidiNote when resizing starts,
143 * i.e. when the user presses mouse-2 on the note
144 * @param note_end which end of the note, NOTE_ON or NOTE_OFF
146 void begin_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end);
149 * This function is called while the user moves the mouse when resizing notes
150 * @param note_end which end of the note, NOTE_ON or NOTE_OFF
151 * @param x the difference in mouse motion, ie the motion difference if relative=true
152 * or the absolute mouse position (track-relative) if relative is false
153 * @param relative true if relative resizing is taking place, false if absolute resizing
155 void update_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end, double x, bool relative);
158 * This function is called while the user releases the mouse button when resizing notes
159 * @param note_end which end of the note, NOTE_ON or NOTE_OFF
160 * @param event_x the absolute mouse position (track-relative)
161 * @param relative true if relative resizing is taking place, false if absolute resizing
163 void commit_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end, double event_x, bool relative);
165 enum MouseState { None, Pressed, SelectTouchDragging, SelectRectDragging, AddDragging, EraseTouchDragging };
166 MouseState mouse_state() const { return _mouse_state; }
168 struct NoteResizeData {
169 ArdourCanvas::CanvasNote *canvas_note;
170 ArdourCanvas::SimpleRect *resize_rect;
177 * this constructor allows derived types
178 * to specify their visibility requirements
179 * to the TimeAxisViewItem parent class
181 MidiRegionView (ArdourCanvas::Group *,
183 boost::shared_ptr<ARDOUR::MidiRegion>,
184 double samples_per_unit,
185 Gdk::Color& basic_color,
186 TimeAxisViewItem::Visibility);
188 void region_resized (ARDOUR::Change);
190 void set_flags (XMLNode *);
193 void reset_width_dependent_items (double pixel_width);
198 void switch_source(boost::shared_ptr<ARDOUR::Source> src);
200 bool canvas_event(GdkEvent* ev);
201 bool note_canvas_event(GdkEvent* ev);
203 void clear_selection_except(ArdourCanvas::CanvasMidiEvent* ev);
204 void clear_selection() { clear_selection_except(NULL); }
205 void update_drag_selection(double last_x, double x, double last_y, double y);
208 * This function provides the snap function for pixel units (double)
209 * instead of nframes_t
211 double snap_to(double x);
213 double _default_note_length;
215 boost::shared_ptr<ARDOUR::MidiModel> _model;
216 std::vector<ArdourCanvas::CanvasMidiEvent*> _events;
217 ArdourCanvas::CanvasNote** _active_notes;
218 ArdourCanvas::Group* _note_group;
219 ARDOUR::MidiModel::DeltaCommand* _delta_command;
221 MouseState _mouse_state;
224 typedef std::set<ArdourCanvas::CanvasMidiEvent*> Selection;
225 Selection _selection;
227 std::vector<NoteResizeData *> _resize_data;
230 #endif /* __gtk_ardour_midi_region_view_h__ */