May 01, 2024, 04:32:06 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dereferencing a pointer supplied by a callback function

Started by SMartin, February 10, 2007, 08:02:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SMartin

February 10, 2007, 08:02:45 PM Last Edit: February 10, 2007, 08:07:15 PM by Paul Turley
I'm writing an app in Aurora to log and date/time stamp midi traffic moving through my control system at work.
Occasionally a device (animatronic bear, Richmond Sound Design Audiobox) will miss a cue and it's nice to know if it was indeed sent the cue.

I've got the program responding to Channel related messages and sysex message now, but I haven't written the message parsers yet.

Here's the problem I'm had...and my cludge around it (for now)

I'm using a callback function to receive the incomming midi. One of the function's parameters (dwParam1) will either be filled with a four byte encoded Channel message or with a pointer to one of 16 MidiInHeader structures I've supplied to the driver for System Exclusive messages. The MidiInHeader pointers are located in an array...

MidiInHeader *InHeaders[16];

In the case of sysex messages I thought I would just be able to dereference the param ...*(MidiInHeader)dwParam1->lpData....and get to the structure memebers.
I couldn't figure out how to make that work and ended up just looping through the array that holds the MidiInHeader pointers and finding the MidiInHeader pointer in the array that matches the passed dwParam1 value. Once I had the index into the array I was able to get to the structure members thus ...InHeader[ x ]->lpdata and so on.

So, anyway, it works...but it just seems like it's too complicated. I've got to be doing this the hard way...(or at least the ugly way).

It's been a long time since I've done anything C or C++ ..ish and I'm very new to Aurora so I would appreciate any help you can give me on this.

Below is the callback function that windows is calling and the function I'm using (for now) to grab the sysex data.



MidiLog::OnMidiIn(UInt hMidiIn,UInt wMsg,UInt dwInstance,UInt dwParam1,UInt dwParam2)
{
Select (wMsg)
{
Case InDeviceOpened:
sbMain->SetPaneText(1,"Midi Activity: In Device Open Event");
Case InDeviceClosed:
sbMain->SetPaneText(1,"Midi Activity: In Device Close Event");
Case InChannelMessage:
sbMain->SetPaneText(1,"Midi Activity: In Device Channel Event");
OnMidiInChannelMessage(dwParam1,dwParam2);
Case InSysexMessage:
sbMain->SetPaneText(1,"Midi Activity: In Device Sysex Event");
OnMidiInSysexMessage(dwParam1,dwParam2);
Case InChannelError:
sbMain->SetPaneText(1,"Midi Activity: In Device Channel Error Event");
Case InSysexError:
sbMain->SetPaneText(1,"Midi Activity: In Device Sysex Error Event");
Case InMoreData:
sbMain->SetPaneText(1,"Midi Activity: In Device More Data Event");
Default:
MessageBox(This,"Unhandled Message","Message In");
}
}

MidiLog::OnMidiInSysexMessage(UInt Buffer,UInt RawTimestamp)
{
If (InRunning) //are we running
{

//find the buffer that got returned
While InHeaders[CurBuffer]<>Buffer
{
CurBuffer++;
If (CurBuffer==InBuffers){CurBuffer=0;}

}
InDevUnprepareHeader(mInDeviceHandle,InHeaders[CurBuffer]);

Int x;
Unsigned Byte SMsg[InBufferSize];
String HexSysexMessage="";
String LilS;
Unsigned Byte *Loc = InHeaders[CurBuffer]->lpData;
//transfer the sysex data from the buffer
For (x=0;x<InHeaders[CurBuffer]->dwBytesRecorded;x++)
{
SMsg[x]=*Loc;
Loc++;
}
//make a string out of it
For (x=0;x<InHeaders[CurBuffer]->dwBytesRecorded;x++)
{
LilS=NumToHex(SMsg[x]);
If (Len(LilS)==1){LilS="0"+LilS;}
LilS+=" ";
HexSysexMessage+=LilS;
}
//present the data
tbxChannelWatch->SetText(HexSysexMessage + chr$(13) + chr$(10) + tbxChannelWatch->GetText());
//put the buffer back into service
InDevPrepareHeader(mInDeviceHandle,InHeaders[CurBuffer]);
InDevAddBuffer(mInDeviceHandle,InHeaders[CurBuffer]);

CurBuffer++; //increment the best guess for the next buffer
If (CurBuffer==InBuffers){CurBuffer=0;}

}
}

Thanks in advance,
Steve Martin



Ionic Wind Support Team

If you are using a dereference then the dot operator is the one to use:

*(MidiInHeader)dwParam1.lpData

The arror operator is only valid for a typed pointer.
Ionic Wind Support Team

SMartin

Paul,

Thanks, that's was what I was doing wrong.

That simplifies the code quite a bit.

Steve...