-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathglue.c
66 lines (48 loc) · 1.51 KB
/
glue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdlib.h>
#include <unistd.h>
#include <gambit.h>
#include <stdio.h>
#include <jack/ringbuffer.h>
#include "midijack.h"
#include "glue.h"
jack_ringbuffer_t *jrb = NULL;
int _setup_jack(void);
int _setup_jack(void) { return setup_jack(&jrb, DEFAULT_RB_SIZE); }
/**
* http://www.metasyntax.net/lang/scheme/gambit.html
*/
#define ___BEGIN_CFUN_SEND_MIDI(src,i) \
if ((___err = SEND_MIDI (src, i)) == ___FIX(___NO_ERR)) {
#define ___END_CFUN_SEND_MIDI(src,i) \
; }
#define ___BEGIN_SFUN_SEND_MIDI(src,dst) \
{ ___err = SEND_MIDI (src, ___RETURN_POS);
#define ___END_SFUN_SEND_MIDI(src) }
//int _send_midi(uint8_t *msg, size_t size) {
int SEND_MIDI(___SCMOBJ msg, size_t size) {
struct midi_msg midi;
___SCMOBJ lst = msg;
if (size == 0)
return 0;
memset(&midi, 0, sizeof(midi));
for (int i=0; i < size && ___PAIRP(lst) && i < MAX_MIDI_MSG; ++i) {
___SCMOBJ scm_int = ___CAR(lst);
uint8_t c_int;
___SCMOBJ ___err;
___err = ___EXT(___SCMOBJ_to_U8) (scm_int, &c_int, size);
if (___err != ___FIX(___NO_ERR)) {
return ___err;
}
midi.msg[i] = c_int;
lst = ___CDR(lst);
}
midi.size = size;
// fprintf(stderr, "m1: %x m2: %x m3: %x\n", midi.msg[0], midi.msg[1], midi.msg[2]);
if (jack_ringbuffer_write_space(jrb) < sizeof(midi)) {
// fprintf(stderr, "midi message will not fit in ringbuffer\n");
return -1;
}
if(jack_ringbuffer_write(jrb, (void*) &midi, sizeof(midi)) != sizeof(midi))
return -1;
return 0;
}