Skip to content

Commit c57b92c

Browse files
authored
Merge pull request #4 from smootalicious/master
Added midi connect and disconnect scripts. Moved setup files to their own folder. Added pkill to M8_pulse.sh
2 parents ca44065 + 829f25f commit c57b92c

File tree

9 files changed

+144
-33
lines changed

9 files changed

+144
-33
lines changed

M8/M8.sh

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
2-
if [ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]; then
3-
sdl_controllerconfig="03000000091200000031000011010000,OpenSimHardware OSH PB Controller,a:b1,b:b0,x:b3,y:b2,leftshoulder:b4,rightshoulder:b5,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftx:a0~,lefty:a1~,leftstick:b8,lefttrigger:b10,rightstick:b9,back:b7,start:b6,rightx:a2,righty:a3,righttrigger:b11,platform:Linux,"
4-
elif [ -e "/dev/input/by-path/platform-odroidgo2-joypad-event-joystick" ]; then
5-
if [ ! -z $(cat /etc/emulationstation/es_input.cfg | grep "190000004b4800000010000001010000") ]; then
6-
sdl_controllerconfig="190000004b4800000010000001010000,GO-Advance Gamepad (rev 1.1),a:b1,b:b0,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,leftx:a0,lefty:a1,back:b12,leftstick:b13,lefttrigger:b6,rightstick:b16,righttrigger:b7,start:b17,platform:Linux,"
7-
else
8-
sdl_controllerconfig="190000004b4800000010000000010000,GO-Advance Gamepad,a:b1,b:b0,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b7,dpleft:b8,dpright:b9,dpup:b6,leftx:a0,lefty:a1,back:b10,lefttrigger:b12,righttrigger:b13,start:b15,platform:Linux,"
9-
fi
10-
elif [ -e "/dev/input/by-path/platform-odroidgo3-joypad-event-joystick" ]; then
11-
sdl_controllerconfig="190000004b4800000011000000010000,GO-Super Gamepad,platform:Linux,x:b2,a:b1,b:b0,y:b3,back:b12,start:b13,dpleft:b10,dpdown:b9,dpright:b11,dpup:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b14,rightstick:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Linux,"
12-
else
13-
sdl_controllerconfig="19000000030000000300000002030000,gameforce_gamepad,leftstick:b14,rightx:a3,leftshoulder:b4,start:b9,lefty:a0,dpup:b10,righty:a2,a:b1,b:b0,guide:b16,dpdown:b11,rightshoulder:b5,righttrigger:b7,rightstick:b15,dpright:b13,x:b2,back:b8,leftx:a1,y:b3,dpleft:b12,lefttrigger:b6,platform:Linux,"
14-
fi
15-
16-
export SDL_GAMECONTROLLERCONFIG="$sdl_controllerconfig"
17-
181
m8_path=ports/M8
192
roms2_path=/roms2/$m8_path
203
roms_path=/roms/$m8_path

