summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2009-08-24 20:26:34 +0000
committerCarl Hetherington <carl@carlh.net>2009-08-24 20:26:34 +0000
commitdf71243d6c18e5ae54706b51a6cbe770476ab419 (patch)
tree6dd88e5506ff5335e291770a1d4f99473ac5ee83
parent29fea7b61d2779532957e709d2d7ecf2b440d415 (diff)
Alter snap modifier so that it turns the grid on when it's off as well as vice-versa.
git-svn-id: svn://localhost/ardour2/branches/3.0@5584 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/editor.cc23
-rw-r--r--gtk2_ardour/editor.h1
-rw-r--r--gtk2_ardour/editor_drag.cc45
-rw-r--r--gtk2_ardour/editor_mouse.cc16
-rw-r--r--gtk2_ardour/keyboard.h5
-rw-r--r--gtk2_ardour/rc_option_editor.cc2
6 files changed, 49 insertions, 43 deletions
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc
index ec351be787..c262a763f2 100644
--- a/gtk2_ardour/editor.cc
+++ b/gtk2_ardour/editor.cc
@@ -2515,6 +2515,29 @@ Editor::trackview_by_y_position (double y)
return std::make_pair ( (TimeAxisView *) 0, 0);
}
+/** Snap a position to the grid, if appropriate, taking into account current
+ * grid settings and also the state of any snap modifier keys that may be pressed.
+ * @param start Position to snap.
+ * @param event Event to get current key modifier information from.
+ */
+void
+Editor::snap_to_with_modifier (nframes64_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
+{
+ if (!session) {
+ return;
+ }
+
+ if (Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
+ if (snap_mode == SnapOff) {
+ snap_to_internal (start, direction, for_mark);
+ }
+ } else {
+ if (snap_mode != SnapOff) {
+ snap_to_internal (start, direction, for_mark);
+ }
+ }
+}
+
void
Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
{
diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h
index 08a4c2996e..3cadb9d4ad 100644
--- a/gtk2_ardour/editor.h
+++ b/gtk2_ardour/editor.h
@@ -1489,6 +1489,7 @@ public:
void redisplay_tempo (bool immediate_redraw);
void snap_to (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
+ void snap_to_with_modifier (nframes64_t& first, GdkEvent const *, int32_t direction = 0, bool for_mark = false);
void snap_to (nframes64_t& first, nframes64_t& last, int32_t direction = 0, bool for_mark = false);
double snap_length_beats (nframes64_t start);
diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc
index 8654cacdd8..73296af864 100644
--- a/gtk2_ardour/editor_drag.cc
+++ b/gtk2_ardour/editor_drag.cc
@@ -159,9 +159,7 @@ Drag::adjusted_current_frame (GdkEvent* event) const
pos = _current_pointer_frame - _pointer_frame_offset;
}
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- _editor->snap_to (pos);
- }
+ _editor->snap_to_with_modifier (pos, event);
return pos;
}
@@ -423,12 +421,7 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, nframes64_t* pending_
sync_frame = *pending_region_position + (sync_dir*sync_offset);
- /* we snap if the snap modifier is not enabled.
- */
-
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- _editor->snap_to (sync_frame);
- }
+ _editor->snap_to_with_modifier (sync_frame, event);
*pending_region_position = _primary->region()->adjust_to_sync (sync_frame);
@@ -1503,9 +1496,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
left_direction = false;
}
- if (obey_snap) {
- _editor->snap_to (_current_pointer_frame);
- }
+ _editor->snap_to_with_modifier (_current_pointer_frame, event);
if (first_move) {
@@ -1846,7 +1837,7 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
nframes64_t where = _editor->event_frame (event, 0, 0);
- _editor->snap_to (where);
+ _editor->snap_to_with_modifier (where, event);
_editor->playhead_cursor->set_position (where);
}
@@ -2499,8 +2490,8 @@ ControlPointDrag::motion (GdkEvent* event, bool)
//translate cx to frames
nframes64_t cx_frames = _editor->unit_to_frame (cx);
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()) && !_x_constrained) {
- _editor->snap_to (cx_frames);
+ if (!_x_constrained) {
+ _editor->snap_to_with_modifier (cx_frames, event);
}
float const fraction = 1.0 - (cy / _point->line().height());
@@ -2648,11 +2639,11 @@ RubberbandSelectDrag::motion (GdkEvent* event, bool first_move)
return;
}
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()) && Config->get_rubberbanding_snaps_to_grid()) {
+ if (Config->get_rubberbanding_snaps_to_grid()) {
if (first_move) {
- _editor->snap_to (_grab_frame);
+ _editor->snap_to_with_modifier (_grab_frame, event);
}
- _editor->snap_to (_current_pointer_frame);
+ _editor->snap_to_with_modifier (_current_pointer_frame, event);
}
/* base start and end on initial click position */
@@ -2750,9 +2741,7 @@ TimeFXDrag::motion (GdkEvent* event, bool)
{
RegionView* rv = _primary;
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- _editor->snap_to (_current_pointer_frame);
- }
+ _editor->snap_to_with_modifier (_current_pointer_frame, event);
if (_current_pointer_frame == _last_pointer_frame) {
return;
@@ -3102,9 +3091,7 @@ RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
break;
}
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- _editor->snap_to (_current_pointer_frame);
- }
+ _editor->snap_to_with_modifier (_current_pointer_frame, event);
/* only alter selection if the current frame is
different from the last frame position.
@@ -3272,12 +3259,10 @@ MouseZoomDrag::motion (GdkEvent* event, bool first_move)
nframes64_t start;
nframes64_t end;
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- _editor->snap_to (_current_pointer_frame);
-
- if (first_move) {
- _editor->snap_to (_grab_frame);
- }
+ _editor->snap_to_with_modifier (_current_pointer_frame, event);
+
+ if (first_move) {
+ _editor->snap_to_with_modifier (_grab_frame, event);
}
if (_current_pointer_frame == _last_pointer_frame) {
diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc
index 41d14c4f1e..4f85f20846 100644
--- a/gtk2_ardour/editor_mouse.cc
+++ b/gtk2_ardour/editor_mouse.cc
@@ -1181,9 +1181,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case MarkerBarItem:
if (!_dragging_playhead) {
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (where, 0, true);
- }
+ snap_to_with_modifier (where, event, 0, true);
mouse_add_new_marker (where);
}
return true;
@@ -1191,18 +1189,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case CdMarkerBarItem:
if (!_dragging_playhead) {
// if we get here then a dragged range wasn't done
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (where, 0, true);
- }
+ snap_to_with_modifier (where, event, 0, true);
mouse_add_new_marker (where, true);
}
return true;
case TempoBarItem:
if (!_dragging_playhead) {
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (where);
- }
+ snap_to_with_modifier (where, event);
mouse_add_new_tempo_event (where);
}
return true;
@@ -2222,9 +2216,7 @@ Editor::point_trim (GdkEvent* event)
nframes64_t new_bound = _drag->current_pointer_frame();
- if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
- snap_to (new_bound);
- }
+ snap_to_with_modifier (new_bound, event);
/* Choose action dependant on which button was pressed */
switch (event->button.button) {
diff --git a/gtk2_ardour/keyboard.h b/gtk2_ardour/keyboard.h
index 2905299334..cff45b11f2 100644
--- a/gtk2_ardour/keyboard.h
+++ b/gtk2_ardour/keyboard.h
@@ -90,6 +90,11 @@ class Keyboard : public sigc::trackable, PBD::Stateful
static bool no_modifiers_active (guint state);
static void set_snap_modifier (guint);
+
+ /** @return Modifier mask to temporarily toggle grid setting; with this modifier
+ * - magnetic or normal grid should become no grid and
+ * - no grid should become normal grid
+ */
static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
static guint edit_button() { return edit_but; }
diff --git a/gtk2_ardour/rc_option_editor.cc b/gtk2_ardour/rc_option_editor.cc
index 662387ef1c..06908ca0c1 100644
--- a/gtk2_ardour/rc_option_editor.cc
+++ b/gtk2_ardour/rc_option_editor.cc
@@ -595,7 +595,7 @@ public:
}
}
- l = manage (new Label (_("Ignore snap using:")));
+ l = manage (new Label (_("Toggle snap using:")));
l->set_name ("OptionsLabel");
l->set_alignment (1.0, 0.5);