aboutsummaryrefslogtreecommitdiff
path: root/chuck/OSCGraphics.ck
blob: 4ca6be5bc7f29365cea2480174403e2d22b3c207 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
public class OSCGraphics {
	static OscSend @osc_send;
	static int free_id;

	fun static void
	clear()
	{
		osc_send.startMsg("/layer/*/delete", "");
	}

	fun static string
	record(string file, string codec)
	{
		osc_send.startMsg("/recorder/start", "ss");
		file => osc_send.addString;
		codec => osc_send.addString;

		return file;
	}
	fun static string
	record(string file)
	{
		return record(file, "");
	}
	fun static string
	record()
	{
		osc_send.startMsg("/recorder/stop", "");
		return "";
	}

	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[], float opacity, string file)
	{
		OSCGraphicsImage img;

		img.init(osc_send, "image", "s",
			 pos, "__image_"+free_id, geo, opacity);
		file => osc_send.addString;

		free_id++;
		return img;
	}
	fun static OSCGraphicsImage @
	newImage(int pos, int geo[], float opacity)
	{
		return newImage(pos, geo, opacity, "");
	}
	fun static OSCGraphicsImage @
	newImage(int pos, int geo[])
	{
		return newImage(pos, geo, 1., "");
	}
	fun static OSCGraphicsImage @
	newImage(int pos)
	{
		return newImage(pos, null, 1., "");
	}
	fun static OSCGraphicsImage @
	newImage()
	{
		return newImage(-1, null, 1., "");
	}

	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[], float opacity, string url)
	{
		OSCGraphicsVideo video;

		video.init(osc_send, "video", "s",
			   pos, "__video_"+free_id, geo, opacity);
		url => osc_send.addString;

		free_id++;
		return video;
	}
	fun static OSCGraphicsVideo @
	newVideo(int pos, int geo[], float opacity)
	{
		return newVideo(pos, geo, 1., "");
	}
	fun static OSCGraphicsVideo @
	newVideo(int pos, int geo[])
	{
		return newVideo(pos, geo, 1., "");
	}
	fun static OSCGraphicsVideo @
	newVideo(int pos)
	{
		return newVideo(pos, null, 1., "");
	}
	fun static OSCGraphicsVideo @
	newVideo()
	{
		return newVideo(-1, null, 1., "");
	}

	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[], float opacity, int color[])
	{
		OSCGraphicsBox box;

		box.init(osc_send, "box", "iii",
			 pos, "__box_"+free_id, geo, opacity);
		for (0 => int i; i < 3; i++)
			color[i] => osc_send.addInt;

		free_id++;
		return box;
	}
	fun static OSCGraphicsBox @
	newBox(int pos, int geo[], int color[])
	{
		return newBox(pos, geo, 1., color);
	}
	fun static OSCGraphicsBox @
	newBox(int pos, int color[])
	{
		return newBox(pos, null, 1., color);
	}
	fun static OSCGraphicsBox @
	newBox(int color[])
	{
		return newBox(-1, null, 1., color);
	}

	fun static OSCGraphicsText @
	getText(string name)
	{
		OSCGraphicsText text;
		osc_send @=> text.osc_send;
		name => text.name;
		return text;
	}
	fun static OSCGraphicsText @
	newText(int pos, int geo[], float opacity, int color[],
		string txt, string font)
	{
		OSCGraphicsText text;

		text.init(osc_send, "text", "iiiss",
			  pos, "__text_"+free_id, geo, opacity);
		for (0 => int i; i < 3; i++)
			color[i] => osc_send.addInt;
		txt => osc_send.addString;
		font => osc_send.addString;

		free_id++;
		return text;
	}
	fun static OSCGraphicsText @
	newText(int pos, int geo[], int color[], string txt, string font)
	{
		return newText(pos, geo, 1., color, txt, font);
	}
	fun static OSCGraphicsText @
	newText(int geo[], int color[], string txt, string font)
	{
		return newText(-1, geo, 1., color, txt, font);
	}
}
/* static initialization */
new OscSend @=> OSCGraphics.osc_send;
OSCGraphics.osc_send.setHost("localhost", 7770);

1 => OSCGraphics.free_id;