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::MidiModel::Note* note)
44 CanvasMidiEvent::selected(bool yn)
49 set_fill_color(UINT_INTERPOLATE(note_fill_color(_note->velocity()),
50 ARDOUR_UI::config()->canvasvar_MidiNoteSelectedOutline.get(), 0.85));
51 set_outline_color(ARDOUR_UI::config()->canvasvar_MidiNoteSelectedOutline.get());
53 set_fill_color(note_fill_color(_note->velocity()));
54 set_outline_color(note_outline_color(_note->velocity()));
62 CanvasMidiEvent::on_event(GdkEvent* ev)
64 static uint8_t drag_delta_note = 0;
65 static double drag_delta_x = 0;
66 static double last_x, last_y;
67 double event_x, event_y, dx, dy;
68 nframes_t event_frame;
69 bool select_mod = false;
71 if (_region.get_time_axis_view().editor.current_mouse_mode() != Editing::MouseNote)
76 if (_note && ev->key.keyval == GDK_Delete) {
78 _region.start_remove_command();
79 _region.command_remove_note(this);
84 if (ev->key.keyval == GDK_Delete) {
85 _region.apply_command();
89 case GDK_ENTER_NOTIFY:
90 select_mod = (ev->motion.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
91 cerr << "ENTER: " << select_mod << " - " << ev->motion.state << endl;
93 _region.note_selected(this, true);
95 Keyboard::magic_widget_grab_focus();
97 _region.note_entered(this);
100 case GDK_LEAVE_NOTIFY:
101 Keyboard::magic_widget_drop_focus();
102 _region.get_canvas_group()->grab_focus();
105 case GDK_BUTTON_PRESS:
109 case GDK_MOTION_NOTIFY:
110 select_mod = (ev->motion.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
111 event_x = ev->motion.x;
112 event_y = ev->motion.y;
113 //cerr << "MOTION @ " << event_x << ", " << event_y << endl;
114 _item->property_parent().get_value()->w2i(event_x, event_y);
117 case Pressed: // Drag begin
119 _item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
120 Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
129 case Dragging: // Drag motion
130 if (ev->motion.is_hint) {
133 GdkModifierType state;
134 gdk_window_get_pointer(ev->motion.window, &t_x, &t_y, &state);
140 event_frame = _region.midi_view()->editor.pixel_to_frame(event_x);
141 _region.midi_view()->editor.snap_to(event_frame);
142 event_x = _region.midi_view()->editor.frame_to_pixel(event_frame);
144 dx = event_x - last_x;
145 dy = event_y - last_y;
152 if (abs(dy) < _region.midi_stream_view()->note_height()) {
155 int8_t this_delta_note;
157 this_delta_note = (int8_t)ceil(dy / _region.midi_stream_view()->note_height() / 2.0);
159 this_delta_note = (int8_t)floor(dy / _region.midi_stream_view()->note_height() / 2.0);
160 drag_delta_note -= this_delta_note;
161 dy = _region.midi_stream_view()->note_height() * this_delta_note;
162 last_y = last_y + dy;
165 _region.move_selection(dx, dy);
173 case GDK_BUTTON_RELEASE:
174 select_mod = (ev->motion.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
175 event_x = ev->button.x;
176 event_y = ev->button.y;
177 _item->property_parent().get_value()->w2i(event_x, event_y);
180 case Pressed: // Clicked
183 if (_selected && !select_mod && _region.selection_size() > 1)
184 _region.unique_select(this);
186 _region.note_deselected(this, select_mod);
188 _region.note_selected(this, select_mod);
191 case Dragging: // Dropped
192 _item->ungrab(ev->button.time);
196 _region.note_dropped(this,
197 _region.midi_view()->editor.pixel_to_frame(abs(drag_delta_x))
198 * ((drag_delta_x < 0.0) ? -1 : 1),
212 } // namespace Canvas