, _grab_frame (0)
, _last_pointer_frame (0)
, _snap_delta (0)
+ , _constraint_pressed (false)
{
}
{
/* we set up x/y dragging constraints on first move */
+ _constraint_pressed = ArdourKeyboard::indicates_constraint (event->button.state);
_raw_grab_frame = _editor->canvas_event_sample (event, &_grab_x, &_grab_y);
if (Config->get_edit_mode() != Lock) {
if (event->motion.state & Gdk::BUTTON2_MASK) {
// if dragging with button2, the motion is x constrained, with constraint modifier it is y constrained
- if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+ if (_constraint_pressed) {
_x_constrained = false;
_y_constrained = true;
} else {
_x_constrained = true;
_y_constrained = false;
}
- } else if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+ } else if (_constraint_pressed) {
// if dragging normally, the motion is constrained to the first direction of movement.
if (_initially_vertical) {
_x_constrained = true;
behind which may be slightly odd from the user's point of view.
*/
- finished (0, true);
+ GdkEvent ev;
+ finished (&ev, true);
if (movement_occurred) {
- _editor->undo ();
+ _editor->session()->undo (1);
}
for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
}
- if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+ if (ArdourKeyboard::indicates_constraint (event->button.state)) {
/* use vertical movement to alter tempo .. should be log */
double new_bpm = _real_section->beats_per_minute() + ((last_pointer_y() - current_pointer_y()) / 5.0);
stringstream strs;
show_verbose_cursor_text (strs.str());
} else if (_movable && !_real_section->locked_to_meter()) {
- const framepos_t pf = adjusted_current_frame (event);
+ framepos_t pf;
+
+ if (_editor->snap_musical()) {
+ /* we can't snap to a grid that we are about to move.
+ * gui_move_tempo() will sort out snap using the supplied beat divisions.
+ */
+ pf = adjusted_current_frame (event, false);
+ } else {
+ pf = adjusted_current_frame (event);
+ }
+
TempoMap& map (_editor->session()->tempo_map());
/* snap to beat is 1, snap to bar is -1 (sorry) */
- int sub_num = _editor->get_grid_music_divisions (event->button.state);
+ const int sub_num = _editor->get_grid_music_divisions (event->button.state);
map.gui_move_tempo (_real_section, pf, sub_num);
pf = adjusted_current_frame (event);
}
- if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
+ if (ArdourKeyboard::indicates_constraint (event->button.state)) {
/* adjust previous tempo to match pointer frame */
_editor->session()->tempo_map().gui_dilate_tempo (_tempo, map.frame_at_pulse (_pulse), pf, _pulse);
}
frameoffset_t
NoteDrag::total_dx (const guint state) const
{
+ if (_x_constrained) {
+ return 0;
+ }
+ TempoMap& map (_editor->session()->tempo_map());
+
/* dx in frames */
frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
/* primary note time */
- frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
+ double const quarter_note_start = map.quarter_note_at_beat (_region->region()->beat() - _region->midi_region()->start_beats().to_double());
+ frameoffset_t const n = map.frame_at_quarter_note (quarter_note_start + _primary->note()->time().to_double());
/* new time of the primary note in session frames */
frameoffset_t st = n + dx + snap_delta (state);
int8_t
NoteDrag::total_dy () const
{
+ if (_y_constrained) {
+ return 0;
+ }
+
MidiStreamView* msv = _region->midi_stream_view ();
double const y = _region->midi_view()->y_position ();
/* new current note */
int8_t const dy = total_dy ();
/* Now work out what we have to do to the note canvas items to set this new drag delta */
- double const tdx = _editor->sample_to_pixel (dx) - _cumulative_dx;
- double const tdy = -dy * _note_height - _cumulative_dy;
+ double const tdx = _x_constrained ? 0 : _editor->sample_to_pixel (dx) - _cumulative_dx;
+ double const tdy = _y_constrained ? 0 : -dy * _note_height - _cumulative_dy;
if (tdx || tdy) {
_cumulative_dx += tdx;
int8_t note_delta = total_dy();
- _region->move_selection (tdx, tdy, note_delta);
+ if (tdx || tdy) {
+ _region->move_selection (tdx, tdy, note_delta);
- /* the new note value may be the same as the old one, but we
- * don't know what that means because the selection may have
- * involved more than one note and we might be doing something
- * odd with them. so show the note value anyway, always.
- */
+ /* the new note value may be the same as the old one, but we
+ * don't know what that means because the selection may have
+ * involved more than one note and we might be doing something
+ * odd with them. so show the note value anyway, always.
+ */
- uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
+ uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
- _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note);
+ _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note);
+ }
}
}
Drag::start_grab (event, cursor);
_drag_rect = new ArdourCanvas::Rectangle (_region_view->get_canvas_group ());
+ TempoMap& map (_editor->session()->tempo_map());
- framepos_t pf = _drags->current_pointer_frame ();
- framecnt_t const g = grid_frames (pf);
+ const framepos_t pf = _drags->current_pointer_frame ();
+ const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
- /* Hack so that we always snap to the note that we are over, instead of snapping
- to the next one if we're more than halfway through the one we're over.
- */
- if (_editor->snap_mode() == SnapNormal && pf > g / 2) {
- pf -= g / 2;
+ double eqaf = map.exact_qn_at_frame (pf, divisions);
+
+ if (divisions != 0) {
+ bool success = false;
+ Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
+ if (!success) {
+ grid_beats = Evoral::Beats(1);
+ }
+
+ const double qaf = map.quarter_note_at_frame (pf);
+
+ /* Hack so that we always snap to the note that we are over, instead of snapping
+ to the next one if we're more than halfway through the one we're over.
+ */
+
+ const double rem = eqaf - qaf;
+ if (rem >= 0.0 && eqaf - grid_beats.to_double() > _region_view->region()->pulse() * 4.0) {
+ eqaf -= grid_beats.to_double();
+ }
}
- _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
+ _note[0] = map.frame_at_quarter_note (eqaf) - _region_view->region()->position();
_note[1] = _note[0];
MidiStreamView* sv = _region_view->midi_stream_view ();
}
void
-NoteCreateDrag::finished (GdkEvent*, bool had_movement)
+NoteCreateDrag::finished (GdkEvent* ev, bool had_movement)
{
if (!had_movement) {
return;
}
framepos_t const start = min (_note[0], _note[1]);
+ framepos_t const start_sess_rel = start + _region_view->region()->position();
framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1]));
framecnt_t const g = grid_frames (start);
Evoral::Beats const one_tick = Evoral::Beats::ticks(1);
- if (_editor->snap_mode() == SnapNormal && length < g) {
+ if (_editor->get_grid_music_divisions (ev->button.state) != 0 && length < g) {
length = g;
}
- Evoral::Beats length_beats = max (
- one_tick, _region_view->region_frames_to_region_beats (length) - one_tick);
+ TempoMap& map (_editor->session()->tempo_map());
+ const double qn_length = map.quarter_note_at_frame (start_sess_rel + length) - map.quarter_note_at_frame (start_sess_rel);
- _region_view->create_note_at (start, _drag_rect->y0(), length_beats, false);
+ Evoral::Beats qn_length_beats = max (one_tick, Evoral::Beats (qn_length));
+ _region_view->create_note_at (start, _drag_rect->y0(), qn_length_beats, ev->button.state, false);
}
double