Unfortunately this still crashes as of CsoundUnity version 3.0.1.
Watch out!
The channels can be retrieved with CsoundUnity.channels, but it could be handy to have this method working.
Any expert with native methods?
This is the current definition of the function:
/// <summary>
/// Provides a dictionary of all currently defined channels resulting from compilation of an orchestra
/// containing channel definitions.
/// Entries, keyed by name, are polymorphically assigned to their correct data type: control, audio, string, pvc.
/// Used by the Csound6SoftwareBus class to initialize its contents.
/// </summary>
/// <returns>a dictionary of all currently defined channels keyed by their name to its ChannelInfo</returns>
public IDictionary<string, ChannelInfo> GetChannelList()
{
IDictionary<string, ChannelInfo> channels = new SortedDictionary<string, ChannelInfo>();
IntPtr ppChannels = IntPtr.Zero;
int size = Csound6.NativeMethods.csoundListChannels(csound, out ppChannels);
if ((size > 0) && (ppChannels != IntPtr.Zero))
{
int proxySize = Marshal.SizeOf(typeof(ChannelInfoProxy));
for (int i = 0; i < size; i++)
{
var proxy = Marshal.PtrToStructure(ppChannels + (i * proxySize), typeof(ChannelInfoProxy)) as ChannelInfoProxy;
string chanName = Marshal.PtrToStringAnsi(proxy.name);
ChannelInfo info = new ChannelInfo(chanName, (ChannelType)(proxy.type & 15), (ChannelDirection)(proxy.type >> 4));
var hintProxy = proxy.hints;
var hints = new ChannelHints((ChannelBehavior)hintProxy.behav, hintProxy.dflt, hintProxy.min, hintProxy.max)
{
x = hintProxy.x,
y = hintProxy.y,
height = hintProxy.height,
width = hintProxy.width,
attributes = (hintProxy.attributes != IntPtr.Zero) ? Marshal.PtrToStringAnsi(hintProxy.attributes) : null
};
info.Hints = hints;
channels.Add(chanName, info);
}
Csound6.NativeMethods.csoundDeleteChannelList(csound, ppChannels);
}
return channels;
}
Edit: after some more investigation, the call that makes this crash is:
string chanName = Marshal.PtrToStringAnsi(proxy.name);
Proxy is defined as:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private class ChannelInfoProxy
{
public IntPtr name;
public int type;
[MarshalAs(UnmanagedType.Struct)]
public ChannelHintsProxy hints;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
private struct ChannelHintsProxy
{
public ChannelHintsProxy(ChannelHints hints)
{
behav = (int)hints.behav;
dflt = hints.dflt; min = hints.min; max = hints.max;
x = hints.x; y = hints.y; height = hints.height; width = hints.width;
attributes = IntPtr.Zero;
}
public int behav;
public double dflt;
public double min;
public double max;
public int x;
public int y;
public int width;
public int height;
public IntPtr attributes;
}