-
Notifications
You must be signed in to change notification settings - Fork 24
/
zynmaster.c
96 lines (81 loc) · 3.01 KB
/
zynmaster.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* ******************************************************************
* ZYNTHIAN PROJECT: Master Output Library
*
* Jack client for managing Master Audio & MIDI output
*
* Copyright (C) 2015-2019 Fernando Moyano <[email protected]>
*
* ******************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE.txt file.
*
* ******************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <jack/jack.h>
#include <jack/midiport.h>
#ifdef ZYNAPTIK_CONFIG
#include "zynaptik.h"
#endif
//-----------------------------------------------------------------------------
jack_client_t *zynmaster_jack_client;
jack_port_t *zynmaster_jack_port_midi_in;
int zynmaster_jack_process(jack_nframes_t nframes, void *arg);
//-----------------------------------------------------------------------------
int init_zynmaster_jack() {
if ((zynmaster_jack_client=jack_client_open("ZynMaster", JackNullOption, 0, 0))==NULL) {
fprintf(stderr, "ZynMaster: Error connecting with jack server.\n");
return 0;
}
zynmaster_jack_port_midi_in=jack_port_register(zynmaster_jack_client, "midi_in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
if (zynmaster_jack_port_midi_in==NULL) {
fprintf(stderr, "ZynMaster: Error creating jack midi input port.\n");
return 0;
}
//Init Jack Process
jack_set_process_callback(zynmaster_jack_client, zynmaster_jack_process, 0);
if (jack_activate(zynmaster_jack_client)) {
fprintf(stderr, "ZynMaster: Error activating jack client.\n");
return 0;
}
return 1;
}
int end_zynmaster_jack() {
if (jack_client_close(zynmaster_jack_client)) {
fprintf(stderr, "ZynMaster: Error closing jack client.\n");
return 0;
}
return 1;
}
int zynmaster_jack_process(jack_nframes_t nframes, void *arg) {
// Read jackd data buffer
void *input_port_buffer = jack_port_get_buffer(zynmaster_jack_port_midi_in, nframes);
if (input_port_buffer==NULL) {
fprintf(stderr, "ZynMaster: Error getting jack input port buffer: %d frames\n", nframes);
return -1;
}
// Process MIDI input messages => Convert to CV/Gate out
int i=0;
jack_midi_event_t ev;
while (jack_midi_event_get(&ev, input_port_buffer, i++)==0) {
//fprintf(stderr, "ZynMaster: Converting MIDI event to CV/Gate => 0x%x, 0x%x, 0x%x\n", ev.buffer[0], ev.buffer[1], ev.buffer[2]);
#ifdef ZYNAPTIK_CONFIG
zynaptik_midi_to_cvout(&ev);
zynaptik_midi_to_gateout(&ev);
#endif
}
return 0;
}
//-----------------------------------------------------------------------------