commit 8783bf12b2f610185865ede4a7a1b16d0f8428e7
parent adf32aa9f4a82989d7645474edaf5a4d2ff1e42d
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date: Fri, 25 Jun 2021 23:20:36 +0100
Brought back portmidi with conditional compilation
Diffstat:
4 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
@@ -6,7 +6,7 @@ An assembler and emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/si
### Linux
-To build the Uxn emulator, you must have [SDL2](https://wiki.libsdl.org/).
+To build the Uxn emulator, you must have [SDL2](https://wiki.libsdl.org/). If you wish to use the `Midi` device, you must also have [Portmidi](http://portmedia.sourceforge.net/portmidi/) installed. The build script indicates whether it has detected Portmidi or not, but will build Uxn either way.
```sh
./build.sh
diff --git a/build.sh b/build.sh
@@ -19,10 +19,17 @@ rm -f ./bin/uxnemu
rm -f ./bin/uxncli
rm -f ./bin/boot.rom
-echo "Building.."
mkdir -p bin
CFLAGS="-std=c89 -Wall -Wno-unknown-pragmas"
UXNEMU_LDFLAGS="-L/usr/local/lib $(sdl2-config --cflags --libs)"
+if cc ${CFLAGS} -c src/devices/mpu.c -o bin/mpu.o 2>/dev/null; then
+ rm -f bin/mpu.o
+ echo "Building with portmidi.."
+ UXNEMU_LDFLAGS="${UXNEMU_LDFLAGS} -lportmidi"
+else
+ echo "Building without portmidi.."
+ CFLAGS="${CFLAGS} -DNO_PORTMIDI"
+fi
if [ "${1}" = '--debug' ];
then
echo "[debug]"
diff --git a/src/devices/mpu.c b/src/devices/mpu.c
@@ -15,7 +15,7 @@ WITH REGARD TO THIS SOFTWARE.
int
initmpu(Mpu *m, Uint8 device)
{
- /*
+#ifndef NO_PORTMIDI
int i;
Pm_Initialize();
for(i = 0; i < Pm_CountDevices(); ++i)
@@ -26,7 +26,7 @@ initmpu(Mpu *m, Uint8 device)
Pm_OpenInput(&m->midi, device, NULL, 128, 0, NULL);
m->queue = 0;
m->error = pmNoError;
- */
+#endif
(void)m;
(void)device;
return 1;
@@ -35,7 +35,7 @@ initmpu(Mpu *m, Uint8 device)
void
listenmpu(Mpu *m)
{
- /*
+#ifndef NO_PORTMIDI
const int result = Pm_Read(m->midi, m->events, 32);
if(result < 0) {
m->error = (PmError)result;
@@ -43,6 +43,6 @@ listenmpu(Mpu *m)
return;
}
m->queue = result;
- */
+#endif
(void)m;
}
diff --git a/src/devices/mpu.h b/src/devices/mpu.h
@@ -1,6 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
-/* #include <portmidi.h> */
/*
Copyright (c) 2021 Devine Lu Linvega
@@ -14,19 +13,23 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
-typedef unsigned char Uint8;
-
+#ifndef NO_PORTMIDI
+#include <portmidi.h>
+#else
typedef struct {
int message;
} PmEvent;
+#endif
+
+typedef unsigned char Uint8;
typedef struct {
Uint8 queue;
PmEvent events[32];
- /*
+#ifndef NO_PORTMIDI
PmStream *midi;
PmError error;
- */
+#endif
} Mpu;
int initmpu(Mpu *m, Uint8 device);