summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-08-02 02:05:00 +0000
committerDavid Robillard <d@drobilla.net>2007-08-02 02:05:00 +0000
commitc96b5583204263e07440ff394e1d3a7f0e54f1b2 (patch)
treebfbb9b88185c73183f9d730ebd1218ceff26aaa3 /gtk2_ardour
parent874f3bbf8b4b8bb3e92f31c96623b1bcb4dd5c8a (diff)
Snap note dragging vertically to note values (rows).
git-svn-id: svn://localhost/ardour2/trunk@2217 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/canvas-midi-event.cc38
-rw-r--r--gtk2_ardour/midi_region_view.cc29
-rw-r--r--gtk2_ardour/midi_region_view.h28
3 files changed, 59 insertions, 36 deletions
diff --git a/gtk2_ardour/canvas-midi-event.cc b/gtk2_ardour/canvas-midi-event.cc
index 90b7ff09df..2895be1eba 100644
--- a/gtk2_ardour/canvas-midi-event.cc
+++ b/gtk2_ardour/canvas-midi-event.cc
@@ -44,7 +44,7 @@ bool
CanvasMidiEvent::on_event(GdkEvent* ev)
{
static double last_x, last_y;
- double event_x, event_y;
+ double event_x, event_y, dx, dy;
if (_region.get_time_axis_view().editor.current_mouse_mode() != Editing::MouseNote)
return false;
@@ -64,22 +64,13 @@ CanvasMidiEvent::on_event(GdkEvent* ev)
break;
case GDK_ENTER_NOTIFY:
- cerr << "ENTERED: " << ev->crossing.state << endl;
Keyboard::magic_widget_grab_focus();
_item->grab_focus();
_region.note_entered(this);
- //if (delete_down)
- // cerr << "DELETE ENTER\n" << endl;
-
- /*if ( (ev->crossing.state & GDK_BUTTON2_MASK) ) {
-
- }*/
break;
case GDK_LEAVE_NOTIFY:
- cerr << "LEAVE: " << ev->crossing.state << endl;
Keyboard::magic_widget_drop_focus();
- //_region.get_time_axis_view().editor.reset_focus();
_region.get_canvas_group()->grab_focus();
break;
@@ -111,10 +102,20 @@ CanvasMidiEvent::on_event(GdkEvent* ev)
event_y = t_y;
}
- _item->move(event_x - last_x, event_y - last_y);
-
+ dx = event_x - last_x;
+ dy = event_y - last_y;
+
last_x = event_x;
- last_y = event_y;
+
+ // Snap to note rows
+ if (abs(dy) < _region.note_height()) {
+ dy = 0.0;
+ } else {
+ dy = _region.note_height() * ((dy > 0) ? 1 : -1);
+ last_y = event_y;
+ }
+
+ _item->move(dx, dy);
return true;
default:
@@ -130,6 +131,17 @@ CanvasMidiEvent::on_event(GdkEvent* ev)
case Dragging: // Dropped
_item->ungrab(ev->button.time);
_state = None;
+ if (_note) {
+ cerr << "Move and stuff." << endl;
+ // This would be nicer with a MoveCommand that doesn't need to copy...
+ /*_region.start_delta_command();
+ _region.command_remove_note(this);
+ Note copy_of_me(*this);
+ copy_of_me.time = trackview.editor.pixel_to_frame(property_x1());
+ copy_of_me.note = stuff;
+ _region.apply_command();
+ */
+ }
return true;
default:
break;
diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc
index eadbb7ce52..6712cb486d 100644
--- a/gtk2_ardour/midi_region_view.cc
+++ b/gtk2_ardour/midi_region_view.cc
@@ -143,7 +143,7 @@ MidiRegionView::canvas_event(GdkEvent* ev)
//group->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, ev->button.time);
_state = Pressed;
press_button = ev->button.button;
- cerr << "PRESSED: " << press_button << endl;
+ //cerr << "PRESSED: " << press_button << endl;
return true;
case GDK_MOTION_NOTIFY:
@@ -308,12 +308,6 @@ MidiRegionView::~MidiRegionView ()
RegionViewGoingAway (this); /* EMIT_SIGNAL */
}
-boost::shared_ptr<ARDOUR::MidiRegion>
-MidiRegionView::midi_region() const
-{
- // "Guaranteed" to succeed...
- return boost::dynamic_pointer_cast<MidiRegion>(_region);
-}
void
MidiRegionView::region_resized (Change what_changed)
@@ -419,19 +413,12 @@ MidiRegionView::add_event (const MidiEvent& ev)
}
printf("\n\n");*/
- MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
- MidiStreamView* const view = mtv->midi_view();
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
- const uint8_t note_range = view->highest_note() - view->lowest_note() + 1;
- const double footer_height = name_highlight->property_y2() - name_highlight->property_y1();
- const double pixel_range = (trackview.height - footer_height - 5.0) / (double)note_range;
-
- if (mtv->note_mode() == Sustained) {
+ if (midi_view()->note_mode() == Sustained) {
if ((ev.buffer()[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
const Byte& note = ev.buffer()[1];
- const double y1 = trackview.height - (pixel_range * (note - view->lowest_note() + 1))
- - footer_height - 3.0;
+ const double y1 = note_y(note);
CanvasNote* ev_rect = new CanvasNote(*this, *group);
ev_rect->property_x1() = trackview.editor.frame_to_pixel (
@@ -439,7 +426,7 @@ MidiRegionView::add_event (const MidiEvent& ev)
ev_rect->property_y1() = y1;
ev_rect->property_x2() = trackview.editor.frame_to_pixel (
_region->length());
- ev_rect->property_y2() = y1 + ceil(pixel_range);
+ ev_rect->property_y2() = y1 + note_height();
ev_rect->property_outline_color_rgba() = 0xFFFFFFAA;
/* outline all but right edge */
ev_rect->property_outline_what() = (guint32) (0x1 & 0x4 & 0x8);
@@ -460,13 +447,13 @@ MidiRegionView::add_event (const MidiEvent& ev)
}
}
- } else if (mtv->note_mode() == Percussive) {
+ } else if (midi_view()->note_mode() == Percussive) {
const Byte& note = ev.buffer()[1];
+ const double diamond_size = std::min(note_height(), 5.0);
const double x = trackview.editor.frame_to_pixel((nframes_t)ev.time());
- const double y = trackview.height - (pixel_range * (note - view->lowest_note() + 1))
- - footer_height - 3.0;
+ const double y = note_y(note) + (diamond_size / 2.0);
- CanvasHit* ev_diamond = new CanvasHit(*this, *group, std::min(pixel_range, 5.0));
+ CanvasHit* ev_diamond = new CanvasHit(*this, *group, diamond_size);
ev_diamond->move(x, y);
ev_diamond->show();
ev_diamond->property_outline_color_rgba() = 0xFFFFFFDD;
diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h
index 9324838abe..c768a539c2 100644
--- a/gtk2_ardour/midi_region_view.h
+++ b/gtk2_ardour/midi_region_view.h
@@ -28,7 +28,7 @@
#include <ardour/types.h>
#include "region_view.h"
-#include "route_time_axis.h"
+#include "midi_time_axis.h"
#include "time_axis_view_item.h"
#include "automation_line.h"
#include "enums.h"
@@ -58,7 +58,31 @@ class MidiRegionView : public RegionView
virtual void init (Gdk::Color& basic_color, bool wfd);
- boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const;
+ inline const boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const
+ { return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region); }
+
+ inline MidiTimeAxisView* midi_view() const
+ { return dynamic_cast<MidiTimeAxisView*>(&trackview); }
+
+ inline MidiStreamView* midi_stream_view() const
+ { return midi_view()->midi_view(); }
+
+ inline uint8_t contents_note_range() const
+ { return midi_stream_view()->highest_note() - midi_stream_view()->lowest_note() + 1; }
+
+ inline double footer_height() const
+ { return name_highlight->property_y2() - name_highlight->property_y1(); }
+
+ inline double contents_height() const
+ { return (trackview.height - footer_height() - 5.0); }
+
+ inline double note_height() const
+ { return contents_height() / (double)contents_note_range(); }
+
+ inline double note_y(uint8_t note) const
+ { return trackview.height
+ - (contents_height() * (note - midi_stream_view()->lowest_note() + 1))
+ - footer_height() - 3.0; }
void set_y_position_and_height (double, double);