Skip to content

Commit

Permalink
Fixes problem with the puredata templates for objects with no mem var…
Browse files Browse the repository at this point in the history
…iables
  • Loading branch information
modlfo committed Oct 24, 2016
1 parent 9376613 commit dfdc2bf
Showing 1 changed file with 57 additions and 16 deletions.
73 changes: 57 additions & 16 deletions src/generators/templates/pd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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#>

Expand All @@ -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>~"),
Expand Down

0 comments on commit dfdc2bf

Please sign in to comment.