1 /* ebu-r128 LV2 GUI
2  *
3  * Copyright (C) 2013 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef MTR_URIS_H
21 #define MTR_URIS_H
22 
23 #include <stdio.h>
24 #include "lv2/lv2plug.in/ns/ext/atom/atom.h"
25 #include "lv2/lv2plug.in/ns/ext/time/time.h"
26 #include "lv2/lv2plug.in/ns/ext/atom/forge.h"
27 #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
28 
29 #define MTR_URI "http://gareus.org/oss/lv2/meters#"
30 
31 #ifdef HAVE_LV2_1_8
32 #define x_forge_object lv2_atom_forge_object
33 #else
34 #define x_forge_object lv2_atom_forge_blank
35 #endif
36 
37 #define HIST_LEN (751)
38 
39 #define DIST_BIN   (361)   // 2 * (DIST_OFF + DIST_RANGE) + 1
40 #define DIST_SIZE  (360.f) // DIST_BIN in float [ 0 .. DIST_BIN [
41 #define DIST_RANGE (150.f)
42 #define DIST_ZERO  (180.f) // DIST_OFF + DIST_RANGE
43 
44 /* offsets in histS for bitmeter */
45 #define BIM_DHIT 0   // + exp + k [count totals]
46 #define BIM_NHIT 23  // + exp
47 
48 #define BIM_DONE 280 // + exp + k [abs-scale]
49 #define BIM_NONE 303 // + exp     [abs-scale (1 + 0) * 2^exp]
50 
51 #define BIM_DSET 560 // + k       [mantissa stats]
52 #define BIM_LAST 584
53 
54 #define MTR__ebulevels        MTR_URI "ebulevels"
55 #define MTR_ebu_loudnessM     MTR_URI "ebu_loudnessM"
56 #define MTR_ebu_maxloudnM     MTR_URI "ebu_maxloudnM"
57 #define MTR_ebu_loudnessS     MTR_URI "ebu_loudnessS"
58 #define MTR_ebu_maxloudnS     MTR_URI "ebu_maxloudnS"
59 #define MTR_ebu_integrated    MTR_URI "ebu_integrated"
60 #define MTR_ebu_range_min     MTR_URI "ebu_range_min"
61 #define MTR_ebu_range_max     MTR_URI "ebu_range_max"
62 #define MTR_ebu_integrating   MTR_URI "ebu_integrating"
63 #define MTR_ebu_integr_time   MTR_URI "ebu_integr_time"
64 
65 #define MTR_ebu_state         MTR_URI "ebu_state"
66 #define MTR_sdh_state         MTR_URI "sdh_state"
67 #define MTR_bim_state         MTR_URI "bim_state"
68 
69 #define MTR__rdr_histogram    MTR_URI "rdr_histogram"
70 #define MTR__rdr_histpoint    MTR_URI "rdr_histpoint"
71 #define MTR__rdr_radarpoint   MTR_URI "rdr_radarpoint"
72 #define MTR__rdr_pointpos     MTR_URI "rdr_pointpos"
73 #define MTR__rdr_pos_cur      MTR_URI "rdr_pos_cur"
74 #define MTR__rdr_pos_max      MTR_URI "rdr_pos_max"
75 
76 #define MTR__sdh_histogram    MTR_URI "sdh_histogram"
77 #define MTR__sdh_hist_max     MTR_URI "sdh_hist_max"
78 #define MTR__sdh_hist_var     MTR_URI "sdh_hist_var"
79 #define MTR__sdh_hist_avg     MTR_URI "sdh_hist_avg"
80 #define MTR__sdh_hist_peak    MTR_URI "sdh_hist_peak"
81 #define MTR__sdh_hist_data    MTR_URI "sdh_hist_data"
82 #define MTR__sdh_information  MTR_URI "sdh_information"
83 
84 #define MTR__bim_information  MTR_URI "bim_information"
85 #define MTR__bim_averaging    MTR_URI "bim_averaging"
86 #define MTR__bim_stats        MTR_URI "bim_stats"
87 #define MTR__bim_data         MTR_URI "bim_data"
88 #define MTR__bim_zero         MTR_URI "bim_zero"
89 #define MTR__bim_pos          MTR_URI "bim_pos"
90 #define MTR__bim_min          MTR_URI "bim_min"
91 #define MTR__bim_max          MTR_URI "bim_max"
92 #define MTR__bim_nan          MTR_URI "bim_nan"
93 #define MTR__bim_inf          MTR_URI "bim_inf"
94 #define MTR__bim_den          MTR_URI "bim_den"
95 
96 #define MTR__truepeak         MTR_URI "truepeak"
97 #define MTR__dr14reset        MTR_URI "dr14reset"
98 
99 #define MTR__cckey    MTR_URI "controlkey"
100 #define MTR__ccval    MTR_URI "controlval"
101 #define MTR__control  MTR_URI "control"
102 
103 #define MTR__meteron  MTR_URI "meteron"
104 #define MTR__meteroff MTR_URI "meteroff"
105 #define MTR__metercfg MTR_URI "metercfg"
106 
107 typedef struct {
108 	LV2_URID atom_Blank;
109 	LV2_URID atom_Object;
110 	LV2_URID atom_Int;
111 	LV2_URID atom_Long;
112 	LV2_URID atom_Float;
113 	LV2_URID atom_Double;
114 	LV2_URID atom_Bool;
115 	LV2_URID atom_Vector;
116 	LV2_URID atom_eventTransfer;
117 
118 	LV2_URID time_Position;
119 	LV2_URID time_speed;
120 	LV2_URID time_frame;
121 
122 	LV2_URID mtr_control; // from backend to UI
123 	LV2_URID mtr_cckey;
124 	LV2_URID mtr_ccval;
125 
126 	LV2_URID mtr_meters_on;
127 	LV2_URID mtr_meters_off;
128 	LV2_URID mtr_meters_cfg; // from UI -> backend
129 
130 	LV2_URID mtr_ebulevels;
131 	LV2_URID ebu_loudnessM;
132 	LV2_URID ebu_maxloudnM;
133 	LV2_URID ebu_loudnessS;
134 	LV2_URID ebu_maxloudnS;
135 	LV2_URID ebu_integrated;
136 	LV2_URID ebu_range_min;
137 	LV2_URID ebu_range_max;
138 	LV2_URID ebu_integrating;
139 	LV2_URID ebu_integr_time;
140 
141 	LV2_URID ebu_state;
142 	LV2_URID sdh_state;
143 	LV2_URID bim_state;
144 
145 	LV2_URID rdr_histogram;
146 	LV2_URID rdr_histpoint;
147 	LV2_URID rdr_radarpoint;
148 	LV2_URID rdr_pointpos;
149 	LV2_URID rdr_pos_cur;
150 	LV2_URID rdr_pos_max;
151 
152 	LV2_URID sdh_histogram;
153 	LV2_URID sdh_hist_max;
154 	LV2_URID sdh_hist_var;
155 	LV2_URID sdh_hist_avg;
156 	LV2_URID sdh_hist_peak;
157 	LV2_URID sdh_hist_data;
158 	LV2_URID sdh_information;
159 
160 	LV2_URID bim_information;
161 	LV2_URID bim_averaging;
162 	LV2_URID bim_stats;
163 	LV2_URID bim_data;
164 	LV2_URID bim_zero;
165 	LV2_URID bim_pos;
166 	LV2_URID bim_min;
167 	LV2_URID bim_max;
168 	LV2_URID bim_nan;
169 	LV2_URID bim_inf;
170 	LV2_URID bim_den;
171 
172 	LV2_URID mtr_truepeak;
173 	LV2_URID mtr_dr14reset;
174 
175 } EBULV2URIs;
176 
177 
178 // numeric keys
179 enum {
180 	KEY_INVALID = 0,
181 	CTL_START,
182 	CTL_PAUSE,
183 	CTL_RESET,
184 	CTL_TRANSPORTSYNC,
185 	CTL_AUTORESET,
186 	CTL_RADARTIME,
187 	CTL_UISETTINGS,
188 	CTL_LV2_RADARTIME,
189 	CTL_LV2_FTM,
190 	CTL_LV2_RESETRADAR,
191 	CTL_LV2_RESYNCDONE,
192 	CTL_SAMPLERATE,
193 	CTL_WINDOWED,
194 	CTL_AVERAGE,
195 };
196 
197 
198 static inline void
map_eburlv2_uris(LV2_URID_Map * map,EBULV2URIs * uris)199 map_eburlv2_uris(LV2_URID_Map* map, EBULV2URIs* uris)
200 {
201 	uris->atom_Blank         = map->map(map->handle, LV2_ATOM__Blank);
202 	uris->atom_Object        = map->map(map->handle, LV2_ATOM__Object);
203 	uris->atom_Int           = map->map(map->handle, LV2_ATOM__Int);
204 	uris->atom_Long          = map->map(map->handle, LV2_ATOM__Long);
205 	uris->atom_Float         = map->map(map->handle, LV2_ATOM__Float);
206 	uris->atom_Double        = map->map(map->handle, LV2_ATOM__Double);
207 	uris->atom_Bool          = map->map(map->handle, LV2_ATOM__Bool);
208 	uris->atom_Vector        = map->map(map->handle, LV2_ATOM__Vector);
209 
210 	uris->atom_eventTransfer = map->map(map->handle, LV2_ATOM__eventTransfer);
211 
212 	uris->time_Position       = map->map(map->handle, LV2_TIME__Position);
213 	uris->time_speed          = map->map(map->handle, LV2_TIME__speed);
214 	uris->time_frame          = map->map(map->handle, LV2_TIME__frame);
215 
216 	uris->mtr_ebulevels       = map->map(map->handle, MTR__ebulevels);
217 	uris->ebu_loudnessM       = map->map(map->handle, MTR_ebu_loudnessM);
218 	uris->ebu_maxloudnM       = map->map(map->handle, MTR_ebu_maxloudnM);
219 	uris->ebu_loudnessS       = map->map(map->handle, MTR_ebu_loudnessS);
220 	uris->ebu_maxloudnS       = map->map(map->handle, MTR_ebu_maxloudnS);
221 	uris->ebu_integrated      = map->map(map->handle, MTR_ebu_integrated);
222 	uris->ebu_range_min       = map->map(map->handle, MTR_ebu_range_min);
223 	uris->ebu_range_max       = map->map(map->handle, MTR_ebu_range_max);
224 	uris->ebu_integrating     = map->map(map->handle, MTR_ebu_integrating);
225 	uris->ebu_integr_time     = map->map(map->handle, MTR_ebu_integr_time);
226 
227 	uris->ebu_state           = map->map(map->handle, MTR_ebu_state);
228 	uris->sdh_state           = map->map(map->handle, MTR_sdh_state);
229 	uris->bim_state           = map->map(map->handle, MTR_bim_state);
230 
231 	uris->rdr_histogram       = map->map(map->handle, MTR__rdr_histogram);
232 	uris->rdr_histpoint       = map->map(map->handle, MTR__rdr_histpoint);
233 	uris->rdr_radarpoint      = map->map(map->handle, MTR__rdr_radarpoint);
234 	uris->rdr_pointpos        = map->map(map->handle, MTR__rdr_pointpos);
235 	uris->rdr_pos_cur         = map->map(map->handle, MTR__rdr_pos_cur);
236 	uris->rdr_pos_max         = map->map(map->handle, MTR__rdr_pos_max);
237 
238 	uris->sdh_histogram       = map->map(map->handle, MTR__sdh_histogram);
239 	uris->sdh_hist_max        = map->map(map->handle, MTR__sdh_hist_max);
240 	uris->sdh_hist_var        = map->map(map->handle, MTR__sdh_hist_var);
241 	uris->sdh_hist_avg        = map->map(map->handle, MTR__sdh_hist_avg);
242 	uris->sdh_hist_peak       = map->map(map->handle, MTR__sdh_hist_peak);
243 	uris->sdh_hist_data       = map->map(map->handle, MTR__sdh_hist_data);
244 	uris->sdh_information     = map->map(map->handle, MTR__sdh_information);
245 
246 	uris->bim_information     = map->map(map->handle, MTR__bim_information);
247 	uris->bim_averaging       = map->map(map->handle, MTR__bim_averaging);
248 	uris->bim_stats           = map->map(map->handle, MTR__bim_stats);
249 	uris->bim_data            = map->map(map->handle, MTR__bim_data);
250 	uris->bim_zero            = map->map(map->handle, MTR__bim_zero);
251 	uris->bim_pos             = map->map(map->handle, MTR__bim_pos);
252 	uris->bim_min             = map->map(map->handle, MTR__bim_min);
253 	uris->bim_max             = map->map(map->handle, MTR__bim_max);
254 	uris->bim_nan             = map->map(map->handle, MTR__bim_nan);
255 	uris->bim_inf             = map->map(map->handle, MTR__bim_inf);
256 	uris->bim_den             = map->map(map->handle, MTR__bim_den);
257 
258 	uris->mtr_truepeak        = map->map(map->handle, MTR__truepeak);
259 	uris->mtr_dr14reset       = map->map(map->handle, MTR__dr14reset);
260 
261 	uris->mtr_cckey          = map->map(map->handle, MTR__cckey);
262 	uris->mtr_ccval          = map->map(map->handle, MTR__ccval);
263 	uris->mtr_control        = map->map(map->handle, MTR__control);
264 
265 	uris->mtr_meters_on       = map->map(map->handle, MTR__meteron);
266 	uris->mtr_meters_off      = map->map(map->handle, MTR__meteroff);
267 	uris->mtr_meters_cfg      = map->map(map->handle, MTR__metercfg);
268 }
269 
270 
271 static inline LV2_Atom *
forge_kvcontrolmessage(LV2_Atom_Forge * forge,const EBULV2URIs * uris,LV2_URID uri,const int key,const float value)272 forge_kvcontrolmessage(LV2_Atom_Forge* forge,
273 		const EBULV2URIs* uris,
274 		LV2_URID uri,
275 		const int key, const float value)
276 {
277 	LV2_Atom_Forge_Frame frame;
278 	lv2_atom_forge_frame_time(forge, 0);
279 	LV2_Atom* msg = (LV2_Atom*)x_forge_object(forge, &frame, 1, uri);
280 
281 	lv2_atom_forge_property_head(forge, uris->mtr_cckey, 0);
282 	lv2_atom_forge_int(forge, key);
283 	lv2_atom_forge_property_head(forge, uris->mtr_ccval, 0);
284 	lv2_atom_forge_float(forge, value);
285 	lv2_atom_forge_pop(forge, &frame);
286 	return msg;
287 }
288 
289 static inline int
get_cc_key_value(const EBULV2URIs * uris,const LV2_Atom_Object * obj,int * k,float * v)290 get_cc_key_value(
291 		const EBULV2URIs* uris, const LV2_Atom_Object* obj,
292 		int *k, float *v)
293 {
294 	const LV2_Atom* key = NULL;
295 	const LV2_Atom* value = NULL;
296 	if (!k || !v) return -1;
297 	*k = 0; *v = 0.0;
298 
299 	if (obj->body.otype != uris->mtr_control && obj->body.otype != uris->mtr_meters_cfg) {
300 		return -1;
301 	}
302 	lv2_atom_object_get(obj, uris->mtr_cckey, &key, uris->mtr_ccval, &value, 0);
303 	if (!key || !value) {
304 		fprintf(stderr, "MTRlv2: Malformed ctrl message has no key or value.\n");
305 		return -1;
306 	}
307 	*k = ((LV2_Atom_Int*)key)->body;
308 	*v = ((LV2_Atom_Float*)value)->body;
309 	return 0;
310 }
311 
312 #endif
313