Browse code

Brought back portmidi with conditional compilation

Andrew Alderwick authored on 25/06/2021 22:20:36
Showing 4 changed files
... ...
@@ -6,7 +6,7 @@ An assembler and emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/si
6 6
 
7 7
 ### Linux 
8 8
 
9
-To build the Uxn emulator, you must have [SDL2](https://wiki.libsdl.org/).
9
+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.
10 10
 
11 11
 ```sh
12 12
 ./build.sh 
... ...
@@ -19,10 +19,17 @@ rm -f ./bin/uxnemu
19 19
 rm -f ./bin/uxncli
20 20
 rm -f ./bin/boot.rom
21 21
 
22
-echo "Building.."
23 22
 mkdir -p bin
24 23
 CFLAGS="-std=c89 -Wall -Wno-unknown-pragmas"
25 24
 UXNEMU_LDFLAGS="-L/usr/local/lib $(sdl2-config --cflags --libs)"
25
+if cc ${CFLAGS} -c src/devices/mpu.c -o bin/mpu.o 2>/dev/null; then
26
+	rm -f bin/mpu.o
27
+	echo "Building with portmidi.."
28
+	UXNEMU_LDFLAGS="${UXNEMU_LDFLAGS} -lportmidi"
29
+else
30
+	echo "Building without portmidi.."
31
+	CFLAGS="${CFLAGS} -DNO_PORTMIDI"
32
+fi
26 33
 if [ "${1}" = '--debug' ]; 
27 34
 then
28 35
 	echo "[debug]"
... ...
@@ -15,7 +15,7 @@ WITH REGARD TO THIS SOFTWARE.
15 15
 int
16 16
 initmpu(Mpu *m, Uint8 device)
17 17
 {
18
-	/*
18
+#ifndef NO_PORTMIDI
19 19
 	int i;
20 20
 	Pm_Initialize();
21 21
 	for(i = 0; i < Pm_CountDevices(); ++i)
... ...
@@ -26,7 +26,7 @@ initmpu(Mpu *m, Uint8 device)
26 26
 	Pm_OpenInput(&m->midi, device, NULL, 128, 0, NULL);
27 27
 	m->queue = 0;
28 28
 	m->error = pmNoError;
29
-	*/
29
+#endif
30 30
 	(void)m;
31 31
 	(void)device;
32 32
 	return 1;
... ...
@@ -35,7 +35,7 @@ initmpu(Mpu *m, Uint8 device)
35 35
 void
36 36
 listenmpu(Mpu *m)
37 37
 {
38
-	/*
38
+#ifndef NO_PORTMIDI
39 39
 	const int result = Pm_Read(m->midi, m->events, 32);
40 40
 	if(result < 0) {
41 41
 		m->error = (PmError)result;
... ...
@@ -43,6 +43,6 @@ listenmpu(Mpu *m)
43 43
 		return;
44 44
 	}
45 45
 	m->queue = result;
46
-	*/
46
+#endif
47 47
 	(void)m;
48 48
 }
... ...
@@ -1,6 +1,5 @@
1 1
 #include <stdio.h>
2 2
 #include <stdlib.h>
3
-/* #include <portmidi.h> */
4 3
 
5 4
 /*
6 5
 Copyright (c) 2021 Devine Lu Linvega
... ...
@@ -14,19 +13,23 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 13
 WITH REGARD TO THIS SOFTWARE.
15 14
 */
16 15
 
17
-typedef unsigned char Uint8;
18
-
16
+#ifndef NO_PORTMIDI
17
+#include <portmidi.h>
18
+#else
19 19
 typedef struct {
20 20
 	int message;
21 21
 } PmEvent;
22
+#endif
23
+
24
+typedef unsigned char Uint8;
22 25
 
23 26
 typedef struct {
24 27
 	Uint8 queue;
25 28
 	PmEvent events[32];
26
-	/*
29
+#ifndef NO_PORTMIDI
27 30
 	PmStream *midi;
28 31
 	PmError error;
29
-	*/
32
+#endif
30 33
 } Mpu;
31 34
 
32 35
 int initmpu(Mpu *m, Uint8 device);