aboutsummaryrefslogtreecommitdiff
path: root/chuck/OSCGraphicsLayer.ck
blob: 2e3ae7607944cb374433e2ad3fc025ecc308eb77 (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
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;
	}
}