aboutsummaryrefslogtreecommitdiff
path: root/external/External.cs
blob: 820c7caa6abb2260dd1285f09f3f23afb9ce702b (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
using System;


namespace PureData
{
	


	public class External
	{
		private IntPtr x;
		
		public External()
		{
			x = IntPtr.Zero;
		}

		

		// this function MUST exist
		public void SetUp(IntPtr pdClass)
		{
			// you must assign pdclass to x !
			x = pdClass;

			// now you can do what you like...
			Console.WriteLine("pointer set!");
			Console.WriteLine("setting selectors..");
			pd.AddSelector(x, "sel1", "Sel1", ParametersType.None);
			pd.AddSelector(x, "sel2", "Sel2", ParametersType.None);
			pd.AddSelector(x, "selFloat", "SelFloat", ParametersType.Float);
			pd.AddSelector(x, "selString", "SelString", ParametersType.Symbol);
			pd.AddSelector(x, "selGenericList", "SelGenericList", ParametersType.List);
			Console.WriteLine("selectors set");
			pd.AddOutlet(x, ParametersType.Float);
			pd.AddInlet(x, "selFloat", ParametersType.Float);
		}



		public void Sel1()
		{
			pd.PostMessage("Sel1 invoked!");
		}

		public void Sel2()
		{
			pd.PostMessage("Sel2 invoked!");
			
			// testing outlets
			Atom[] atoms = new Atom[2];
			atoms[0] = new Atom("ciao");
			atoms[1] = new Atom(1.5f);
			pd.ToOutlet(x, 0, atoms.Length, atoms);

		}

		public void SelFloat(float f)
		{
			pd.PostMessage("SelFloat received " + f);


		}

		public void SelString(ref string s)
		{
			pd.PostMessage("SelString received " + s);
		}

		public void SelGenericList(Atom [] list)
		{
			for (int i = 0; i<list.Length; i++)
			{
				Atom a = (Atom) list[i];
				switch (a.type)
				{
					case (AtomType.Null):
					{
						pd.PostMessage("element null");
						break;
					}
					case (AtomType.Float):
					{
						pd.PostMessage("" + a.float_value);
						break;
					}
					case (AtomType.Symbol):
					{
						pd.PostMessage(a.string_value);
						break;
					}
				}
			}		
		}


	}





}