uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 08b64ec33cd4f2e2027006d0754ab31bea01baba
parent 606c7707ff8936aab3d6a579f8cfbe23062e2a21
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri, 25 Jun 2021 21:28:42 -0700

Implemented Midi device

Diffstat:
Msrc/devices/mpu.c | 25++++++++++++++++---------
Msrc/devices/mpu.h | 9++++++---
Msrc/uxnemu.c | 10++++++----
3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/devices/mpu.c b/src/devices/mpu.c @@ -13,30 +13,28 @@ WITH REGARD TO THIS SOFTWARE. */ int -initmpu(Mpu *m, Uint8 device) +initmpu(Mpu *m, Uint8 dev_in, Uint8 dev_out) { #ifndef NO_PORTMIDI int i; Pm_Initialize(); for(i = 0; i < Pm_CountDevices(); ++i) - printf("Device #%d -> %s%s\n", - i, - Pm_GetDeviceInfo(i)->name, - i == device ? "[x]" : "[ ]"); - Pm_OpenInput(&m->midi, device, NULL, 128, 0, NULL); + printf("Device #%d -> %s%s\n", i, Pm_GetDeviceInfo(i)->name, i == dev_in ? "[x]" : "[ ]"); + Pm_OpenInput(&m->input, dev_in, NULL, 128, 0, NULL); + Pm_OpenOutput(&m->output, dev_out, NULL, 128, 0, NULL, 1); m->queue = 0; m->error = pmNoError; #endif (void)m; - (void)device; + (void)dev_in; return 1; } void -listenmpu(Mpu *m) +getmidi(Mpu *m) { #ifndef NO_PORTMIDI - const int result = Pm_Read(m->midi, m->events, 32); + const int result = Pm_Read(m->input, m->events, 32); if(result < 0) { m->error = (PmError)result; m->queue = 0; @@ -46,3 +44,11 @@ listenmpu(Mpu *m) #endif (void)m; } + +void +putmidi(Mpu *m, Uint8 chan, Uint8 note, Uint8 velo) +{ +#ifndef NO_PORTMIDI + Pm_WriteShort(m->output, Pt_Time(), Pm_Message(0x90 + chan, note, velo)); +#endif +} +\ No newline at end of file diff --git a/src/devices/mpu.h b/src/devices/mpu.h @@ -15,6 +15,7 @@ WITH REGARD TO THIS SOFTWARE. #ifndef NO_PORTMIDI #include <portmidi.h> +#include <porttime.h> #else typedef struct { int message; @@ -27,10 +28,11 @@ typedef struct { Uint8 queue; PmEvent events[32]; #ifndef NO_PORTMIDI - PmStream *midi; + PmStream *input, *output; PmError error; #endif } Mpu; -int initmpu(Mpu *m, Uint8 device); -void listenmpu(Mpu *m); +int initmpu(Mpu *m, Uint8 dev_in, Uint8 dev_out); +void getmidi(Mpu *m); +void putmidi(Mpu *m, Uint8 chan, Uint8 note, Uint8 velo); +\ No newline at end of file diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -126,7 +126,7 @@ init(void) gRect.y = PAD; gRect.w = ppu.width; gRect.h = ppu.height; - if(!initmpu(&mpu, 1)) + if(!initmpu(&mpu, 1, 0)) return error("MPU", "Init failure"); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) return error("Init", SDL_GetError()); @@ -326,9 +326,11 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w) void midi_talk(Device *d, Uint8 b0, Uint8 w) { + if(w && b0 == 0x9) { + putmidi(&mpu, d->dat[0x8], d->dat[0x9], 127); + putmidi(&mpu, d->dat[0x8], d->dat[0x9], 0); + } (void)d; - (void)b0; - (void)w; } void @@ -382,7 +384,7 @@ start(Uxn *u) break; } } - listenmpu(&mpu); + getmidi(&mpu); for(i = 0; i < mpu.queue; ++i) { devmidi->dat[2] = mpu.events[i].message; devmidi->dat[3] = mpu.events[i].message >> 8;