diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2023-04-20 18:52:53 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2023-04-20 18:52:53 +0300 |
commit | e919ad41b01595d2cd8fb0771bd3542817ec1058 (patch) | |
tree | b8e4a6965dc860d1b2268004cf08fc51058464f5 /src/midi.c | |
parent | c161e1016a04566a56b4858ea43502fed88dcc7f (diff) | |
download | synth-project-e919ad41b01595d2cd8fb0771bd3542817ec1058.tar.gz synth-project-e919ad41b01595d2cd8fb0771bd3542817ec1058.tar.bz2 synth-project-e919ad41b01595d2cd8fb0771bd3542817ec1058.zip |
Midi also plays notes now
Diffstat (limited to 'src/midi.c')
-rw-r--r-- | src/midi.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -1,8 +1,9 @@ #include "midi.h" +#include "notes.h" #include <string.h> -void midi_decode(uint32_t msg) { +void midi_decode(uint32_t msg, synth_t * synth) { // printf("MIDI message: 0x%X\n", msg); uint8_t status = msg; uint8_t data1 = (msg >> 8) & 0xFF; @@ -13,9 +14,21 @@ void midi_decode(uint32_t msg) { switch (message) { case 0x08: printf("Note Off: channel=%d, note=%d, velocity=%d\n", channel, data1, data2); + if (synth->n.key == data1) { + synth->n.noteOff = Pa_GetStreamTime(synth->stream); + } break; case 0x09: printf("Note On: channel=%d, note=%d, velocity=%d\n", channel, data1, data2); + synth->n.key = data1; + synth->n.freq = notes[data1 % 12][(data1 / 12) % 8]; + synth->n.noteOn = Pa_GetStreamTime(synth->stream); + synth->n.noteOff = 0; + synth->n.elapsed = 0; + synth->adsr.elapsed = 0; + synth->active = 1; + synth->gain = data2 / 127.0; + break; case 0x0A: printf("Aftertouch: channel=%d, note=%d, pressure=%d\n", channel, data1, data2); @@ -51,7 +64,7 @@ midiCallback(PtTimestamp timestamp, void *userData) { Pm_Read(m->stream, &buf, 1); //printf("%d\n", buf.message); - midi_decode(buf.message); + midi_decode(buf.message, m->synth); } @@ -59,7 +72,8 @@ void init_midi(midi_t *m, synth_t *synth) { m->stream = NULL; - + m->synth = synth; + Pm_Initialize(); printf("midi devs: %d\n", Pm_CountDevices()); |