Debian Codegraph @

docs/_sources/examples/16-midi/01-midi-scan.rst.txt

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