commit 8637855b1eafbf575fa346ace872b0c25a66adf0
parent 462fc3f4b59587721e6bedd147daf66d9c5f00b4
Author: prenev <an2qzavok@gmail.com>
Date: Sat, 10 Apr 2021 19:40:32 +0300
usynth: implement note stack
Diffstat:
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/usynth.c b/usynth.c
@@ -3,6 +3,7 @@
#include <unistd.h>
#include <stdint.h>
#include <sndio.h>
+#include <string.h>
#include <assert.h>
#include "midi.h"
#include "wavetable.h"
@@ -12,6 +13,7 @@ struct sio_hdl *sh;
size_t bs;
int16_t *sbuf;
int16_t* vm;
+int keystack[32], kp;
void note_on(uint8_t*);
void note_off(uint8_t*);
@@ -40,7 +42,7 @@ s_init(char *sdev)
int
main(void)
{
- s_init("snd/0");
+ s_init("default");
wt_init();
m_init("midithru/0");
m_vector.note_on = note_on;
@@ -61,6 +63,10 @@ main(void)
void
note_on(uint8_t *m)
{
+ int i;
+ keystack[kp] = m[2];
+ kp++;
+ if (kp > 32) kp = 32;
vm[VM_ACTIVE] = 1;
vm[VM_KEY] = m[2];
vm[VM_KEY_ON] = 1;
@@ -69,11 +75,18 @@ note_on(uint8_t *m)
void
note_off(uint8_t *m)
{
- //if (vm[VM_KEY] == m[2]) {
- // temporary
+ int i;
+ for (i = 0; i < 32; i++) {
+ if (keystack[i] == m[2]) {
+ memcpy(keystack+i, keystack+i+1, 32 - i);
+ kp--;
+ }
+ }
+ if (kp <= 0) {
vm[VM_KEY_ON] = 0;
+ // temporary:
vm[VM_ACTIVE] = 0;
- //}
+ } else vm[VM_KEY] = keystack[kp-1];
}
void