samer@0: *** samer@0: *** plosc - OSC message sending from SWI Prolog samer@0: *** samer@0: samer@0: This module allows Prolog code to send Open Sound Control (OSC) samer@0: messages using liblo. samer@0: samer@0: samer@0: PREREQUISITES samer@0: samer@0: - SWI Prolog samer@0: - liblo samer@0: samer@0: samer@0: INSTALLATION samer@0: samer@0: First check and edit as necessary the variables in the top half of the samer@0: root Makefile. samer@0: samer@0: The build process installs a Prolog module file and a foreign library samer@0: to ~/lib/prolog by default. If you wish to change this, edit the root Makefile samer@0: accordingly and be sure that the referenced directories are in your samer@0: Prolog file_search_path. samer@0: samer@0: In the root directory of this package, type samer@0: samer@0: $ make install samer@0: samer@0: samer@0: samer@0: USAGE samer@0: samer@0: This example talks to a Supercollider server running on the local machine samer@0: listening to port 57110. It sends a message to create a Synth from SynthDef 'Square' samer@0: with some given parameters. samer@0: samer@0: __________________________________________________________ samer@0: :- use_module(library(plosc)). samer@0: :- dynamic osc_addr/1. samer@0: samer@0: init :- samer@0: osc_mk_address(localhost,57110, A), samer@0: assert(osc_addr(A)). samer@0: samer@0: bing :- samer@0: osc_addr(A), samer@0: get_time(T), samer@0: osc_send(A,'/s_new',[string('Square'),int(-1),int(0),int(1),string('freq'),float(440)],T). samer@0: samer@0: :- init, bing. samer@0: __________________________________________________________ samer@0: samer@0: samer@0: The following code shows how to make an OSC server. samer@0: __________________________________________________________ samer@0: :- use_module(library(plosc)). samer@0: samer@0: dumposc(P,A) :- writeln(msg(P,A)). samer@0: forward(P,[string(Host),int(Port),string(Msg)|Args]) :- samer@0: osc_mk_address(Host,Port,Addr), samer@0: osc_send(Addr,Msg,Args). samer@0: samer@0: :- osc_mk_server(7770,S), samer@0: osc_mk_address(localhost,7770,P), samer@0: osc_add_handler(S,'/fish',any,dumposc), samer@0: osc_add_handler(S,'/fwd',any,forward), samer@0: assert(server(S,P)). samer@0: samer@0: % start and stop the asynchronous server samer@0: start :- server(S,_), osc_start_server(S). samer@0: stop :- server(S,_), osc_stop_server(S). samer@0: samer@0: % run the server synchronously - send /plosc/stop to stop it samer@0: run :- server(S,_), osc_run_server(S). samer@0: samer@0: % send a message to the current server samer@0: send(M,A) :- server(_,P), osc_send(P,M,A). samer@0: __________________________________________________________ samer@0: samer@0: samer@0: To run the code in the example directory, from the shell type samer@0: samer@0: $ swipl -s example/testosc.pl samer@0: samer@0: samer@0: samer@0: BUGS AND LIMITATIONS samer@0: samer@0: The message sending predicates are limited in the types of arguments samer@0: they can use - currently, the following functors can be used: samer@0: samer@0: Head functor OSC Type samer@0: ------------ -------- samer@0: int i - 32 bit integer samer@0: float f - Single precision float samer@0: double d - Double precision float samer@0: string s - String samer@0: symbol S - Symbol samer@0: true T - True samer@0: false F - False samer@0: nil N - Nil samer@0: inf I - Infinitum or Impuse samer@0: samer@0: BLOBs, 64 bit integers, 8 bit integers, time tags and MIDI messages cannot be sent. samer@0: However, all types can be received except BLOBs. samer@0: samer@0: