From: WANG Date: Wed, 7 Aug 2013 16:37:08 +0000 (+0200) Subject: Refactoring of process classes in faustexp.ml. X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/commitdiff_plain/73e86244c539dd6ff8af5d8527b11fde18c8d070?ds=inline Refactoring of process classes in faustexp.ml. --- diff --git a/interpretor/faustexp.ml b/interpretor/faustexp.ml index ea50c66..d0b5ec0 100644 --- a/interpretor/faustexp.ml +++ b/interpretor/faustexp.ml @@ -55,6 +55,7 @@ class dimension : int * int -> dimension_type = else raise (Dimension_error "rec dimension not matched.") end;; +(* class process : faust_exp -> process_type = fun (exp_init : faust_exp) -> object (self) @@ -89,7 +90,7 @@ class process : faust_exp -> process_type = method to_string = "NotYetDone" method virtual evaluate : beam_type -> beam_type end;; - +*) class proc_const : faust_exp -> process_type = fun (exp_init : faust_exp) -> @@ -105,11 +106,11 @@ class proc_const : faust_exp -> process_type = method exp = _exp method dim = _dim method delay = _delay - method const = _const + method private const = _const method eval : beam_type -> beam_type = fun (input : beam_type) -> - if input = [||] then + if input#get = [||] then new beam [| new signal 0 (fun t -> new value self#const)|] else raise (Process_error "proc_const accepts no input.") @@ -125,7 +126,7 @@ class proc_ident : faust_exp -> process_type = | Ident s -> s | _ -> raise (Process_error "ident process constructor.") - val _dim = new dimension (dimension_of_symbol _symbol) + val _dim = new dimension (dimension_of_symbol self#symb) val _delay = delay_of_symbol _symbol method exp = _exp @@ -186,39 +187,173 @@ class proc_ident : faust_exp -> process_type = end;; -class exp_par = - object - inherit expression +class proc_par : faust_exp -> process_type = + fun (exp_init : faust_exp) -> + object (self) + val _exp = exp_init + val _exp_left = + match exp_init with + | Par (e1, e2) -> e1 + | _ -> raise (Process_error "par process constructor.") + val _exp_right = + match exp_init with + | Par (e1, e2) -> e2 + | _ -> raise (Process_error "par process constructor.") - end;; + val proc_left = (new proc_factory)#make _exp_left + val proc_right = (new proc_factory)#make _exp_right + val _dim = (proc_left#dim)#par proc_right#dim + val _delay = max proc_left#delay proc_right#delay -class exp_split = - object - inherit expression + method exp = _exp + method dim = _dim + method delay = _delay - end;; + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + let (sub_input1, sub_input2) = input#cut proc_left#dim#input in + let sub_output1 = proc_left#eval sub_input1 in + let sub_output2 = proc_right#eval sub_input2 in + sub_output1#append sub_output2 + end +and proc_split : faust_exp -> process_type = + fun (exp_init : faust_exp) -> + object (self) + val _exp = exp_init + val _exp_left = + match exp_init with + | Split (e1, e2) -> e1 + | _ -> raise (Process_error "par process constructor.") + val _exp_right = + match exp_init with + | Split (e1, e2) -> e2 + | _ -> raise (Process_error "par process constructor.") -class exp_merge = - object - inherit expression + val proc_left = (new proc_factory)#make _exp_left + val proc_right = (new proc_factory)#make _exp_right - end;; + val _dim = (proc_left#dim)#split proc_right#dim + val _delay = proc_left#delay + proc_right#delay -class exp_seq = - object - inherit expression + method exp = _exp + method dim = _dim + method delay = _delay - end;; + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + let mid_output = proc_left#eval input in + let mid_input = mid_output#matching proc_right#dim#input in + proc_right#eval mid_input + end -class exp_rec = - object - inherit expression - end;; +and proc_merge : faust_exp -> process_type = + fun (exp_init : faust_exp) -> + object (self) + val _exp = exp_init + val _exp_left = + match exp_init with + | Merge (e1, e2) -> e1 + | _ -> raise (Process_error "merge process constructor.") + val _exp_right = + match exp_init with + | Merge (e1, e2) -> e2 + | _ -> raise (Process_error "merge process constructor.") + + val proc_left = (new proc_factory)#make _exp_left + val proc_right = (new proc_factory)#make _exp_right + + val _dim = (proc_left#dim)#merge proc_right#dim + val _delay = proc_left#delay + proc_right#delay + + method exp = _exp + method dim = _dim + method delay = _delay + + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + let mid_output = proc_left#eval input in + let mid_input = mid_output#matching proc_right#dim#input in + proc_right#eval mid_input + + end + +and proc_seq : faust_exp -> process_type = + fun (exp_init : faust_exp) -> + object (self) + val _exp = exp_init + val _exp_left = + match exp_init with + | Seq (e1, e2) -> e1 + | _ -> raise (Process_error "seq process constructor.") + val _exp_right = + match exp_init with + | Seq (e1, e2) -> e2 + | _ -> raise (Process_error "seq process constructor.") + + val proc_left = (new proc_factory)#make _exp_left + val proc_right = (new proc_factory)#make _exp_right + + val _dim = (proc_left#dim)#seq proc_right#dim + val _delay = proc_left#delay + proc_right#delay + + method exp = _exp + method dim = _dim + method delay = _delay + + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + let mid_output = proc_left#eval input in + proc_right#eval mid_output + end + +and proc_rec : faust_exp -> process_type = + fun (exp_init : faust_exp) -> + object (self) + val _exp = exp_init + val _exp_left = + match exp_init with + | Rec (e1, e2) -> e1 + | _ -> raise (Process_error "rec process constructor.") + val _exp_right = + match exp_init with + | Rec (e1, e2) -> e2 + | _ -> raise (Process_error "rec process constructor.") + + val proc_left = (new proc_factory)#make _exp_left + val proc_right = (new proc_factory)#make _exp_right + + val _dim = (proc_left#dim)#_rec proc_right#dim + val _delay = proc_left#delay + + method exp = _exp + method dim = _dim + method delay = _delay + + method eval : beam_type -> beam_type = + fun (input : beam_type) -> + let mid_output = proc_left#eval input in + proc_right#eval mid_output + + + end + +and proc_factory = + object + method make : faust_exp -> process_type = + fun (exp : faust_exp) -> + match exp with + | Const b -> new proc_const exp + | Ident s -> new proc_ident exp + | Par (e1, e2) -> new proc_par exp + | Seq (e1, e2) -> new proc_seq exp + | Split (e1, e2) -> new proc_split exp + | Merge (e1, e2) -> new proc_merge exp + | Rec (e1, e2) -> new proc_rec exp + end;; -*)