pedal working checkpoint
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
MidiController::MidiController(NoteQueue& queue) : noteQueue_(queue) {
|
MidiController::MidiController(NoteQueue& queue) : noteQueue_(queue) {
|
||||||
try {
|
try {
|
||||||
midiIn_ = std::make_unique<RtMidiIn>();
|
midiIn_ = std::make_unique<RtMidiIn>();
|
||||||
midiIn_->ignoreTypes(true, true, true);
|
midiIn_->ignoreTypes(false, false, false);
|
||||||
} catch (RtMidiError& e) {
|
} catch (RtMidiError& e) {
|
||||||
std::cerr << "RtMidi init failed: " << e.getMessage() << std::endl;
|
std::cerr << "RtMidi init failed: " << e.getMessage() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -55,21 +55,23 @@ void MidiController::midiCallback(double /*deltaTime*/, std::vector<unsigned cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
|
void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
|
||||||
unsigned char status = msg[0] & 0xF0;
|
|
||||||
unsigned char data1 = msg[1];
|
if(msg.size() <= 1) return;
|
||||||
unsigned char data2 = msg[2];
|
|
||||||
|
uint8_t status = msg[0] & 0xF0;
|
||||||
|
uint8_t data1 = msg[1];
|
||||||
|
uint8_t data2 = msg[2];
|
||||||
|
|
||||||
if(status == 0xFE) return;
|
if(status == 0xFE) return;
|
||||||
if(status == 0xF8) return;
|
if(status == 0xF8) return;
|
||||||
|
|
||||||
if(status == 0xB0 && data1 == 64) {
|
if(status == 0xB0 && data1 == 64) {
|
||||||
handleSustain(data2 >= 64);
|
handleSustain(data2 >= 64);
|
||||||
std::cout << "sustain event: " << data2 << std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char note = msg.size() > 1 ? msg[1] : 0;
|
unsigned char note = msg.size() > 1 ? msg[1] : 0;
|
||||||
unsigned char vel = msg.size() > 2 ? msg[2] : 0;
|
unsigned char vel = msg.size() > 2 ? msg[2] : 0;
|
||||||
|
|
||||||
// Note On (velocity > 0)
|
// Note On (velocity > 0)
|
||||||
if (status == 0x90 && vel > 0) {
|
if (status == 0x90 && vel > 0) {
|
||||||
@@ -83,6 +85,8 @@ void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MidiController::noteOn(uint8_t note, uint8_t vel) {
|
void MidiController::noteOn(uint8_t note, uint8_t vel) {
|
||||||
|
sustainedNotes_.erase(note);
|
||||||
|
|
||||||
noteQueue_.push({
|
noteQueue_.push({
|
||||||
NoteEventType::NoteOn,
|
NoteEventType::NoteOn,
|
||||||
static_cast<uint8_t>(note),
|
static_cast<uint8_t>(note),
|
||||||
@@ -92,6 +96,10 @@ void MidiController::noteOn(uint8_t note, uint8_t vel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MidiController::noteOff(uint8_t note) {
|
void MidiController::noteOff(uint8_t note) {
|
||||||
|
if(sustainDown_) {
|
||||||
|
sustainedNotes_.insert(note);
|
||||||
|
return;
|
||||||
|
}
|
||||||
noteQueue_.push({
|
noteQueue_.push({
|
||||||
NoteEventType::NoteOff,
|
NoteEventType::NoteOff,
|
||||||
static_cast<uint8_t>(note),
|
static_cast<uint8_t>(note),
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ void Synth::handleNoteEvent(const NoteEvent& event) {
|
|||||||
|
|
||||||
if(event.type == NoteEventType::NoteOn) {
|
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
|
// 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
|
// find inactive voice and start it with the given note
|
||||||
for(Voice& v : voices_) {
|
for(Voice& v : voices_) {
|
||||||
@@ -45,7 +54,6 @@ void Synth::handleNoteEvent(const NoteEvent& event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// find voice associated with note event and end it
|
// find voice associated with note event and end it
|
||||||
|
|||||||
Reference in New Issue
Block a user