Browse Source

Ignore MIDI messages > MSG_BUFFER_SIZE

tags/v1.9.13
Thomas Brand 6 years ago
parent
commit
a4b588bde0
1 changed files with 12 additions and 9 deletions
  1. +12
    -9
      example-clients/midi_dump.c

+ 12
- 9
example-clients/midi_dump.c View File

@@ -19,10 +19,6 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif


#ifndef MAX
#define MAX(a,b) ( (a) < (b) ? (b) : (a) )
#endif

static jack_port_t* port; static jack_port_t* port;
static jack_ringbuffer_t *rb = NULL; static jack_ringbuffer_t *rb = NULL;
static pthread_mutex_t msg_thread_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t msg_thread_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -31,10 +27,11 @@ static pthread_cond_t data_ready = PTHREAD_COND_INITIALIZER;
static int keeprunning = 1; static int keeprunning = 1;
static uint64_t monotonic_cnt = 0; static uint64_t monotonic_cnt = 0;


#define RBSIZE 100000
#define RBSIZE 100
#define MSG_BUFFER_SIZE 4096


typedef struct { typedef struct {
uint8_t buffer[4096];
uint8_t buffer[MSG_BUFFER_SIZE];
uint32_t size; uint32_t size;
uint32_t tme_rel; uint32_t tme_rel;
uint64_t tme_mon; uint64_t tme_mon;
@@ -85,14 +82,19 @@ process (jack_nframes_t frames, void* arg)


r = jack_midi_event_get (&event, buffer, i); r = jack_midi_event_get (&event, buffer, i);


if (r == 0 && jack_ringbuffer_write_space (rb) >= sizeof(midimsg)) {
if(event.size>MSG_BUFFER_SIZE) {
fprintf(stderr, "Error: MIDI message was too large, skipping event. Max. allowed size: %d bytes\n", MSG_BUFFER_SIZE);
}
else if (r == 0 && jack_ringbuffer_write_space (rb) >= sizeof(midimsg)) {
midimsg m; midimsg m;
m.tme_mon = monotonic_cnt; m.tme_mon = monotonic_cnt;
m.tme_rel = event.time; m.tme_rel = event.time;
m.size = event.size; m.size = event.size;
memcpy (m.buffer, event.buffer, MAX(sizeof(m.buffer), event.size));
memcpy (m.buffer, event.buffer, event.size);
jack_ringbuffer_write (rb, (void *) &m, sizeof(midimsg)); jack_ringbuffer_write (rb, (void *) &m, sizeof(midimsg));

}
else {
fprintf(stderr, "Error: ringbuffer was full, skipping event.\n");
} }
} }


@@ -107,6 +109,7 @@ process (jack_nframes_t frames, void* arg)
} }


static void wearedone(int sig) { static void wearedone(int sig) {
fprintf(stderr, "Shutting down\n");
keeprunning = 0; keeprunning = 0;
} }




Loading…
Cancel
Save