@@ -147,28 +147,34 @@ pub const State = struct {
147147 null ,
148148 );
149149 }
150- };
151150
152- pub fn processEvent (comptime Plugin : type , clap_plugin : * const c.clap_plugin_t , event : * const c.clap_event_header_t ) void {
153- const state = State .fromClap (clap_plugin );
154- switch (event .type ) {
155- c .CLAP_EVENT_PARAM_VALUE = > {
156- std .debug .assert (@hasDecl (Plugin , "Parameters" ));
157-
158- const value_event : * const c.clap_event_param_value = @ptrCast (@alignCast (event ));
159- const param = state .plugin .parameters .? .slice [value_event .param_id ];
160-
161- switch (param .* ) {
162- inline else = > | * p | {
163- const value = @TypeOf (p .* ).fromFloat (value_event .value );
164- p .set (value );
165- zigplug .log .debug ("parameter '{s}' = {any}" , .{ p .options .name , value });
166- },
151+ // TODO: handle param_mod
152+ pub fn handleParamEvent (self : * State , event : * const c.clap_event_param_value ) void {
153+ const param : * zigplug.Parameter = blk : {
154+ if (event .cookie ) | ptr |
155+ break :blk @ptrCast (@alignCast (ptr ))
156+ else {
157+ @branchHint (.unlikely );
158+ break :blk self .plugin .parameters .? .slice [event .param_id ];
167159 }
168- },
169- else = > {},
160+ };
161+
162+ switch (param .* ) {
163+ inline else = > | * p | {
164+ const value = @TypeOf (p .* ).fromFloat (event .value );
165+ p .set (value );
166+ zigplug .log .debug ("parameter '{s}' = {any}" , .{ p .options .name , value });
167+ },
168+ }
170169 }
171- }
170+
171+ pub fn handleEvent (self : * State , event : * const c.clap_event_header_t ) void {
172+ switch (event .type ) {
173+ c .CLAP_EVENT_PARAM_VALUE = > self .handleParamEvent (@ptrCast (@alignCast (event ))),
174+ else = > {},
175+ }
176+ }
177+ };
172178
173179fn ClapPlugin (comptime Plugin : type ) type {
174180 return extern struct {
@@ -226,15 +232,11 @@ fn ClapPlugin(comptime Plugin: type) type {
226232
227233 const event_count = clap_process .* .in_events .* .size .? (clap_process .* .in_events );
228234
229- var event_i : u32 = 0 ;
230-
231- while (event_i < event_count ) {
232- const event = clap_process .* .in_events .* .get .? (clap_process .* .in_events , event_i );
233- event_i += 1 ;
235+ for (0.. event_count ) | i | {
236+ const event = clap_process .* .in_events .* .get .? (clap_process .* .in_events , @intCast (i ));
234237 switch (event .* .type ) {
235238 c .CLAP_EVENT_PARAM_VALUE = > {
236239 const value_event : * const c.clap_event_param_value = @ptrCast (@alignCast (event ));
237- const param = state .plugin .parameters .? .slice [value_event .param_id ];
238240
239241 if (comptime Plugin .meta .sample_accurate_automation ) {
240242 end = value_event .header .time ;
@@ -248,15 +250,9 @@ fn ClapPlugin(comptime Plugin: type) type {
248250 end = samples ;
249251 }
250252
251- switch (param .* ) {
252- inline else = > | * p | {
253- const value = @TypeOf (p .* ).fromFloat (value_event .value );
254- p .set (value );
255- zigplug .log .debug ("parameter '{s}' = {any} at {}" , .{ p .options .name , value , value_event .header .time });
256- },
257- }
253+ state .handleParamEvent (value_event );
258254 },
259- else = > continue ,
255+ else = > state . handleEvent ( event ) ,
260256 }
261257 }
262258
0 commit comments