1 /*
2  * Copyright (c) 2015-2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
3  *
4  * This is free software: you can redistribute it and/or modify
5  * it under the terms of the Artistic License 2.0 as published by
6  * The Perl Foundation.
7  *
8  * This source is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * Artistic License 2.0 for more details.
12  *
13  * You should have received a copy of the Artistic License 2.0
14  * along the source as a COPYING file. If not, obtain it from
15  * http://www.perlfoundation.org/artistic_license_2_0.
16  */
17 
18 #ifndef _SYNTHPOD_APP_H
19 #define _SYNTHPOD_APP_H
20 
21 #include <lv2/lv2plug.in/ns/lv2core/lv2.h>
22 #include <lv2/lv2plug.in/ns/ext/atom/atom.h>
23 #include <lv2/lv2plug.in/ns/ext/atom/forge.h>
24 #include <lv2/lv2plug.in/ns/ext/urid/urid.h>
25 #include <lv2/lv2plug.in/ns/ext/log/log.h>
26 #include <lv2/lv2plug.in/ns/ext/worker/worker.h>
27 #include <lv2/lv2plug.in/ns/ext/state/state.h>
28 #include <lv2/lv2plug.in/ns/ext/options/options.h>
29 #include <lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
30 
31 #include <lilv/lilv.h>
32 
33 #include <synthpod_common.h>
34 #include <osc.lv2/osc.h>
35 
36 typedef enum _sp_app_features_t sp_app_features_t;
37 typedef enum _system_port_t system_port_t;
38 
39 typedef struct _sp_app_t sp_app_t;
40 typedef struct _sp_app_system_source_t sp_app_system_source_t;
41 typedef struct _sp_app_system_sink_t sp_app_system_sink_t;
42 typedef struct _sp_app_driver_t sp_app_driver_t;
43 
44 typedef void *(*sp_to_request_t)(size_t minimum, size_t *maximum, void *data);
45 typedef void (*sp_to_advance_t)(size_t written, void *data);
46 
47 typedef void *(*sp_system_port_add)(void *data, system_port_t type,
48 	const char *short_name, const char *pretty_name, const char *designation,
49 	bool input, uint32_t order);
50 typedef void (*sp_system_port_del)(void *data, void *sys_port);
51 
52 typedef void (*sp_close_request_t)(void *data);
53 
54 enum _sp_app_features_t {
55 	SP_APP_FEATURE_FIXED_BLOCK_LENGTH				= (1 << 0),
56 	SP_APP_FEATURE_POWER_OF_2_BLOCK_LENGTH	= (1 << 1)
57 };
58 
59 enum _system_port_t {
60 	SYSTEM_PORT_NONE = 0,
61 	SYSTEM_PORT_CONTROL,
62 	SYSTEM_PORT_AUDIO,
63 	SYSTEM_PORT_CV,
64 	SYSTEM_PORT_MIDI,
65 	SYSTEM_PORT_OSC,
66 	SYSTEM_PORT_COM
67 };
68 
69 struct _sp_app_system_source_t {
70 	system_port_t type;
71 	void *sys_port;
72 	void *buf;
73 };
74 
75 struct _sp_app_system_sink_t {
76 	system_port_t type;
77 	void *sys_port;
78 	const void *buf;
79 };
80 
81 struct _sp_app_driver_t {
82 	float sample_rate;
83 	float update_rate;
84 	uint32_t min_block_size;
85 	uint32_t max_block_size;
86 	uint32_t seq_size;
87 	uint32_t num_periods;
88 
89 	LV2_URID_Map *map;
90 	LV2_URID_Unmap *unmap;
91 	xpress_map_t *xmap;
92 
93 	// from app
94 	sp_to_request_t to_ui_request;
95 	sp_to_advance_t to_ui_advance;
96 
97 	sp_to_request_t to_worker_request;
98 	sp_to_advance_t to_worker_advance;
99 
100 	// from worker
101 	sp_to_request_t to_app_request;
102 	sp_to_advance_t to_app_advance;
103 
104 	// logging
105 	LV2_Log_Log *log;
106 
107 	// system_port
108 	sp_system_port_add system_port_add;
109 	sp_system_port_del system_port_del;
110 
111 	// clock_sync
112 	LV2_OSC_Schedule *osc_sched;
113 
114 	sp_app_features_t features;
115 
116 	unsigned num_slaves;
117 
118 	int audio_prio;
119 	bool bad_plugins;
120 	bool cpu_affinity;
121 
122 	sp_close_request_t close_request;
123 };
124 
125 sp_app_t *
126 sp_app_new(const LilvWorld *world, sp_app_driver_t *driver, void *data);
127 
128 void
129 sp_app_activate(sp_app_t *app);
130 
131 const sp_app_system_source_t *
132 sp_app_get_system_sources(sp_app_t *app);
133 
134 const sp_app_system_sink_t *
135 sp_app_get_system_sinks(sp_app_t *app);
136 
137 bool
138 sp_app_from_ui(sp_app_t *app, const LV2_Atom *atom);
139 
140 bool
141 sp_app_from_worker(sp_app_t *app, uint32_t len, const void *data);
142 
143 void
144 sp_worker_from_app(sp_app_t *app, uint32_t len, const void *data);
145 
146 void
147 sp_app_run_pre(sp_app_t *app, uint32_t nsamples);
148 
149 void
150 sp_app_run_post(sp_app_t *app, uint32_t nsamples);
151 
152 void
153 sp_app_deactivate(sp_app_t *app);
154 
155 void
156 sp_app_free(sp_app_t *app);
157 
158 LV2_State_Status
159 sp_app_save(sp_app_t *app, LV2_State_Store_Function store,
160 	LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features);
161 
162 LV2_Atom_Object *
163 sp_app_stash(sp_app_t *app, LV2_State_Retrieve_Function retrieve,
164 	LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features);
165 
166 void
167 sp_app_apply(sp_app_t *app, LV2_Atom_Object *obj, char *bundle_path);
168 
169 const LV2_Feature *const *
170 sp_app_state_features(sp_app_t *app, void *prefix_path);
171 
172 LV2_State_Status
173 sp_app_restore(sp_app_t *app, LV2_State_Retrieve_Function retrieve,
174 	LV2_State_Handle state, uint32_t flags, const LV2_Feature *const *features);
175 
176 const void *
177 sp_app_state_retrieve(LV2_State_Handle state, uint32_t key, size_t *size,
178 	uint32_t *type, uint32_t *flags);
179 
180 void
181 sp_app_set_bundle_path(sp_app_t *app, const char *bundle_path);
182 
183 bool
184 sp_app_bypassed(sp_app_t *app);
185 
186 uint32_t
187 sp_app_options_set(sp_app_t *app, const LV2_Options_Option *options);
188 
189 int
190 sp_app_nominal_block_length(sp_app_t *app, uint32_t nsamples);
191 
192 int
193 sp_app_com_event(sp_app_t *app, LV2_URID otype);
194 
195 void
196 sp_app_bundle_load(sp_app_t *app, LV2_URID urn, bool via_app);
197 
198 void
199 sp_app_bundle_save(sp_app_t *app, LV2_URID urn, bool via_app);
200 
201 #endif // _SYNTHPOD_APP_H
202