2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <proto/dos.h>
12 #include "camd_intern.h"
15 /*****************************************************************************
19 AROS_LH3(void, ParseMidi
,
22 AROS_LHA(struct MidiLink
*, midilink
, A0
),
23 AROS_LHA(UBYTE
*, buffer
, A1
),
24 AROS_LHA(ULONG
, length
, D0
),
27 struct CamdBase
*, CamdBase
, 33, Camd
)
30 Puts a midibuffer to a midilinks clusters midilinks midinodes and hardware.
31 To help understand what it does, the following macro makes PutMidi
32 use ParseMidi instead of calling camd.library's PutMidi function for
35 #define PutMidi(midilink,message) ParseMidi((midilink),&(message),MidiMsgLen(message))
37 (But please don't use this macro, since its not big-endian compatible,
38 and that PutMidi is faster than ParseMidi)
45 If its more convenient to use PutMidi and PutSysEx instead of ParseMidi,
46 do that. ParseMidi is a bit heavier function to use than PutMidi and
49 MLINK_Parse must have be set when calling either AddMidiLinkA or
63 2001-01-12 ksvalast first created
65 *****************************************************************************/
70 /* The implementation of ParseMidi is really a hack. Because I thought
71 the function was supposed to do somthing else when I started implementing
72 camd.library. But when I saw that PlayMF only uses
73 ParseMidi for sending midi, and after reading PlayMF's source, it came
74 pretty clear what ParseMidi is supposed to do. I'm allso quite shure that this
75 hack should work nice (PlayMF works ok now), but the code is
78 What it does is to simulate a hardware-driver input-stream
79 and calling some receiver-functions in MidiFromDriver.c. SysEx to
80 hardware couldn't be handled that way because the buffer
81 might have realtime-messages inside a sysex-message (you never
82 know :), so that is treated seperately.
87 struct DriverData
*driverdata
=midilink
->ml_ParserData
;
88 struct DriverData
*TOdriverdata
=NULL
;
91 if(driverdata
==NULL
) return;
93 driverdata
->lastsysex
=NULL
;
94 driverdata
->Input_Treat
=Receiver_init
;
100 if(TOdriverdata
==NULL
){
101 if(midilink
->ml_Location
!=NULL
){
102 ObtainSemaphoreShared(CB(CamdBase
)->CLSemaphore
);
103 TOdriverdata
=FindReceiverDriverInCluster(midilink
->ml_Location
);
104 ReleaseSemaphore(CB(CamdBase
)->CLSemaphore
);
107 if(TOdriverdata
!=NULL
){
108 driverdata
->lastsysex
=buffer
;
113 Receiver_RealTime(driverdata
,data
);
115 (*driverdata
->Input_Treat
)(driverdata
,data
);
118 if(driverdata
->lastsysex
!=NULL
&& data
>=0x80 && data
<0xf8 && data
!=0xf0){
120 ObtainSemaphore(&TOdriverdata
->sysexsemaphore
);
122 TOdriverdata
->buffer_sx
=driverdata
->lastsysex
;
123 TOdriverdata
->buffercurrsend_sx
=0;
124 TOdriverdata
->issending_sx
=1;
126 while(SysEx2Driver(TOdriverdata
,driverdata
->lastsysex
)==FALSE
) CamdWait();
127 while(TOdriverdata
->issending_sx
!=0) CamdWait();
129 ReleaseSemaphore(&TOdriverdata
->sysexsemaphore
);
131 driverdata
->lastsysex
=NULL
;