aboutsummaryrefslogtreecommitdiff
path: root/chuck
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-16 22:04:50 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-16 22:04:50 +0200
commitb8a8747208bf50520178a0398368fb54768483c4 (patch)
tree075a68ea57db12fe8ccdcfef64d06e765287832c /chuck
parent86dcfb27c1a126cbf3b6d0804cf0bf3d3a91b6a6 (diff)
downloadosc-graphics-b8a8747208bf50520178a0398368fb54768483c4.tar.gz
added chuck wrappers
Diffstat (limited to 'chuck')
-rw-r--r--chuck/OSCGraphics.ck121
-rw-r--r--chuck/OSCGraphicsBox.ck2
-rw-r--r--chuck/OSCGraphicsImage.ck2
-rw-r--r--chuck/OSCGraphicsLayer.ck75
-rw-r--r--chuck/OSCGraphicsVideo.ck2
-rw-r--r--chuck/lib.ck10
6 files changed, 212 insertions, 0 deletions
diff --git a/chuck/OSCGraphics.ck b/chuck/OSCGraphics.ck
new file mode 100644
index 0000000..603706f
--- /dev/null
+++ b/chuck/OSCGraphics.ck
@@ -0,0 +1,121 @@
+public class OSCGraphics {
+ static OscSend @osc_send;
+ 1 => static int free_id;
+
+ fun static void
+ clear()
+ {
+ osc_send.startMsg("/layer/*/delete", "");
+ }
+
+ fun static OSCGraphicsImage @
+ getImage(string name)
+ {
+ OSCGraphicsImage img;
+ osc_send @=> img.osc_send;
+ name => img.name;
+ return img;
+ }
+ fun static OSCGraphicsImage @
+ newImage(int pos, int geo[], string file)
+ {
+ OSCGraphicsImage img;
+
+ img.init(osc_send, "image", "s", pos, "__image_"+free_id, geo);
+ file => osc_send.addString;
+
+ free_id++;
+ return img;
+ }
+ fun static OSCGraphicsImage @
+ newImage(int pos, int geo[])
+ {
+ return newImage(pos, geo, "");
+ }
+ fun static OSCGraphicsImage @
+ newImage(int pos)
+ {
+ return newImage(pos, null, "");
+ }
+ fun static OSCGraphicsImage @
+ newImage()
+ {
+ return newImage(-1, null, "");
+ }
+
+ fun static OSCGraphicsVideo @
+ getVideo(string name)
+ {
+ OSCGraphicsVideo video;
+ osc_send @=> video.osc_send;
+ name => video.name;
+ return video;
+ }
+ fun static OSCGraphicsVideo @
+ newVideo(int pos, int geo[], string file)
+ {
+ OSCGraphicsVideo video;
+
+ video.init(osc_send, "video", "s", pos, "__video_"+free_id, geo);
+ file => osc_send.addString;
+
+ free_id++;
+ return video;
+ }
+ fun static OSCGraphicsVideo @
+ newVideo(int pos, int geo[])
+ {
+ return newVideo(pos, geo, "");
+ }
+ fun static OSCGraphicsVideo @
+ newVideo(int pos)
+ {
+ return newVideo(pos, null, "");
+ }
+ fun static OSCGraphicsVideo @
+ newVideo()
+ {
+ return newVideo(-1, null, "");
+ }
+
+ fun static OSCGraphicsBox @
+ getBox(string name)
+ {
+ OSCGraphicsBox box;
+ osc_send @=> box.osc_send;
+ name => box.name;
+ return box;
+ }
+ fun static OSCGraphicsBox @
+ newBox(int pos, int geo[], int color[], float opacity)
+ {
+ OSCGraphicsBox box;
+
+ box.init(osc_send, "box", "iiif", pos, "__box_"+free_id, geo);
+ for (0 => int i; i < color.cap(); i++)
+ color[i] => osc_send.addInt;
+ opacity => osc_send.addFloat;
+
+ free_id++;
+ return box;
+ }
+ fun static OSCGraphicsBox @
+ newBox(int pos, int geo[], int color[])
+ {
+ return newBox(pos, geo, color, 1.);
+ }
+ fun static OSCGraphicsBox @
+ newBox(int pos, int color[])
+ {
+ return newBox(pos, null, color, 1.);
+ }
+ fun static OSCGraphicsBox @
+ newBox(int color[])
+ {
+ return newBox(-1, null, color, 1.);
+ }
+
+}
+/* static initialization */
+new OscSend @=> OSCGraphics.osc_send;
+OSCGraphics.osc_send.setHost("localhost", 7770);
diff --git a/chuck/OSCGraphicsBox.ck b/chuck/OSCGraphicsBox.ck
new file mode 100644
index 0000000..489bcf5
--- /dev/null
+++ b/chuck/OSCGraphicsBox.ck
@@ -0,0 +1,2 @@
+public class OSCGraphicsBox extends OSCGraphicsLayer {
+}
diff --git a/chuck/OSCGraphicsImage.ck b/chuck/OSCGraphicsImage.ck
new file mode 100644
index 0000000..927cacd
--- /dev/null
+++ b/chuck/OSCGraphicsImage.ck
@@ -0,0 +1,2 @@
+public class OSCGraphicsImage extends OSCGraphicsLayer {
+}
diff --git a/chuck/OSCGraphicsLayer.ck b/chuck/OSCGraphicsLayer.ck
new file mode 100644
index 0000000..2e3ae76
--- /dev/null
+++ b/chuck/OSCGraphicsLayer.ck
@@ -0,0 +1,75 @@
+public class OSCGraphicsLayer {
+ OscSend @osc_send;
+ string name;
+
+ fun void
+ init(OscSend @osc_send, string type, string osc_types,
+ int pos, string name, int geo[]) /* pseudo-constructor */
+ {
+ if (geo == null)
+ [0, 0, 0, 0] @=> geo;
+
+ osc_send @=> this.osc_send;
+ name => this.name;
+
+ osc_send.startMsg("/layer/new/"+type, "isiiii"+osc_types);
+ pos => osc_send.addInt;
+ name => osc_send.addString;
+ for (0 => int i; i < geo.cap(); i++)
+ geo[i] => osc_send.addInt;
+ }
+
+ fun int[]
+ geo(int geo[])
+ {
+ if (geo == null)
+ [0, 0, 0, 0] @=> geo;
+
+ osc_send.startMsg("/layer/"+name+"/geo", "iiii");
+ for (0 => int i; i < geo.cap(); i++)
+ geo[i] => osc_send.addInt;
+
+ return geo;
+ }
+ fun int[]
+ geo()
+ {
+ return geo(null);
+ }
+
+ class AlphaPort extends Chubgraph {
+ inlet => blackhole;
+ inlet => outlet;
+
+ fun void
+ poll(OSCGraphicsLayer @layer)
+ {
+ inlet.last() => float prev;
+
+ while (50::ms => now)
+ if (inlet.last() != prev)
+ inlet.last() => layer.alpha => prev;
+ }
+ }
+ fun UGen @
+ getAlphaPort()
+ {
+ AlphaPort p;
+ spork ~ p.poll(this);
+ return p;
+ }
+ fun float
+ alpha(float opacity)
+ {
+ osc_send.startMsg("/layer/"+name+"/alpha", "f");
+ opacity => osc_send.addFloat;
+ return opacity;
+ }
+
+ fun void
+ delete()
+ {
+ osc_send.startMsg("/layer/"+name+"/delete", "");
+ "" => name;
+ }
+}
diff --git a/chuck/OSCGraphicsVideo.ck b/chuck/OSCGraphicsVideo.ck
new file mode 100644
index 0000000..def61f4
--- /dev/null
+++ b/chuck/OSCGraphicsVideo.ck
@@ -0,0 +1,2 @@
+public class OSCGraphicsVideo extends OSCGraphicsLayer {
+}
diff --git a/chuck/lib.ck b/chuck/lib.ck
new file mode 100644
index 0000000..a94550e
--- /dev/null
+++ b/chuck/lib.ck
@@ -0,0 +1,10 @@
+"/usr/local" => string prefix;
+
+prefix+"/share/osc-graphics/chuck" => string path;
+
+path+"/OSCGraphicsLayer.ck" => Machine.add;
+path+"/OSCGraphicsImage.ck" => Machine.add;
+path+"/OSCGraphicsVideo.ck" => Machine.add;
+path+"/OSCGraphicsBox.ck" => Machine.add;
+
+path+"/OSCGraphics.ck" => Machine.add;