| 1 | (***************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Liquidsoap, a programmable audio stream generator. |
|---|
| 4 | Copyright 2003-2009 Savonet team |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details, fully stated in the COPYING |
|---|
| 15 | file at the root of the liquidsoap distribution. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with this program; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | *****************************************************************************) |
|---|
| 22 | |
|---|
| 23 | (** Values and types of the liquidsoap language. *) |
|---|
| 24 | |
|---|
| 25 | (** The type of a value. *) |
|---|
| 26 | type kind = Lang_types.t |
|---|
| 27 | |
|---|
| 28 | (** {2 Values} *) |
|---|
| 29 | |
|---|
| 30 | (** A typed value. *) |
|---|
| 31 | type value = { mutable t : kind ; value : in_value } |
|---|
| 32 | and env = (string * value) list |
|---|
| 33 | and in_value = |
|---|
| 34 | | Unit |
|---|
| 35 | | Bool of bool |
|---|
| 36 | | Int of int |
|---|
| 37 | | String of string |
|---|
| 38 | | Float of float |
|---|
| 39 | | Source of Source.source |
|---|
| 40 | | Request of Request.raw Request.t option |
|---|
| 41 | (* Request.raw is arbitrary: this information is violated |
|---|
| 42 | * in the script language until it has enough expressivity. *) |
|---|
| 43 | | List of value list |
|---|
| 44 | | Product of value * value |
|---|
| 45 | | Fun of (string * string * value option) list * |
|---|
| 46 | env * env * Lang_values.term |
|---|
| 47 | | FFI of (string * string * value option) list * |
|---|
| 48 | env * env * (env -> kind -> value) |
|---|
| 49 | |
|---|
| 50 | (** Get a string representation of a value. *) |
|---|
| 51 | val print_value : value -> string |
|---|
| 52 | |
|---|
| 53 | (** Iter a function over all sources contained in a value. *) |
|---|
| 54 | val iter_sources : (Source.source -> unit) -> value -> unit |
|---|
| 55 | |
|---|
| 56 | (** {2 Computation} *) |
|---|
| 57 | |
|---|
| 58 | (** Multiapply a value to arguments. *) |
|---|
| 59 | val apply : value -> (string * value) list -> value |
|---|
| 60 | |
|---|
| 61 | (** {3 Helpers for source builtins} *) |
|---|
| 62 | |
|---|
| 63 | type proto = |
|---|
| 64 | (string * kind * value option * string option) list |
|---|
| 65 | |
|---|
| 66 | (** Some flags that can be attached to operators. *) |
|---|
| 67 | type doc_flag = |
|---|
| 68 | | Hidden (** Don't list the plugin in the documentation. *) |
|---|
| 69 | | Deprecated (** The plugin should not be used. *) |
|---|
| 70 | | Experimental (** The plugin should not considered as stable. *) |
|---|
| 71 | |
|---|
| 72 | (** Add an builtin to the language. *) |
|---|
| 73 | val add_builtin : |
|---|
| 74 | category:string -> |
|---|
| 75 | descr:string -> |
|---|
| 76 | ?flags:doc_flag list -> |
|---|
| 77 | string -> |
|---|
| 78 | proto -> kind -> (env -> kind -> value) -> |
|---|
| 79 | unit |
|---|
| 80 | |
|---|
| 81 | (** Category of an operator. *) |
|---|
| 82 | type category = |
|---|
| 83 | | Input (** Input. *) |
|---|
| 84 | | Output (** Output. *) |
|---|
| 85 | | TrackProcessing (** Operations on tracks (e.g. mixing, etc.). *) |
|---|
| 86 | | SoundProcessing (** Operations on sound (e.g. compression, etc.). *) |
|---|
| 87 | | VideoProcessing (** Operations on video. *) |
|---|
| 88 | | Visualization (** Visializations of the sound. *) |
|---|
| 89 | |
|---|
| 90 | (** Get a string representation of a [doc_flag]. *) |
|---|
| 91 | val string_of_flag : doc_flag -> string |
|---|
| 92 | |
|---|
| 93 | (** Add an operator to the language and to the documentation. *) |
|---|
| 94 | val add_operator : |
|---|
| 95 | category:category -> |
|---|
| 96 | descr:string -> |
|---|
| 97 | ?flags:doc_flag list -> |
|---|
| 98 | string -> |
|---|
| 99 | proto -> (env -> kind -> Source.source) -> |
|---|
| 100 | unit |
|---|
| 101 | |
|---|
| 102 | (** {2 Manipulation of values} *) |
|---|
| 103 | |
|---|
| 104 | val to_bool : value -> bool |
|---|
| 105 | val to_string : value -> string |
|---|
| 106 | val to_string_getter : value -> unit -> string |
|---|
| 107 | val to_float : value -> float |
|---|
| 108 | val to_float_getter : value -> unit -> float |
|---|
| 109 | val to_source : value -> Source.source |
|---|
| 110 | (** Expands a value representing a request |
|---|
| 111 | * Value here *must* be an audio request. |
|---|
| 112 | * Assert false if not.. *) |
|---|
| 113 | val to_request : value -> Request.audio Request.t option |
|---|
| 114 | val to_request_raw : value -> Request.raw Request.t option |
|---|
| 115 | val to_int : value -> int |
|---|
| 116 | val to_list : value -> value list |
|---|
| 117 | val to_product : value -> value * value |
|---|
| 118 | val to_metadata : value -> Frame.metadata |
|---|
| 119 | val to_string_list : value -> string list |
|---|
| 120 | val to_int_list : value -> int list |
|---|
| 121 | val to_source_list : value -> Source.source list |
|---|
| 122 | |
|---|
| 123 | (** [assoc x n l] returns the [n]-th [y] such that [(x,y)] is in the list [l]. |
|---|
| 124 | * This is useful for retreiving arguments of a function. *) |
|---|
| 125 | val assoc : 'a -> int -> ('a * 'b) list -> 'b |
|---|
| 126 | |
|---|
| 127 | val int_t : kind |
|---|
| 128 | val unit_t : kind |
|---|
| 129 | val float_t : kind |
|---|
| 130 | val bool_t : kind |
|---|
| 131 | val string_t : kind |
|---|
| 132 | val source_t : kind |
|---|
| 133 | val request_t : kind |
|---|
| 134 | val list_t : kind -> kind |
|---|
| 135 | val product_t : kind -> kind -> kind |
|---|
| 136 | |
|---|
| 137 | (** [fun_t args r] is the type of a function taking [args] as parameters |
|---|
| 138 | * and returning values of type [r]. |
|---|
| 139 | * The elements of [r] are of the form [(b,l,t)] where [b] indicates if |
|---|
| 140 | * the argument is optional, [l] is the label of the argument ([""] means no |
|---|
| 141 | * label) and [t] is the type of the argument. *) |
|---|
| 142 | val fun_t : (bool * string * kind) list -> kind -> kind |
|---|
| 143 | val univ_t : ?constraints:Lang_types.constraints -> int -> kind |
|---|
| 144 | |
|---|
| 145 | (** A shortcut for lists of pairs of strings. *) |
|---|
| 146 | val metadata_t : kind |
|---|
| 147 | |
|---|
| 148 | (** A string getter. The argument is the number of the universal type parameter |
|---|
| 149 | * (should be >= 1). *) |
|---|
| 150 | val string_getter_t : int -> kind |
|---|
| 151 | (** A float getter. The argument is the number of the universal type parameter |
|---|
| 152 | * (should be >= 1). *) |
|---|
| 153 | val float_getter_t : int -> kind |
|---|
| 154 | |
|---|
| 155 | val unit : value |
|---|
| 156 | val int : int -> value |
|---|
| 157 | val bool : bool -> value |
|---|
| 158 | val float : float -> value |
|---|
| 159 | val string : string -> value |
|---|
| 160 | val list : value list -> value |
|---|
| 161 | val source : Source.source -> value |
|---|
| 162 | val request : Request.raw Request.t option -> value |
|---|
| 163 | val product : value -> value -> value |
|---|
| 164 | val val_fun : |
|---|
| 165 | (string * string * value option) list -> (env -> kind -> value) -> value |
|---|
| 166 | |
|---|
| 167 | (** Specialized builder for constant functions. |
|---|
| 168 | * It is slightly less opaque and allows the printing of the closure |
|---|
| 169 | * when the constant is ground. *) |
|---|
| 170 | val val_cst_fun : (string * string * value option) list -> value -> value |
|---|
| 171 | |
|---|
| 172 | (** Convert a metadata packet to a list associating strings to strings. *) |
|---|
| 173 | val metadata : Frame.metadata -> value |
|---|
| 174 | |
|---|
| 175 | (** {2 Errors raised by other modules} *) |
|---|
| 176 | |
|---|
| 177 | exception Invalid_value of value * string |
|---|
| 178 | |
|---|
| 179 | (** {2 Main script evaluation} *) |
|---|
| 180 | |
|---|
| 181 | (** Load the external libraries. *) |
|---|
| 182 | val load_libs : ?parse_only:bool -> unit -> unit |
|---|
| 183 | |
|---|
| 184 | (** Evaluate a script from an [in_channel]. *) |
|---|
| 185 | val from_in_channel : ?parse_only:bool -> in_channel -> unit |
|---|
| 186 | |
|---|
| 187 | (** Evaluate a script from a file. *) |
|---|
| 188 | val from_file : ?parse_only:bool -> string -> unit |
|---|
| 189 | |
|---|
| 190 | (** Evaluate a script from a string. *) |
|---|
| 191 | val from_string : ?parse_only:bool -> string -> unit |
|---|