Subversion Repositories svn.mios32

Rev

Rev 78 | Rev 89 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
32 tk 1
// $Id: mios32_midi.c 80 2008-10-13 23:26:38Z tk $
2
/*
3
 * MIDI layer functions for MIOS32
4
 *
33 tk 5
 * the mios32_midi_package_t format complies with USB MIDI spec (details see there)
6
 * and is used for transfers between other MIDI ports as well.
7
 *
32 tk 8
 * ==========================================================================
9
 *
10
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
11
 *  Licensed for personal non-commercial use only.
12
 *  All other rights reserved.
13
 *
14
 * ==========================================================================
15
 */
16
 
17
/////////////////////////////////////////////////////////////////////////////
18
// Include files
19
/////////////////////////////////////////////////////////////////////////////
20
 
21
#include <mios32.h>
22
 
23
// this module can be optionally disabled in a local mios32_config.h file (included from mios32.h)
24
#if !defined(MIOS32_DONT_USE_MIDI)
25
 
26
 
27
/////////////////////////////////////////////////////////////////////////////
28
// Global variables
29
/////////////////////////////////////////////////////////////////////////////
30
 
80 tk 31
// this global array is read from MIOS32_IIC_MIDI and MIOS32_UART_MIDI to
32
// determine the number of MIDI bytes which are part of a package
33
const u8 mios32_midi_pcktype_num_bytes[16] = {
34
  0, // 0: invalid/reserved event
35
  0, // 1: invalid/reserved event
36
  2, // 2: two-byte system common messages like MTC, Song Select, etc.
37
  3, // 3: three-byte system common messages like SPP, etc.
38
  3, // 4: SysEx starts or continues
39
  1, // 5: Single-byte system common message or sysex sends with following single byte
40
  2, // 6: SysEx sends with following two bytes
41
  3, // 7: SysEx sends with following three bytes
42
  3, // 8: Note Off
43
  3, // 9: Note On
44
  3, // a: Poly-Key Press
45
  3, // b: Control Change
46
  2, // c: Program Change
47
  2, // d: Channel Pressure
48
  3, // e: PitchBend Change
49
  1  // f: single byte
50
};
32 tk 51
 
80 tk 52
 
32 tk 53
/////////////////////////////////////////////////////////////////////////////
54
// Local variables
55
/////////////////////////////////////////////////////////////////////////////
56
 
57
 
58
/////////////////////////////////////////////////////////////////////////////
59
// Initializes MIDI layer
34 tk 60
// IN: <mode>: 0: MIOS32_MIDI_Send* works in blocking mode - function will
61
//                (shortly) stall if the output buffer is full
62
//             1: MIOS32_MIDI_Send* works in non-blocking mode - function will
63
//                return -2 if buffer is full, the caller has to loop if this
64
//                value is returned until the transfer was successful
65
//                A common method is to release the RTOS task for 1 mS
66
//                so that other tasks can be executed until the sender can
67
//                continue
32 tk 68
// OUT: returns < 0 if initialisation failed
69
/////////////////////////////////////////////////////////////////////////////
70
s32 MIOS32_MIDI_Init(u32 mode)
71
{
72
  s32 ret = 0;
73
 
34 tk 74
  // currently only mode 0 and 1 (blocking/non-blocking) supported
75
  if( mode != 0 && mode != 1 )
32 tk 76
    return -1; // unsupported mode
77
 
78
#if !defined(MIOS32_DONT_USE_USB)
78 tk 79
  if( MIOS32_USB_MIDI_Init(mode) < 0 )
32 tk 80
    ret |= (1 << 0);
81
#endif
82
 
80 tk 83
#if !defined(MIOS32_DONT_USE_UART) && !defined(MIOS32_DONT_USE_UART_MIDI)
84
  if( MIOS32_UART_MIDI_Init(mode) < 0 )
85
    ret |= (1 << 1);
86
#endif
87
 
78 tk 88
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
89
  if( MIOS32_IIC_MIDI_Init(mode) < 0 )
80 tk 90
    ret |= (1 << 2);
78 tk 91
#endif
92
 
32 tk 93
  return -ret;
94
}
95
 
96
 
97
/////////////////////////////////////////////////////////////////////////////
78 tk 98
// This function checks the availability of a MIDI port
99
// IN: <port>: MIDI port 
100
//             DEFAULT, USB0..USB7, UART0..UART1, IIC0..IIC7
101
// OUT: 1: port available
102
//      0: port not available
103
/////////////////////////////////////////////////////////////////////////////
104
s32 MIOS32_MIDI_CheckAvailable(mios32_midi_port_t port)
105
{
106
  // if default port: select mapped port
107
  if( !(port & 0xf0) ) {
108
    port = MIOS32_MIDI_DEFAULT_PORT;
109
  }
110
 
111
  // branch depending on selected port
112
  switch( port >> 4 ) {
113
    case 1:
114
#if !defined(MIOS32_DONT_USE_USB) && !defined(MIOS32_DONT_USE_USB_MIDI)
115
      return MIOS32_USB_MIDI_CheckAvailable();
116
#else
117
      return 0; // USB has been disabled
118
#endif
119
 
120
    case 2:
80 tk 121
#if !defined(MIOS32_DONT_USE_UART) && !defined(MIOS32_DONT_USE_UART_MIDI)
122
      return MIOS32_UART_MIDI_CheckAvailable(port & 0xf);
123
#else
124
      return 0; // UART_MIDI has been disabled
125
#endif
78 tk 126
 
127
    case 3:
128
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
129
      return MIOS32_IIC_MIDI_CheckAvailable(port & 0xf);
130
#else
131
      return 0; // IIC_MIDI has been disabled
132
#endif
133
 
134
    case 4:
135
      return 0; // Ethernet not implemented yet
136
 
137
    default:
138
      // invalid port
139
      return 0;
140
  }
141
}
142
 
143
 
144
/////////////////////////////////////////////////////////////////////////////
32 tk 145
// Sends a package over given port
33 tk 146
// This is a low level function - use the remaining MIOS32_MIDI_Send* functions
147
// to send specific MIDI events
32 tk 148
// IN: <port>: MIDI port 
78 tk 149
//             DEFAULT, USB0..USB7, UART0..UART1, IIC0..IIC7
32 tk 150
//     <package>: MIDI package (see definition in mios32_midi.h)
151
// OUT: returns -1 if port not available
34 tk 152
//      returns -2 if non-blocking mode activated: buffer is full
153
//                 caller should retry until buffer is free again
32 tk 154
//      returns 0 on success
155
/////////////////////////////////////////////////////////////////////////////
69 tk 156
s32 MIOS32_MIDI_SendPackage(mios32_midi_port_t port, mios32_midi_package_t package)
32 tk 157
{
80 tk 158
  // if default port: select mapped port
159
  if( !(port & 0xf0) ) {
160
    port = MIOS32_MIDI_DEFAULT_PORT;
161
  }
162
 
32 tk 163
  // insert subport number into package
33 tk 164
  package.type = (package.type&0x0f) | (port << 4);
32 tk 165
 
166
  // branch depending on selected port
167
  switch( port >> 4 ) {
80 tk 168
    case 1:
78 tk 169
#if !defined(MIOS32_DONT_USE_USB) && !defined(MIOS32_DONT_USE_USB_MIDI)
170
      return MIOS32_USB_MIDI_MIDIPackageSend(package);
32 tk 171
#else
172
      return -1; // USB has been disabled
173
#endif
174
 
80 tk 175
    case 2:
176
#if !defined(MIOS32_DONT_USE_UART) && !defined(MIOS32_DONT_USE_UART_MIDI)
177
      return MIOS32_UART_MIDI_PackageSend(package.cable, package);
178
#else
179
      return -1; // UART_MIDI has been disabled
180
#endif
32 tk 181
 
80 tk 182
    case 3:
78 tk 183
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
184
      return MIOS32_IIC_MIDI_PackageSend(package.cable, package);
185
#else
186
      return -1; // IIC_MIDI has been disabled
187
#endif
32 tk 188
 
80 tk 189
    case 4:
32 tk 190
      return -1; // Ethernet not implemented yet
191
 
192
    default:
193
      // invalid port
194
      return -1;
195
  }
196
}
197
 
198
 
199
/////////////////////////////////////////////////////////////////////////////
33 tk 200
// Sends a MIDI Event
201
// This function is provided for a more comfortable use model
202
//    o MIOS32_MIDI_SendNoteOff(port, chn, note, vel)
203
//    o MIOS32_MIDI_SendNoteOn(port, chn, note, vel)
204
//    o MIOS32_MIDI_SendPolyAftertouch(port, chn, note, val)
205
//    o MIOS32_MIDI_SendCC(port, chn, cc, val)
206
//    o MIOS32_MIDI_SendProgramChange(port, chn, prg)
207
//    o MIOS32_MIDI_ChannelAftertouch(port, chn, val)
208
//    o MIOS32_MIDI_PitchBend(port, chn, val)
209
//
210
// IN: <port>: MIDI port 
211
//     <evnt0> <evnt1> <evnt2> up to 3 bytes
212
// OUT: returns -1 if port not available
34 tk 213
//      returns -2 if non-blocking mode activated: buffer is full
214
//                 caller should retry until buffer is free again
33 tk 215
//      returns 0 on success
32 tk 216
/////////////////////////////////////////////////////////////////////////////
69 tk 217
s32 MIOS32_MIDI_SendEvent(mios32_midi_port_t port, u8 evnt0, u8 evnt1, u8 evnt2)
32 tk 218
{
33 tk 219
  mios32_midi_package_t package;
220
 
221
  // MEMO: don't optimize this function by calling MIOS32_MIDI_SendSpecialEvent
222
  // from here, because the 4 * u8 parameter list of this function leads
223
  // to best compile results (4*u8 combined to a single u32)
224
 
225
  package.type  = evnt0 >> 4;
226
  package.evnt0 = evnt0;
227
  package.evnt1 = evnt1;
228
  package.evnt2 = evnt2;
229
  return MIOS32_MIDI_SendPackage(port, package);
32 tk 230
}
231
 
69 tk 232
s32 MIOS32_MIDI_SendNoteOff(mios32_midi_port_t port, mios32_midi_chn_t chn, u8 note, u8 vel)
233
{ MIOS32_MIDI_SendEvent(port, 0x80 | chn, note, vel); }
32 tk 234
 
69 tk 235
s32 MIOS32_MIDI_SendNoteOn(mios32_midi_port_t port, mios32_midi_chn_t chn, u8 note, u8 vel)
236
{ MIOS32_MIDI_SendEvent(port, 0x90 | chn, note, vel); }
237
 
238
s32 MIOS32_MIDI_SendPolyPressure(mios32_midi_port_t port, mios32_midi_chn_t chn, u8 note, u8 val)
239
{ MIOS32_MIDI_SendEvent(port, 0xa0 | chn, note, val); }
240
 
241
s32 MIOS32_MIDI_SendCC(mios32_midi_port_t port, mios32_midi_chn_t chn, u8 cc, u8 val)
242
{ MIOS32_MIDI_SendEvent(port, 0xb0 | chn, cc,   val); }
243
 
244
s32 MIOS32_MIDI_SendProgramChange(mios32_midi_port_t port, mios32_midi_chn_t chn, u8 prg)
245
{ MIOS32_MIDI_SendEvent(port, 0xc0 | chn, prg,  0x00); }
246
 
247
s32 MIOS32_MIDI_SendAftertouch(mios32_midi_port_t port, mios32_midi_chn_t chn, u8 val)
248
{ MIOS32_MIDI_SendEvent(port, 0xd0 | chn, val,  0x00); }
249
 
250
s32 MIOS32_MIDI_SendPitchBend(mios32_midi_port_t port, mios32_midi_chn_t chn, u16 val)
251
{ MIOS32_MIDI_SendEvent(port, 0xe0 | chn, val & 0x7f, val >> 7); }
252
 
253
 
