Skip to content

Commit

Permalink
RingArea tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiel committed Jul 16, 2012
1 parent 86d2619 commit fa8321f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 109 deletions.
8 changes: 8 additions & 0 deletions TECH-NOTES.md
Expand Up @@ -2,6 +2,9 @@


## General ## General


- We need to generalise ADSRH (e.g. in Pads): these actually take
expressions.

## Specific Objects ## Specific Objects


### Container ### Container
Expand All @@ -16,3 +19,8 @@
- There's no clear documentation for the properties `Multilabel` and - There's no clear documentation for the properties `Multilabel` and
`Multicolor` - I'm guessing these are scriptable/OSC controllable `Multicolor` - I'm guessing these are scriptable/OSC controllable
only. For now, they're always off. only. For now, they're always off.

- Need to generalise ADSRH (see above).

- To-do: "Capture", "light". (Light can apparently be a vector or
expression; we should investigate this.)
150 changes: 50 additions & 100 deletions scratch.clj
Expand Up @@ -18,92 +18,6 @@


(with-out-str (px/prxml [:p {:class "greet"} [:i "Ladies & gentlemen"]])) (with-out-str (px/prxml [:p {:class "greet"} [:i "Ladies & gentlemen"]]))


;; Do everything in bytes; the Lemur's OSC spec uses blobs, and I doubt it's going
;; to handle any non-ASCII encoding such as UTF-8.


(def xxx (byte-array (map byte [2 3 4])))

(def yyy (byte-array 10))

(System/arraycopy xxx 0 yyy 0 (count xxx))

(map #(get yyy %) (range (count yyy)))

;; --- OSC experiments (obsolete: the Lemur protocol isn't OSC).

(def a (atom nil))

(def LEMUR_HOST "localhost")
(def LEMUR_HOST "10.0.0.125")
(def LEMUR_PORT 8001)

; loopback test.
(def server (osc-server 8001))
(osc-handle server "/interface" (fn [msg] (reset! a msg)))
(osc-close server)

(def client (osc-client LEMUR_HOST LEMUR_PORT))

(osc-send client
"/interface"
(count ba)
(int 0)
(int (u/crc ba))
ba)

@a

;; --- XML file into byte-array.

(def ba (io/read-file "test-data/tiny.jzml"))
(count ba)

;; --- Bespoke, Lemur-specific broken OSC:

;; Header is 20 bytes / 5 int32s.
;; 0: padded payload length + 16
;; 1+2: "/jzml" padded
;; 3: ",b" padded
;; 4: unpadded payload length
;;
;; Actual (padded) payload is sent "raw", in packets limited to 1448 bytes.


(def HEADER_SIZE_BYTES 20)



(def chan (DatagramChannel/open))
(.connect chan (InetSocketAddress. "10.0.0.125" 8002))



(.write chan (ByteBuffer/wrap (byte-array (map byte [1 2 3 4]))))



(.disconnect chan)

(let
[ba (io/pad-string-to-bytes "AB")]
(map (partial get ba) (range (count ba))))

(int \c)

(map count
(p/package-data (byte-array (map byte [1 2 3 4 5]))))


(def ba (io/read-file "test-data/tiny_PREPPED.jzml"))
(count ba)

(io/transmit-payload "127.0.0.1" 8002 ba)
(io/transmit-payload "10.0.0.125" 8002 ba)




(x/format-project-for-file [:fooble] [:gooble]) (x/format-project-for-file [:fooble] [:gooble])


(x/format-project-for-upload [:fooble] [:gooble]) (x/format-project-for-upload [:fooble] [:gooble])
Expand All @@ -112,17 +26,7 @@


(with-out-str (p/prxml (x/fudge-container [100 100] [200 50] [80 80 80] [:foo]))) (with-out-str (p/prxml (x/fudge-container [100 100] [200 50] [80 80 80] [:foo])))


(io/transmit-payload ;; Nested container example. (container() takes varargs for the contents.)
"10.0.0.125"
8002
(.getBytes (x/format-project-for-upload
(x/project "TestProject")
(x/fudge-window (x/fudge-container
[100 100]
[200 200]
[80 80 80]
(x/fudge-container [5 5] [50 50] [255 255 255]))))))



(defn boz [size] (defn boz [size]
(if (< size 30) (if (< size 30)
Expand All @@ -147,7 +51,55 @@


(sp/sierpinski 3) (sp/sierpinski 3)


(concat [1 2 3] [4 5 6]) ;; More examples.

(io/transmit-payload
"10.0.0.125"
8002
(.getBytes (x/format-project-for-upload
(x/project "TestProject")
(x/interface [(obj/container
{:position [100 100]
:size [300 300]
:colour [80 120 120]}
(obj/pads {:id 987
:name "pads"
:position [0 0]
:size [284 284]
:off-colour [50 50 50]
:on-colour [255 255 255]}))]))))

(io/transmit-payload
"10.0.0.125"
8002
(.getBytes (x/format-project-for-upload
(x/project "TestProject")
(x/interface [(obj/container
{:position [100 100]
:size [300 300]
:colour [80 120 120]}
(obj/ringarea {:id 987
:name "ra"
:position [0 0]
:size 284
:colour [150 150 150]}))]))))

(io/transmit-payload
"10.0.0.125"
8002
(.getBytes (x/format-project-for-upload
(x/project "TestProject")
(x/interface [(obj/container
{:position [10 10]
:size [700 700]
:colour [80 120 120]}
(map #(obj/ringarea
{:id %
:name (format "ra%d" %)
:position [(int (* 278 (inc (Math/sin (* % Math/PI 0.125)))))
(int (* 278 (inc (Math/cos (* % Math/PI 0.125)))))]
:size 120
:colour [(- 255 (* % 10)) 200 150]}) (range 16)))]))))


(io/transmit-payload (io/transmit-payload
"10.0.0.125" "10.0.0.125"
Expand All @@ -169,8 +121,6 @@
:off-colour c :off-colour c
:on-colour [255 0 0]}))))])))) :on-colour [255 0 0]}))))]))))


