Skip to content

Commit 7bb8626

Browse files
committed
v2.1
1 parent a37a03c commit 7bb8626

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Usage: midi2vjoy -m <midi_device> -c <config_file> [-v]
1818
-m --midi: MIDI device to use. To see available devices, use -t
1919
-c --config: path to a config file (see example_config.conf)
2020
-v --verbose: verbose output
21+
22+
Standard config file is mapping.conf in the same directory as midi2vjoy.exe.
23+
Standard MIDI device is 1.
2124
```
2225
```
2326
__ _

build.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyinstaller --onefile -i icon.webp midi2vjoy.py

icon.webp

6.85 KB
Loading

midi2vjoy.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#
2020
#
2121

22+
from inspect import trace
2223
from os import path
2324
import sys
2425
import time
@@ -74,44 +75,37 @@ def midi_test():
7475

7576
# List all the devices and make a choice
7677
print('Input MIDI devices:')
77-
for device_number in range(device_count):
78-
(interf, name, input, output,
79-
opened) = pygame.midi.get_device_info(device_number)
80-
if input:
81-
print(str(device_number) + ":", "\"" + name.decode() + "\"")
78+
for device_id in range(device_count):
79+
(i_interf, i_name, i_input, i_output,
80+
i_opened) = pygame.midi.get_device_info(device_id)
81+
if i_input == 1:
82+
print(str(device_id) + ":", "\"" + i_name.decode() + "\"")
83+
device_id_input = int(input('Select MIDI device to test: '))
84+
85+
# Open the device for testing
86+
midi = None
87+
print('Opening MIDI device:', device_id_input)
8288
try:
83-
selected_device_number = int(input('Select MIDI device to test: '))
84-
except KeyboardInterrupt:
85-
sys.exit()
89+
midi = pygame.midi.Input(device_id_input)
8690
except:
87-
if(options.verbose):
88-
traceback.print_exc()
89-
else:
90-
print('You have to specify a valid device number')
91-
if m is not None:
92-
m.close()
93-
midi_test()
94-
# Open the device for testing
91+
traceback.print_exc()
92+
if midi != None:
93+
midi.close()
94+
print('Device opened for testing. Use ctrl-c to quit.')
9595
try:
96-
m = None
97-
print('Opening MIDI device:', selected_device_number)
98-
m = pygame.midi.Input(selected_device_number)
99-
print('Device opened for testing. Use ctrl-c to quit.')
10096
while True:
101-
while m.poll():
102-
print(m.read(1))
97+
while midi.poll():
98+
midi_input = midi.read(1)[0][0]
99+
print("MIDI: {: 4d} {: 4d} {: 4d}".format(
100+
midi_input[0], midi_input[1], midi_input[2]))
103101
time.sleep(0.1)
102+
except KeyboardInterrupt:
103+
if midi != None:
104+
midi.close()
105+
sys.exit()
104106
except:
105-
if options.verbose:
106-
traceback.print_exc()
107-
else:
108-
print('You have to specify a valid device number')
109-
if m is not None:
110-
m.close()
111-
midi_test()
112-
finally:
113-
if m is not None:
114-
m.close()
107+
traceback.print_exc()
108+
sys.exit()
115109

116110

117111
'''
@@ -335,7 +329,8 @@ def verbose(*message):
335329
print(string)
336330

337331

338-
help = '''
332+
def help_page():
333+
print('''
339334
_ _ _ ____ _
340335
_ __ ___ (_) __| (_)___ \__ __ | | ___ _ _
341336
| '_ ` _ \| |/ _` | | __) \ \ / / | |/ _ \| | | |
@@ -351,11 +346,10 @@ def verbose(*message):
351346
-m --midi: MIDI device to use. To see available devices, use -t
352347
-c --config: path to a config file (see example_config.conf)
353348
-v --verbose: verbose output
354-
'''
355-
356-
357-
def help_page():
358-
print(help)
349+
350+
Standard config file is mapping.conf in the same directory as midi2vjoy.exe.
351+
Standard MIDI device is 1.
352+
''')
359353

360354

361355
def help_config():

0 commit comments

Comments
 (0)