summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-11-16 01:05:21 -0500
committerDavid Robillard <d@drobilla.net>2014-11-16 22:35:45 -0500
commitfd9ccc7058cf7cfadbfa1dfb9676e2de3a14e1b0 (patch)
treeb65c03818c9eded429651ca621773d728f9e1976
parent9c5e63bcc69290e1df84ea345b1899a241b7655e (diff)
Use an enum for RoundMode instead of magic numbers.
No functional changes in this one (for easier auditing), but towards having round up/down only if necessary modes, rather than kludging around that situation with a double round as we do currently.
-rw-r--r--gtk2_ardour/editor.cc8
-rw-r--r--gtk2_ardour/editor.h25
-rw-r--r--gtk2_ardour/editor_drag.cc10
-rw-r--r--gtk2_ardour/editor_mouse.cc4
-rw-r--r--gtk2_ardour/editor_ops.cc4
-rw-r--r--gtk2_ardour/midi_region_view.cc2
-rw-r--r--gtk2_ardour/midi_time_axis.cc2
-rw-r--r--gtk2_ardour/public_editor.h9
-rw-r--r--gtk2_ardour/region_view.cc4
-rw-r--r--gtk2_ardour/step_editor.cc2
-rw-r--r--gtk2_ardour/tempo_dialog.cc2
-rw-r--r--libs/ardour/ardour/tempo.h9
-rw-r--r--libs/ardour/ardour/types.h6
-rw-r--r--libs/ardour/tempo.cc8
14 files changed, 60 insertions, 35 deletions
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc
index da5dcb2df5..ac59ecab4f 100644
--- a/gtk2_ardour/editor.cc
+++ b/gtk2_ardour/editor.cc
@@ -2553,7 +2553,7 @@ Editor::trackview_by_y_position (double y, bool trackview_relative_offset) const
* @param event Event to get current key modifier information from, or 0.
*/
void
-Editor::snap_to_with_modifier (framepos_t& start, GdkEvent const * event, int32_t direction, bool for_mark)
+Editor::snap_to_with_modifier (framepos_t& start, GdkEvent const * event, RoundMode direction, bool for_mark)
{
if (!_session || !event) {
return;
@@ -2571,7 +2571,7 @@ Editor::snap_to_with_modifier (framepos_t& start, GdkEvent const * event, int32_
}
void
-Editor::snap_to (framepos_t& start, int32_t direction, bool for_mark)
+Editor::snap_to (framepos_t& start, RoundMode direction, bool for_mark)
{
if (!_session || _snap_mode == SnapOff) {
return;
@@ -2581,7 +2581,7 @@ Editor::snap_to (framepos_t& start, int32_t direction, bool for_mark)
}
void
-Editor::timecode_snap_to_internal (framepos_t& start, int32_t direction, bool /*for_mark*/)
+Editor::timecode_snap_to_internal (framepos_t& start, RoundMode direction, bool /*for_mark*/)
{
const framepos_t one_timecode_second = (framepos_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame());
framepos_t one_timecode_minute = (framepos_t)(rint(_session->timecode_frames_per_second()) * _session->frames_per_timecode_frame() * 60);
@@ -2638,7 +2638,7 @@ Editor::timecode_snap_to_internal (framepos_t& start, int32_t direction, bool /*
}
void
-Editor::snap_to_internal (framepos_t& start, int32_t direction, bool for_mark)
+Editor::snap_to_internal (framepos_t& start, RoundMode direction, bool for_mark)
{
const framepos_t one_second = _session->frame_rate();
const framepos_t one_minute = _session->frame_rate() * 60;
diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h
index 2831fc894f..09b81c4e64 100644
--- a/gtk2_ardour/editor.h
+++ b/gtk2_ardour/editor.h
@@ -412,9 +412,19 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
Gtkmm2ext::TearOff* mouse_mode_tearoff () const { return _mouse_mode_tearoff; }
Gtkmm2ext::TearOff* tools_tearoff () const { return _tools_tearoff; }
- void snap_to (framepos_t& first, int32_t direction = 0, bool for_mark = false);
- void snap_to_with_modifier (framepos_t& first, GdkEvent const *, int32_t direction = 0, bool for_mark = false);
- void snap_to (framepos_t& first, framepos_t& last, int32_t direction = 0, bool for_mark = false);
+ void snap_to (framepos_t& first,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false);
+
+ void snap_to_with_modifier (framepos_t& first,
+ GdkEvent const * ev,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false);
+
+ void snap_to (framepos_t& first,
+ framepos_t& last,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false);
void begin_reversible_command (std::string cmd_name);
void begin_reversible_command (GQuark);
@@ -2018,8 +2028,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
void select_next_route ();
void select_prev_route ();
- void snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
- void timecode_snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
+ void snap_to_internal (framepos_t& first,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false);
+
+ void timecode_snap_to_internal (framepos_t& first,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false);
RhythmFerret* rhythm_ferret;
diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc
index 1237c73c3d..9df013264f 100644
--- a/gtk2_ardour/editor_drag.cc
+++ b/gtk2_ardour/editor_drag.cc
@@ -2764,7 +2764,7 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
motion (event, false);
TempoMap& map (_editor->session()->tempo_map());
- framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
+ framepos_t beat_time = map.round_to_beat (last_pointer_frame(), RoundNearest);
Timecode::BBT_Time when;
map.bbt_time (beat_time, when);
@@ -3401,7 +3401,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
} else if (new_start < copy_location->end()) {
copy_location->set_start (new_start);
} else if (newframe > 0) {
- _editor->snap_to (next, 1, true);
+ _editor->snap_to (next, RoundUpAlways, true);
copy_location->set_end (next);
copy_location->set_start (newframe);
}
@@ -3414,7 +3414,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
} else if (new_end > copy_location->start()) {
copy_location->set_end (new_end);
} else if (newframe > 0) {
- _editor->snap_to (next, -1, true);
+ _editor->snap_to (next, RoundDownAlways, true);
copy_location->set_start (next);
copy_location->set_end (newframe);
}
@@ -4221,9 +4221,9 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
if (first_move) {
grab = adjusted_current_frame (event, false);
if (grab < pending_position) {
- _editor->snap_to (grab, -1);
+ _editor->snap_to (grab, RoundDownAlways);
} else {
- _editor->snap_to (grab, 1);
+ _editor->snap_to (grab, RoundUpAlways);
}
}
diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc
index 3ad9f0a54c..f7a7855eaa 100644
--- a/gtk2_ardour/editor_mouse.cc
+++ b/gtk2_ardour/editor_mouse.cc
@@ -1521,7 +1521,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case MarkerBarItem:
if (!_dragging_playhead) {
- snap_to_with_modifier (where, event, 0, true);
+ snap_to_with_modifier (where, event, RoundNearest, true);
mouse_add_new_marker (where);
}
return true;
@@ -1529,7 +1529,7 @@ 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
- snap_to_with_modifier (where, event, 0, true);
+ snap_to_with_modifier (where, event, RoundNearest, true);
mouse_add_new_marker (where, true);
}
return true;
diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index f6ec077301..3d5ae6cb14 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -6463,7 +6463,7 @@ Editor::playhead_forward_to_grid ()
framepos_t pos = playhead_cursor->current_frame ();
if (pos < max_framepos - 1) {
pos += 2;
- snap_to_internal (pos, 1, false);
+ snap_to_internal (pos, RoundUpAlways, false);
_session->request_locate (pos);
}
}
@@ -6479,7 +6479,7 @@ Editor::playhead_backward_to_grid ()
framepos_t pos = playhead_cursor->current_frame ();
if (pos > 2) {
pos -= 2;
- snap_to_internal (pos, -1, false);
+ snap_to_internal (pos, RoundDownAlways, false);
_session->request_locate (pos);
}
}
diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc
index a620154866..d519bd1a04 100644
--- a/gtk2_ardour/midi_region_view.cc
+++ b/gtk2_ardour/midi_region_view.cc
@@ -3087,7 +3087,7 @@ MidiRegionView::nudge_notes (bool forward)
next_pos -= 1;
}
- trackview.editor().snap_to (next_pos, (forward ? 1 : -1), false);
+ trackview.editor().snap_to (next_pos, (forward ? RoundUpAlways : RoundDownAlways), false);
distance = ref_point - next_pos;
}
diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc
index 772baf834f..4d55f2e8e1 100644
--- a/gtk2_ardour/midi_time_axis.cc
+++ b/gtk2_ardour/midi_time_axis.cc
@@ -1587,7 +1587,7 @@ MidiTimeAxisView::add_region (framepos_t pos, framecnt_t length, bool commit)
real_editor->begin_reversible_command (Operations::create_region);
playlist()->clear_changes ();
- real_editor->snap_to (pos, 0);
+ real_editor->snap_to (pos, RoundNearest);
boost::shared_ptr<Source> src = _session->create_midi_source_by_stealing_name (view()->trackview().track());
PropertyList plist;
diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h
index 4bf03bc72f..9969d9d49e 100644
--- a/gtk2_ardour/public_editor.h
+++ b/gtk2_ardour/public_editor.h
@@ -141,7 +141,9 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible, publi
virtual void set_snap_threshold (double t) = 0;
/** Snap a value according to the current snap setting. */
- virtual void snap_to (framepos_t& first, int32_t direction = 0, bool for_mark = false) = 0;
+ virtual void snap_to (framepos_t& first,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false) = 0;
/** Undo some transactions.
* @param n Number of transactions to undo.
@@ -411,7 +413,10 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible, publi
virtual ARDOUR::Location* find_location_from_marker (Marker *, bool &) const = 0;
virtual Marker* find_marker_from_location_id (PBD::ID const &, bool) const = 0;
- virtual void snap_to_with_modifier (framepos_t &, GdkEvent const *, int32_t direction = 0, bool for_mark = false) = 0;
+ virtual void snap_to_with_modifier (framepos_t & first,
+ GdkEvent const * ev,
+ ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
+ bool for_mark = false) = 0;
virtual void get_regions_at (RegionSelection &, framepos_t where, TrackViewList const &) const = 0;
virtual RegionSelection get_regions_from_selection_and_mouse (framepos_t) = 0;
diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc
index 4e59137957..49b47332ae 100644
--- a/gtk2_ardour/region_view.cc
+++ b/gtk2_ardour/region_view.cc
@@ -963,12 +963,12 @@ RegionView::snap_frame_to_frame (frameoffset_t x) const
/* try a snap in either direction */
framepos_t frame = session_frame;
- editor.snap_to (frame, 0);
+ editor.snap_to (frame, RoundNearest);
/* if we went off the beginning of the region, snap forwards */
if (frame < _region->position ()) {
frame = session_frame;
- editor.snap_to (frame, 1);
+ editor.snap_to (frame, RoundUpAlways);
}
/* back to region relative */
diff --git a/gtk2_ardour/step_editor.cc b/gtk2_ardour/step_editor.cc
index 4665da348b..ef3caad5d1 100644
--- a/gtk2_ardour/step_editor.cc
+++ b/gtk2_ardour/step_editor.cc
@@ -398,7 +398,7 @@ StepEditor::step_edit_bar_sync ()
}
framepos_t fpos = step_edit_region_view->region_beats_to_absolute_frames (step_edit_beat_pos);
- fpos = _session->tempo_map().round_to_bar (fpos, 1);
+ fpos = _session->tempo_map().round_to_bar (fpos, RoundUpAlways);
step_edit_beat_pos = ceil (step_edit_region_view->region_frames_to_region_beats (fpos - step_edit_region->position()));
step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
}
diff --git a/gtk2_ardour/tempo_dialog.cc b/gtk2_ardour/tempo_dialog.cc
index a969581369..5671ae4dda 100644
--- a/gtk2_ardour/tempo_dialog.cc
+++ b/gtk2_ardour/tempo_dialog.cc
@@ -289,7 +289,7 @@ MeterDialog::MeterDialog (TempoMap& map, framepos_t frame, const string&)
: ArdourDialog (_("New Meter"))
{
Timecode::BBT_Time when;
- frame = map.round_to_bar(frame,0);
+ frame = map.round_to_bar(frame, RoundNearest);
Meter meter (map.meter_at(frame));
map.bbt_time (frame, when);
diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h
index 8fa5ed45a0..15cd1662f0 100644
--- a/libs/ardour/ardour/tempo.h
+++ b/libs/ardour/ardour/tempo.h
@@ -297,10 +297,9 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
void replace_tempo (const TempoSection&, const Tempo&, const Timecode::BBT_Time& where);
void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where);
- framepos_t round_to_bar (framepos_t frame, int dir);
- framepos_t round_to_beat (framepos_t frame, int dir);
- framepos_t round_to_beat_subdivision (framepos_t fr, int sub_num, int dir);
- framepos_t round_to_tick (framepos_t frame, int dir);
+ framepos_t round_to_bar (framepos_t frame, RoundMode dir);
+ framepos_t round_to_beat (framepos_t frame, RoundMode dir);
+ framepos_t round_to_beat_subdivision (framepos_t fr, int sub_num, RoundMode dir);
void set_length (framepos_t frames);
@@ -355,7 +354,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
BBTPointList::const_iterator bbt_before_or_at (const Timecode::BBT_Time&);
BBTPointList::const_iterator bbt_after_or_at (framepos_t);
- framepos_t round_to_type (framepos_t fr, int dir, BBTPointType);
+ framepos_t round_to_type (framepos_t fr, RoundMode dir, BBTPointType);
void bbt_time (framepos_t, Timecode::BBT_Time&, const BBTPointList::const_iterator&);
framecnt_t bbt_duration_at_unlocked (const Timecode::BBT_Time& when, const Timecode::BBT_Time& bbt, int dir);
diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h
index 165afd0dd9..1b0ba5ea3c 100644
--- a/libs/ardour/ardour/types.h
+++ b/libs/ardour/ardour/types.h
@@ -216,6 +216,12 @@ namespace ARDOUR {
TrackColor
};
+ enum RoundMode {
+ RoundDownAlways = -1, ///< Always round down, even if on a division
+ RoundNearest = 0, ///< Round to nearest
+ RoundUpAlways = 1 ///< Always round up, even if on a division
+ };
+
class AnyTime {
public:
enum Type {
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc
index 6f3f734116..77128bd0c2 100644
--- a/libs/ardour/tempo.cc
+++ b/libs/ardour/tempo.cc
@@ -1223,19 +1223,19 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
}
framepos_t
-TempoMap::round_to_bar (framepos_t fr, int dir)
+TempoMap::round_to_bar (framepos_t fr, RoundMode dir)
{
return round_to_type (fr, dir, Bar);
}
framepos_t
-TempoMap::round_to_beat (framepos_t fr, int dir)
+TempoMap::round_to_beat (framepos_t fr, RoundMode dir)
{
return round_to_type (fr, dir, Beat);
}
framepos_t
-TempoMap::round_to_beat_subdivision (framepos_t fr, int sub_num, int dir)
+TempoMap::round_to_beat_subdivision (framepos_t fr, int sub_num, RoundMode dir)
{
require_map_to (fr);
@@ -1354,7 +1354,7 @@ TempoMap::round_to_beat_subdivision (framepos_t fr, int sub_num, int dir)
}
framepos_t
-TempoMap::round_to_type (framepos_t frame, int dir, BBTPointType type)
+TempoMap::round_to_type (framepos_t frame, RoundMode dir, BBTPointType type)
{
require_map_to (frame);