M8/M8_pulse.sh

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
if [ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-joystick" ]; then
2-
sdl_controllerconfig="03000000091200000031000011010000,OpenSimHardware OSH PB Controller,a:b1,b:b0,x:b3,y:b2,leftshoulder:b4,rightshoulder:b5,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftx:a0~,lefty:a1~,leftstick:b8,lefttrigger:b10,rightstick:b9,back:b7,start:b6,rightx:a2,righty:a3,righttrigger:b11,platform:Linux,"
3-
elif [ -e "/dev/input/by-path/platform-odroidgo2-joypad-event-joystick" ]; then
4-
if [ ! -z $(cat /etc/emulationstation/es_input.cfg | grep "190000004b4800000010000001010000") ]; then
5-
sdl_controllerconfig="190000004b4800000010000001010000,GO-Advance Gamepad (rev 1.1),a:b1,b:b0,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,leftx:a0,lefty:a1,back:b12,leftstick:b13,lefttrigger:b6,rightstick:b16,righttrigger:b7,start:b17,platform:Linux,"
6-
else
7-
sdl_controllerconfig="190000004b4800000010000000010000,GO-Advance Gamepad,a:b1,b:b0,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b7,dpleft:b8,dpright:b9,dpup:b6,leftx:a0,lefty:a1,back:b10,lefttrigger:b12,righttrigger:b13,start:b15,platform:Linux,"
8-
fi
9-
elif [ -e "/dev/input/by-path/platform-odroidgo3-joypad-event-joystick" ]; then
10-
sdl_controllerconfig="190000004b4800000011000000010000,GO-Super Gamepad,platform:Linux,x:b2,a:b1,b:b0,y:b3,back:b12,start:b13,dpleft:b10,dpdown:b9,dpright:b11,dpup:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b14,rightstick:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Linux,"
11-
else
12-
sdl_controllerconfig="19000000030000000300000002030000,gameforce_gamepad,leftstick:b14,rightx:a3,leftshoulder:b4,start:b9,lefty:a0,dpup:b10,righty:a2,a:b1,b:b0,guide:b16,dpdown:b11,rightshoulder:b5,righttrigger:b7,rightstick:b15,dpright:b13,x:b2,back:b8,leftx:a1,y:b3,dpleft:b12,lefttrigger:b6,platform:Linux,"
13-
fi
14-
15-
export SDL_GAMECONTROLLERCONFIG="$sdl_controllerconfig"
16-
171
m8_path=ports/M8
182
roms2_path=/roms2/$m8_path
193
roms_path=/roms/$m8_path
@@ -27,3 +11,5 @@ fi
2711
sudo pulseaudio --start --file=_other_files/pulseaudio_config.pa
2812

2913
./_m8c/m8c
14+
15+
sudo pkill -f '_other_files/pulseaudio_config.pa'

M8/midi_connect.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"""
2+
Connect all midi devices to each other!
3+
"""
4+
5+
import sys
6+
import logging
7+
import subprocess
8+
import re
9+
10+
__author__ = 'Stephen Brown (Little Fish Solutions LTD)'
11+
12+
13+
if sys.version_info.major < 3:
14+
sys.exit('Sorry, this script only supports Python 3')
15+
16+
log = logging.getLogger(__name__)
17+
18+
VERSION = '0.0.0'
19+
20+
VERBOSE = False
21+
22+
if __name__ == '__main__':
23+
if VERBOSE:
24+
logging.basicConfig(level=logging.DEBUG)
25+
else:
26+
logging.basicConfig(level=logging.INFO, format='%(message)s')
27+
28+
log.info('Midi Connect v{}'.format(VERSION))
29+
30+
# Run aconnect and get the output
31+
aconnect_process = subprocess.run(['aconnect', '-i', '-l'], stdout=subprocess.PIPE,
32+
stderr=subprocess.STDOUT)
33+
34+
# Keep a list of clients
35+
clients = {}
36+
37+
# Keep a list of existing mappings (from, to)
38+
existing_connections = []
39+
40+
def add_client_port(client_number, port_number):
41+
if client_number not in clients:
42+
clients[client_number] = []
43+
44+
clients[client_number].append(port_number)
45+
46+
# Regular expressions used for parsing
47+
client_regex = re.compile(r'^client ([0-9]+): \'([^\']*)\'.*$')
48+
port_regex = re.compile(r'^\s*([0-9]+) \'([^\']*)\'.*$')
49+
connecting_to_regex = re.compile(r'^\s*Connecting To: (.*)$')
50+
connecting_from_regex = re.compile(r'^\sConnected From:.*$')
51+
52+
client_number = None
53+
client_name = None
54+
skip_client = False
55+
56+
# break up into lines for processing
57+
lines = aconnect_process.stdout.decode().split('\n')
58+
for line in lines:
59+
if not line.strip():
60+
continue
61+
62+
client_match = client_regex.match(line)
63+
if client_match:
64+
client_number = client_match.group(1)
65+
client_name = client_match.group(2)
66+
67+
log.debug('Found client {} "{}"'.format(client_number, client_name))
68+
69+
skip_client = client_name in ['System', 'Midi Through']
70+
if skip_client:
71+
log.debug(' - Skipping client "{}"'.format(client_name))
72+
73+
continue
74+
75+
port_match = port_regex.match(line)
76+
if port_match:
77+
if client_number is None:
78+
raise Exception('Found port without client: {}'.format(line))
79+
80+
if skip_client:
81+
continue
82+
83+
port_number = port_match.group(1)
84+
port_name = port_match.group(2)
85+
86+
log.debug(' - Found port {} "{}"'.format(port_number, port_name))
87+
add_client_port(client_number, port_number)
88+
89+
continue
90+
91+
connecting_to_match = connecting_to_regex.match(line)
92+
if connecting_to_match:
93+
connecting_from = '{}:{}'.format(client_number, port_number)
94+
connecting_to_str = connecting_to_match.group(1)
95+
connecting_to_list = [s.strip() for s in connecting_to_str.split(',')]
96+
for connecting_to in connecting_to_list:
97+
log.debug('Existing connection {} -> {}'.format(connecting_from, connecting_to))
98+
existing_connections.append((connecting_from, connecting_to))
99+
100+
continue
101+
102+
connecting_from_match = connecting_from_regex.match(line)
103+
if connecting_from_match:
104+
continue
105+
106+
raise Exception('Unhandled line: {}'.format(line))
107+
108+
# We now have our clients dict
109+
for (from_client_number, from_ports) in clients.items():
110+
for (to_client_number, to_ports) in clients.items():
111+
if from_client_number == to_client_number:
112+
# Don't map things onto themselves
113+
continue
114+
115+
for from_port in from_ports:
116+
for to_port in to_ports:
117+
from_str = '{}:{}'.format(from_client_number, from_port)
118+
to_str = '{}:{}'.format(to_client_number, to_port)
119+
120+
if (from_str, to_str) in existing_connections:
121+
log.info('{} is already connected to {} - skipping'.format(
122+
from_str, to_str
123+
))
124+
125+
continue
126+
127+
log.info('Mapping {} -> {}'.format(from_str, to_str))
128+
129+
map_process = subprocess.run([
130+
'aconnect', from_str, to_str
131+
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
132+
133+
output = map_process.stdout
134+
if output:
135+
log.warning(output.decode())
136+

M8/midi_connect.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
3+
cd $SCRIPT_PATH
4+
python3 midi_connect.py

M8/midi_disconnect.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
aconnect -x
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)