MCPcopy Create free account
hub / github.com/DamRsn/NeuralNote / buildMidiEventsVector

Method buildMidiEventsVector

NeuralNote/Source/SynthController.cpp:16–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16std::vector<MidiMessage> SynthController::buildMidiEventsVector(const std::vector<Notes::Event>& inNoteEvents)
17{
18 // TODO: Deal with pitch bends
19 bool INCLUDE_PITCH_BENDS = false;
20 // Compute size of single event vector
21 size_t num_midi_messages = 0;
22
23 for (const auto& note_event: inNoteEvents) {
24 num_midi_messages += 2;
25
26 if (INCLUDE_PITCH_BENDS) {
27 if (!note_event.bends.empty())
28 num_midi_messages += note_event.bends.size();
29 }
30 }
31
32 std::vector<MidiMessage> out(num_midi_messages);
33
34 size_t i = 0;
35
36 for (const auto& note_event: inNoteEvents) {
37 bool include_bends = INCLUDE_PITCH_BENDS && !note_event.bends.empty();
38 float first_bend = include_bends ? float(note_event.bends[0]) / 3.0f : 0.0f;
39
40 // TODO: Use different channels if there's a pitch bend
41 out[i++] =
42 MidiMessage::noteOn(1, note_event.pitch, (float) note_event.amplitude).withTimeStamp(note_event.startTime);
43
44 if (include_bends) {
45 for (size_t j = 0; j < note_event.bends.size(); j++) {
46 out[i++] =
47 MidiMessage::pitchWheel(
48 1, MidiMessage::pitchbendToPitchwheelPos(static_cast<float>(note_event.bends[j]) / 3.0f, 2))
49 .withTimeStamp(note_event.startTime + double(j) * 0.011);
50 }
51 }
52
53 out[i++] = MidiMessage::noteOff(1, note_event.pitch).withTimeStamp(note_event.endTime);
54
55 jassert(i <= num_midi_messages);
56 }
57
58 std::sort(out.begin(), out.end(), [](const MidiMessage& a, const MidiMessage& b) {
59 return a.getTimeStamp() < b.getTimeStamp();
60 });
61
62 return out;
63}
64
65void SynthController::setNewMidiEventsVectorToUse(std::vector<MidiMessage>& inEvents)
66{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected