Debian Codegraph @

pyo/examples/x16-midi/01-midi-scan.py

raw symbols SCIP
1 """
2 01-midi-scan.py - Scan for MIDI channels and controller numbers.
3
4 CtlScan and CtlScan2 objects are useful to find controller numbers used
5 by your MIDI devices.
6
7 List of MIDI-related functions:
8
9 - pm_count_devices:
10 Returns the number of devices found by Portmidi.
11 - pm_get_default_input:
12 Returns the index number of Portmidi's default input device.
13 - pm_get_default_output:
14 Returns the index number of Portmidi's default output device.
15 - pm_get_input_devices:
16 Returns midi input devices (device names, device indexes) found by Portmidi.
17 - pm_get_output_devices:
18 Returns midi output devices (device names, device indexes) found by Portmidi.
19 - pm_list_devices:
20 Prints a list of all devices found by Portmidi.
21
22 """
23 from pyo import *
24
25 # Print the list of available MIDI devices to the console.
26 pm_list_devices()
27
28 s = Server(duplex=0)
29
30 # Give the ID of the desired device (as listed by pm_list_devices()) to the
31 # setMidiInputDevice() of the Server. A bigger number than the higher device
32 # ID will open all connected MIDI devices.
33 s.setMidiInputDevice(99)
34
35 # The MIDI device must be set before booting the server.
36 s.boot().start()
37
38 print("Play with your Midi controllers...")
39
40 # Function called by CtlScan2 object.
41 def scanner(ctlnum, midichnl):
42 print("MIDI channel: %d, controller number: %d" % (midichnl, ctlnum))
43
44
45 # Listen to controller input.
46 scan = CtlScan2(scanner, toprint=False)
47
48 s.gui(locals())