mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
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.
This commit is contained in:
parent
9c5e63bcc6
commit
fd9ccc7058
14 changed files with 60 additions and 35 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue