grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / camd / putsysex.c
blobb11ae8ef2d44b0813b4e2d87cf034d2336065790
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <proto/exec.h>
10 #include <proto/dos.h>
12 #include "camd_intern.h"
15 /*****************************************************************************
17 NAME */
19 AROS_LH2(void, PutSysEx,
21 /* SYNOPSIS */
22 AROS_LHA(struct MidiLink *, midilink, A0),
23 AROS_LHA(UBYTE *, buffer, A1),
25 /* LOCATION */
26 struct CamdBase *, CamdBase, 26, Camd)
28 /* FUNCTION
29 Distributes a SysEx message. First sends the message to the hardware
30 and all midinodes connected to the midilinks cluster, then waits
31 for the complete message to be sent to the hardware, if any. If
32 a midinodes sysex-buffer is to small to carry the message, it will
33 not be sent. If the buffer is big enough, but there is not enough
34 room, a sysex-full-error will be set to the node. The message is
35 sent to hardware regardless of transmit buffer size.
37 INPUTS
38 midilink - pointer to link.
39 buffer - message to send, must start with 0xf0 and end with 0xf7.
40 No bytes higher than 0x7f are allowed in the message.
41 RESULT
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 GetSysEx()
52 INTERNALS
54 HISTORY
56 2001-01-12 ksvalast first created
58 *****************************************************************************/
60 AROS_LIBFUNC_INIT
62 struct Node *node;
63 struct DriverData *driverdata=NULL;
64 struct MyMidiCluster *mycluster=(struct MyMidiCluster *)midilink->ml_Location;
65 BOOL driversuccess=TRUE;
66 UBYTE *buffer2;
68 ObtainSemaphoreShared(&mycluster->semaphore);
70 if( ! (IsListEmpty(&midilink->ml_Location->mcl_Receivers))){
72 node=midilink->ml_Location->mcl_Receivers.lh_Head;
74 while(node->ln_Succ!=NULL){
75 if(node->ln_Type==NT_USER-MLTYPE_NTypes){
77 driverdata=(struct DriverData *)node;
78 ObtainSemaphore(&driverdata->sysexsemaphore);
80 driverdata->buffer_sx=buffer;
81 driverdata->buffercurrsend_sx=0;
82 driverdata->issending_sx=1;
84 driversuccess=SysEx2Driver(driverdata,buffer);
86 }else{
87 buffer2=buffer;
88 while(PutSysEx2Link((struct MidiLink *)node,*buffer2)==TRUE){
89 buffer2++;
92 node=node->ln_Succ;
95 if(driverdata!=NULL){
97 if(driversuccess==FALSE){
98 while(SysEx2Driver(driverdata,buffer)==FALSE) CamdWait();
101 // Not a very good way to wait for the data to be sent, but it should
102 // hopefully quite seldom be very important.
103 while(driverdata->issending_sx!=0) CamdWait();
105 ReleaseSemaphore(&driverdata->sysexsemaphore);
109 ReleaseSemaphore(&mycluster->semaphore);
111 AROS_LIBFUNC_EXIT