File: 01-midi-scan.rst.txt

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (51 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
01-midi-scan.py - Scan for MIDI channels and controller numbers.
============================================================================================================================================


CtlScan and CtlScan2 objects are useful to find controller numbers used
by your MIDI devices.

List of MIDI-related functions:

- pm_count_devices:
    Returns the number of devices found by Portmidi.
- pm_get_default_input:
    Returns the index number of Portmidi's default input device.
- pm_get_default_output:
    Returns the index number of Portmidi's default output device.
- pm_get_input_devices:
    Returns midi input devices (device names, device indexes) found by Portmidi.
- pm_get_output_devices:
    Returns midi output devices (device names, device indexes) found by Portmidi.
- pm_list_devices:
    Prints a list of all devices found by Portmidi.

.. code-block:: python

    from pyo import *
    
    # Print the list of available MIDI devices to the console.
    pm_list_devices()
    
    s = Server(duplex=0)
    
    # Give the ID of the desired device (as listed by pm_list_devices()) to the
    # setMidiInputDevice() of the Server. A bigger number than the higher device
    # ID will open all connected MIDI devices.
    s.setMidiInputDevice(99)
    
    # The MIDI device must be set before booting the server.
    s.boot().start()
    
    print("Play with your Midi controllers...")
    
    # Function called by CtlScan2 object.
    def scanner(ctlnum, midichnl):
        print("MIDI channel: %d, controller number: %d" % (midichnl, ctlnum))
    
    
    # Listen to controller input.
    scan = CtlScan2(scanner, toprint=False)
    
    s.gui(locals())