33 tk 254
/////////////////////////////////////////////////////////////////////////////
255
// Sends a special type MIDI Event
256
// This function is provided for a more comfortable use model
69 tk 257
// It is aliased to following functions
33 tk 258
//    o MIOS32_MIDI_SendMTC(port, val)
259
//    o MIOS32_MIDI_SendSongPosition(port, val)
260
//    o MIOS32_MIDI_SendSongSelect(port, val)
261
//    o MIOS32_MIDI_SendTuneRequest()
262
//    o MIOS32_MIDI_SendClock()
263
//    o MIOS32_MIDI_SendTick()
264
//    o MIOS32_MIDI_SendStart()
265
//    o MIOS32_MIDI_SendStop()
266
//    o MIOS32_MIDI_SendContinue()
267
//    o MIOS32_MIDI_SendActiveSense()
268
//    o MIOS32_MIDI_SendReset()
269
//
270
// IN: <port>: MIDI port 
271
//     <type>: the event type
272
//     <evnt0> <evnt1> <evnt2> up to 3 bytes
273
// OUT: returns -1 if port not available
34 tk 274
//      returns -2 if non-blocking mode activated: buffer is full
275
//                 caller should retry until buffer is free again
33 tk 276
//      returns 0 on success
277
/////////////////////////////////////////////////////////////////////////////
69 tk 278
s32 MIOS32_MIDI_SendSpecialEvent(mios32_midi_port_t port, u8 type, u8 evnt0, u8 evnt1, u8 evnt2)
33 tk 279
{
280
  mios32_midi_package_t package;
281
 
282
  package.type  = type;
283
  package.evnt0 = evnt0;
284
  package.evnt1 = evnt1;
285
  package.evnt2 = evnt2;
286
  return MIOS32_MIDI_SendPackage(port, package);
287
}
288
 
289
 
69 tk 290
s32 MIOS32_MIDI_SendMTC(mios32_midi_port_t port, u8 val)
291
{ MIOS32_MIDI_SendSpecialEvent(port, 0x2, 0xf1, val, 0x00); }
292
 
293
s32 MIOS32_MIDI_SendSongPosition(mios32_midi_port_t port, u16 val)
294
{ MIOS32_MIDI_SendSpecialEvent(port, 0x3, 0xf2, val & 0x7f, val >> 7); }
295
 
296
s32 MIOS32_MIDI_SendSongSelect(mios32_midi_port_t port, u8 val)
297
{ MIOS32_MIDI_SendSpecialEvent(port, 0x2, 0xf3, val, 0x00); }
298
 
299
s32 MIOS32_MIDI_SendTuneRequest(mios32_midi_port_t port)
300
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xf6, 0x00, 0x00); }
301
 
302
s32 MIOS32_MIDI_SendClock(mios32_midi_port_t port)
303
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xf8, 0x00, 0x00); }
304
 
305
s32 MIOS32_MIDI_SendTick(mios32_midi_port_t port)
306
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xf9, 0x00, 0x00); }
307
 
308
s32 MIOS32_MIDI_SendStart(mios32_midi_port_t port)
309
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xfa, 0x00, 0x00); }
310
 
311
s32 MIOS32_MIDI_SendStop(mios32_midi_port_t port)
312
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xfb, 0x00, 0x00); }
313
 
314
s32 MIOS32_MIDI_SendContinue(mios32_midi_port_t port)
315
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xfc, 0x00, 0x00); }
316
 
317
s32 MIOS32_MIDI_SendActiveSense(mios32_midi_port_t port)
318
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xfe, 0x00, 0x00); }
319
 
320
s32 MIOS32_MIDI_SendReset(mios32_midi_port_t port)
321
{ MIOS32_MIDI_SendSpecialEvent(port, 0x5, 0xff, 0x00, 0x00); }
322
 
323
 
