Cabbage Logo
Back to Cabbage Site

Exposing csoundRewindScore in CsoundUnity

Hiya all, been using CsoundUnity and its class, but have found myself in need of csound’s rewindScore function, I tried my hand at exposing it:
[DllImport(_dllVersion, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern void csoundRewindScore([In] IntPtr csound);
in CsoundCsharp.cs,
public void RewindScore()
{
Csound6.NativeMethods.csoundRewindScore(csound);
}
in CsoundUnityBridge.cs, and
public void RewindScore()
{
csound.RewindScore();
}
in CsoundUnity.cs
So doing that means i can call CsoundUnity.RewindScore(), but doing so crashes the program, its totally feesible me doing that is misguided, I’m the first to admit that I basically don’t know how dlls work, but yeah, any advice would be unreal (pardon the pun)
Cheers dudes

Looks good to me.
Try removing some attributes in the DllImport, since you aren’t passing any string.

[DllImport(_dllVersion, CallingConvention = CallingConvention.Cdecl)]
internal static extern void csoundRewindScore([In] IntPtr csound);

Are you using the develop branch or the 2.3 release of CsoundUnity?

1 Like

Oh really? Will drop the extra attributes, I thought maybe that meant to read the actual symbol name from the dll as ansi rather than the args
I’m using a version Rory imported into our repo, so I think it’s probably latest develop

Yeah okay that works to expose it, turns out I’m dumb and actually want the csdl rewindScore function (to clear the score event buffer) but realised I can literally write a plugin opcode that just does that, ah well at least I learned something along the way!
And yeah for anyone wanting to add more function bindings, you just need to declare a public function in CsoundUnityBridge.cs which calls your imported dll function (so for example, Csound6.NativeEvents.csoundRewindScore(csound); and then also declare a public function that calls your newly wrapped method in CsoundUnity.cs!
Cheers Giovanni!

1 Like