/ examples / midi_intest1.py
midi_intest1.py
 1  import time
 2  import usb_midi
 3  import adafruit_midi
 4  
 5  # A subset of messages/events
 6  # pylint: disable=unused-import
 7  from adafruit_midi.timing_clock import TimingClock
 8  
 9  # from adafruit_midi.channel_pressure        import ChannelPressure
10  from adafruit_midi.control_change import ControlChange
11  from adafruit_midi.note_off import NoteOff
12  from adafruit_midi.note_on import NoteOn
13  from adafruit_midi.pitch_bend import PitchBend
14  
15  
16  # 0 is MIDI channel 1
17  midi = adafruit_midi.MIDI(midi_in=usb_midi.ports[0], in_channel=0)
18  
19  print("Midi input test with pauses")
20  
21  # Convert channel numbers at the presentation layer to the ones musicians use
22  print("Input channel:", midi.in_channel + 1)
23  
24  # play with the pause to simulate code doing other stuff
25  # in the loop
26  pauses = [0] * 10 + [0.010] * 10 + [0.100] * 10 + [1.0] * 10
27  
28  while True:
29      for pause in pauses:
30          msg = midi.receive()
31          if msg is not None:
32              print(time.monotonic(), msg)
33          if pause:
34              time.sleep(pause)