Jump to content

How to read a sysex message in C-program?


ReinerS

Recommended Posts

Hello all,

I have been using Mido128 for quite a while now to control the Hauptwerk virtual organ software from my old organ console. This works fine, but now I want to show the Hauptwerk status messages, which are send as text wrapped in a sysex message, on the LCD connected to the core. I have looked into modifying the assembler version of the midio128 application, but since I never worked with assembler before, it all looks very strange to me.

So now I am looking into the C-wrapper for Mios and the Ain64-Din128-Dout128 example, and this looks a lot easier and more familiar to me. I got the toolchain working, so I can change code, compile and upload to the core without problem.

However, I cannot find an example here on how to read a sysex-message in a MIOS-C-program. Can anyone point me to an example or post some sample code how this can be done?

Many thanks

Reiner

Link to comment
Share on other sites

Hello Reiner,

basically a SysEx Message consists only of two "known" bytes, that is:

SysEx Start (CC 240 / 0xF0)

... a lot of customized data ...

SysEx Stop ("EOX: End of SysEx", CC 247 0xF7)

What's in between those two bytes depends on the manufacturer, in your case Hauptwerk. So either you'll find some internet docu or you may try to decode it by yourself (which may be quite difficult if it's not open :P )

You can download the MM-Application (from the C-Section of the download-page @ucApps), IIRC there should be a SysEx implementation that shows you how to implement SysEx reading/writing in your code once the protocol issue has been solved.

Best Regards,

Michael

Link to comment
Share on other sites

Hello Michael,

thanks for the link to the programming example, that was the missing piece!

I simply didn't think about the MPROC_NotifyReceivedByte function and was looking for something that delivers the content of a sysex message directly. But of course it is straightforward to program that myself following the example.

The message content for the Hauptwerk status message is public and well documented, so there is no problem here.

BTW, how is the hierarchy between the MPROC_Notify functions? When e.g. a Note_On is received, will MIOS call the ReceivedByte function three times (upon each byte) and then the ReceivedEvent function after it has decoded the event? Or is the ReceivedByte not called when standard events are received? (Doesn't make a difference for my programming, but just out of curiosity).

Again, thanks for your help!

And also thanks to Thorsten for this wonderful and well documented software!

Reiner

Link to comment
Share on other sites

Hi Reiner,

BTW, how is the hierarchy between the MPROC_Notify functions? When e.g. a Note_On is received, will MIOS call the ReceivedByte function three times (upon each byte) and then the ReceivedEvent function after it has decoded the event? Or is the ReceivedByte not called when standard events are received? (Doesn't make a difference for my programming, but just out of curiosity).

MPROC_Notify_ReceivedByte(unsigned char byte) is only called for single byte events, such as realtime messages (for example), whereas MPROC_Notify_ReceivedEvent(byte0, byte1, byte2) is for all the remaining 3-byte-messages like Note-Ons/-Offs etc...

Cheers!

Michael

Link to comment
Share on other sites

  • 1 year later...

this thread missguided me a bit at first, so here's the result of my research and emails to TK:

-MPROC_Notify_ReceivedByte receives EVERY byte of incoming MIDI-data (status bytes and data bytes). also the bytes later passed to MPROC_Notify_ReceivedEvent

-MPROC_Notify_ReceivedEvent receives all channel-voice and channel-mode messages

[glow=red,2,300]so this quote is completly wrong:[/glow]

MPROC_Notify_ReceivedByte(unsigned char byte) is only called for single byte events, such as realtime messages (for example), whereas MPROC_Notify_ReceivedEvent(byte0, byte1, byte2) is for all the remaining 3-byte-messages like Note-Ons/-Offs etc...

-channel specific (channel-voice, channel-mode) messages have alway evnt0 < 0xf0

-system messages (sysex, system-common, system-realtime) can be handled in MPROC_Notify_ReceivedByte and have always byte >= 0xf0

use this implementation of MPROC_Notify_ReceivedByte to forward all system-messages to the output:

void MPROC_NotifyReceivedByte(unsigned char byte) __wparam{
	//this function forwards all system messages to the output
	static unsigned char fx_status = 0;
	if(byte >= 0xf0){//system status byte
		MIOS_MIDI_TxBufferPut(byte);
	   //determine status
		switch(byte){
			case 0xf1://midi timecode 
			case 0xf3://songselect
				fx_status = 1;
				break; 	
			case 0xf2://songposition pointer
				fx_status = 2;				
				break;
			case 0xf0://sysex, forward until 0xf7
				fx_status = 0xff;
				break;
			default://applies also on 0xf7!
				fx_status = 0;
		 	}   
    	}
  	else if(fx_status){
      MIOS_MIDI_TxBufferPut(byte);
      if(fx_status!=0xff)
      	fx_status--;
   	}
 	}
the above code is a "pimped" version of the code by TK:
void MPROC_NotifyReceivedByte(unsigned char byte) __wparam
{
  static char fx_status;

  // normal MIDI events are forwarded in MPROC_NotifyReceivedEvnt
  // this function handles sysex and realtime messages
  if( byte & 0x80 ) { // Status message
    if( byte >= 0xf0 )
      MIOS_MIDI_TxBufferPut(byte); // transfer byte

    // determine status
    if( byte == 0xf0 ) {
      fx_status = 0xff; // forward until 0xf7
    } else if( byte == 0xf7 ) {
      fx_status = 0;    // f7 reached, no forward
    } else if( byte == 0xf1 || byte == 0xf3 ) {
      fx_status = 1;    // expecting one additional byte
    } else if( byte == 0xf2 ) {
      fx_status = 2;    // expecting two additional bytes
    } else {
      fx_status = 0;    // expecting no additional byte
    }
  } else {
    // check if fx status active
    if( fx_status ) {
      // forward data byte
      MIOS_MIDI_TxBufferPut(byte);

      // decrement counter if required
      if( fx_status != 0xff )
        --fx_status;
    }
  }
}

when you want to manipulate / parse the data, replace MIOS_MIDI_TxBufferPut(byte) with your code

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...