Audiokinetic's Community Q&A is the forum where users can ask and answer questions within the Wwise and Strata communities. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

AkMIDIPost C# Unity Integration

+2 votes
Hello,

I've been looking at the example of what seems like calling custom MIDI events to Wwise in the SDK (https://www.audiokinetic.com/library/edge/?source=SDK&id=quickstart__sample__integration__midi.html)

And have been trying to translate it into C# that can be called by Unity.

It seems like I can define the "byChan" and "byType" of my AkMIDIPost instance, but when I try to define "NoteOnOff.byNote" and "NoteOnOff.byVelocity", the namespace doesn't recognize these things. Is this not possible in C# Unity Integration?
asked Aug 9, 2016 in General Discussion by Aaron I. (220 points)

1 Answer

0 votes

Hi Aaron,

I just ran into this same issue. I think it's a Wwise bug - Wwise is using SWIG to wrap its C++ API for C# in Unity. It seems like this SWIG code was generated in an automated fashion, and didn't take inheritance into account - the AkMidiPost type inherits from their MIDI event type, which has all of the stuff you need. However getters and setters are not implemented, which you can see by looking at either the SoundEngine_wrap.cxx file located in the AkSoundEngine source, or in the generated AkSoundEnginePINVOKE_Windows.cs file generated with your Unity integration (Windows because I'm on Windows, presumably.) 

The fix is to add getters and setters for the MIDI data you need, but I would stay away unless you're familiar with C/C++ (or at least know what unions and structs are.) I think this is something that AK will have to implement in a future update. 

Her'e's how I did byNote and byVelocity - however, because those two are part of a struct that's part of a union, you have to be careful about context (and I'm sure AK wouldn't publish code like this)


SoundEngine_wrap.cxx

[code]

SWIGEXPORT void SWIGSTDCALL CSharp_AkMIDIPost_tNoteOnOff_byNote_set( void * jarg1, byte jarg2 )
{
    AkMIDIPost *arg1 = (AkMIDIPost *) 0;
    AkUInt8 arg2, arg3;
    arg1 = (AkMIDIPost *) jarg1;
    arg2 = (AkUInt8) jarg2;
    if ( arg1 )
    {
        arg1->NoteOnOff.byNote = arg2;
    }
}


SWIGEXPORT unsigned char SWIGSTDCALL CSharp_AkMIDIPost_tNoteOnOff_byNote_get( void * jarg1 )
{
    unsigned char jresult;
    AkMIDIPost *arg1 = (AkMIDIPost *) 0;
    AkUInt8 result;

    arg1 = (AkMIDIPost *) jarg1;
    result = arg1->NoteOnOff.byNote;
    jresult = (unsigned char) result;
    return jresult;
}

SWIGEXPORT void SWIGSTDCALL CSharp_AkMIDIPost_tNoteOnOff_byVelocity_set( void * jarg1, byte jarg2 )
{
    AkMIDIPost *arg1 = (AkMIDIPost *) 0;
    AkUInt8 arg2, arg3;
    arg1 = (AkMIDIPost *) jarg1;
    arg2 = (AkUInt8) jarg2;
    if ( arg1 )
    {
        arg1->NoteOnOff.byVelocity = arg2;
    }
}

SWIGEXPORT unsigned char SWIGSTDCALL CSharp_AkMIDIPost_tNoteOnOff_byVelocity_get( void * jarg1 )
{
    unsigned char jresult;
    AkMIDIPost *arg1 = (AkMIDIPost *) 0;
    AkUInt8 result;

    arg1 = (AkMIDIPost *) jarg1;
    result = arg1->NoteOnOff.byVelocity;
    jresult = (unsigned char) result;
    return jresult;
}

[/code]


AkSoundEnginePINVOKE_Windows.cs

[code]

    [DllImport("AkSoundEngine", EntryPoint = "CSharp_AkMIDIPost_tNoteOnOff_byNote_set")]
    public static extern void CSharp_AkMIDIPost_tNoteOnOff_byNote_set(IntPtr jarg1, byte jarg2);
    [DllImport("AkSoundEngine", EntryPoint = "CSharp_AkMIDIPost_tNoteOnOff_byNote_get")]
    public static extern byte CSharp_AkMIDIPost_tNoteOnOff_byNote_get(IntPtr jarg1);

    [DllImport("AkSoundEngine", EntryPoint = "CSharp_AkMIDIPost_tNoteOnOff_byVelocity_set")]
    public static extern void CSharp_AkMIDIPost_tNoteOnOff_byVelocity_set(IntPtr jarg1, byte jarg2);
    [DllImport("AkSoundEngine", EntryPoint = "CSharp_AkMIDIPost_tNoteOnOff_byVelocity_get")]
    public static extern byte CSharp_AkMIDIPost_tNoteOnOff_byVelocity_get(IntPtr jarg1);

[/code]


AkMIDIPost.cs

[code]

    public byte byNote
    {
        set
        {
            AkSoundEnginePINVOKE.CSharp_AkMIDIPost_tNoteOnOff_byNote_set(swigCPtr, value);

        }
        get
        {
            byte ret = AkSoundEnginePINVOKE.CSharp_AkMIDIPost_tNoteOnOff_byNote_get(swigCPtr);

            return ret;
        }
    }
    public byte byVelocity
    {
        set
        {
            AkSoundEnginePINVOKE.CSharp_AkMIDIPost_tNoteOnOff_byVelocity_set(swigCPtr, value);

        }
        get
        {
            byte ret = AkSoundEnginePINVOKE.CSharp_AkMIDIPost_tNoteOnOff_byVelocity_get(swigCPtr);

            return ret;
        }
    }

[/code]

 

Sorry for any formatting issues...

answered Feb 23, 2017 by John J. (340 points)
Even more broken now?
...