From dfdc2bf20a41ce55343130ec7d2189c44186b65d Mon Sep 17 00:00:00 2001 From: Leonardo Date: Mon, 24 Oct 2016 23:27:04 +0300 Subject: [PATCH] Fixes problem with the puredata templates for objects with no mem variables --- src/generators/templates/pd.ml | 73 ++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/src/generators/templates/pd.ml b/src/generators/templates/pd.ml index 1c6be9a8..37fe1c45 100644 --- a/src/generators/templates/pd.ml +++ b/src/generators/templates/pd.ml @@ -146,6 +146,54 @@ let tildePerformFunctionVector (config:configuration) : int * Pla.t = (* we return the number of buffers used *) count + 1, decl + +let getInitDefaultCalls module_name params = + if params.config.pass_data then + [%pla{|<#module_name#s>_process_type|}], + [%pla{|<#module_name#s>_default(x->data);|}], + [%pla{|<#module_name#s>_process_init(x->data);|}] + else + Pla.string "float", Pla.unit, Pla.unit + +let noteFunctions (params:params) = + let output = params.output in + let module_name = params.module_name in + let on_args = + ["(int)note"; "(int)velocity"; "(int)channel"] + |> (fun a -> if params.config.pass_data then "x->data"::a else a) + |> Pla.map_sep Pla.comma Pla.string + in + let off_args = + ["(int)note"; "(int)channel"] + |> (fun a -> if params.config.pass_data then "x->data"::a else a) + |> Pla.map_sep Pla.comma Pla.string + in + [%pla{| +void <#output#s>_noteOn(t_<#output#s>_tilde *x, t_floatarg note, t_floatarg velocity, t_floatarg channel){ + if((int)velocity) <#module_name#s>_noteOn(<#on_args#>); + else <#module_name#s>_noteOff(<#off_args#>); +} +|}], + [%pla{| +void <#output#s>_noteOff(t_<#output#s>_tilde *x, t_floatarg note, t_floatarg channel) { + <#module_name#s>_noteOff(<#off_args#>); +} +|}] + +let controlChangeFunction (params:params) = + let output = params.output in + let module_name = params.module_name in + let ctrl_args = + ["(int)control"; "(int)value"; "(int)channel"] + |> (fun a -> if params.config.pass_data then "x->data"::a else a) + |> Pla.map_sep Pla.comma Pla.string + in + [%pla{| +void <#output#s>_controlChange(t_<#output#s>_tilde *x, t_floatarg control, t_floatarg value, t_floatarg channel) { + <#module_name#s>_controlChange(<#ctrl_args#>); +} +|}] + (** Implementation function *) let implementation (params:params) (code:Pla.t) : Pla.t = let output = params.output in @@ -158,6 +206,9 @@ let implementation (params:params) (code:Pla.t) : Pla.t = let dsp_nargs,vec_decl = tildeNewFunction params.config in let last_w, io_decl = tildePerformFunctionVector params.config in let process_call = tildePerformFunctionCall module_name params params.config in + let main_type, init_call, default_call = getInitDefaultCalls module_name params in + let note_on, note_off = noteFunctions params in + let ctr_change = controlChangeFunction params in {pla| /* Code automatically generated by Vult https://github.com/modlfo/vult */ #include "<#output#s>.h" @@ -171,7 +222,7 @@ static t_class *<#output#s>_tilde_class; typedef struct _<#output#s>_tilde { t_object x_obj; float dummy; - <#module_name#s>_process_type data; + <#main_type#> data; } t_<#output#s>_tilde; t_int *<#output#s>_tilde_perform(t_int *w) @@ -196,8 +247,8 @@ void *<#output#s>_tilde_new() { t_<#output#s>_tilde *x = (t_<#output#s>_tilde *)pd_new(<#output#s>_tilde_class); - <#module_name#s>_process_init(x->data); - <#module_name#s>_default(x->data); + <#init_call#> + <#default_call#> <#inlets#> <#outlets#> @@ -207,19 +258,9 @@ void *<#output#s>_tilde_new() void <#output#s>_tilde_delete(t_<#output#s>_tilde *x){ } - -void <#output#s>_noteOn(t_<#output#s>_tilde *x, t_floatarg note, t_floatarg velocity, t_floatarg channel){ - if((int)velocity) <#module_name#s>_noteOn(x->data, (int)note, (int)velocity, (int)channel); - else <#module_name#s>_noteOff(x->data, (int)note, (int)channel); -} - -void <#output#s>_noteOff(t_<#output#s>_tilde *x, t_floatarg note, t_floatarg channel) { - <#module_name#s>_noteOff(x->data, (int)note, (int)channel); -} - -void <#output#s>_controlChange(t_<#output#s>_tilde *x, t_floatarg control, t_floatarg value, t_floatarg channel) { - <#module_name#s>_controlChange(x->data, (int)control, (int)value, (int)channel); -} +<#note_on#> +<#note_off#> +<#ctr_change#> void <#output#s>_tilde_setup(void) { <#output#s>_tilde_class = class_new(gensym("<#output#s>~"),