16 BUTTON_INDICES0 = range(32, 38)
17 BUTTON_INDICES1 = [46, 47, 48, 49, 42, 43, 44, 98, 99, 100, 101, 102, 103, 35, 36, 37, 34, 104, 45, 50, 32, 33]
18 SCRATCH_INDICES = [16, 17]
20 AXIS_INDICES1 = [28, 27, 17, 18, 19, 20, 26, 16, 29]
21 AXIS_INDICES2 = [22, 17, 28, 19, 18, 21, 27, 20, 23]
27 devices = pygame.midi.get_count()
29 print(
"No MIDI devices detected")
31 print(
"Found %d MIDI devices" % devices)
34 input_dev = int(sys.argv[1])
36 for i
in range(devices):
37 info = pygame.midi.get_device_info(i)
38 if 'Vestax Spin 2 MIDI' in info[1]:
43 print(
"No MIDI device")
45 print(
"Using input device %d" % input_dev)
47 controller = pygame.midi.Input(input_dev)
50 rospy.init_node(
'kontrol')
51 pub = rospy.Publisher(
'/joy_pad', Joy, latch=
True)
54 m.axes = [ 0 ] * (2 + len(AXIS_INDICES0) + len(AXIS_INDICES1) + len(AXIS_INDICES2))
55 m.buttons = [ 0 ] * (len(BUTTON_INDICES0) + 2 * len(BUTTON_INDICES1))
60 while not rospy.is_shutdown():
61 m.header.stamp = rospy.Time.now()
65 while controller.poll():
67 data = controller.read(1)
76 if control[0]
in [144,145,146]:
77 player = control[0] - 144
78 button_index = control[1]
79 pressed =
True if control[2] == 127
else False 81 for bi, i
in zip(BUTTON_INDICES0, range(len(BUTTON_INDICES0))):
82 if button_index == bi:
89 for bi, i
in zip(BUTTON_INDICES1, range(len(BUTTON_INDICES1))):
90 if button_index == bi:
91 offset = player * len(BUTTON_INDICES1) + len(BUTTON_INDICES0)
93 m.buttons[i + offset] = 1
95 m.buttons[i + offset] = 0
98 elif control[0]
in [176, 177, 180]:
99 player = control[0] - 176
100 axis_index = control[1]
103 for bi, i
in zip(AXIS_INDICES0, range(len(AXIS_INDICES0))):
105 offset = len(SCRATCH_INDICES)
106 m.axes[i + offset] = control[2] / 127.0
109 for bi, i
in zip(AXIS_INDICES1, range(len(AXIS_INDICES1))):
111 offset = len(SCRATCH_INDICES) + len(AXIS_INDICES0)
112 m.axes[i + offset] = control[2] / 127.0
115 for bi, i
in zip(AXIS_INDICES2, range(len(AXIS_INDICES2))):
117 offset = len(SCRATCH_INDICES) + len(AXIS_INDICES0) + len(AXIS_INDICES1)
118 m.axes[i + offset] = control[2] / 127.0
121 elif control[0] == 178:
122 for s, i
in zip(SCRATCH_INDICES, range(len(SCRATCH_INDICES))):
125 m.axes[i] = (control[2] - 65) / 15.0
127 m.axes[i] = (control[2] - 63) / 15.0
139 if __name__ ==
'__main__':
142 except rospy.ROSInterruptException:
pass