diff options
Diffstat (limited to 'src/midi.c')
-rw-r--r-- | src/midi.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -92,7 +92,19 @@ void midi_decode(uint32_t msg, synth_t * synth) { printf("Channel Pressure: channel=%d, pressure=%d\n", channel, data1); break; case 0x0E: - printf("Pitch Bend: channel=%d, value=%d\n", channel, ((data2 << 7) | data1) - 8192); + int val = ((data2 << 7) | data1) - 8192; + printf("Pitch Bend: channel=%d, value=%d\n", channel, val); + float pitch; + float semitones = 2; + if (val == 0) { + pitch = 1; + } else if (val > 0) { + pitch = 1 + ((float)val / 8191) * semitones * pow(2.0, 1.0 / 12.0) / 12; + } else { + pitch = 1 + ((float)val / 8192) * semitones * pow(2.0, 1.0 / 12.0) / 12; + } + synth->cc_pitch.target = pitch; + /* cc_step(synth->cc_pitch, 1); */ break; default: printf("Unknown MIDI message\n"); |