root/ocaml-remix/trunk/instrument.ml

Revision 508, 1.1 kB (checked in by shans, 1 year ago)

Layers now accept plugins instead of sounds (getting closer to original remix
approach). To embed sounds, use Plugin.from_sound.

Line 
1
2 type length = float;;
3 type amplitude = Volume.volume;;
4
5 type soundFunction = amplitude -> Tone.tone -> Sound.sound;;
6 type instrument = {sound_function : soundFunction; mutable position : float};;
7
8 let from_sound_function ?(start=0.0) sf = {sound_function=sf; position=start};;
9
10 let add_note instrument layer amplitude tone length =
11   Layer.add_plugin layer
12                   (Plugin.from_sound (instrument.sound_function amplitude tone))
13                   (Time.Beats instrument.position, Time.Beats length);
14   instrument.position <- instrument.position +. length;;
15
16 let calc_length l = List.fold_right (fun (t,l) s -> l +. s) l 0.;;
17
18 let add_notes instrument layer volume notes =
19   let start_pos = instrument.position in
20   let len = calc_length notes in
21   let rec _add_notes notes =
22     match notes with
23     | (t,l)::r -> (
24         let spos = instrument.position -. start_pos in
25         let epos = spos +. l in
26         let s = Volume.amplitude volume spos len in
27         let e = Volume.amplitude volume epos len in
28         let newv = Volume.ramp s e in
29         add_note instrument layer newv t l;
30         _add_notes r)
31     | [] -> () in
32   _add_notes notes;;
33  
Note: See TracBrowser for help on using the browser.