pedal working checkpoint

This commit is contained in:
2026-01-14 20:49:43 -06:00
parent cf377cf3b0
commit 5661e4662c
2 changed files with 24 additions and 8 deletions

View File

@@ -7,7 +7,7 @@
MidiController::MidiController(NoteQueue& queue) : noteQueue_(queue) {
try {
midiIn_ = std::make_unique<RtMidiIn>();
midiIn_->ignoreTypes(true, true, true);
midiIn_->ignoreTypes(false, false, false);
} catch (RtMidiError& e) {
std::cerr << "RtMidi init failed: " << e.getMessage() << std::endl;
}
@@ -55,16 +55,18 @@ void MidiController::midiCallback(double /*deltaTime*/, std::vector<unsigned cha
}
void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
unsigned char status = msg[0] & 0xF0;
unsigned char data1 = msg[1];
unsigned char data2 = msg[2];
if(msg.size() <= 1) return;
uint8_t status = msg[0] & 0xF0;
uint8_t data1 = msg[1];
uint8_t data2 = msg[2];
if(status == 0xFE) return;
if(status == 0xF8) return;
if(status == 0xB0 && data1 == 64) {
handleSustain(data2 >= 64);
std::cout << "sustain event: " << data2 << std::endl;
return;
}
@@ -83,6 +85,8 @@ void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
}
void MidiController::noteOn(uint8_t note, uint8_t vel) {
sustainedNotes_.erase(note);
noteQueue_.push({
NoteEventType::NoteOn,
static_cast<uint8_t>(note),
@@ -92,6 +96,10 @@ void MidiController::noteOn(uint8_t note, uint8_t vel) {
}
void MidiController::noteOff(uint8_t note) {
if(sustainDown_) {
sustainedNotes_.insert(note);
return;
}
noteQueue_.push({
NoteEventType::NoteOff,
static_cast<uint8_t>(note),

View File

@@ -36,6 +36,15 @@ void Synth::handleNoteEvent(const NoteEvent& event) {
if(event.type == NoteEventType::NoteOn) {
// TODO: this should get fixed if we tie voices to midi notes
// end all voices already playing this note
for(Voice& v : voices_) {
if(v.isActive() && v.note() == event.note) {
v.noteOff();
break;
}
}
// TODO: find quietest voice and assign a note to it instead of just the first inactive one
// find inactive voice and start it with the given note
for(Voice& v : voices_) {
@@ -45,7 +54,6 @@ void Synth::handleNoteEvent(const NoteEvent& event) {
}
}
} else {
// find voice associated with note event and end it