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-note-event.h"
40 #include "canvas-program-change.h"
47 class MidiTimeAxisView;
49 class AutomationTimeAxisView;
50 class AutomationRegionView;
52 class MidiRegionView : public RegionView
55 MidiRegionView (ArdourCanvas::Group *,
57 boost::shared_ptr<ARDOUR::MidiRegion>,
58 double initial_samples_per_unit,
59 Gdk::Color& basic_color);
63 virtual void init (Gdk::Color& basic_color, bool wfd);
65 inline const boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const
66 { return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region); }
68 inline MidiTimeAxisView* midi_view() const
69 { return dynamic_cast<MidiTimeAxisView*>(&trackview); }
71 inline MidiStreamView* midi_stream_view() const
72 { return midi_view()->midi_view(); }
74 void set_y_position_and_height (double, double);
76 void set_frame_color();
78 void redisplay_model();
80 GhostRegion* add_ghost (TimeAxisView&);
82 void add_note(const boost::shared_ptr<Evoral::Note> note);
83 void resolve_note(uint8_t note_num, double end_time);
85 void add_pgm_change(boost::shared_ptr<Evoral::Event> event);
89 void extend_active_notes();
91 void create_note_at(double x, double y, double duration);
93 void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
95 void start_delta_command(string name = "midi edit");
96 void command_add_note(const boost::shared_ptr<Evoral::Note> note, bool selected);
97 void command_remove_note(ArdourCanvas::CanvasNoteEvent* ev);
100 void abort_command();
102 void note_entered(ArdourCanvas::CanvasNoteEvent* ev);
103 void unique_select(ArdourCanvas::CanvasNoteEvent* ev);
104 void note_selected(ArdourCanvas::CanvasNoteEvent* ev, bool add);
105 void note_deselected(ArdourCanvas::CanvasNoteEvent* ev, bool add);
106 void delete_selection();
107 size_t selection_size() { return _selection.size(); }
109 void move_selection(double dx, double dy);
110 void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double dt, uint8_t dnote);
113 * This function is needed to subtract the region start in pixels
114 * from world coordinates submitted by the mouse
116 double get_position_pixels(void);
119 * This function is called by CanvasMidiNote when resizing starts,
120 * i.e. when the user presses mouse-2 on the note
121 * @param note_end which end of the note, NOTE_ON or NOTE_OFF
123 void begin_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end);
126 * This function is called while the user moves the mouse when resizing notes
127 * @param note_end which end of the note, NOTE_ON or NOTE_OFF
128 * @param x the difference in mouse motion, ie the motion difference if relative=true
129 * or the absolute mouse position (track-relative) if relative is false
130 * @param relative true if relative resizing is taking place, false if absolute resizing
132 void update_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end, double x, bool relative);
135 * This function is called while the user releases the mouse button when resizing notes
136 * @param note_end which end of the note, NOTE_ON or NOTE_OFF
137 * @param event_x the absolute mouse position (track-relative)
138 * @param relative true if relative resizing is taking place, false if absolute resizing
140 void commit_resizing(ArdourCanvas::CanvasNote::NoteEnd note_end, double event_x, bool relative);
143 * This function is called while the user adjusts the velocity on a selection of notes
144 * @param velocity the relative or absolute velocity, depending on the value of relative
145 * @param relative true if the given velocity represents a delta to be applied to all notes, false
146 * if the absolute value of the note shoud be set
148 void change_velocity(uint8_t velocity, bool relative=false);
151 * This function is called when the user adjusts the midi channel of a selection of notes
152 * @param channel - the channel number of the new channel, zero-based
154 void change_channel(uint8_t channel);
156 enum MouseState { None, Pressed, SelectTouchDragging, SelectRectDragging, AddDragging, EraseTouchDragging };
157 MouseState mouse_state() const { return _mouse_state; }
159 struct NoteResizeData {
160 ArdourCanvas::CanvasNote *canvas_note;
161 ArdourCanvas::SimpleRect *resize_rect;
166 * This function provides the snap function for region position relative coordinates
167 * for pixel units (double) instead of nframes64_t
168 * @param x a pixel coordinate relative to region start
169 * @return the snapped pixel coordinate relative to region start
171 double snap_to_pixel(double x);
174 * This function provides the snap function for region position relative coordinates
175 * for pixel units (double) instead of nframes64_t
176 * @param x a pixel coordinate relative to region start
177 * @return the snapped nframes64_t coordinate relative to region start
179 nframes64_t snap_to_frame(double x);
182 * This function provides the snap function for region position relative coordinates
183 * @param x a pixel coordinate relative to region start
184 * @return the snapped nframes64_t coordinate relative to region start
186 nframes64_t snap_to_frame(nframes64_t x);
191 * this constructor allows derived types
192 * to specify their visibility requirements
193 * to the TimeAxisViewItem parent class
195 MidiRegionView (ArdourCanvas::Group *,
197 boost::shared_ptr<ARDOUR::MidiRegion>,
198 double samples_per_unit,
199 Gdk::Color& basic_color,
200 TimeAxisViewItem::Visibility);
202 void region_resized (ARDOUR::Change);
204 void set_flags (XMLNode *);
207 void reset_width_dependent_items (double pixel_width);
212 void switch_source(boost::shared_ptr<ARDOUR::Source> src);
214 bool canvas_event(GdkEvent* ev);
215 bool note_canvas_event(GdkEvent* ev);
217 void midi_channel_mode_changed(ARDOUR::ChannelMode mode, uint16_t mask);
219 void clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev);
220 void clear_selection() { clear_selection_except(NULL); }
221 void update_drag_selection(double last_x, double x, double last_y, double y);
223 int8_t _force_channel;
224 uint16_t _last_channel_selection;
225 double _default_note_length;
227 boost::shared_ptr<ARDOUR::MidiModel> _model;
228 std::vector<ArdourCanvas::CanvasNoteEvent*> _events;
229 std::vector< boost::shared_ptr<ArdourCanvas::CanvasProgramChange> > _pgm_changes;
230 ArdourCanvas::CanvasNote** _active_notes;
231 ArdourCanvas::Group* _note_group;
232 ARDOUR::MidiModel::DeltaCommand* _delta_command;
234 MouseState _mouse_state;
237 typedef std::set<ArdourCanvas::CanvasNoteEvent*> Selection;
238 /// Currently selected CanvasNoteEvents
239 Selection _selection;
241 /** New notes (created in the current command) which should be selected
242 * when they appear after the command is applied. */
243 std::set< boost::shared_ptr<Evoral::Note> > _marked_for_selection;
245 std::vector<NoteResizeData *> _resize_data;
248 #endif /* __gtk_ardour_midi_region_view_h__ */