66 if (total == 0)
return;
68 const std::size_t event_count =
midi.size();
74 for (std::size_t i = 1; i < event_count; ++i) {
75 assert(
midi[i].sample_offset >=
midi[i - 1].sample_offset
76 &&
"for_each_midi_subblock requires a sorted MidiBuffer");
80 auto emit = [&](std::size_t block_start,
81 std::size_t block_end,
82 std::size_t event_first,
83 std::size_t event_last) {
84 if (block_end <= block_start)
return;
85 auto out_slice = output.
slice(block_start, block_end - block_start);
86 auto in_slice = input.
slice(block_start, block_end - block_start);
87 const auto boundary = event_last > event_first
88 ? std::span<const midi::MidiEvent>(&
midi[event_first],
89 event_last - event_first)
90 : std::span<const midi::MidiEvent>{};
94 std::size_t start = 0;
96 std::size_t boundary_first = 0;
99 while (idx < event_count
100 &&
midi[idx].sample_offset <= 0) {
103 std::size_t boundary_last = idx;
105 while (idx < event_count) {
106 const auto offset =
midi[idx].sample_offset;
107 if (
static_cast<std::size_t
>(offset) >= total) {
112 const auto split =
static_cast<std::size_t
>(offset);
114 emit(start, split, boundary_first, boundary_last);
116 boundary_first = idx;
120 while (idx < event_count
121 &&
midi[idx].sample_offset == offset) {
128 emit(start, total, boundary_first, boundary_last);