Browse Source

simplify playback to only one note at a time

main
cinnaboot 1 month ago
parent
commit
b43933b580
  1. 83
      src/main.cpp

83
src/main.cpp

@ -33,7 +33,7 @@
// range // range
#define USE_10V_MAX_CV true #define USE_10V_MAX_CV true
#define MAX_DAC_INPUT 4095 // 2^12 - 1 #define MAX_DAC_INPUT 4095 // 2^12 - 1
#define TEST_DELAY 5 // seconds to sleep in the test loop #define TEST_DELAY 1 // seconds to sleep in the test loop
void void
@ -70,12 +70,10 @@ convertNoteToDACInput(u8 midi_note)
void void
loopMIDI(alsa_sequencer* seq, spi_connection* spi, gpio_info* gpio) loopMIDI(alsa_sequencer* seq, spi_connection* spi, gpio_info* gpio)
{ {
// TODO: there's probably a more elegant way to handle this, but this was // NOTE: we're starting off with monophonic output for testing
// the first idea that came up, and seems to work
// NOTE: MIDI Note '0' is a vaild note, but 255 is not. So, we'll use 255 // NOTE: MIDI Note '0' is a vaild note, but 255 is not. So, we'll use 255
// as a placeholder to represent an unused PLAYING_NOTE // as a placeholder to represent an unused PLAYING_NOTE
static const u32 MAX_NOTES = 6; static u8 PLAYING_NOTE = 255;
static u8 PLAYING_NOTES[MAX_NOTES] = {255,255,255,255,255,255};
while(1) while(1)
{ {
@ -83,61 +81,54 @@ loopMIDI(alsa_sequencer* seq, spi_connection* spi, gpio_info* gpio)
snd_seq_event_t *ev = nullptr; snd_seq_event_t *ev = nullptr;
snd_seq_event_input(seq->seq_handle, &ev); snd_seq_event_input(seq->seq_handle, &ev);
// FIXME: we should only be processing notes from the first channel // TODO: add option to choose other channels?
// TODO: polyphonic on the same channel
// FIXME: probably a bug here since we don't have an early out for non-
// note events
alsa_note_event nev = midiProcess(ev); alsa_note_event nev = midiProcess(ev);
bool note_tracked = false; // NOTE: only process notes from the 0 (keyboard) or 1 (aplaymidi) channel
//if (nev.channel != 0 && nev.channel != 1) continue;
for (u32 i = 0; i < MAX_NOTES; i++) { if (nev.channel != 1) continue;
if (PLAYING_NOTES[i] == nev.note) {
note_tracked = true; // NOTE: the way we're going to handle overlapping note ons will be the
// easiest. the gate will be on for the previous note, and there won't
if (nev.note_on) { // do nothing // be a distinct gate on or trigger for the overlapping note.
break; // TODO: fix overlapping trigger for envelope
} else { // remove note from tracked list if (PLAYING_NOTE == nev.note && nev.note_on == false) {
assert(gpioSetValue(gpio, 0)); // send set gate off assert(gpioSetValue(gpio, 0)); // send set gate off
PLAYING_NOTES[i] = 255; PLAYING_NOTE = 255;
break; } else if (nev.note_on) { // new note
} PLAYING_NOTE = nev.note;
} assert(gpioSetValue(gpio, 1)); // send gate on
}
// send note voltage to DAC, and add note to tracked list
if (!note_tracked && nev.note_on ) {
for (u32 i = 0; i < MAX_NOTES; i++) {
if (PLAYING_NOTES[i] == 255) {
PLAYING_NOTES[i] = nev.note;
assert(gpioSetValue(gpio, 1)); // send set gate on
break;
}
}
i32 dac_in = convertNoteToDACInput(nev.note); i32 dac_in = convertNoteToDACInput(nev.note);
// TODO: could check return value here for SPI error // TODO: could check return value here for SPI error
spiSendVoltage(spi, dac_in); spiSendVoltage(spi, dac_in);
} }
printf("PLAYING_NOTES: %d,%d,%d,%d,%d,%d\n", printf("PLAYING_NOTE: %d\n", PLAYING_NOTE);
PLAYING_NOTES[0],
PLAYING_NOTES[1],
PLAYING_NOTES[2],
PLAYING_NOTES[3],
PLAYING_NOTES[4],
PLAYING_NOTES[5]);
} }
} }
void void
loopTestVoltages(spi_connection* spi) loopTestVoltages(spi_connection* spi, gpio_info* gpio)
{ {
u32 one_volt = 408; u32 one_volt = 408;
u32 scale = 0;
for (u32 i = 0;; i++) { for (u32 i = 0;; i++) {
#if 0 //u32 volts = (i % 2 == 0) ? 0 : one_volt;
u32 volts = (i % 2 == 0) ? 0 : one_volt; //spiSendVoltage(spi, volts);
spiSendVoltage(spi, volts);
#else spiSendVoltage(spi, scale * one_volt);
spiSendVoltage(spi, 10 * one_volt); scale++;
#endif if (scale > 10) scale = 0;
// NOTE: toggle gate on/off every other 'tick'
u32 gpio_value = (i % 2 == 0) ? 0 : 1;
assert(gpioSetValue(gpio, gpio_value));
//spiSendVoltage(spi, 10 * one_volt);
sleep(TEST_DELAY); sleep(TEST_DELAY);
} }
} }
@ -182,7 +173,7 @@ main(i32 argc, char* argv[])
loopMIDI(&seq, &spi, &gpio); loopMIDI(&seq, &spi, &gpio);
break; break;
case 't': case 't':
loopTestVoltages(&spi); loopTestVoltages(&spi, &gpio);
break; break;
case 'h': case 'h':
default: default:

Loading…
Cancel
Save