How to use mido - 10 common examples

To help you get started, we’ve selected a few mido examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aubio / aubio / python / demos / demo_wav2midi.py View on Github external
win_s = 512 // downsample # fft size
hop_s = 256 // downsample # hop size

s = source(filename, samplerate, hop_s)
samplerate = s.samplerate

tolerance = 0.8

notes_o = notes("default", win_s, hop_s, samplerate)

print("%8s" % "time","[ start","vel","last ]")

# create a midi file
mid = MidiFile()
track = MidiTrack()
mid.tracks.append(track)

ticks_per_beat = mid.ticks_per_beat # default: 480
bpm = 120 # default midi tempo

tempo = bpm2tempo(bpm)
track.append(MetaMessage('set_tempo', tempo=tempo))
track.append(MetaMessage('time_signature', numerator=4, denominator=4))

def frames2tick(frames, samplerate=samplerate):
    sec = frames / float(samplerate)
    return int(second2tick(sec, ticks_per_beat, tempo))

last_time = 0

# total number of frames read
github segfault16 / modular-led-controller-workstation / tests / test_midi_full_controller.py View on Github external
caplog.set_level(logging.DEBUG)
    logging.debug("UPDATE TEST")
    f = mock.Mock()
    version._test_version = "0.0.0"
    tmpDirPath = os.path.join(tmpdir, "pyu-data", "deploy")
    # tmpDirPath = os.getcwd()  # Enable for testing after creating release or release-dev
    # Write test files
    if not os.path.exists(tmpDirPath):
        os.makedirs(tmpDirPath)

    opts = midi_full.MidiProjectControllerOptions()
    opts.update_paths = [os.path.join(tmpDirPath, "pyu-data", "deploy")]
    # opts.client_config = TConfig()
    ctrl = midi_full.MidiProjectController(callback=f, options=opts)
    # Update message
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x11]
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, None)
    if f.call_count > 0:
        retMsg = f.call_args[0][0]
        assert retMsg.data[0] == 0x00
        assert retMsg.data[1] == 0x1F
github segfault16 / modular-led-controller-workstation / tests / test_midi_full_controller.py View on Github external
def test_delete_project_not_found():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x70] + sysex_data.encode(bytes("blubb", encoding='utf8'))
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    proj.stopProcessing()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x7F
github onlaj / Piano-LED-Visualizer / tests / printmidimessages.py View on Github external
import mido
from mido import MidiFile, Message, tempo2bpm, MidiTrack,MetaMessage

ports = mido.get_input_names()

for port in ports:
	if "Through" not in port and "RPi" not in port and "RtMidOut" not in port:
		try:
			inport =  mido.open_input(port)
			print("Inport set to "+port)
		except:
			print ("Failed to set "+port+" as inport")

while True:
	for msg in inport.iter_pending():
		print(msg)
github onlaj / Piano-LED-Visualizer / tests / lightkeys.py View on Github external
parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()

        # Create NeoPixel object with appropriate configuration.
        self.strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        self.strip.begin()

ledstrip = LedStrip()

ports = mido.get_input_names()

for port in ports:
	if "Through" not in port and "RPi" not in port and "RtMidOut" not in port:
		try:
			inport =  mido.open_input(port)
			print("Inport set to "+port)
		except:
			print ("Failed to set "+port+" as inport")

green = 255
red = 255
blue = 255

while True:
	for msg in inport.iter_pending():
		note = find_between(str(msg), "note=", " ")
		original_note = note
		note = int(note)
		if "note_off" in str(msg):
			velocity = 0
		else:
github ManiacalLabs / BiblioPixel / scripts / release_test / features.py View on Github external
def midi():
        import mido
        return set(mido.get_input_names()) - MIDI_PORTS_TO_REMOVE
github mido / mido / tests / test_syx.py View on Github external
def test_handle_any_whitespace(tmpdir):
    path = tmpdir.join("test.syx").strpath

    with open(path, 'wt') as outfile:
        outfile.write('F0 01 02 \t F7\n   F0 03 04 F7\n')
    assert read_syx_file(path) == [Message('sysex', data=[1, 2]),
                                   Message('sysex', data=[3, 4])]
github mido / mido / mido / test_messages.py View on Github external
def test_pitchwheel():
    """Check if pitchwheel type check and encoding is working."""
    msg = Message('pitchwheel', pitch=MIN_PITCHWHEEL)
    bytes = msg.bytes()
    assert bytes[1] == bytes[2]

    msg = Message('pitchwheel', pitch=MAX_PITCHWHEEL)
    bytes = msg.bytes()
    assert bytes[1] == bytes[2] == 127
github mido / mido / tests / messages / test_strings.py View on Github external
def test_decode_sysex():
    assert Message.from_str('sysex data=(1,2,3)').data == (1, 2, 3)
github mido / mido / tests / midifiles / test_tracks.py View on Github external
def test_track_repr():
    track = MidiTrack([
        Message('note_on', channel=1, note=2, time=3),
        Message('note_off', channel=1, note=2, time=3),
    ])
    track_eval = eval(repr(track))
    for m1, m2 in zip(track, track_eval):
        assert m1 == m2