|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Show MIDI events for a device. |
| 4 | +# |
| 5 | +# Some restrictions apply: |
| 6 | +# - This will only work if a device has an in- AND output, because the Launchpad |
| 7 | +# classes always open both directions. |
| 8 | +# - If multiple devices are attached or the search string returns more than one device, |
| 9 | +# only the first one will be openend. Remove devices as necessary. |
| 10 | +# - Picking the wrong device might result in no output. |
| 11 | +# - Quit with CTRL-C :) |
| 12 | +# |
| 13 | +# |
| 14 | +# FMMT666(ASkr) 7/2013..8/2020 |
| 15 | +# www.askrprojects.net |
| 16 | + |
| 17 | +import sys |
| 18 | + |
| 19 | +try: |
| 20 | + import launchpad_py as launchpad |
| 21 | +except ImportError: |
| 22 | + try: |
| 23 | + import launchpad |
| 24 | + except ImportError: |
| 25 | + sys.exit("error loading launchpad.py") |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +def cmdInput( prompt ): |
| 30 | + if sys.version_info.major == 2: |
| 31 | + inName = str(raw_input( prompt )) |
| 32 | + elif sys.version_info.major == 3: |
| 33 | + inName = str(input( prompt )) |
| 34 | + else: |
| 35 | + print('Meh, please consider running this with either Python 2 or 3') |
| 36 | + sys.exit(-1) |
| 37 | + |
| 38 | + return inName |
| 39 | + |
| 40 | + |
| 41 | +def main(): |
| 42 | + |
| 43 | + lp = launchpad.Launchpad() |
| 44 | + |
| 45 | + print("===\nAvailable MIDI devices:") |
| 46 | + lp.ListAll( ) |
| 47 | + print("===") |
| 48 | + |
| 49 | + print("Enter a part of the device name, that shall be monitored.") |
| 50 | + print("The string needs to cover the in- and output channels of a device!") |
| 51 | + print("Otherwise, opening only one input or one output channel will result in an error.") |
| 52 | + print("The search string is case-insensitive.") |
| 53 | + |
| 54 | + inName = cmdInput( " search string:" ) |
| 55 | + |
| 56 | + while True: |
| 57 | + print("===") |
| 58 | + lp.ListAll( searchString = inName ) |
| 59 | + print("===") |
| 60 | + |
| 61 | + inOk = cmdInput( " ENTER to continue or new search string:" ) |
| 62 | + if inOk == '': |
| 63 | + break |
| 64 | + else: |
| 65 | + inName = inOk |
| 66 | + |
| 67 | + try: |
| 68 | + lp.Open( 0, inName ) |
| 69 | + except: |
| 70 | + print("error opening this device") |
| 71 | + sys.exit(-1) |
| 72 | + |
| 73 | + print("===") |
| 74 | + print("Now hit the keys, turn the knobs or push the buttons:") |
| 75 | + |
| 76 | + while(True): |
| 77 | + events = lp.EventRaw() |
| 78 | + if events != []: |
| 79 | + print( events ) |
| 80 | + |
| 81 | + |
| 82 | +if __name__ == '__main__': |
| 83 | + main() |
0 commit comments