X-Git-Url: https://svn.cri.ensmp.fr/git/Faustine.git/blobdiff_plain/c55d1f23d06e85b0e21cdf5cbc5c8efb6ac3bc1a..e3449439410ee92986e5ef95fc933813dfa6c67b:/interpreter/faustio.ml diff --git a/interpreter/faustio.ml b/interpreter/faustio.ml index 47e07ce..9539bf3 100644 --- a/interpreter/faustio.ml +++ b/interpreter/faustio.ml @@ -79,7 +79,7 @@ class waveio : io_type = Array.init n (fun i -> _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".wav") else if n = 1 then - let () = Unix.unlink "_filename" in [|(_filename ^ ".wav")|] + let () = Unix.unlink _filename in [|_filename|] else raise (Faustine_IO_Error ("The process has several output signals, however stdout supports only one output signal. Please remove the '> " ^ _filename ^ "'.")) in @@ -141,7 +141,7 @@ class csvio : io_type = Array.init n (fun i -> _dir ^ _basename ^ (string_of_int (i + 1)) ^ ".csv") else if n = 1 then - let () = Unix.unlink _filename in [|(_filename ^ ".csv")|] + let () = Unix.unlink _filename in [|_filename|] else raise (Faustine_IO_Error ("The process has several output signals, however stdout supports only one output signal. Please remove the '> " ^ _filename ^ "'.")) in @@ -171,15 +171,9 @@ class iomanager = val mutable _format = "" val mutable _basename = "" - method private grab_format : string -> string = - fun (path : string) -> - let fragments = Str.split (Str.regexp "\.") path in - let n = List.length fragments in - List.nth fragments (n - 1) - method read : string list -> beam_type = fun (paths : string list) -> - let formats = List.map self#grab_format paths in + let formats = List.map format_of_file paths in let read_one : string -> string -> beam_type = fun (format : string) -> fun (path : string) -> @@ -206,12 +200,19 @@ class iomanager = method write : rate array -> data -> string array = fun (rates : rate array) -> fun (data : data) -> - if _format = "" then - raise (Invalid_argument "output format unset.") - else if _format = "wav" then - wave#write rates data - else if _format = "csv" then - csv#write rates data - else raise (Invalid_argument "unknown format.") - + if _output_filename = "" then ( + if _format = "" then + raise (Invalid_argument "output format unset.") + else if _format = "wav" then + wave#write rates data + else if _format = "csv" then + csv#write rates data + else raise (Invalid_argument "unknown format.")) + else ( + let format = format_of_file _output_filename in + if format = "wav" then + wave#write rates data + else if format = "csv" then + csv#write rates data + else raise (Invalid_argument ("unknown format" ^ format))) end;;