33 tk 324
/////////////////////////////////////////////////////////////////////////////
325
// Sends a SysEx Stream
326
// This function is provided for a more comfortable use model
327
// IN: <port>: MIDI port 
328
//     <stream>: pointer to SysEx stream
329
//     <count>: number of bytes
330
// OUT: returns -1 if port not available
34 tk 331
//      returns -2 if non-blocking mode activated: buffer is full
332
//                 caller should retry until buffer is free again
33 tk 333
//      returns 0 on success
334
/////////////////////////////////////////////////////////////////////////////
69 tk 335
s32 MIOS32_MIDI_SendSysEx(mios32_midi_port_t port, u8 *stream, u32 count)
33 tk 336
{
337
  s32 res;
338
  u32 offset;
339
  mios32_midi_package_t package;
340
 
341
  // MEMO: have a look into the project.lss file - gcc optimizes this code pretty well :)
342
 
343
  for(offset=0; offset<count;) {
344
    // package type depends on number of remaining bytes
345
    switch( count-offset ) {
346
      case 1:
347
    package.type = 0x5; // SysEx ends with following single byte. 
348
    package.evnt0 = stream[offset++];
349
    package.evnt1 = 0x00;
350
    package.evnt2 = 0x00;
351
    break;
352
      case 2:
353
    package.type = 0x6; // SysEx ends with following two bytes.
354
    package.evnt0 = stream[offset++];
355
    package.evnt1 = stream[offset++];
356
    package.evnt2 = 0x00;
357
    break;
358
      case 3:
359
    package.type = 0x7; // SysEx ends with following three bytes. 
360
    package.evnt0 = stream[offset++];
361
    package.evnt1 = stream[offset++];
362
    package.evnt2 = stream[offset++];
363
    break;
364
      default:
365
    package.type = 0x4; // SysEx starts or continues
366
    package.evnt0 = stream[offset++];
367
    package.evnt1 = stream[offset++];
368
    package.evnt2 = stream[offset++];
369
    }
370
 
371
    while( (res=MIOS32_MIDI_SendPackage(port, package)) == -2 ) {
34 tk 372
      // TODO: SysEx always sent in blocking mode to avoid inconsistent stream!
373
      // We poll until buffer is free again.
33 tk 374
      // Are there better ways?
375
    }
376
 
377
    // other expection? (e.g., port not available)
378
    if( res < 0 )
379
      return res;
380
  }
381
 
382
  return 0;
383
}
384
 
385
 
