aboutsummaryrefslogtreecommitdiff
path: root/chuck/OSCGraphics.ck
blob: 626c92de49e3b67103b18fc89094976345993469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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 < 3; 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);