5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
13 # include <exec/types.h>
15 #ifndef EXEC_LIBRARIES_H
16 # include <exec/libraries.h>
20 # define AROS_LIBFUNC_INIT
21 # define AROS_LIBFUNC_EXIT
23 # define aros_print_not_implemented(a) kprintf("camd.library: "a" is not implemented\n");
25 # define aros_print_not_implemented(a) DebugPrintF("camd.library: "a" is not implemented\n");
27 # define AROS_PTRALIGN 2
29 # ifndef AROS_LIBCALL_H
30 # include <aros/libcall.h>
37 #ifndef UTILITY_UTILITY_H
38 # include <utility/utility.h>
42 # include <midi/camd.h>
45 #ifndef MIDI_CAMDDEVICES_H
46 # include <midi/camddevices.h>
49 #ifndef EXEC_SEMAPHORES_H
50 # include <exec/semaphores.h>
53 # include <exec/memory.h>
55 #ifndef DOS_DOSEXTENS_H
56 #include <dos/dosextens.h>
62 # include <aros/debug.h>
67 # include <libcore/base.h>
68 # include <interfaces/camd.h>
69 # define CAMD_LIBBASE_DECL(a,b) a b = (a) ICamd->Data.LibBase;
74 /****************************************************************************************/
76 #define OUTBUFFERSIZE 1025
77 #define OUTBUFFERSIZE_RT 1025
78 #define RECEIVERPROCBUFFERSIZE 1025
79 #define SYSEXRECEIVERPROCBUFFERSIZE 1025
80 #define NUMBEROFSYSEXSTORECEIVE 1025
82 struct MyMidiMessage2
{
90 struct MidiCluster cluster
;
91 struct SignalSemaphore semaphore
;
95 struct Node outnode
; // Used for the outcluster's receiverlist
96 struct Node innode
; // Used for the incluster's senderlist
98 struct Drivers
*driver
;
99 struct MyMidiCluster
*incluster
; // Clusters we belong to.
100 // in = sender cluster
101 // out = receiver cluster
102 struct MyMidiCluster
*outcluster
;
103 struct MidiPortData
*midiportdata
;
104 struct MidiDeviceData
*mididevicedata
;
107 BOOL isInOpen
; // Driver is opened if at least one of these two ones is TRUE
110 ULONG
*buffer
; // Sendbuffer start
111 ULONG
*buffercurrsend
; // Sendbuffer write
112 ULONG
*buffercurr
; // Sendbuffer read
113 ULONG
*bufferend
; // Sendbuffer end
115 int sendpos
; // 0,1 or 2. Position in current sendmessage. (Is only 0 at startup, so 1 or 2 are the only used values)
116 int status
; // Current send running status
118 int unsent
; // Number of messages waiting to be sent
119 int unsent_rt
; // Number of realtime messages waiting to be sent
120 int issending_sx
; // =1 if a sysex message is currently being sent.
122 int buffercurrsend_sx
; // Number of bytes in the current sysex message being sent.
123 UBYTE
*buffer_sx
; // Pointer to user-suplied sysex message
124 int unsent_sx
; // Used by miditodriver_oldformat
126 UBYTE
*buffer_rt
; // Realtime sendbuffer start
127 UBYTE
*buffercurrsend_rt
; // Realtime sendbuffer write
128 UBYTE
*buffercurr_rt
; // Realtime sendbuffer read
129 UBYTE
*bufferend_rt
; // Realtime sendbuffer end
130 int isnowtransmitting
; // Used by mididitodriver_oldformat
132 int realtimesysx
; // =1 if the current sysex message being sent is realtime.
134 ULONG (*transmitfunc
)( // Virtual function for the transmitter driver-code.
135 struct DriverData
*driverdata
138 struct MyMidiMessage2 msg2
; // In-message, to be supplied to the midinodes.
140 struct SignalSemaphore sendsemaphore
; // Obtained when putting message to driver
141 struct SignalSemaphore sysexsemaphore
; // Obtained when putting sysex to driver.
143 void (*Input_Treat
)( // Virtual function for the receiver driver-code.
144 struct DriverData
*driverdata
,
149 // The following datas are for the ReceiverProcess.
151 struct Process
*ReceiverProc
;
160 // To know the status of a ReceiverProcess. 0=not alive, or not initialized yet. 1=alive and fine. 2=signal failed.
161 LONG isReceiverProcessAlive
;
162 // Keep pointer so it can be freed after the process dies.
163 char *ReceiverProcName
;
165 // The following is for ParseMidi
170 struct Drivers
*next
;
173 struct MidiDeviceData
*mididevicedata
;
174 struct DriverData
**driverdatas
;
179 struct MidiNode midinode
;
189 MidiMsg
*in_curr_get
;
191 ULONG dummytimestamp
; // To avoid reading from NULL if no timestamp was defined.
193 struct SignalSemaphore receiversemaphore
;
195 // For sysex receiving. (probably needs some rewriting)
197 struct SignalSemaphore sysexsemaphore
;
198 struct SignalSemaphore sysexsemaphore2
;
203 UBYTE
*sysex_laststart
;
205 UBYTE lastreadstatus
;
208 struct CamdBase_intern
{
210 struct Library library
;
214 struct Drivers
*drivers
;
215 struct List mymidinodes
;
216 struct List midiclusters
;
218 struct List clusnotifynodes
;
221 /* Lock semaphore. Obtained Shared before reading various lists and
222 obtained exclusive before adding/deleting to/from various lists. */
224 struct SignalSemaphore
*CLSemaphore
;
229 extern void kprintf(char *bla
,...);
231 # ifndef __amigaos4__
234 # define bug DebugPrintF
240 # ifndef CONST_STRPTR
241 # define CONST_STRPTR const APTR
244 # define VOID_FUNC APTR // Yeah.
246 # define AROS_DEBUG_H_FILE "camd_intern.h" // DoNothing
248 # define AROS_DEBUG_H_FILE <aros/debug.h>
251 /****************************************************************************************/
254 # define CB(b) ((struct CamdBase_intern *)b)
256 /****************************************************************************************/
260 # define NEWLIST(l) (((struct List *)l)->lh_TailPred = (struct Node *)(l),((struct List *)l)->lh_Tail=0,((struct List *)l)->lh_Head = (struct Node *)&(((struct List *)l)->lh_Tail))
264 #ifndef FUNCTIONTABLE
267 struct CamdBase
{struct Library library
;};
268 BYTE
GetMsgLen(LONG msg
);
270 struct MidiLink
*midilink
,
271 struct MyMidiMessage2
*msg2
,
274 void UnlinkMidiLink(struct MidiLink
*midilink
,BOOL unlinkfromnode
,struct CamdBase
*CamdBase
);
275 BOOL
Midi2Driver_internal(
276 struct DriverData
*driverdata
,
280 BOOL
Midi2Driver_internal_oldformat(
281 struct DriverData
*driverdata
,
286 ULONG ASM
Transmitter(REG(a2
) struct DriverData
*driverdata
);
287 ULONG ASM
Transmitter_oldformat(REG(a2
) struct DriverData
*driverdata
);
289 ULONG
Transmitter(struct DriverData
*driverdata
);
290 ULONG ASM
Transmitter_oldformat(REG(a2
, struct DriverData
*driverdata
));
292 BOOL
SysEx2Driver(struct DriverData
*driverdata
,UBYTE
*buffer
);
293 BOOL
SysEx2Driver_oldformat(struct DriverData
*driverdata
, UBYTE
*buffer
);
294 void RemoveCluster(struct MidiCluster
*cluster
,struct CamdBase
*CamdBase
);
295 void LinkHasBeenRemovedFromCluster(struct MidiCluster
*cluster
,struct CamdBase
*CamdBase
);
296 struct MidiCluster
*NewCluster(char *name
,struct CamdBase
*CamdBase
);
297 struct DriverData
*FindReceiverDriverInCluster(struct MidiCluster
*cluster
);
298 struct DriverData
*FindSenderDriverInCluster(struct MidiCluster
*cluster
);
299 BOOL
AddClusterReceiver(
300 struct MidiCluster
*cluster
,
303 struct CamdBase
*CamdBase
305 BOOL
AddClusterSender(
306 struct MidiCluster
*cluster
,
309 struct CamdBase
*CamdBase
311 BOOL
SetClusterForLink(
312 struct MidiLink
*midilink
,
315 struct CamdBase
*CamdBase
318 BOOL
CreateReceiverProc(
319 struct DriverData
*driverdata
,
323 struct CamdBase
*CamdBase
326 void EndReceiverProc(
327 struct DriverData
*driverdata
,
328 struct CamdBase
*CamdBase
331 void Receiver_SysExSuperTreat(
332 struct DriverData
*driverdata
,
335 int GetSysXLen(UBYTE
*buffer
);
336 BOOL
PutSysEx2Link(struct MidiLink
*midilink
,UBYTE data
);
337 void Receiver_SetError(
338 struct DriverData
*driverdata
,
341 void Receiver_RealTime(
342 struct DriverData
*driverdata
,
346 struct DriverData
*driverdata
,
351 struct DriverData
*driverdata
357 REG(a2
) struct DriverData
*driverdata
361 REG(d0
, UWORD input
),
362 REG(a2
, struct DriverData
*driverdata
)
366 extern WORD
MidiMsgType_status(UBYTE status
);
367 extern WORD
MidiMsgType_CMB_Ctrl(UBYTE data1
);
368 extern WORD
MidiMsgType_status_data1(UBYTE status
,UBYTE data1
);
370 BOOL
OpenDriver(struct DriverData
*driverdata
,ULONG
*ErrorCode
,struct CamdBase
*CamdBase
);
371 void CloseDriver(struct DriverData
*driverdata
,struct CamdBase
*CamdBase
);
373 void FreeDriverData(struct Drivers
*driver
,
374 struct CamdBase
*CamdBase
376 void LoadDriver(char *name
,
377 struct CamdBase
*CamdBase
380 struct Drivers
*FindPrevDriverForMidiDeviceData(
381 struct MidiDeviceData
*mididevicedata
,
382 struct CamdBase
*CamdBase
385 ULONG
mystrlen(char *string
);
386 BOOL
mystrcmp(char *one
,char *two
);
387 char *findonlyfilename(char *pathfile
);
389 void mysprintf(struct CamdBase
*camdbase
,char *string
,char *fmt
,...);
391 # define mysprintf(camdbase, string, fmt, ...) SNPrintf(string, 256, fmt, __VA_ARGS__)
393 struct MidiLink
*GetMidiLinkFromOwnerNode(struct MinNode
*node
);
399 BOOL
InitCamdTimer(void);
400 void UninitCamdTimer(void);
403 APTR
GoodPutMidi ( struct CamdIFace
*ICamd
, struct MidiLink
* midilink
, uint32 msg
, uint32 maxbuff
);
407 BOOL
InitCamd(struct CamdIFace
*ICamd
);
408 void UninitCamd(struct CamdIFace
*ICamd
);
410 BOOL
InitCamd(struct CamdBase
*CamdBase
);
411 void UninitCamd(struct CamdBase
*CamdBase
);
414 #endif /* CAMD_INTERN_H */