1919#
2020#
2121
22+ from inspect import trace
2223from os import path
2324import sys
2425import 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
361355def help_config ():
0 commit comments