more movement of code and members from Editor => EditingContext

This commit is contained in:
Paul Davis 2023-11-19 11:37:31 -07:00
parent e9d63a707a
commit 4398fe931b
7 changed files with 347 additions and 399 deletions

View file

@ -234,8 +234,6 @@ Editor::Editor ()
, constructed (false)
, _properties_box (0)
, no_save_visual (false)
, samples_per_pixel (2048)
, zoom_focus (ZoomFocusPlayhead)
, mouse_mode (MouseObject)
, marker_click_behavior (MarkerClickSelectOnly)
, _join_object_range_state (JOIN_OBJECT_RANGE_NONE)
@ -2545,55 +2543,6 @@ Editor::set_snapped_cursor_position (timepos_t const & pos)
}
/** 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, or 0.
*/
void
Editor::snap_to_with_modifier (timepos_t& start, GdkEvent const * event, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap)
{
if (!_session || !event) {
return;
}
if (ArdourKeyboard::indicates_snap (event->button.state)) {
if (_snap_mode == SnapOff) {
snap_to_internal (start, direction, pref, ensure_snap);
}
} else {
if (_snap_mode != SnapOff) {
snap_to_internal (start, direction, pref);
} else if (ArdourKeyboard::indicates_snap_delta (event->button.state)) {
/* SnapOff, but we pressed the snap_delta modifier */
snap_to_internal (start, direction, pref, ensure_snap);
}
}
}
void
Editor::snap_to (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap)
{
if (!_session || (_snap_mode == SnapOff && !ensure_snap)) {
return;
}
snap_to_internal (start, direction, pref, ensure_snap);
}
static void
check_best_snap (timepos_t const & presnap, timepos_t &test, timepos_t &dist, timepos_t &best)
{
timepos_t diff = timepos_t (presnap.distance (test).abs ());
if (diff < dist) {
dist = diff;
best = test;
}
test = timepos_t::max (test.time_domain()); // reset this so it doesn't get accidentally reused
}
timepos_t
Editor::snap_to_timecode (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref)
{
@ -2744,117 +2693,6 @@ Editor::snap_to_cd_frames (timepos_t const & presnap, Temporal::RoundMode direct
return timepos_t (presnap_sample);
}
timepos_t
Editor::snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref)
{
return _snap_to_bbt (presnap, direction, gpref, _grid_type);
}
timepos_t
Editor::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref, GridType grid_type)
{
timepos_t ret(presnap);
TempoMap::SharedPtr tmap (TempoMap::use());
/* Snap to bar always uses bars, and ignores visual grid, so it may
* sometimes snap to bars that are not visually distinguishable.
*
* XXX this should probably work totally different: we should get the
* nearby grid and walk towards the next bar point.
*/
if (grid_type == GridTypeBar) {
return timepos_t (tmap->quarters_at (presnap).round_to_subdivision (get_grid_beat_divisions(_grid_type), direction));
}
if (gpref != SnapToGrid_Unscaled) { // use the visual grid lines which are limited by the zoom scale that the user selected
/* Determine the most obvious divisor of a beat to use
* for the snap, based on the grid setting.
*/
float divisor;
switch (_grid_type) {
case GridTypeBeatDiv3:
case GridTypeBeatDiv6:
case GridTypeBeatDiv12:
case GridTypeBeatDiv24:
divisor = 3;
break;
case GridTypeBeatDiv5:
case GridTypeBeatDiv10:
case GridTypeBeatDiv20:
divisor = 2.5;
break;
case GridTypeBeatDiv7:
case GridTypeBeatDiv14:
case GridTypeBeatDiv28:
/* Septuplets suffer from drifting until libtemporal handles fractional ticks
* or if ticks_per_beat (ppqn) is raised to a point where the result
*/
divisor = 3.5;
break;
case GridTypeBeat:
divisor = 1;
break;
case GridTypeNone:
return ret;
default:
divisor = 2;
break;
};
/* bbt_ruler_scale reflects the level of detail we will show
* for the visual grid. Adjust the "natural" divisor to reflect
* this level of detail, and snap to that.
*
* So, for example, if the grid is Div3, we use 3 divisions per
* beat, but if the visual grid is using bbt_show_sixteenths (a
* fairly high level of detail), we will snap to (2 * 3)
* divisions per beat. Etc.
*/
BBTRulerScale scale = bbt_ruler_scale;
switch (scale) {
case bbt_show_many:
case bbt_show_64:
case bbt_show_16:
case bbt_show_4:
case bbt_show_1:
/* Round to Bar */
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (-1, direction));
break;
case bbt_show_quarters:
/* Round to Beat */
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (1, direction));
break;
case bbt_show_eighths:
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (1 * divisor, direction));
break;
case bbt_show_sixteenths:
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (2 * divisor, direction));
break;
case bbt_show_thirtyseconds:
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (4 * divisor, direction));
break;
case bbt_show_sixtyfourths:
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (8 * divisor, direction));
break;
case bbt_show_onetwentyeighths:
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (16 * divisor, direction));
break;
}
} else {
/* Just use the grid as specified, without paying attention to
* zoom level
*/
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (get_grid_beat_divisions(_grid_type), direction));
}
return ret;
}
timepos_t
Editor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref)
{
@ -2916,90 +2754,6 @@ Editor::snap_to_marker (timepos_t const & presnap, Temporal::RoundMode direction
return test;
}
void
Editor::snap_to_internal (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap)
{
UIConfiguration const& uic (UIConfiguration::instance ());
const timepos_t presnap = start;
timepos_t test = timepos_t::max (start.time_domain()); // for each snap, we'll use this value
timepos_t dist = timepos_t::max (start.time_domain()); // this records the distance of the best snap result we've found so far
timepos_t best = timepos_t::max (start.time_domain()); // this records the best snap-result we've found so far
/* check Grid */
if ( (_grid_type != GridTypeNone) && (uic.get_snap_target () != SnapTargetOther) ) {
timepos_t pre (presnap);
timepos_t post (snap_to_grid (pre, direction, pref));
check_best_snap (presnap, post, dist, best);
if (uic.get_snap_target () == SnapTargetGrid) {
goto check_distance;
}
}
/* check snap-to-marker */
if ((pref == SnapToAny_Visual) && uic.get_snap_to_marks ()) {
test = snap_to_marker (presnap, direction);
check_best_snap (presnap, test, dist, best);
}
/* check snap-to-playhead */
if ((pref == SnapToAny_Visual) && uic.get_snap_to_playhead () && !_session->transport_rolling ()) {
test = timepos_t (_session->audible_sample());
check_best_snap (presnap, test, dist, best);
}
/* check snap-to-region-{start/end/sync} */
if ((pref == SnapToAny_Visual) && (uic.get_snap_to_region_start () || uic.get_snap_to_region_end () || uic.get_snap_to_region_sync ())) {
if (!region_boundary_cache.empty ()) {
set<timepos_t>::iterator prev = region_boundary_cache.begin ();
set<timepos_t>::iterator next = std::upper_bound (region_boundary_cache.begin (), region_boundary_cache.end (), presnap);
if (next != region_boundary_cache.begin ()) {
prev = next;
prev--;
}
if (next == region_boundary_cache.end ()) {
next--;
}
if ((direction == Temporal::RoundUpMaybe || direction == Temporal::RoundUpAlways)) {
test = *next;
} else if ((direction == Temporal::RoundDownMaybe || direction == Temporal::RoundDownAlways)) {
test = *prev;
} else if (direction == 0) {
if ((*prev).distance (presnap) < presnap.distance (*next)) {
test = *prev;
} else {
test = *next;
}
}
}
check_best_snap (presnap, test, dist, best);
}
check_distance:
if (timepos_t::max (start.time_domain()) == best) {
return;
}
/* now check "magnetic" state: is the grid within reasonable on-screen distance to trigger a snap?
* this also helps to avoid snapping to somewhere the user can't see. (i.e.: I clicked on a region and it disappeared!!)
* ToDo: Perhaps this should only occur if EditPointMouse?
*/
samplecnt_t snap_threshold_s = pixel_to_sample (uic.get_snap_threshold ());
if (!ensure_snap && ::llabs (best.distance (presnap).samples()) > snap_threshold_s) {
return;
}
start = best;
}
void
Editor::setup_toolbar ()
@ -6657,30 +6411,6 @@ Editor::use_own_window (bool and_fill_it)
return win;
}
double
Editor::time_to_pixel (timepos_t const & pos) const
{
return sample_to_pixel (pos.samples());
}
double
Editor::time_to_pixel_unrounded (timepos_t const & pos) const
{
return sample_to_pixel_unrounded (pos.samples());
}
double
Editor::duration_to_pixels (timecnt_t const & dur) const
{
return sample_to_pixel (dur.samples());
}
double
Editor::duration_to_pixels_unrounded (timecnt_t const & dur) const
{
return sample_to_pixel_unrounded (dur.samples());
}
void
Editor::start_track_drag (TimeAxisView& tav, int y, Gtk::Widget& w, bool can_change_cursor)
{