Jump to content

midi programing in C: sysex-problem


tazumi

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest jtbalogh

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...