Skip to content

Commit 34ef187

Browse files
committed
funnel filter, update dist
1 parent 6bd8c1e commit 34ef187

File tree

8 files changed

+62
-53
lines changed

8 files changed

+62
-53
lines changed

Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ all:
55
@echo "Pick a target... install to copy from dist/ to system, dist to copy from system to dist/"
66

77
dist:
8-
cp /usr/local/bin/midi_connect.sh ./dist/usr/local/bin/
9-
cp /etc/udev/rules.d/95-midi.rules ./dist/etc/udev/rules.d/
8+
touch ./dist/var/log/midi-server.log
9+
cp /usr/local/bin/midi_connect.sh ./dist/usr/local/bin/
10+
cp /usr/local/bin/midi_disconnect.sh ./dist/usr/local/bin/
11+
cp /etc/udev/rules.d/95-midi.rules ./dist/etc/udev/rules.d/
12+
cp /etc/systemd/system/midibus.service ./dist/etc/systemd/system/
13+
cp /etc/systemd/system/midi-server.service ./dist/etc/systemd/system/
1014

1115
install:
12-
cp -R dist/{usr,etc} /
16+
cp -R dist/{etc,usr,var} /
1317

dist/etc/systemd/system/midi-server.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ After=sound.target
66

77
[Service]
88
Restart=no
9-
ExecStart=/home/pi/Development/midibus/server/midi-server
9+
ExecStart=/bin/sh -c '/home/pi/Development/midibus/server/midi-server >> /var/log/midi-server.log'
1010
ExecStop=/bin/sh -c '/bin/kill -s SIGINT $MAINPID 2>/dev/null'
1111
#OOMScoreAdjust=-100
1212
TimeoutStopSec=10s

dist/usr/local/bin/midi_connect.sh

+1-43
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,5 @@ card_number=$(cat /sys/$1/device/number)
44
name=$(head -n1 /proc/asound/card${card_number}/midi0)
55
aconnect=/usr/bin/aconnect
66

7-
keys="JUNO-DS"
8-
clock="Deluge"
9-
bcr="BCR2000"
10-
11-
msed="s/.*: '\(.*\)' .*/\1/g"
12-
others=$($aconnect -o | /bin/grep '^client' | /bin/grep 'card=' | /bin/sed "$msed" | grep -v "$name")
13-
SAVEIFS=$IFS
14-
IFS=$'\n'
15-
others=($others)
16-
IFS=$SAVEIFS
17-
18-
if [ "$name" == "$keys" ]; then
19-
for (( i=0; i<${#others[@]}; i++ )); do
20-
other="${others[$i]}"
21-
$aconnect "$keys:0" "$other:0"
22-
done
23-
else
24-
$aconnect "$keys:0" "$name:0"
25-
fi
26-
27-
if [ "$name" == "$clock" ]; then
28-
for (( i=0; i<${#others[@]}; i++ )); do
29-
other="${others[$i]}"
30-
$aconnect "$clock:0" "$other:0"
31-
$aconnect "$other:0" "$clock:0"
32-
done
33-
else
34-
$aconnect "$clock:0" "$name:0"
35-
$aconnect "$name:0" "$clock:0"
36-
fi
37-
38-
if [ "$name" == "$bcr" ]; then
39-
for (( i=0; i<${#others[@]}; i++ )); do
40-
other="${others[$i]}"
41-
$aconnect "$bcr:0" "$other:0"
42-
$aconnect "$other:0" "$bcr:0"
43-
done
44-
else
45-
$aconnect "$bcr:0" "$name:0"
46-
$aconnect "$name:0" "$bcr:0"
47-
fi
48-
49-
pid=$(pgrep -f "python.*matrix.py")
7+
pid=$(pgrep -x "midi-server")
508
[ -n "$pid" ] && kill -s SIGHUP $pid

dist/usr/local/bin/midi_disconnect.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

3-
pid=$(pgrep -f "python.*matrix.py")
3+
pid=$(pgrep -x "midi-server")
44
[ -n "$pid" ] && kill -s SIGHUP $pid

dist/var/log/midi-server.log

Whitespace-only changes.

pygame/client.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ def listen(s):
3737
print('Socket error')
3838
return
3939
s.callback_name = response[0][0]
40-
print "calling " + s.callback_name
41-
s.callbacks[ s.callback_name ](response[1:])
42-
return True
40+
if s.callback_name in s.callbacks:
41+
print "calling " + s.callback_name
42+
s.callbacks[ s.callback_name ](response[1:])
43+
return True
44+
else:
45+
print "cannot call '" + s.callback_name + "'"
4346
def ask(s, what):
4447
s.server_socket.send(what + "\n")
4548
def get_config(s):

server/midi-server.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
hw:JUNODS hw:Circuit channel 1,2,10
22
hw:JUNODS hw:II channel 3
33
hw:JUNODS hw:Deluge channel 8
4-
hw:Circuit hw:Deluge channel 1,2,10
4+
hw:Circuit hw:Deluge funnel 9
55
hw:II hw:Deluge channel 3
66
hw:Deluge hw:Circuit channel rt,1,2,10
77
hw:Deluge hw:II channel rt,3
@@ -16,6 +16,6 @@ hw:mio hw:BCR2000 thru thru
1616
hw:Circuit hw:mio channel 1,2,10,sysex
1717
hw:JUNODS hw:mio channel all,sysex
1818
hw:II hw:mio channel 3,sysex
19-
hw:Deluge hw:mio channel rt,8
19+
hw:Deluge hw:mio channel rt,1,2,4,8
2020
hw:sampler hw:mio channel 15,16
2121
hw:BCR2000 hw:mio thru thru

server/write.c

+44
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,44 @@ ssize_t write_buffer(snd_rawmidi_t *port, unsigned char *buf, size_t n_bytes)
1919
return n_bytes;
2020
}
2121

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+
2260
int write_channel_filter(struct write_data *data, unsigned char *buf, int n_bytes, void *args)
2361
{
2462
snd_rawmidi_t *port = data->output_device->midi;
@@ -90,6 +128,12 @@ void setup_write_func( struct write_data *data )
90128
data->args = (void *) data->args_name;
91129
printf("W %s realtime %s\n", data->port_name, data->args_name);
92130
}
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+
}
93137
else if( strcmp(data->func_name, "channel") == 0 )
94138
{
95139
data->func = write_channel_filter;

0 commit comments

Comments
 (0)