Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

promote osc-msg osc-send-bundle to public ns. Also rename generic pee…

…r to the more specific client and server in public ns fn args to increase clarity for new users.
  • Loading branch information...
commit 0f92c9184fd6222370dfd3df4168fd13e88a35c1 1 parent 2a00985
@samaaron samaaron authored
74 src/osc.clj
@@ -16,28 +16,29 @@
(defn osc-listen
"Attach a generic listener function that will be called with every incoming osc message.
(osc-listen s (fn [msg] (println \"listener: \" msg)) :foo)"
- [peer listener key]
+ [server listener key]
- (alter (:listeners peer) assoc key listener)))
+ (alter (:listeners server) assoc key listener))
+ server)
(defn osc-rm-listener
"Remove the generic listener associated with the specific key
(osc-rm-listener s :foo)"
- [peer key]
+ [server key]
- (alter (:listeners peer) dissoc key)))
+ (alter (:listeners server) dissoc key)))
(defn osc-listeners
"Return a seq of all registered listeners
(osc-listeners s) ;=> (:foo)"
- [peer]
- (keys @(:listeners peer)))
+ [server]
+ (keys @(:listeners server)))
(defn osc-rm-all-listeners
- "Remove all generic listeners associated with peer"
- [peer]
+ "Remove all generic listeners associated with server"
+ [server]
- (ref-set (:listeners peer) {})))
+ (ref-set (:listeners server) {})))
(defn osc-handle
"Add a handle fn to an OSC path with the specified key. This handle will be
@@ -47,20 +48,21 @@
The path you specify may not contain any of the OSC reserved chars:
# * , ? [ ] { } and whitespace"
- ([peer path handler] (osc-handle peer path handler handler))
- ([peer path handler key]
- (peer-handle peer path handler key)))
+ ([server path handler] (osc-handle server path handler handler))
+ ([server path handler key]
+ (peer-handle server path handler key)
+ server))
(defn osc-rm-handler
"Remove the handler at path with the specified key. This just removes one
specific handler (if found)"
- [peer path key]
- (peer-rm-handler peer path key))
+ [server path key]
+ (peer-rm-handler server path key))
(defn osc-rm-handlers
"Remove all the handlers at path."
- [peer path]
- (peer-rm-handlers peer path))
+ [server path]
+ (peer-rm-handlers server path))
(defn osc-rm-all-handlers
"Remove all registered handlers for the supplied path (defaulting to /)
@@ -69,32 +71,46 @@
have been registered for both /foo/bar and /foo/bar/baz and
osc-rm-all-handlers is called with /foo/bar, then all handlers associated
with both /foo/bar and /foo/bar/baz will be removed."
- ([peer] (osc-rm-all-handlers peer "/"))
- ([peer path] (peer-rm-all-handlers peer path)))
+ ([server] (osc-rm-all-handlers server "/"))
+ ([server path] (peer-rm-all-handlers server path)))
(defn osc-recv
"Register a one-shot handler which will remove itself once called. If a
timeout is specified, it will return nil if a message matching the path
is not received within timeout milliseconds. Otherwise, it will block
the current thread until a message has been received."
- [peer path & [timeout]]
- (peer-recv peer path timeout))
+ [server path & [timeout]]
+ (peer-recv server path timeout))
(defn osc-send
"Creates an OSC message and either sends it to the server immediately
or if a bundle is currently being formed it adds it to the list of messages."
[client path & args]
- (osc-send-msg client (apply osc-msg path (osc-type-tag args) args)))
+ (osc-send-msg client (apply mk-osc-msg path (osc-type-tag args) args)))
-(defn osc-send-bundle
- "Send OSC bundle to peer."
- [peer bundle]
- (peer-send-bundle peer bundle))
+(defn osc-msg
+ "Returns a map representing an OSC message with the specified path and args."
+ [path & args]
+ (apply mk-osc-msg path (osc-type-tag args) args))
+(defn osc-bundle
+ "Returns an OSC bundle, which is a timestamped set of OSC messages and/or bundles."
+ [timestamp & items]
+ (mk-osc-bundle timestamp items))
-(defmacro in-osc-bundle [client timestamp & body]
+(defn osc-send-bundle
+ "Send OSC bundle to client."
+ [client bundle]
+ (peer-send-bundle client bundle))
+(defmacro in-osc-bundle
+ "Send a bundle with associated timestamp enclosing the messages in body. Can
+ be used to wrap around an arbtrary form. All osc-sends within will be
+ automatically added to the bundle."
+ [client timestamp & body]
`(binding [*osc-msg-bundle* (atom [])]
(let [res# (do ~@body)]
- (osc-send-bundle ~client (osc-bundle ~timestamp @*osc-msg-bundle*))
+ (osc-send-bundle ~client (mk-osc-bundle ~timestamp @*osc-msg-bundle*))
(defn osc-client
@@ -112,8 +128,8 @@
(defn osc-target
"Update the target address of an OSC client so future calls to osc-send
will go to a new destination. Automatically updates zeroconf if necessary."
- [peer host port]
- (update-peer-target peer host port))
+ [client host port]
+ (update-peer-target client host port))
(defn osc-server
"Returns a live OSC server ready to register handler functions. By default
4 src/osc/decode.clj
@@ -47,7 +47,7 @@
\s (decode-string buf))))
(rest type-tag))]
- (apply osc-msg path type-tag args)))
+ (apply mk-osc-msg path type-tag args)))
(defn- decode-timetag
"Decode OSC timetag from current pos in buf."
@@ -82,7 +82,7 @@
"Decode a bundle - ignore the first string as it simply identifies the bundle."
(decode-string buf) ; #bundle
- (osc-bundle (decode-timetag buf) (decode-bundle-items buf)))
+ (mk-osc-bundle (decode-timetag buf) (decode-bundle-items buf)))
(defn osc-decode-packet
"Decode an OSC packet buffer into a bundle or message map."
20 src/osc/util.clj
@@ -62,8 +62,8 @@
-(defn osc-msg
- "Returns a map representing an OSC message.
+(defn mk-osc-msg
+ "Create an OSC message
An OSC message consists of:
* a path prefixed with /
@@ -85,18 +85,18 @@
(rest (str/split path #"/")))
-(defn osc-msg?
- "Returns true if obj is an OSC message"
- [obj]
- (= :osc-msg (type obj)))
-(defn osc-bundle
- "Returns an OSC bundle, which is a timestamped set of OSC messages and/or bundles."
+(defn mk-osc-bundle
+ "Create an osc bundle"
[timestamp items]
(with-meta {:timestamp timestamp
:items items}
{:type :osc-bundle}))
+(defn osc-msg?
+ "Returns true if obj is an OSC message"
+ [obj]
+ (= :osc-msg (type obj)))
(defn osc-bundle?
"Returns true if obj is an OSC Bundle"
@@ -106,4 +106,4 @@
(defn osc-msg-infer-types
"Returns an OSC message. Infers the types of the args."
[path & args]
- (apply osc-msg path (osc-type-tag args) args))
+ (apply mk-osc-msg path (osc-type-tag args) args))
13 test/bundle_test.clj
@@ -31,25 +31,25 @@
(compare-packets packet (osc-decode-packet buf))))
(deftest encode-decode-empty []
- (encode-decode-compare (osc-bundle OSC-TIMETAG-NOW [])))
+ (encode-decode-compare (mk-osc-bundle OSC-TIMETAG-NOW [])))
(deftest encode-decode-one []
- (encode-decode-compare (osc-bundle OSC-TIMETAG-NOW
+ (encode-decode-compare (mk-osc-bundle OSC-TIMETAG-NOW
[(osc-msg-infer-types "/encode-decode-one"
1 (float 11.0) "encode-decode--one")])))
(deftest encode-decode-two []
- (encode-decode-compare (osc-bundle OSC-TIMETAG-NOW
+ (encode-decode-compare (mk-osc-bundle OSC-TIMETAG-NOW
[(osc-msg-infer-types "/encode-decode-two"
1 (float 11.0) "encode-decode-two")
(osc-msg-infer-types "/encode-decode-two"
2 (float 22.0) "encode-decode-two")])))
(deftest encode-decode-nested []
- (encode-decode-compare (osc-bundle OSC-TIMETAG-NOW
+ (encode-decode-compare (mk-osc-bundle OSC-TIMETAG-NOW
[(osc-msg-infer-types "/encode-decode"
1 (float 11.0) "encode-decode")
- (osc-bundle OSC-TIMETAG-NOW
+ (mk-osc-bundle OSC-TIMETAG-NOW
[(osc-msg-infer-types "/encode-decode-nested"
11 (float 111.0) "encode-decode-nested")])
(osc-msg-infer-types "/encode-decode"
@@ -58,7 +58,7 @@
(deftest round-trip []
(let [server (osc-server PORT)
client (osc-client HOST PORT)
- bundle (osc-bundle OSC-TIMETAG-NOW
+ bundle (mk-osc-bundle OSC-TIMETAG-NOW
[(osc-msg-infer-types "/round-trip/begin")
(osc-msg-infer-types "/round-trip/data" 1 (float 11.0) "round-trip-data")
(osc-msg-infer-types "/round-trip/end")])
@@ -90,4 +90,3 @@
(osc-close server true)
(osc-close client true)))))
Please sign in to comment.
Something went wrong with that request. Please try again.