13
0

tempo twisting: GUI improvements, including undo/redo logic

This commit is contained in:
Paul Davis 2023-03-17 18:30:39 -06:00
parent 393929a55b
commit 0aea2a2ef8
3 changed files with 15 additions and 45 deletions

View File

@ -3712,7 +3712,8 @@ MappingStretchDrag::aborted (bool moved)
MappingTwistDrag::MappingTwistDrag (Editor* e, ArdourCanvas::Item* i, Temporal::TempoMap::WritableSharedPtr& wmap, MappingTwistDrag::MappingTwistDrag (Editor* e, ArdourCanvas::Item* i, Temporal::TempoMap::WritableSharedPtr& wmap,
TempoPoint& prv, TempoPoint& prv,
TempoPoint& fcus, TempoPoint& fcus,
TempoPoint& nxt) TempoPoint& nxt,
XMLNode& before)
: Drag (e, i, Temporal::BeatTime) : Drag (e, i, Temporal::BeatTime)
, prev (prv) , prev (prv)
, focus (fcus) , focus (fcus)
@ -3720,7 +3721,7 @@ MappingTwistDrag::MappingTwistDrag (Editor* e, ArdourCanvas::Item* i, Temporal::
, map (wmap) , map (wmap)
, direction (0.) , direction (0.)
, delta (0.) , delta (0.)
, _before_state (0) , _before_state (&before)
, _drag_valid (true) , _drag_valid (true)
{ {
DEBUG_TRACE (DEBUG::Drags, "New MappingTwistDrag\n"); DEBUG_TRACE (DEBUG::Drags, "New MappingTwistDrag\n");
@ -3736,9 +3737,6 @@ MappingTwistDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
void void
MappingTwistDrag::setup_pointer_offset () MappingTwistDrag::setup_pointer_offset ()
{ {
/* get current state */
_before_state = &map->get_state();
Beats grab_qn = max (Beats(), raw_grab_time().beats()); Beats grab_qn = max (Beats(), raw_grab_time().beats());
uint32_t divisions = _editor->get_grid_beat_divisions (_editor->grid_type()); uint32_t divisions = _editor->get_grid_beat_divisions (_editor->grid_type());
@ -3754,20 +3752,6 @@ MappingTwistDrag::setup_pointer_offset ()
void void
MappingTwistDrag::motion (GdkEvent* event, bool first_move) MappingTwistDrag::motion (GdkEvent* event, bool first_move)
{ {
if (first_move) {
_editor->begin_reversible_command (_("map tempo w/twist"));
}
samplepos_t mouse_pos;
if (_editor->grid_musical()) {
mouse_pos = adjusted_current_time (event, false).samples();
} else {
mouse_pos = adjusted_current_time (event).samples();
}
double pixels_moved = _drags->current_pointer_x() - last_pointer_x();
if (_drags->current_pointer_x() < last_pointer_x()) { if (_drags->current_pointer_x() < last_pointer_x()) {
if (direction < 0.) { if (direction < 0.) {
direction = 1.; direction = 1.;
@ -3795,7 +3779,7 @@ MappingTwistDrag::motion (GdkEvent* event, bool first_move)
map->twist_tempi (prev, focus, next, initial_npm + delta); map->twist_tempi (prev, focus, next, initial_npm + delta);
// _editor->mapping_cursor->set_position (Duple (_editor->sample_to_pixel_unrounded (mouse_pos), _editor->mapping_cursor->position().y)); _editor->mapping_cursor->set_position (Duple (_editor->sample_to_pixel_unrounded (superclock_to_samples (focus.sclock(), TEMPORAL_SAMPLE_RATE)), _editor->mapping_cursor->position().y));
_editor->mid_tempo_change (Editor::MappingChanged); _editor->mid_tempo_change (Editor::MappingChanged);
} }
@ -3807,26 +3791,21 @@ MappingTwistDrag::finished (GdkEvent* event, bool movement_occurred)
/* click, no drag */ /* click, no drag */
_editor->abort_tempo_mapping (); _editor->abort_tempo_mapping ();
_editor->abort_reversible_command ();
_editor->session()->request_locate (grab_sample(), false, _was_rolling ? MustRoll : RollIfAppropriate); _editor->session()->request_locate (grab_sample(), false, _was_rolling ? MustRoll : RollIfAppropriate);
return; return;
} }
if (!_drag_valid) { if (!_drag_valid) {
_editor->abort_tempo_mapping (); _editor->abort_tempo_mapping ();
_editor->abort_reversible_command ();
return; return;
} }
XMLNode &after = map->get_state(); XMLNode &after = map->get_state();
_editor->session()->add_command (new Temporal::TempoCommand (_("move BBT point"), _before_state, &after)); _editor->session()->add_command (new Temporal::TempoCommand (_("twist tempo"), _before_state, &after));
_editor->commit_reversible_command (); _editor->commit_reversible_command ();
/* 2nd argument means "update tempo map display after the new map is
* installed. We need to do this because the code above has not
* actually changed anything about how tempo is displayed, it simply
* modified the map.
*/
_editor->commit_tempo_mapping (map); _editor->commit_tempo_mapping (map);
} }
@ -3893,14 +3872,6 @@ TempoTwistDrag::motion (GdkEvent* event, bool first_move)
} }
} }
samplepos_t mouse_pos;
if (_editor->grid_musical()) {
mouse_pos = adjusted_current_time (event, false).samples();
} else {
mouse_pos = adjusted_current_time (event).samples();
}
/* adjust this and the next tempi to match pointer sample */ /* adjust this and the next tempi to match pointer sample */
// map->twist_tempi (_tempo, adjusted_time (grab_time(), 0, false).samples(), mouse_pos); // map->twist_tempi (_tempo, adjusted_time (grab_time(), 0, false).samples(), mouse_pos);

View File

@ -977,7 +977,8 @@ public:
MappingTwistDrag (Editor *, ArdourCanvas::Item *, Temporal::TempoMap::WritableSharedPtr&, MappingTwistDrag (Editor *, ArdourCanvas::Item *, Temporal::TempoMap::WritableSharedPtr&,
Temporal::TempoPoint& prev, Temporal::TempoPoint& prev,
Temporal::TempoPoint& focus, Temporal::TempoPoint& focus,
Temporal::TempoPoint& next); Temporal::TempoPoint& next,
XMLNode&);
void start_grab (GdkEvent *, Gdk::Cursor* c = 0); void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
void motion (GdkEvent *, bool); void motion (GdkEvent *, bool);

View File

@ -2993,6 +2993,11 @@ Editor::choose_mapping_drag (ArdourCanvas::Item* item, GdkEvent* event)
TempoPoint* before; TempoPoint* before;
TempoPoint* focus; TempoPoint* focus;
/* Reversible command starts here, must be ended/aborted in drag */
begin_reversible_command (_("map tempo/twist"));
XMLNode* before_state = &map->get_state();
if (tempo.bbt() < bbt) { if (tempo.bbt() < bbt) {
/* Add a new tempo marker at the nearest beat point /* Add a new tempo marker at the nearest beat point
@ -3005,7 +3010,6 @@ Editor::choose_mapping_drag (ArdourCanvas::Item* item, GdkEvent* event)
Tempo copied_no_ramp (map->tempo_at (bbt)); Tempo copied_no_ramp (map->tempo_at (bbt));
TempoPoint& added = const_cast<TempoPoint&> (map->set_tempo (copied_no_ramp, bbt)); TempoPoint& added = const_cast<TempoPoint&> (map->set_tempo (copied_no_ramp, bbt));
focus = &added; focus = &added;
std::cerr << "Focus will be " << *focus << std::endl;
reset_tempo_marks (); reset_tempo_marks ();
} else { } else {
@ -3019,12 +3023,6 @@ Editor::choose_mapping_drag (ArdourCanvas::Item* item, GdkEvent* event)
focus = &tempo; focus = &tempo;
} }
std::cerr << "Prev: " << *before << std::endl; _drags->set (new MappingTwistDrag (this, item, map, *before, *focus, *after, *before_state), event);
std::cerr << "Focus: " << *focus << std::endl;
std::cerr << "Next: " << *after << std::endl;
std::cerr << "focus says next at " << focus->superclock_at (after->beats()) << " vs. " << after->sclock() << std::endl;
_drags->set (new MappingTwistDrag (this, item, map, *before, *focus, *after), event);
std::cerr << ":Twist\n";
} }