From 20047e09f26ac96e057eaded19f257741c9c7c9b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 7 Nov 2018 20:54:22 -0500 Subject: [PATCH] mouse drag operations in beatbox --- gtk2_ardour/beatbox_gui.cc | 31 +++++++++++++++++++++++++++++++ gtk2_ardour/beatbox_gui.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/gtk2_ardour/beatbox_gui.cc b/gtk2_ardour/beatbox_gui.cc index dab698dca5..e3c3902aa8 100644 --- a/gtk2_ardour/beatbox_gui.cc +++ b/gtk2_ardour/beatbox_gui.cc @@ -451,6 +451,7 @@ StepView::StepView (SequencerGrid& sg, Step& s, ArdourCanvas::Item* parent) , _step (s) , _seq (sg) , text (new Text (this)) + , grabbed (false) { set_fill_color (UIConfiguration::instance().color ("selection")); @@ -552,6 +553,31 @@ StepView::on_event (GdkEvent *ev) bool StepView::motion_event (GdkEventMotion* ev) { + if (!grabbed) { + return false; + } + + const double xdelta = ev->x - last_motion.first; + const double ydelta = last_motion.second - ev->y; + //const double distance = sqrt (xdelta * xdelta + ydelta * ydelta); + const double distance = ydelta; + + if ((ev->state & GDK_MOD1_MASK) || _seq.mode() == SequencerGrid::Pitch) { + cerr << "adjust pitch by " << distance << endl; + adjust_step_pitch (distance); + } else if (_seq.mode() == SequencerGrid::Velocity) { + cerr << "adjust velocity by " << distance << endl; + adjust_step_velocity (distance); + } else if (_seq.mode() == SequencerGrid::Duration) { + cerr << "adjust duration by " << Step::DurationRatio (distance, 32) << endl; + adjust_step_duration (Step::DurationRatio (distance, 32)); /* adjust by 1/32 of the sequencer step size */ + } else if (_seq.mode() == SequencerGrid::Octave) { + adjust_step_octave (distance); + } else if (_seq.mode() == SequencerGrid::Group) { + } + + last_motion = std::make_pair (ev->x, ev->y); + return true; } @@ -559,12 +585,17 @@ bool StepView::button_press_event (GdkEventButton* ev) { grab_at = std::make_pair (ev->x, ev->y); + last_motion = grab_at; + grab (); + grabbed = true; return true; } bool StepView::button_release_event (GdkEventButton* ev) { + ungrab (); + grabbed = false; return true; } diff --git a/gtk2_ardour/beatbox_gui.h b/gtk2_ardour/beatbox_gui.h index d349b5ceb4..4728216c03 100644 --- a/gtk2_ardour/beatbox_gui.h +++ b/gtk2_ardour/beatbox_gui.h @@ -78,8 +78,10 @@ class StepView : public ArdourCanvas::Rectangle, public sigc::trackable { ARDOUR::Step& _step; SequencerGrid& _seq; ArdourCanvas::Text* text; + bool grabbed; std::pair grab_at; + std::pair last_motion; bool motion_event (GdkEventMotion*); bool button_press_event (GdkEventButton*);