2 Copyright (C) 2007 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "canvas-midi-event.h"
22 #include "midi_region_view.h"
23 #include "public_editor.h"
24 #include "editing_syms.h"
28 using ARDOUR::MidiModel;
34 CanvasMidiEvent::CanvasMidiEvent(MidiRegionView& region, Item* item, const ARDOUR::Note* note, bool copy_note)
38 , _note((copy_note && note) ? new ARDOUR::Note(*note) : note)
39 , _own_note(copy_note)
45 CanvasMidiEvent::~CanvasMidiEvent()
53 CanvasMidiEvent::selected(bool yn)
58 set_fill_color(UINT_INTERPOLATE(note_fill_color(_note->velocity()),
59 ARDOUR_UI::config()->canvasvar_MidiNoteSelectedOutline.get(), 0.85));
60 set_outline_color(ARDOUR_UI::config()->canvasvar_MidiNoteSelectedOutline.get());
62 set_fill_color(note_fill_color(_note->velocity()));
63 set_outline_color(note_outline_color(_note->velocity()));
71 CanvasMidiEvent::on_event(GdkEvent* ev)
73 static uint8_t drag_delta_note = 0;
74 static double drag_delta_x = 0;
75 static double last_x, last_y;
76 double event_x, event_y, dx, dy;
77 nframes_t event_frame;
80 if (_region.get_time_axis_view().editor.current_mouse_mode() != Editing::MouseNote)
85 cerr << "EV KEY PRESS\n";
86 if (_note && ev->key.keyval == GDK_Delete) {
87 cerr << "EV DELETE KEY\n";
89 _region.start_remove_command();
90 _region.command_remove_note(this);
95 cerr << "EV KEY RELEASE\n";
96 if (ev->key.keyval == GDK_Delete) {
97 _region.apply_command();
101 case GDK_ENTER_NOTIFY:
102 _region.note_entered(this);
104 Keyboard::magic_widget_grab_focus();
107 case GDK_LEAVE_NOTIFY:
108 Keyboard::magic_widget_drop_focus();
109 _region.get_canvas_group()->grab_focus();
112 case GDK_BUTTON_PRESS:
116 case GDK_MOTION_NOTIFY:
117 event_x = ev->motion.x;
118 event_y = ev->motion.y;
119 //cerr << "MOTION @ " << event_x << ", " << event_y << endl;
120 _item->property_parent().get_value()->w2i(event_x, event_y);
123 case Pressed: // Drag begin
124 if (_region.mouse_state() != MidiRegionView::SelectTouchDragging) {
125 _item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
126 Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
132 _region.note_selected(this, true);
136 case Dragging: // Drag motion
137 if (ev->motion.is_hint) {
140 GdkModifierType state;
141 gdk_window_get_pointer(ev->motion.window, &t_x, &t_y, &state);
147 event_frame = _region.midi_view()->editor.pixel_to_frame(event_x);
148 _region.midi_view()->editor.snap_to(event_frame);
149 event_x = _region.midi_view()->editor.frame_to_pixel(event_frame);
151 dx = event_x - last_x;
152 dy = event_y - last_y;
159 if (abs(dy) < _region.midi_stream_view()->note_height()) {
162 int8_t this_delta_note;
164 this_delta_note = (int8_t)ceil(dy / _region.midi_stream_view()->note_height() / 2.0);
166 this_delta_note = (int8_t)floor(dy / _region.midi_stream_view()->note_height() / 2.0);
167 drag_delta_note -= this_delta_note;
168 dy = _region.midi_stream_view()->note_height() * this_delta_note;
169 last_y = last_y + dy;
172 _region.move_selection(dx, dy);
180 case GDK_BUTTON_RELEASE:
181 select_mod = (ev->motion.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
182 event_x = ev->button.x;
183 event_y = ev->button.y;
184 _item->property_parent().get_value()->w2i(event_x, event_y);
187 case Pressed: // Clicked
188 if (_region.midi_view()->editor.current_midi_edit_mode() == Editing::MidiEditSelect) {
191 if (_selected && !select_mod && _region.selection_size() > 1)
192 _region.unique_select(this);
194 _region.note_deselected(this, select_mod);
196 _region.note_selected(this, select_mod);
197 } else if (_region.midi_view()->editor.current_midi_edit_mode() == Editing::MidiEditErase) {
198 _region.start_remove_command();
199 _region.command_remove_note(this);
200 _region.apply_command();
204 case Dragging: // Dropped
205 _item->ungrab(ev->button.time);
209 _region.note_dropped(this,
210 _region.midi_view()->editor.pixel_to_frame(abs(drag_delta_x))
211 * ((drag_delta_x < 0.0) ? -1 : 1),
225 } // namespace Canvas