@@ -19,6 +19,44 @@ ssize_t write_buffer(snd_rawmidi_t *port, unsigned char *buf, size_t n_bytes)
19
19
return n_bytes ;
20
20
}
21
21
22
+ int write_funnel_filter (struct write_data * data , unsigned char * buf , int n_bytes , void * args )
23
+ {
24
+ snd_rawmidi_t * port = data -> output_device -> midi ;
25
+ unsigned char out_buf [BUFSIZE ];
26
+ unsigned char target = (unsigned char ) (int ) args ;
27
+ unsigned int mask = MASK_ALL ; // any channel message is fine
28
+ unsigned int current_mask = 0 ;
29
+ if ( data -> output_device -> midi_in_exclusive == data -> midi_in )
30
+ current_mask = MASK_SYSEX ;
31
+
32
+ int a = 0 ;
33
+ for ( int b = 0 ; b < n_bytes ; ++ b )
34
+ {
35
+ if ( buf [b ] >= 0xf8 )
36
+ current_mask = MASK_RT ;
37
+ else if ( buf [b ] >= 0xf0 )
38
+ {
39
+ if ( buf [b ] == 0xf0 )
40
+ data -> output_device -> midi_in_exclusive = data -> midi_in ;
41
+ else if ( buf [b ] == 0xf7 )
42
+ data -> output_device -> midi_in_exclusive = NULL ;
43
+ current_mask = MASK_SYSEX ;
44
+ }
45
+ else if ( buf [b ] >= 0x80 )
46
+ {
47
+ current_mask = 2 << (buf [b ] & 0x0f );
48
+ out_buf [a ++ ] = buf [b ] & 0xf0 | target ;
49
+ continue ;
50
+ }
51
+
52
+ if ( mask & current_mask )
53
+ {
54
+ out_buf [a ++ ] = buf [b ];
55
+ }
56
+ }
57
+ return write_buffer ( port , out_buf , a );
58
+ }
59
+
22
60
int write_channel_filter (struct write_data * data , unsigned char * buf , int n_bytes , void * args )
23
61
{
24
62
snd_rawmidi_t * port = data -> output_device -> midi ;
@@ -90,6 +128,12 @@ void setup_write_func( struct write_data *data )
90
128
data -> args = (void * ) data -> args_name ;
91
129
printf ("W %s realtime %s\n" , data -> port_name , data -> args_name );
92
130
}
131
+ else if ( strcmp (data -> func_name , "funnel" ) == 0 )
132
+ {
133
+ data -> func = write_funnel_filter ;
134
+ data -> args = (void * ) ( atoi ( data -> args_name ) - 1 & 0x0f );
135
+ printf ("W %s funnel %s\n" , data -> port_name , data -> args_name );
136
+ }
93
137
else if ( strcmp (data -> func_name , "channel" ) == 0 )
94
138
{
95
139
data -> func = write_channel_filter ;
0 commit comments