MCPcopy Create free account
hub / github.com/audacity/audacity / Shift

Method Shift

libraries/lib-note-track/NoteTrack.cpp:529–554  ·  view source on GitHub ↗

Call this function to manipulate the underlying sequence data. This is NOT the function that handles horizontal dragging.

Source from the content-addressed store, hash-verified

527// Call this function to manipulate the underlying sequence data. This is
528// NOT the function that handles horizontal dragging.
529bool NoteTrack::Shift(double t) // t is always seconds
530{
531 if (t > 0) {
532 auto &seq = GetSeq();
533 // insert an even number of measures
534 seq.convert_to_beats();
535 // get initial tempo
536 double tempo = seq.get_tempo(0.0);
537 double beats_per_measure = seq.get_bar_len(0.0);
538 int m = ROUND(t * tempo / beats_per_measure);
539 // need at least 1 measure, so if we rounded down to zero, fix it
540 if (m == 0) m = 1;
541 // compute NEW tempo so that m measures at NEW tempo take t seconds
542 tempo = beats_per_measure * m / t; // in beats per second
543 seq.insert_silence(0.0, beats_per_measure * m);
544 seq.set_tempo(tempo * 60.0 /* bpm */, 0.0, beats_per_measure * m);
545 seq.write("afterShift.gro");
546 } else if (t < 0) {
547 auto &seq = GetSeq();
548 seq.convert_to_seconds();
549 seq.clear(0, t, true);
550 } else { // offset is zero, no modifications
551 return false;
552 }
553 return true;
554}
555
556QuantizedTimeAndBeat NoteTrack::NearestBeatTime( double time ) const
557{

Callers 2

MakeExportableSeqMethod · 0.80
OnScoreAlignFunction · 0.80

Calls 8

convert_to_beatsMethod · 0.80
get_tempoMethod · 0.80
get_bar_lenMethod · 0.80
insert_silenceMethod · 0.80
set_tempoMethod · 0.80
convert_to_secondsMethod · 0.80
writeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected