forked from cryptix/popcorn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
97 lines (79 loc) · 2.01 KB
/
main.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
97
/*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <jack/jack.h>
#include "configuration/json.h"
#include "processing/voices.h"
#include "jack.h"
#define PROGNAME "popcorn(0.0)"
jack_port_t *output_port;
jack_port_t *input_port;
unsigned int sampleRate;
typedef enum {KALL=1, HELP, QUIT, UNKWN} MOptions;
int getmopt(void);
void usage(void) {
printf("(1) Kill all voices\n");
printf("(2) This Help\n");
printf("(3) Quit\n");
}
int main(int argc, char *argv[]) {
int mopt;
jack_client_t *client;
if(argc < 2) {
fprintf(stderr, "Usage: %s <conf.pop> (<client-name>) (<output-port>)\n", argv[0]);
exit(-1);
}
/* route */
routing(argv[1]);
/* jack */
client = jack_client_new( (argc > 2) ? argv[2] : PROGNAME);
if(client == NULL) {
fprintf(stderr, "jack server not running or name taken?\n");
return -1;
}
jack_set_process_callback(client, jackProcess, 0);
jack_set_sample_rate_callback(client, jackSRateChanged, 0);
jack_on_shutdown(client, jackShutdown, 0);
output_port = jack_port_register(client, "audio_out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
input_port = jack_port_register(client, "midi_in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
if(jack_activate(client)) {
fprintf(stderr, "cannot activate client");
return 1;
}
if(argc == 4) {
if(jack_connect(client, jack_port_name(output_port), argv[3])) {
fprintf(stderr, "couldn't connect output ports\n");
return 1;
}
} else {
if(jack_connect(client, jack_port_name(output_port), "system:playback_1")) {
fprintf(stderr, "couldn't connect output ports\n");
return 1;
}
if(jack_connect(client, jack_port_name(output_port), "system:playback_2")) {
fprintf(stderr, "couldn't connect output ports\n");
return 1;
}
}
/* END jack */
usage();
while((mopt = getmopt()) != EOF) {
switch(mopt) {
case KALL:
killVoices();
break;
case HELP:
usage();
break;
case QUIT:
jack_client_close(client);
exit(0);
break;
}
}
jack_client_close(client);
return 0;
}