Le vendredi 5 février 2010 06:11:50, Tom Wright a écrit : > Hi all, Hi !
> Is it possible to tell liquidsoap to switch to/from a harbor input by > using the unix interface? Yes ! :-) There are several possible ways, but I can see one very general way. You first register a mutable boolean, using the following code: 8<-------------------------------->8 # A string reference x = string.ref("false") # First component is the get function get = fst(x) # Second component is the set function set = snd(x) # Wrap the two functions to operate on booleans: get = fun () -> bool_of_string(get ()) set = fun (x) -> set("#{x}") 8<-------------------------------->8 Now, you have two functions. One returns the current value, true or false, and the other one sets the value. you can then use these functions like this: 8<-------------------------------->8 # Create a toggle function def toggle(_) = if get () then set(false) else set(true) end "Value set to #{get ()}" #Note: this could also be simply: set(not get()) end # Register the function as a server command server.register(usage="toggle", description="Change the boolean value", "toggle", toggle) 8<-------------------------------->8 Now, using the server (unix interface), you have a new command, "toggle", that will switch the boolean value. Eventually, you can use this to create a source that will be available only when the boolean is true: 8<-------------------------------->8 # The original source s = (...) # input.harbor in your case # Wrap the source s = switch(track_sensitive=false, [(get, s)]) 8<-------------------------------->8 Now, the new source s is available only when the original source s is available *and* the boolean is true. In the case of harbor, this means the source is available when there is a source client connected *and* the boolean is true. You can then use that source in a fallback, for instance, and use the server command to switch back and forth to that source: 8<-------------------------------->8 # Fallback with many other sources: x = fallback(track_sensitive=false, [s, ...]) 8<-------------------------------->8 Few notes about this: * The boolean reference is much easier in the current SVN. If you plan on using it, I could update this. * The harbor source should probably be made active. By active, I mean that even though the source is disabled in the switch, data should be consumed. Otherwise, the buffer will get full and liquidsoap will drop new data or behave unexpectedly. There is a simple way to do this: 8<-------------------------------->8 output.dummy(fallible=true s) 8<-------------------------------->8 This registers a dummy output on the source s, which will consume data from s at any time.. The fallible option is available in 0.9.2 only. For older versions, you should do: 8<-------------------------------->8 output.dummy(mksafe(s)) 8<-------------------------------->8 > Also (bonus question) is it possible to query which inputs are available? Yes. If the harbor input has id "harbor", you have a command: "harbor.status" which will return its current status, for instance "source client connected" Thanks for your interest in liquidsoap and have fun :-) Romain ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ Savonet-users mailing list Savonet-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/savonet-users