Subversion Repositories svn.mios

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
163 tk 1
HEADER 3 MIOS C Example
2
 
3
<H3>Filter out all MIDI events which are not sent on Channel #1</H3>
4
 
5
<P CLASS=INFO>We want to create a MIDI filter, which only forwards MIDI events which are sent over MIDI Channel #1.</P>
6
 
7
<P CLASS=INFO>Copy the SDCC skeleton into a new directory, open the main.c file and enhance the hooks like described below. Thereafter type "make" in the command shell, and upload the new project.hex file to the core.</P>
8
 
9
<TT><PRE>
10
/////////////////////////////////////////////////////////////////////////////
11
//  This function is called by MIOS when a complete MIDI event has been received
12
/////////////////////////////////////////////////////////////////////////////
13
void MPROC_NotifyReceivedEvnt(
14
  unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
15
{
16
  // check MIDI channel, it should be 0 (-> channel #1)
17
  if( (evnt0 & 0x0f) == 0 ) {
18
 
19
    // before forwarding, we have to differ between 2-byte and 3-byte MIDI events!
20
    // for understanding the MIDI coding, please refer to the MIDI spec
21
    // (-> http://www.borg.com/~jglatt/tech/midispec.htm)
22
 
23
    switch( evnt0 & 0xf0 ) {
24
      case 0x80: // Note-Off: 3 bytes
25
      case 0x90: // Note-On: 3 bytes
26
      case 0xa0: // Aftertouch: 3 bytes
27
      case 0xb0: // CC: 3 bytes
28
      case 0xe0: // Pitchbend: 3 bytes
29
        MIOS_MIDI_TxBufferPut(evnt0);
30
        MIOS_MIDI_TxBufferPut(evnt1);
31
        MIOS_MIDI_TxBufferPut(evnt2);
32
        break;
33
      case 0xc0: // Program Change: 2 bytes
34
      case 0xd0: // Poly Aftertouch: 2 bytes
35
        MIOS_MIDI_TxBufferPut(evnt0);
36
        MIOS_MIDI_TxBufferPut(evnt1);
37
        break;
38
      default:
39
        // note: status messages must be handled within MPROC_NotifyReceivedByte()
40
        break;
41
     }
42
  }
43
}
44
</PRE></TT>
45
 
46
<P CLASS=INFO>If SysEx or Realtime messages should be forwarded as well, then you need to enhance the MPROC_NotifyReceivedByte() function like shown below:</P>
47
 
48
<TT><PRE>
49
/////////////////////////////////////////////////////////////////////////////
50
// This function is called by MIOS when a MIDI byte has been received
51
/////////////////////////////////////////////////////////////////////////////
52
void MPROC_NotifyReceivedByte(unsigned char byte) __wparam
53
{
54
  static char fx_status;
55
 
56
  // normal MIDI events are forwarded in MPROC_NotifyReceivedEvnt
57
  // this function handles sysex and realtime messages
58
  if( byte & 0x80 ) { // Status message
59
    if( byte >= 0xf0 )
60
      MIOS_MIDI_TxBufferPut(byte); // transfer byte
61
 
62
    // determine status
63
    if( byte == 0xf0 ) {
64
      fx_status = 0xff; // forward until 0xf7
65
    } else if( byte == 0xf7 ) {
66
      fx_status = 0;    // f7 reached, no forward
67
    } else if( byte == 0xf1 || byte == 0xf3 ) {
68
      fx_status = 1;    // expecting one additional byte
69
    } else if( byte == 0xf2 ) {
70
      fx_status = 2;    // expecting two additional bytes
71
    } else {
72
      fx_status = 0;    // expecting no additional byte
73
    }
74
  } else {
75
    // check if fx status active
76
    if( fx_status ) {
77
      // forward data byte
78
      MIOS_MIDI_TxBufferPut(byte);
79
 
80
      // decrement counter if required
81
      if( fx_status != 0xff )
82
        --fx_status;
83
    }
84
  }
85
}
86
</PRE></TT>
87
 
88
<P CLASS=INFO>A list of available MIOS function can be found <A HREF="cmios_fun.html">here</A>.</P>
89
 
90
FOOTER