Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / camd / setmidilinkattrsa.c
blobaf777682f5f29c44441d1c309dd288647e6ff252
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/utility.h>
7 #include <proto/exec.h>
9 #include "camd_intern.h"
11 # undef DEBUG
12 # define DEBUG 1
13 #ifndef __amigaos4__
14 # include AROS_DEBUG_H_FILE
15 #endif
17 /*****************************************************************************
19 NAME */
21 AROS_LH2(BOOL, SetMidiLinkAttrsA,
23 /* SYNOPSIS */
24 AROS_LHA(struct MidiLink *, midilink, A0),
25 AROS_LHA(struct TagItem *, tags, A1),
27 /* LOCATION */
28 struct CamdBase *, CamdBase, 16, Camd)
30 /* FUNCTION
31 Remind me to fill in things here later.
33 INPUTS
35 RESULT
37 NOTES
38 - If the midilink is not owned by yourself, please lock
39 camd to ensure it wont go away.
41 - Allthough you are able to modify midilinks owned by
42 others, please avoid it, its normally "non of your buziness",
43 and may lead to crashes and other "unexpected" behaviours.
44 However, if you have full control of the owner of the
45 midilink (f.ex when both you and the owner belongs to the
46 same probram and you are absolutely shure you know what
47 you are doing), there is no problem.
49 - Warning! If another task have locked Camd and is waiting
50 for you to finish, there will be a deadlock if you try
51 to change priority or change/set cluster.
53 EXAMPLE
55 BUGS
57 SEE ALSO
58 GetMidiLinkAttrsA()
60 INTERNALS
62 *****************************************************************************/
64 AROS_LIBFUNC_INIT
66 struct TagItem *tag;
67 struct TagItem *tstate=tags;
69 BOOL ret=TRUE;
70 char *clustername;
71 int type=midilink->ml_Node.ln_Type;
72 struct MyMidiCluster *mycluster;
73 struct DriverData *driverdata=NULL;
75 ULONG *ErrorCode = (ULONG *)GetTagData(MLINK_ErrorCode, (IPTR) NULL,tags);
77 while((tag=NextTagItem(&tstate))){
78 switch(tag->ti_Tag){
79 case MLINK_Name:
80 midilink->ml_Node.ln_Name=(char *)tag->ti_Data;
81 break;
82 case MLINK_Location:
83 break;
84 case MLINK_ChannelMask:
85 midilink->ml_ChannelMask=tag->ti_Data;
86 break;
87 case MLINK_EventMask:
88 midilink->ml_EventTypeMask=tag->ti_Data;
89 break;
90 case MLINK_UserData:
91 midilink->ml_UserData=(void *)tag->ti_Data;
92 break;
93 case MLINK_Comment:
94 // Not implemented because it's not used.
95 // if(midilink
96 break;
97 case MLINK_PortID:
98 midilink->ml_PortID=tag->ti_Data;
99 break;
100 case MLINK_Private:
101 midilink->ml_Flags|=MLF_PrivateLink*tag->ti_Data;
102 break;
103 case MLINK_Priority:
104 mycluster=(struct MyMidiCluster *)midilink->ml_Location;
105 if(mycluster!=NULL){
106 ObtainSemaphore(CB(CamdBase)->CLSemaphore);
107 if(type==NT_USER-MLTYPE_Receiver){
108 ObtainSemaphore(&mycluster->semaphore);
111 Remove(&midilink->ml_Node);
112 midilink->ml_Node.ln_Pri=tag->ti_Data;
113 if(type==NT_USER-MLTYPE_Receiver){
114 Enqueue(&midilink->ml_Location->mcl_Receivers,&midilink->ml_Node);
115 }else{
116 Enqueue(&midilink->ml_Location->mcl_Senders,&midilink->ml_Node);
118 if(type==NT_USER-MLTYPE_Receiver){
119 ReleaseSemaphore(&mycluster->semaphore);
121 ReleaseSemaphore(CB(CamdBase)->CLSemaphore);
122 }else{
123 midilink->ml_Node.ln_Pri=tag->ti_Data;
125 break;
126 case MLINK_SysExFilter:
127 midilink->ml_SysExFilter.sxf_Packed=0xffffff & tag->ti_Data;
128 break;
129 case MLINK_SysExFilterX:
130 midilink->ml_SysExFilter.sxf_Packed=0x01000000 | tag->ti_Data;
131 break;
132 case MLINK_Parse:
133 driverdata=AllocMem(sizeof(struct DriverData),MEMF_ANY|MEMF_CLEAR|MEMF_PUBLIC);
134 if(driverdata==NULL){
135 if(ErrorCode!=NULL){
136 *ErrorCode=CME_NoMem;
138 ret=FALSE;
139 break;
141 driverdata->Input_Treat=Receiver_init;
142 break;
143 case MLINK_ErrorCode:
144 break;
145 default:
146 break;
150 if(ret!=FALSE){
151 clustername = (char *) GetTagData(MLINK_Location, (IPTR) NULL, tags);
152 if(clustername!=NULL){
153 ObtainSemaphore(CB(CamdBase)->CLSemaphore);
154 if(SetClusterForLink(midilink,clustername,ErrorCode,CamdBase)==FALSE){
155 ret=FALSE;
157 ReleaseSemaphore(CB(CamdBase)->CLSemaphore);
161 if(driverdata!=NULL && midilink->ml_Location!=NULL){
162 driverdata->incluster=(struct MyMidiCluster *)midilink->ml_Location;
163 midilink->ml_ParserData=driverdata;
164 }else{
165 midilink->ml_ParserData=NULL;
168 return ret;
170 AROS_LIBFUNC_EXIT
173 #ifdef __amigaos4__
174 #include <stdarg.h>
175 BOOL VARARGS68K SetMidiLinkAttrs(
176 struct CamdIFace *Self,
177 struct MidiLink * ml,
181 va_list ap;
182 struct TagItem * varargs;
183 va_startlinear(ap, ml);
184 varargs = va_getlinearva(ap, struct TagItem *);
185 return Self->SetMidiLinkAttrsA(
187 varargs);
189 #endif