| 640 | } |
| 641 | |
| 642 | Alg_seq *NoteTrack::MakeExportableSeq(std::unique_ptr<Alg_seq> &cleanup) const |
| 643 | { |
| 644 | cleanup.reset(); |
| 645 | double offset = mOrigin; |
| 646 | if (offset == 0) |
| 647 | return &GetSeq(); |
| 648 | // make a copy, deleting events that are shifted before time 0 |
| 649 | double start = -offset; |
| 650 | if (start < 0) start = 0; |
| 651 | // notes that begin before "start" are not included even if they |
| 652 | // extend past "start" (because "all" parameter is set to false) |
| 653 | cleanup.reset( GetSeq().copy(start, GetSeq().get_dur() - start, false) ); |
| 654 | auto seq = cleanup.get(); |
| 655 | if (offset > 0) { |
| 656 | { |
| 657 | // swap cleanup and mSeq so that Shift operates on the NEW copy |
| 658 | swap( this->mSeq, cleanup ); |
| 659 | auto cleanup2 = finally( [&] { swap( this->mSeq, cleanup ); } ); |
| 660 | |
| 661 | const_cast< NoteTrack *>( this )->Shift(offset); |
| 662 | } |
| 663 | #ifdef OLD_CODE |
| 664 | // now shift events by offset. This must be done with an integer |
| 665 | // number of measures, so first, find the beats-per-measure |
| 666 | double beats_per_measure = 4.0; |
| 667 | Alg_time_sig_ptr tsp = NULL; |
| 668 | if (seq->time_sig.length() > 0 && seq->time_sig[0].beat < ALG_EPS) { |
| 669 | // there is an initial time signature |
| 670 | tsp = &(seq->time_sig[0]); |
| 671 | beats_per_measure = (tsp->num * 4) / tsp->den; |
| 672 | } |
| 673 | // also need the initial tempo |
| 674 | double bps = ALG_DEFAULT_BPM / 60; |
| 675 | Alg_time_map_ptr map = seq->get_time_map(); |
| 676 | Alg_beat_ptr bp = &(map->beats[0]); |
| 677 | if (bp->time < ALG_EPS) { // tempo change at time 0 |
| 678 | if (map->beats.len > 1) { // compute slope to get tempo |
| 679 | bps = (map->beats[1].beat - map->beats[0].beat) / |
| 680 | (map->beats[1].time - map->beats[0].time); |
| 681 | } else if (seq->get_time_map()->last_tempo_flag) { |
| 682 | bps = seq->get_time_map()->last_tempo; |
| 683 | } |
| 684 | } |
| 685 | // find closest number of measures to fit in the gap |
| 686 | // number of measures is offset / measure_time |
| 687 | double measure_time = beats_per_measure / bps; // seconds per measure |
| 688 | int n = ROUND(offset / measure_time); |
| 689 | if (n == 0) n = 1; |
| 690 | // we will insert n measures. Compute the desired duration of each. |
| 691 | measure_time = offset / n; |
| 692 | bps = beats_per_measure / measure_time; |
| 693 | // insert integer multiple of measures at beginning |
| 694 | seq->convert_to_beats(); |
| 695 | seq->insert_silence(0, beats_per_measure * n); |
| 696 | // make sure time signature at 0 is correct |
| 697 | if (tsp) { |
| 698 | seq->set_time_sig(0, tsp->num, tsp->den); |
| 699 | } |
nothing calls this directly
no test coverage detected