2008-03-14 20:47:30 -04:00
|
|
|
#include "canvas-note.h"
|
|
|
|
#include "midi_region_view.h"
|
|
|
|
#include "public_editor.h"
|
2008-09-18 20:47:49 -04:00
|
|
|
#include "evoral/Note.hpp"
|
2008-03-14 20:47:30 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
namespace Gnome {
|
|
|
|
namespace Canvas {
|
|
|
|
|
|
|
|
bool
|
|
|
|
CanvasNote::on_event(GdkEvent* ev)
|
|
|
|
{
|
|
|
|
double event_x;
|
2008-03-26 07:11:47 -04:00
|
|
|
static double middle_point, last_x;
|
2008-03-14 20:47:30 -04:00
|
|
|
Gdk::Cursor cursor;
|
|
|
|
static NoteEnd note_end;
|
2008-03-26 07:11:47 -04:00
|
|
|
Editing::MidiEditMode edit_mode = _region.get_trackview().editor.current_midi_edit_mode();
|
2008-03-14 20:47:30 -04:00
|
|
|
|
|
|
|
switch(ev->type) {
|
|
|
|
case GDK_BUTTON_PRESS:
|
2008-03-26 07:11:47 -04:00
|
|
|
if (ev->button.button == 2 ||
|
|
|
|
(ev->button.button == 1 &&
|
|
|
|
edit_mode == Editing::MidiEditResize)) {
|
|
|
|
double region_start = _region.get_position_pixels();
|
2008-03-14 20:47:30 -04:00
|
|
|
event_x = ev->button.x;
|
2008-03-26 07:11:47 -04:00
|
|
|
middle_point = region_start + x1() + (x2() - x1()) / 2.0L;
|
2008-03-14 20:47:30 -04:00
|
|
|
|
|
|
|
if(event_x <= middle_point) {
|
|
|
|
cursor = Gdk::Cursor(Gdk::LEFT_SIDE);
|
|
|
|
note_end = NOTE_ON;
|
|
|
|
} else {
|
|
|
|
cursor = Gdk::Cursor(Gdk::RIGHT_SIDE);
|
|
|
|
note_end = NOTE_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
_item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, cursor, ev->motion.time);
|
|
|
|
|
|
|
|
if (_region.mouse_state() == MidiRegionView::SelectTouchDragging) {
|
2008-03-26 07:11:47 -04:00
|
|
|
_note_state = AbsoluteResize;
|
2008-03-14 20:47:30 -04:00
|
|
|
} else {
|
2008-03-26 07:11:47 -04:00
|
|
|
_note_state = RelativeResize;
|
2008-03-14 20:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_region.note_selected(this, true);
|
|
|
|
_region.begin_resizing(note_end);
|
2008-03-26 07:11:47 -04:00
|
|
|
last_x = event_x;
|
2008-03-14 20:47:30 -04:00
|
|
|
|
|
|
|
return true;
|
2008-04-14 02:23:11 -04:00
|
|
|
}
|
|
|
|
|
2008-03-14 20:47:30 -04:00
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
event_x = ev->motion.x;
|
|
|
|
|
2008-03-26 07:11:47 -04:00
|
|
|
if (_note_state == RelativeResize) {
|
2008-03-14 20:47:30 -04:00
|
|
|
_region.update_resizing(note_end, event_x - last_x, true);
|
|
|
|
last_x = event_x;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-03-26 07:11:47 -04:00
|
|
|
if (_note_state == AbsoluteResize) {
|
2008-03-14 20:47:30 -04:00
|
|
|
_region.update_resizing(note_end, event_x, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
event_x = ev->button.x;
|
|
|
|
|
2008-03-26 07:11:47 -04:00
|
|
|
switch (_note_state) {
|
2008-03-14 20:47:30 -04:00
|
|
|
case RelativeResize: // Clicked
|
|
|
|
_item->ungrab(ev->button.time);
|
|
|
|
_region.commit_resizing(note_end, event_x, true);
|
2008-03-26 07:11:47 -04:00
|
|
|
_note_state = None;
|
2008-03-14 20:47:30 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case AbsoluteResize: // Clicked
|
|
|
|
_item->ungrab(ev->button.time);
|
|
|
|
_region.commit_resizing(note_end, event_x, false);
|
2008-03-26 07:11:47 -04:00
|
|
|
_note_state = None;
|
2008-03-14 20:47:30 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2008-04-29 03:28:24 -04:00
|
|
|
return CanvasNoteEvent::on_event(ev);
|
2008-03-14 20:47:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2008-04-29 03:28:24 -04:00
|
|
|
return CanvasNoteEvent::on_event(ev);
|
2008-03-14 20:47:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Gnome
|
|
|
|
} // namespace Canvas
|