13
0

Make exact beat calculation of tempi a bit less cumbersome. Move tempi on an audio basis for non-musical snap.

This commit is contained in:
nick_m 2016-06-12 02:46:13 +10:00
parent e973e39f06
commit 24f64b3ea7
5 changed files with 62 additions and 12 deletions

View File

@ -4046,6 +4046,47 @@ Editor::get_grid_beat_divisions(framepos_t position)
return 0;
}
/** returns the current musical grid divisiions using the supplied modifier mask from a GtkEvent.
if the grid is non-musical, returns 0.
if the grid is snapped to bars, returns -1.
@param event_state the current keyboard modifier mask.
*/
unsigned
Editor::get_grid_music_divisions (uint32_t event_state)
{
if (snap_mode() == Editing::SnapOff && !ArdourKeyboard::indicates_snap (event_state)) {
return 0;
}
if (snap_mode() != Editing::SnapOff && ArdourKeyboard::indicates_snap (event_state)) {
return 0;
}
switch (_snap_type) {
case SnapToBeatDiv128: return 128;
case SnapToBeatDiv64: return 64;
case SnapToBeatDiv32: return 32;
case SnapToBeatDiv28: return 28;
case SnapToBeatDiv24: return 24;
case SnapToBeatDiv20: return 20;
case SnapToBeatDiv16: return 16;
case SnapToBeatDiv14: return 14;
case SnapToBeatDiv12: return 12;
case SnapToBeatDiv10: return 10;
case SnapToBeatDiv8: return 8;
case SnapToBeatDiv7: return 7;
case SnapToBeatDiv6: return 6;
case SnapToBeatDiv5: return 5;
case SnapToBeatDiv4: return 4;
case SnapToBeatDiv3: return 3;
case SnapToBeatDiv2: return 2;
case SnapToBeat: return 1;
case SnapToBar : return -1;
default: return 0;
}
return 0;
}
Evoral::Beats
Editor::get_grid_type_as_beats (bool& success, framepos_t position)
{

View File

@ -330,6 +330,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
unsigned get_grid_beat_divisions(framepos_t position);
Evoral::Beats get_grid_type_as_beats (bool& success, framepos_t position);
unsigned get_grid_music_divisions (uint32_t event_state);
void nudge_forward (bool next, bool force_playhead);
void nudge_backward (bool next, bool force_playhead);

View File

@ -3338,16 +3338,10 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
const framepos_t pf = adjusted_current_frame (event);
TempoMap& map (_editor->session()->tempo_map());
/* snap to beat is -2, snap to bar is -3 (sorry) */
int sub_num = _editor->get_grid_beat_divisions (0);
/* snap to beat is 1, snap to bar is -1 (sorry) */
int sub_num = _editor->get_grid_music_divisions (event->button.state);
if (_editor->snap_type() == SnapToBar) {
sub_num = -3;
} else if (_editor->snap_type() == SnapToBeat) {
sub_num = -2;
}
map.gui_move_tempo (_real_section, pf, _editor->get_grid_beat_divisions (0));
map.gui_move_tempo (_real_section, pf, sub_num);
show_verbose_cursor_time (_real_section->frame());
}

View File

@ -297,6 +297,7 @@ class PublicEditor : public Gtkmm2ext::Tabbable {
virtual framecnt_t get_paste_offset (framepos_t pos, unsigned paste_count, framecnt_t duration) = 0;
virtual unsigned get_grid_beat_divisions(framepos_t position) = 0;
virtual Evoral::Beats get_grid_type_as_beats (bool& success, framepos_t position) = 0;
virtual unsigned get_grid_music_divisions (uint32_t event_state) = 0;
virtual void edit_notes (MidiRegionView*) = 0;
virtual void queue_visual_videotimeline_update () = 0;

View File

@ -2531,6 +2531,14 @@ void
TempoMap::gui_move_tempo (TempoSection* ts, const framepos_t& frame, const int& sub_num)
{
Metrics future_map;
bool was_musical = ts->position_lock_style() == MusicTime;
if (sub_num == 0 && was_musical) {
/* if we're not snapping to music,
AudioTime and MusicTime may be treated identically.
*/
ts->set_position_lock_style (AudioTime);
}
if (ts->position_lock_style() == MusicTime) {
{
@ -2539,16 +2547,16 @@ TempoMap::gui_move_tempo (TempoSection* ts, const framepos_t& frame, const int&
TempoSection* tempo_copy = copy_metrics_and_point (_metrics, future_map, ts);
double beat = beat_at_frame_locked (future_map, frame);
if (sub_num > 0) {
if (sub_num > 1) {
beat = floor (beat) + (floor (((beat - floor (beat)) * (double) sub_num) + 0.5) / sub_num);
} else if (sub_num == -2) {
} else if (sub_num == 1) {
/* snap to beat */
beat = floor (beat + 0.5);
}
double pulse = pulse_at_beat_locked (future_map, beat);
if (sub_num == -3) {
if (sub_num == -1) {
/* snap to bar */
pulse = floor (pulse + 0.5);
}
@ -2571,6 +2579,10 @@ TempoMap::gui_move_tempo (TempoSection* ts, const framepos_t& frame, const int&
}
}
if (sub_num == 0 && was_musical) {
ts->set_position_lock_style (MusicTime);
}
Metrics::const_iterator d = future_map.begin();
while (d != future_map.end()) {
delete (*d);