-
Notifications
You must be signed in to change notification settings - Fork 0
/
aqua-host.c
117 lines (103 loc) · 2.96 KB
/
aqua-host.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#define HTTPSERVER_IMPL
#define AQUA_IMPL
#include "aqua.h"
bool standalone{true};
/*
The standalone app is used for debugging as well as the UI remote process for LV2 UI.
With --plugin argument, it runs as a plugin UI and prints 'C' for CC or 'N' for note on/off
using hexadecimal representation prefixed as in "#xx,#xx\n" format.
It must call fflush(stdout) every time so that the plugin UI module can process an entire line.
*/
void initialized_callback(void* context)
{
if (standalone)
printf("'Initizlied' callback\n");
else {
printf("I\n");
fflush(stdout);
}
}
void control_change_callback(void* context, int cc, int value)
{
if (standalone)
printf("Control change callback: CC#%x = %d\n", cc, value);
else {
printf("C#%x,#%x\n", cc, value);
fflush(stdout);
}
}
void note_callback(void* context, int key, int velocity)
{
if (standalone)
printf("Note callback: key %d velocity %d\n", key, velocity);
else {
printf("N#%x,#%x\n", key, velocity);
fflush(stdout);
}
}
void change_program_callback(void* context, const char* sfzFilename)
{
if (standalone)
printf("Change program callback: %s\n", sfzFilename);
else {
printf("P %s\n", sfzFilename);
fflush(stdout);
}
}
void* launch_aqua(void* context) {
aqua_start((aqua*) context);
return nullptr;
};
#ifdef WIN32
int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine,
int nCmdShow) {
#else
int main(int argc, char** argv) {
#endif
for (int i = 1; i < argc; i++)
if (strcmp(argv[i], "--plugin") == 0)
standalone = false;
char* rpath = realpath(argv[0], nullptr);
*strrchr(rpath, '/') = '\0';
std::string path{rpath};
free(rpath);
path = path + "/web";
printf("#aqua-host: started. Web directory is %s \n", path.c_str());
fflush(stdout);
auto aqua = aqua_create(path.c_str());
aqua_set_initialized_callback(aqua, initialized_callback, nullptr);
aqua_set_control_change_callback(aqua, control_change_callback, nullptr);
aqua_set_note_callback(aqua, note_callback, nullptr);
aqua_set_change_program_callback(aqua, change_program_callback, nullptr);
pthread_t aqua_thread;
pthread_create(&aqua_thread, nullptr, launch_aqua, aqua);
while (!aqua->webview_ready)
usleep(1000);
if (standalone)
puts("Type \"quit\" (all in lowercase) to stop");
char input[1024];
while (1) {
if (!fgets(input, 1023, stdin)) {
puts("#aqua-host: error - could not read input. aborting.");
break;
}
int len = strlen(input);
if (len > 0 && input[len - 1] == '\n')
input[--len] = '\0';
if (len > 0 && input[len - 1] == '\r')
input[--len] = '\0';
if (strcmp(input, "quit") == 0)
break;
else if (strcmp(input, "hide") == 0)
aqua_hide_window(aqua);
else if (strcmp(input, "show") == 0)
aqua_show_window(aqua);
else if (strncmp(input, "SFZ ", 4) == 0)
aqua_load_sfz(aqua, input + 4);
else
printf("#aqua-host: unknown user input (after removing CR/LF): %s\n", input);
}
puts("#aqua-host: stopped");
aqua_stop(aqua);
aqua_free(aqua);
}