grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / camd / mididistr.c
blob7d858c468334fcb15ace7e27030b54fff5f20420
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/utility.h>
14 #include "camd_intern.h"
17 void PutMidi2Link(
18 struct MidiLink *midilink,
19 struct MyMidiMessage2 *msg2,
20 ULONG timestamp
22 ULONG type;
23 MidiMsg *msg;
24 MidiMsg hmsg;
25 struct MyMidiNode *mymidinode=(struct MyMidiNode *)midilink->ml_MidiNode;
27 if(mymidinode->error&CMEF_BufferFull){
28 return;
31 if(msg2->status<0x80){
32 type=CMB_SysEx;
33 }else{
34 type=MidiMsgType_status_data1(msg2->status,msg2->data1);
37 if(! ( (1L<<type) & midilink->ml_EventTypeMask) ){
38 return;
41 if( (midilink->ml_ChannelMask!=(UWORD)~0) && ((1L<<type)&CMF_Channel) ){
42 if( ! (
43 ( 1L<< (msg2->status&0xf) )
45 midilink->ml_ChannelMask
46 ) ){
47 return;
51 if(type==CMB_SysEx){
52 if(midilink->ml_SysExFilter.sxf_Mode!=0){
53 if(midilink->ml_SysExFilter.sxf_Mode&SXFM_3Byte){
54 if(
55 midilink->ml_SysExFilter.sxf_ID1!=msg2->status ||
56 midilink->ml_SysExFilter.sxf_ID1!=msg2->status ||
57 midilink->ml_SysExFilter.sxf_ID1!=msg2->status
59 mymidinode->sysex_write=mymidinode->sysex_laststart;
60 return;
62 }else{
63 if(midilink->ml_SysExFilter.sxf_ID1==msg2->status) goto outofhere;
64 if(midilink->ml_SysExFilter.sxf_ID2==msg2->status) goto outofhere;
65 if(midilink->ml_SysExFilter.sxf_ID3==msg2->status) goto outofhere;
66 mymidinode->sysex_write=mymidinode->sysex_laststart;
67 return;
70 outofhere:
71 msg2->data2=msg2->data1;
72 msg2->data1=msg2->status;
73 msg2->status=0xf0;
77 if(mymidinode->midinode.mi_ReceiveHook!=NULL){
79 /* I haven`t found any documentation about what the hooks carry. But the
80 camd in tool hook for Barsnpipes has the following proto:
82 static ULONG __asm __saveds midiinhook(register __a0 struct Hook *hook,
83 register __a2 struct MidiLink *link,
84 register __a1 MidiMsg *msg,
85 register __d0 long sysexlen,
86 register __a3 void *sysexdata);
87 ... So I do that. -K.Matheussen.
89 #if 0
90 CallHookPkt(mymidinode->midinode.mi_ReceiveHook,NULL,NULL);
91 #endif
93 hmsg.mm_Time=timestamp;
95 hmsg.mm_Status=msg2->status;
96 if(msg2->len>1){
97 hmsg.mm_Data1=msg2->data1;
98 }else{
99 hmsg.mm_Data1=0;
101 if(msg2->len>2){
102 hmsg.mm_Data2=msg2->data2;
103 }else{
104 hmsg.mm_Data2=0;
106 hmsg.mm_Port=midilink->ml_PortID;
110 #ifdef __amigaos4__
111 (ULONG (* ASM)(
112 REG(a0, struct Hook*),
113 REG(a2, struct MidiLink*),
114 REG(a1, MidiMsg*),
115 REG(d0, long),
116 REG(a3, void*)
118 #else
119 (ULONG (* ASM)(
120 REG(a0) struct Hook*,
121 REG(a2) struct MidiLink*,
122 REG(a1) MidiMsg*,
123 REG(d0) long,
124 REG(a3) void*
126 #endif
128 (mymidinode->midinode.mi_ReceiveHook->h_Entry)
131 mymidinode->midinode.mi_ReceiveHook,
132 midilink,
133 &hmsg,
134 hmsg.mm_Status==0xf0?GetSysXLen(mymidinode->sysex_laststart):0L,
135 hmsg.mm_Status==0xf0?mymidinode->sysex_laststart:NULL
139 }else{
141 msg=mymidinode->in_curr;
142 if(msg==NULL){ //If no buffer.
143 return;
146 if(mymidinode->unpicked+1==mymidinode->midinode.mi_MsgQueueSize-1){
147 mymidinode->error |= CMEF_BufferFull;
148 return;
151 msg->mm_Time=timestamp;
153 msg->mm_Status=msg2->status;
154 if(msg2->len>1){
155 msg->mm_Data1=msg2->data1;
156 }else{
157 msg->mm_Data1=0;
159 if(msg2->len>2){
160 msg->mm_Data2=msg2->data2;
161 }else{
162 msg->mm_Data2=0;
164 msg->mm_Port=midilink->ml_PortID;
166 mymidinode->unpicked++;
168 mymidinode->in_curr++;
169 if(mymidinode->in_curr==mymidinode->in_end){
170 mymidinode->in_curr=mymidinode->in_start;
173 if(mymidinode->midinode.mi_ReceiveSigBit!=-1){
174 Signal(mymidinode->midinode.mi_SigTask,1L<<mymidinode->midinode.mi_ReceiveSigBit);