386
/////////////////////////////////////////////////////////////////////////////
387
// Checks for incoming MIDI messages, calls either the callback_event or
388
// callback_sysex function with following parameters:
69 tk 389
//    callback_event(mios32_midi_port_t port, mios32_midi_package_t midi_package)
390
//    callback_sysex(mios32_midi_port_t port, u8 sysex_byte)
33 tk 391
// OUT: returns < 0 on errors
392
/////////////////////////////////////////////////////////////////////////////
393
s32 MIOS32_MIDI_Receive_Handler(void *_callback_event, void *_callback_sysex)
394
{
395
  u8 port;
396
  mios32_midi_package_t package;
397
 
69 tk 398
  void (*callback_event)(mios32_midi_port_t port, mios32_midi_package_t midi_package) = _callback_event;
399
  void (*callback_sysex)(mios32_midi_port_t port, u8 sysex_byte) = _callback_sysex;
33 tk 400
 
78 tk 401
  u8 intf = 0; // interface to be checked
402
  u8 total_packages_forwarded = 0; // number of forwards - stop after 10 forwards to yield some CPU time for other tasks
403
  u8 packages_forwarded = 0;
404
  u8 again = 1;
33 tk 405
  do {
78 tk 406
    // Round Robin
407
    // TODO: maybe a list based approach would be better
408
    // it would allow to add/remove interfaces dynamically
409
    // this would also allow to give certain ports a higher priority (to add them multiple times to the list)
410
    // it would also improve this spagetthi code ;)
411
    s32 error = -1;
412
    switch( intf++ ) {
413
#if !defined(MIOS32_DONT_USE_USB) && !defined(MIOS32_DONT_USE_USB_MIDI)
414
      case 0: error = MIOS32_USB_MIDI_MIDIPackageReceive(&package); port = package.cable; break;
415
#else
416
      case 0: error = -1; break;
417
#endif
80 tk 418
#if !defined(MIOS32_DONT_USE_UART) && !defined(MIOS32_DONT_USE_UART_MIDI)
419
      case 1: error = MIOS32_UART_MIDI_PackageReceive(0, &package); port = UART0; break;
78 tk 420
#else
421
      case 1: error = -1; break;
422
#endif
80 tk 423
#if !defined(MIOS32_DONT_USE_UART) && !defined(MIOS32_DONT_USE_UART_MIDI)
424
      case 2: error = MIOS32_UART_MIDI_PackageReceive(1, &package); port = UART1; break;
78 tk 425
#else
426
      case 2: error = -1; break;
427
#endif
428
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
80 tk 429
      case 3: error = MIOS32_IIC_MIDI_PackageReceive(0, &package); port = IIC0; break;
78 tk 430
#else
431
      case 3: error = -1; break;
432
#endif
433
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
80 tk 434
      case 4: error = MIOS32_IIC_MIDI_PackageReceive(1, &package); port = IIC1; break;
78 tk 435
#else
436
      case 4: error = -1; break;
437
#endif
438
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
80 tk 439
      case 5: error = MIOS32_IIC_MIDI_PackageReceive(2, &package); port = IIC2; break;
78 tk 440
#else
441
      case 5: error = -1; break;
442
#endif
443
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
80 tk 444
      case 6: error = MIOS32_IIC_MIDI_PackageReceive(3, &package); port = IIC3; break;
78 tk 445
#else
446
      case 6: error = -1; break;
447
#endif
448
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
80 tk 449
      case 7: error = MIOS32_IIC_MIDI_PackageReceive(4, &package); port = IIC4; break;
78 tk 450
#else
451
      case 7: error = -1; break;
452
#endif
453
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
80 tk 454
      case 8: error = MIOS32_IIC_MIDI_PackageReceive(5, &package); port = IIC5; break;
78 tk 455
#else
456
      case 8: error = -1; break;
457
#endif
80 tk 458
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
459
      case 9: error = MIOS32_IIC_MIDI_PackageReceive(6, &package); port = IIC6; break;
460
#else
461
      case 9: error = -1; break;
462
#endif
463
#if !defined(MIOS32_DONT_USE_IIC) && !defined(MIOS32_DONT_USE_IIC_MIDI)
464
      case 10: error = MIOS32_IIC_MIDI_PackageReceive(7, &package); port = IIC7; break;
465
#else
466
      case 10: error = -1; break;
467
#endif
78 tk 468
      default:
469
    // allow 10 forwards maximum to yield some CPU time for other tasks
470
    if( packages_forwarded && total_packages_forwarded < 10 ) {
471
      intf = 0; // restart with USB
472
      packages_forwarded = 0; // for checking, if packages still have been forwarded in next round
473
    } else {
474
      again = 0; // no more interfaces to be processed
475
    }
476
    error = -1; // empty round - no message
477
    }
33 tk 478
 
78 tk 479
    // message received?
480
    if( error >= 0 ) {
481
      // notify that a package has been forwarded
482
      ++packages_forwarded;
483
      ++total_packages_forwarded;
33 tk 484
 
78 tk 485
      // remove cable number from package (MIOS32_MIDI passes it's own port number)
69 tk 486
      package.cable = 0;
33 tk 487
 
78 tk 488
      // branch depending on package type
33 tk 489
      if( package.type >= 0x8 ) {
490
    callback_event(port, package);
491
      } else {
492
    switch( package.type ) {
493
    case 0x0: // reserved, ignore
494
    case 0x1: // cable events, ignore
495
      break;
496
 
497
    case 0x2: // Two-byte System Common messages like MTC, SongSelect, etc. 
498
    case 0x3: // Three-byte System Common messages like SPP, etc. 
499
      callback_event(port, package); // -> forwarded as event
500
      break;
501
    case 0x4: // SysEx starts or continues (3 bytes)
502
      callback_sysex(port, package.evnt0); // -> forwarded as SysEx
503
      callback_sysex(port, package.evnt1); // -> forwarded as SysEx
504
      callback_sysex(port, package.evnt2); // -> forwarded as SysEx
505
      break;
506
    case 0x5: // Single-byte System Common Message or SysEx ends with following single byte. 
507
      if( package.evnt0 >= 0xf8 )
508
        callback_event(port, package); // -> forwarded as event
509
      else
510
        callback_sysex(port, package.evnt0); // -> forwarded as SysEx
511
      break;
512
    case 0x6: // SysEx ends with following two bytes.
513
      callback_sysex(port, package.evnt0); // -> forwarded as SysEx
514
      callback_sysex(port, package.evnt1); // -> forwarded as SysEx
515
      break;
516
    case 0x7: // SysEx ends with following three bytes.
517
      callback_sysex(port, package.evnt0); // -> forwarded as SysEx
518
      callback_sysex(port, package.evnt1); // -> forwarded as SysEx
519
      callback_sysex(port, package.evnt2); // -> forwarded as SysEx
520
      break;
521
    }
522
      }
523
    }
524
  } while( again );
525
 
526
  return 0;
527
}
528
 
529
 
32 tk 530
#endif /* MIOS32_DONT_USE_MIDI */