Jump to content

Recommended Posts

Posted

Hi,

i don´t know if anybody in here already did some

Midi programing in C?  (serge?) ;)

we´ve got a problem with receiving sysex-messages. to receive a sysex message you have to call the method "midiInAddBuffer" to provice a buffer where the sysex-data can be stored in. you have to call it for every package of the message.

this works great so far - but the problem is if i close the Indevice now and try to open it again it crashes.

if i call "midiInAddBuffer" only once at the beginning, i can reveive only the first package for sure, but now i can close and open the device without any problems.

has anyone an idea what we do wrong?

thanks

tazumi

Posted

We're using the standard Windows midi api.

I do not have the source code here, so I will try to explain what I do in the code.

I open a midi device with the midiInOpen function. I also defined a callback function, where I can receive the messages.

After opening the device I start the receiving with midiInStart and add a buffer with midiInAddBuffer.

Before adding the buffer I prepare it with midiInPrepareHeader. It all works fine. Now I can receive SysEx messages (and other midi messages).

But only the first block. To receive more than one block I make another call of midiInAddBuffer in the callback function (after I received a block). Now I can receive all the other blocks, too.

But the device doesn't close (midiInClose) right now and I cannot open it anymore. Do I have to do something else, before calling the second time midiInAddBuffer.

I will post the source code as soon as possible.

Guest jtbalogh
Posted

Everything you did looks okay. Now use the complimentary midiInUnprepareHeader() too. Always unprepare before using each sysex and before closing.

Initialize:

- open with midiInOpen() using callback function

- prepare with midiInPrepareHeader() for next sysex

- buffer with midiInAddBuffer() for next sysex

- start with midiInStart()

In callback function:

- unprepare with midiInUnprepareHeader() old sysex

- analyze or use the sysex data retrieved

- prepare with midiInPrepareHeader() for next sysex

- buffer with midiInAddBuffer() for next sysex

- exit

When closing application:

- stop with midiInStop()

- reset with midiInReset()

- unprepare with midiInUnprepareHeader() old sysex

- close with midiInClose()

Something like this helped me in windows c programming. This was extracted from my more complicated code so forgive any errors in the suggestions.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...