(concat 1 2 [4 5])

;; ----- ;; -----


(obj/pads {:id 345 (obj/pads {:id 345
Expand Down
14 changes: 13 additions & 1 deletion src/sifaka/object_common.clj
Expand Up @@ -37,14 +37,26 @@
:osc_message (format "/%s/%s" object-name var-name)}) :osc_message (format "/%s/%s" object-name var-name)})


(defn variable (defn variable
^{:doc "Common settings for an object variable. Value assumed to be float."} ^{:doc "Common settings for an object variable. Value assumed to be float."}
[object-name var-name var-value] [object-name var-name var-value]
[:VARIABLE (merge {:name (format "%s=%f" var-name var-value) [:VARIABLE (merge {:name (format "%s=%f" var-name var-value)
:send 0} :send 0}
(base-osc-params object-name var-name) (base-osc-params object-name var-name)
fudge-midi-params fudge-midi-params
fudge-kbmouse-params)]) fudge-kbmouse-params)])


(defn param
^{:doc "Common settings for an object parameter."}
[obj-name param-name value]
[:PARAM (merge {:name (format "%s=" param-name)
:value value
:send 17 ; Is this the trigger mode?
:midi_scale "0,16363"
:osc_scale "0.0,1.0"}
(base-osc-params obj-name param-name)
fudge-midi-params
fudge-kbmouse-params)])

(defn window (defn window
^{:doc "Window phrase, with attributes (map) and sub-items (seq)."} ^{:doc "Window phrase, with attributes (map) and sub-items (seq)."}
[attributes sub-items] [attributes sub-items]
Expand Down
42 changes: 34 additions & 8 deletions src/sifaka/objects.clj
Expand Up @@ -50,12 +50,38 @@
:multicolor 0 :multicolor 0
:multilabel 0} :multilabel 0}
(cons (cons
[:PARAM (merge {:name "x=" (com/param name "x" 0.0)
:value 0.0
:send 17
:midi_scale "0,16363"
:osc_scale "0.0,1.0"}
(com/base-osc-params name "x")
com/fudge-midi-params ; Actually, midi_trigger=1 here.
com/fudge-kbmouse-params)]
(com/env name {})))) (com/env name {}))))

(defn ringarea
^{:doc "RingArea control."}
[{id :id
name :name
[x y] :position
size :size
[r g b] :colour}]
(let [params [(com/param name "x" 0.5)
(com/param name "y" 0.5)]
variables [(com/variable name "attraction" 1.0)
(com/variable name "friction" 0.8)
(com/variable name "speed" 1.0)
(com/variable name "attraction_x" 0.5)
(com/variable name "attraction_y" 0.5)]]
(com/window {:class "RingArea"
:id id
:text name
:x x
:y y
:width size
:height size
:label 0
:state 1
:group 0
:send 1
:capture 1
:font "tahoma,10,0"
:osc_target -2
:midi_target -2
:kbmouse_target -2
:color (com/colour r g b)}
(concat params variables))))
14 changes: 14 additions & 0 deletions test-data/one-ringarea.jzml
@@ -0,0 +1,14 @@
<JZML>
<PROJECT version="3020" width="1024" height="724" osc_target="-2" midi_target="-2" kbmouse_target="-2"/>
<WINDOW class="JAZZINTERFACE" text="Default" x="0" y="0" width="1024" height="724" state="1" group="0" font="tahoma,11,0" >
<WINDOW class="RingArea" text="RingArea" x="402" y="184" width="200" height="200" id="2" state="1" group="0" font="tahoma,10,0" send="1" osc_target="-2" midi_target="-2" kbmouse_target="-2" capture="1" color="32768" label="0">
<PARAM name="x=" value="0.500000" send="17" osc_target="0" osc_trigger="1" osc_message="/RingArea/x" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" osc_scale="0.000000,1.000000" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
<PARAM name="y=" value="0.500000" send="17" osc_target="0" osc_trigger="1" osc_message="/RingArea/y" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" osc_scale="0.000000,1.000000" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
<VARIABLE name="attraction=1" send="0" osc_target="0" osc_trigger="1" osc_message="/RingArea/attraction" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
<VARIABLE name="friction=0.8" send="0" osc_target="0" osc_trigger="1" osc_message="/RingArea/friction" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
<VARIABLE name="speed=1" send="0" osc_target="0" osc_trigger="1" osc_message="/RingArea/speed" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
<VARIABLE name="attraction_x=0.5" send="0" osc_target="0" osc_trigger="1" osc_message="/RingArea/attraction_x" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
<VARIABLE name="attraction_y=0.5" send="0" osc_target="0" osc_trigger="1" osc_message="/RingArea/attraction_y" midi_target="-1" midi_trigger="1" midi_message="0x90,0x90,0,0" midi_scale="0,16383" kbmouse_target="-1" kbmouse_trigger="1" kbmouse_message="0,0,0" kbmouse_scale="0,1,0,1"/>
</WINDOW>
</WINDOW>
</JZML>

0 comments on commit fa8321f

Please sign in to comment.