-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpatchmatrix.c
More file actions
169 lines (146 loc) · 4.2 KB
/
patchmatrix.c
File metadata and controls
169 lines (146 loc) · 4.2 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (c) 2016-2018 Hanspeter Portner (dev@open-music-kontrollers.ch)
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Artistic License 2.0 as published by
* The Perl Foundation.
*
* This source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the iapplied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Artistic License 2.0 for more details.
*
* You should have received a copy of the Artistic License 2.0
* along the source as a COPYING file. If not, obtain it from
* http://www.perlfoundation.org/artistic_license_2_0.
*/
#include <sys/wait.h>
#include <patchmatrix.h>
#include <patchmatrix_jack.h>
#include <patchmatrix_nk.h>
#define NK_PUGL_API
#define NK_PUGL_IMPLEMENTATION
#include <nk_pugl/nk_pugl.h>
static app_t app;
static void
_sig_interrupt(int signum)
{
_ui_signal(&app);
atomic_store_explicit(&app.done, true, memory_order_release);
}
static void
_sig_child(int signum)
{
const pid_t any_child = -1;
while(waitpid(any_child, 0, WNOHANG) > 0)
{
// reap zombies
}
}
int
main(int argc, char **argv)
{
atomic_init(&app.done, false);
app.scale = 1.f;
app.nxt_source = 30; //FIXME make dependent on widget height
app.nxt_sink = 720/2;
app.nxt_default = 30;
app.server_name = NULL;
app.session_id = NULL;
fprintf(stderr,
"%s "PATCHMATRIX_VERSION"\n"
"Copyright (c) 2016-2018 Hanspeter Portner (dev@open-music-kontrollers.ch)\n"
"Released under Artistic License 2.0 by Open Music Kontrollers\n", argv[0]);
int c;
while((c = getopt(argc, argv, "vhn:u:d:")) != -1)
{
switch(c)
{
case 'v':
fprintf(stderr,
"--------------------------------------------------------------------\n"
"This is free software: you can redistribute it and/or modify\n"
"it under the terms of the Artistic License 2.0 as published by\n"
"The Perl Foundation.\n"
"\n"
"This source is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"Artistic License 2.0 for more details.\n"
"\n"
"You should have received a copy of the Artistic License 2.0\n"
"along the source as a COPYING file. If not, obtain it from\n"
"http://www.perlfoundation.org/artistic_license_2_0.\n\n");
return 0;
case 'h':
fprintf(stderr,
"--------------------------------------------------------------------\n"
"USAGE\n"
" %s [OPTIONS]\n"
"\n"
"OPTIONS\n"
" [-v] print version and full license information\n"
" [-h] print usage information\n"
" [-n] server-name connect to named JACK daemon\n"
" [-u] client-uuid client UUID for JACK session management\n"
" [-d] session-dir directory for JACK session management\n\n"
, argv[0]);
return 0;
case 'n':
app.server_name = optarg;
break;
case 'u':
app.session_id = optarg;
break;
case 'd':
app.root = _load_session(optarg);
break;
case '?':
if( (optopt == 'n') || (optopt == 'u') || (optopt == 'd') )
fprintf(stderr, "Option `-%c' requires an argument.\n", optopt);
else if(isprint(optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
return -1;
default:
return -1;
}
}
signal(SIGINT, _sig_interrupt);
signal(SIGCHLD, _sig_child);
if(!(app.from_jack = varchunk_new(0x10000, true)))
goto cleanup;
if(_ui_init(&app))
goto cleanup;
if(_jack_init(&app))
goto cleanup;
while(!atomic_load_explicit(&app.done, memory_order_acquire))
{
if(!app.animating)
{
nk_pugl_wait_for_event(&app.win);
}
else
{
usleep(1000000 / 25); //FIXME
nk_pugl_post_redisplay(&app.win);
}
if( _jack_anim(&app)
|| nk_pugl_process_events(&app.win) )
{
atomic_store_explicit(&app.done, true, memory_order_release);
}
}
cleanup:
_jack_deinit(&app);
if(app.from_jack)
{
_jack_anim(&app); // drain ringbuffer
varchunk_free(app.from_jack);
}
_ui_deinit(&app);
if(app.root)
cJSON_Delete(app.root);
return 0;
}