aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpd/AssemblyInfo.cs2
-rwxr-xr-xpd/Atom.cs82
-rw-r--r--pd/PureData.cs46
-rwxr-xr-xpd/pd.cs114
-rwxr-xr-xpd/pd.csproj4
5 files changed, 115 insertions, 133 deletions
diff --git a/pd/AssemblyInfo.cs b/pd/AssemblyInfo.cs
index 74d5e94..a9f1b83 100755
--- a/pd/AssemblyInfo.cs
+++ b/pd/AssemblyInfo.cs
@@ -11,7 +11,7 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("Davide Morelli")]
+[assembly: AssemblyCopyright("Davide Morelli, Thomas Grill")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/pd/Atom.cs b/pd/Atom.cs
index e6c723e..532956e 100755
--- a/pd/Atom.cs
+++ b/pd/Atom.cs
@@ -3,34 +3,83 @@ using System.Runtime.InteropServices; // for structures
namespace PureData
{
- public enum AtomType {Null = 0, Float=1, Symbol=2, List=3, Bang=4};
+ public enum AtomType {Null = 0, Float = 1, Symbol = 2, Pointer = 3};
- //[StructLayout (LayoutKind.Explicit)]
+ [StructLayout (LayoutKind.Sequential)]
+ sealed public class Symbol
+ {
+ // this should NOT be public
+ readonly private IntPtr ptr;
+
+ public Symbol(IntPtr p)
+ {
+ ptr = p;
+ }
+
+ public Symbol(Symbol s)
+ {
+ ptr = s.ptr;
+ }
+
+ public Symbol(string s)
+ {
+ ptr = Core.GenSym(s);
+ }
+
+ override public string ToString()
+ {
+ return Core.EvalSym(this);
+ }
+ }
+
+ [StructLayout (LayoutKind.Sequential)]
+ sealed public class Pointer
+ {
+ public IntPtr ptr;
+ }
+
+ [StructLayout (LayoutKind.Explicit)]
+ public struct Word
+ {
+ [FieldOffset(0)] public float w_float;
+ [FieldOffset(0)] public Symbol w_symbol;
+ [FieldOffset(0)] public Pointer w_pointer;
+ }
+
+ //[StructLayout (LayoutKind.Explicit)]
[StructLayout (LayoutKind.Sequential)]
- public struct Atom
+ sealed public class Atom
{
+
public AtomType type;
- public float float_value;
- public string string_value;
+ public Word word;
+
public Atom(float f)
{
- this.type = AtomType.Float;
- this.float_value = f;
- this.string_value = "float";
+ type = AtomType.Float;
+ word.w_float = f;
}
+
public Atom(int i)
{
- this.type = AtomType.Float;
- this.float_value = (float) i;
- this.string_value = "float";
- }
+ type = AtomType.Float;
+ word.w_float = (float)i;
+ }
+
+ public Atom(Symbol s)
+ {
+ type = AtomType.Symbol;
+ word.w_symbol = s;
+ }
+
public Atom(string s)
{
- this.type = AtomType.Symbol;
- this.float_value = 0;
- this.string_value = s;
+ type = AtomType.Symbol;
+ word.w_symbol = new Symbol(s);
}
}
+
+
// this struct is relative to this c struct, see clr.c
/*
@@ -51,4 +100,5 @@ namespace PureData
} stuff;
};
*/
-}
+
+} \ No newline at end of file
diff --git a/pd/PureData.cs b/pd/PureData.cs
new file mode 100644
index 0000000..2ff8cfe
--- /dev/null
+++ b/pd/PureData.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Runtime.CompilerServices; // for extern import
+
+namespace PureData
+{
+ // PD core functions
+ public class Core
+ {
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern static void Post(string message);
+
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern static void PostError(string message);
+
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern static void PostBug(string message);
+
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern static void PostVerbose(string message);
+
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern static IntPtr GenSym(string sym);
+
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ public extern static string EvalSym(Symbol sym);
+ }
+
+ // This is the base class for a PD/CLR external
+ public class External
+ : Core
+ {
+ private readonly IntPtr ptr;
+
+ protected virtual void MethodBang() { Post("No bang handler"); }
+
+ protected virtual void MethodFloat(float f) { Post("No float handler"); }
+
+ protected virtual void MethodSymbol(Symbol s) { Post("No symbol handler"); }
+
+ protected virtual void MethodPointer(Pointer p) { Post("No pointer handler");}
+
+ protected virtual void MethodList(Atom[] lst) { Post("No list handler"); }
+
+ protected virtual void MethodAnything(Atom[] lst) { Post("No list handler"); }
+ }
+}
diff --git a/pd/pd.cs b/pd/pd.cs
deleted file mode 100755
index 1ec0903..0000000
--- a/pd/pd.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-using System;
-using System.Runtime.CompilerServices; // for extern import
-
-
-
-namespace PureData
-{
- public enum ParametersType {None = 0, Float=1, Symbol=2, List=3, Bang=4};
-
- public class pd
- {
- public delegate void DelegateWithoutArguments();
- public delegate void DelegateFloat(float f);
- public delegate void DelegateString(ref string s);
- public delegate void DelegateArray(Atom [] atoms);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern static void RegisterSelector (IntPtr x, string sel, string met, int type);
- // function called by the user
- public static void AddSelector(IntPtr x, string sel, DelegateWithoutArguments func)
- {
- RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.None);
- }
- public static void AddSelector(IntPtr x, string sel, DelegateFloat func)
- {
- RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.Float);
- }
- public static void AddSelector(IntPtr x, string sel, DelegateString func)
- {
- RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.Symbol);
- }
- public static void AddSelector(IntPtr x, string sel, DelegateArray func)
- {
- RegisterSelector (x, sel, func.Method.Name, (int) ParametersType.List);
- }
- public static void AddSelector(IntPtr x, DelegateWithoutArguments func)
- {
- RegisterSelector (x, "", func.Method.Name, (int) ParametersType.None);
- }
- public static void AddSelector(IntPtr x, DelegateFloat func)
- {
- RegisterSelector (x, "", func.Method.Name, (int) ParametersType.Float);
- }
- public static void AddSelector(IntPtr x, DelegateString func)
- {
- RegisterSelector (x, "", func.Method.Name, (int) ParametersType.Symbol);
- }
- public static void AddSelector(IntPtr x, DelegateArray func)
- {
- RegisterSelector (x, "", func.Method.Name, (int) ParametersType.List);
- }
-
- // send stuff to an outlet
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern static void ToOutlet (IntPtr x, int outlet, int atoms_length, Atom [] atoms);
- public static void SendToOutlet (IntPtr x, int outlet, Atom [] atoms)
- {
- ToOutlet (x, outlet, atoms.Length, atoms);
- }
- public static void SendToOutlet (IntPtr x, int outlet, Atom atom)
- {
- Atom [] atoms = new Atom[1];
- atoms[0] = atom;
- ToOutlet (x, outlet, atoms.Length, atoms);
- }
- public static void SendToOutlet (IntPtr x, int outlet, float f)
- {
- Atom [] atoms = new Atom[1];
- atoms[0] = new Atom(f);
- ToOutlet (x, outlet, atoms.Length, atoms);
- }
- public static void SendToOutlet (IntPtr x, int outlet, int i)
- {
- Atom [] atoms = new Atom[1];
- atoms[0] = new Atom((float) i);
- ToOutlet (x, outlet, atoms.Length, atoms);
- }
- public static void SendToOutlet (IntPtr x, int outlet, string s)
- {
- Atom [] atoms = new Atom[1];
- atoms[0] = new Atom(s);
- ToOutlet (x, outlet, atoms.Length, atoms);
- }
-
- // create an outlet
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern static void CreateOutlet (IntPtr x, int type);
- // function called by the user
- public static void AddOutlet(IntPtr x, ParametersType type)
- {
- CreateOutlet (x, (int) type);
- }
-
- // create an inlet
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern static void CreateInlet (IntPtr x, string selector, int type);
- // function called by the user
- public static void AddInlet(IntPtr x, string selector, ParametersType type)
- {
- CreateInlet (x, selector, (int) type);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void PostMessage (string message);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void ErrorMessage (string message);
-
- }
-
-
-
-
-}
diff --git a/pd/pd.csproj b/pd/pd.csproj
index 915ac50..29dcf7d 100755
--- a/pd/pd.csproj
+++ b/pd/pd.csproj
@@ -36,7 +36,7 @@
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
- OutputPath = "bin\Debug\"
+ OutputPath = "..\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
@@ -94,7 +94,7 @@
BuildAction = "Compile"
/>
<File
- RelPath = "pd.cs"
+ RelPath = "PureData.cs"
SubType = "Code"
BuildAction = "Compile"
/>