Changeset 6706

Show
Ignore:
Timestamp:
07/01/09 13:01:24 (14 months ago)
Author:
smimram
Message:

Operators for manipulating midi channels.

Location:
trunk/liquidsoap/src
Files:
3 modified
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/liquidsoap/src/Makefile

    r6701 r6706  
    8888        operators/time_wrap.ml operators/lag.ml \ 
    8989        operators/video_effects.ml operators/video_fade.ml \ 
    90         operators/fork.ml 
     90        operators/fork.ml operators/midi_routing.ml 
    9191#       operators/pipe.ml 
    9292 
  • trunk/liquidsoap/src/lang/lang.ml

    r6695 r6706  
    7979type category = 
    8080  | Input | Output 
    81   | TrackProcessing | SoundProcessing | VideoProcessing 
     81  | TrackProcessing | SoundProcessing | VideoProcessing | MIDIProcessing 
    8282  | Visualization | SoundSynthesis 
    8383 
     
    8888  | SoundProcessing -> "Sound Processing" 
    8989  | VideoProcessing -> "Video Processing" 
     90  | MIDIProcessing -> "MIDI Processing" 
    9091  | SoundSynthesis -> "Sound Synthesis" 
    9192  | Visualization -> "Visualization" 
  • trunk/liquidsoap/src/lang/lang.mli

    r6695 r6706  
    8686  | SoundProcessing (** Operations on sound (e.g. compression, etc.). *) 
    8787  | VideoProcessing (** Operations on video. *) 
     88  | MIDIProcessing (** Operations on MIDI. *) 
    8889  | Visualization (** Visializations of the sound. *) 
    8990  | SoundSynthesis (** Synthesis. *) 
  • trunk/liquidsoap/src/operators/midi_routing.ml

    r6527 r6706  
    2323open Source 
    2424 
    25 class id (source:source) = 
     25class virtual base (source:source) = 
    2626object (self) 
    2727  inherit operator [source] as super 
     
    3434 
    3535  method abort_track = source#abort_track 
     36end 
    3637 
    37   method private get_frame buf = source#get buf 
     38class merge (source:source) out = 
     39object (self) 
     40  inherit base (source) 
     41 
     42  method private get_frame buf = 
     43    source#get buf; 
     44    let m = MFrame.tracks buf in 
     45      for c = 0 to Array.length m - 1 do 
     46        m.(out) := !(m.(c)) @ !(m.(out)); 
     47        if c <> out then m.(c) := [] 
     48      done; 
     49      m.(out) := List.sort (fun (t1, _) (t2, _) -> t1 - t2) !(m.(out)) 
     50end 
     51 
     52class remove (source:source) t = 
     53object (self) 
     54  inherit base (source) 
     55 
     56  method private get_frame buf = 
     57    source#get buf; 
     58    let m = MFrame.tracks buf in 
     59      List.iter (fun c -> m.(c) := []) t 
    3860end 
    3961 
    4062let () = 
    41   Lang.add_operator "id" 
    42     ["", Lang.source_t, None, None] 
    43     ~category:Lang.SoundProcessing 
    44     ~descr:"Identity: does not do anything." 
    45     ~flags:[Lang.Hidden] 
     63  Lang.add_operator "midi.merge_all" 
     64    [ 
     65      "track_out", Lang.int_t, Some (Lang.int 0), Some "Destination track."; 
     66      "", Lang.source_t, None, None 
     67    ] 
     68    ~category:Lang.MIDIProcessing 
     69    ~descr:"Merge all MIDI tracks in one." 
    4670    (fun p _ -> 
    4771       let f v = List.assoc v p in 
     72       let out = Lang.to_int (f "track_out") in 
    4873       let src = Lang.to_source (f "") in 
    49          new id src) 
     74         new merge src out) 
     75 
     76let () = 
     77  Lang.add_operator "midi.remove" 
     78    [ 
     79      "", Lang.list_t Lang.int_t, None, Some "Tracks to remove."; 
     80      "", Lang.source_t, None, None 
     81    ] 
     82    ~category:Lang.MIDIProcessing 
     83    ~descr:"Remove MIDI tracks." 
     84    (fun p _ -> 
     85       (* let f v = List.assoc v p in *) 
     86       let t = List.map Lang.to_int (Lang.to_list (Lang.assoc "" 1 p)) in 
     87       let src = Lang.to_source (Lang.assoc "" 2 p) in 
     88         new remove src t)