Beispiel #1
0
def test_io_midi_sync():
    tempo = 150
    midi_out = iso.MidiOutputDevice(VIRTUAL_DEVICE_NAME,
                                    virtual=True,
                                    send_clock=True)
    print("Created MIDI out: %s" % midi_out)
    clock = iso.Clock(tempo=tempo, clock_target=midi_out)

    midi_in = iso.MidiInputDevice(VIRTUAL_DEVICE_NAME)

    clock.background()
    time.sleep(0.1)
    clock.stop()
    assert midi_in.tempo == pytest.approx(tempo, rel=0.03)
Beispiel #2
0
def test_timeline_tempo(dummy_timeline):
    # Set tempo of internal clock
    dummy_timeline.clock_source = iso.Clock(dummy_timeline, 120)
    dummy_timeline.tempo = 180
    assert dummy_timeline.clock_source.tempo == 180

    # Set tempo of external clock (raise exception)
    try:
        dummy_timeline.clock_source = iso.MidiInputDevice("Virtual Device", virtual=True)
        assert dummy_timeline.tempo is None
        with pytest.raises(RuntimeError):
            dummy_timeline.tempo = 180
    except iso.DeviceNotFoundException:
        # Fail quietly on machines that don't support MIDI
        pass
Beispiel #3
0
def test_io_midi():
    """
    Send a MIDI message through a virtual loopback device.
    Note that virtual=True is not needed for subsequent calls, as it has already been
    created so is visible to rtmidi as an existing device.
    """
    events = []

    def log_event(message):
        nonlocal events
        events.append(message)

    midi_in = iso.MidiInputDevice(VIRTUAL_DEVICE_NAME, virtual=True)
    midi_in.callback = log_event
    midi_out = iso.MidiOutputDevice(VIRTUAL_DEVICE_NAME)

    timeline = iso.Timeline(120, midi_out)
    timeline.stop_when_done = True
    timeline.schedule({"note": iso.PSequence([60], 1), "duration": 0.1})
    timeline.run()
    assert len(events) == 1
Beispiel #4
0
#
# 1. takes MIDI input, and constructs three markov chains for pitch, duration
#    and amplitude.
# 2. after receiving a keyboard interrupt (ctrl-c), plays back melodies which are
#    statistically similar to the input.
#------------------------------------------------------------------------

import isobar as iso

import logging

logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")

import time

midi_in = iso.MidiInputDevice()
midi_out = iso.MidiOutputDevice()

learner = iso.MarkovParallelLearners(3)
clock0 = time.time()

print("Listening for MIDI events...")

try:
    while True:
        message = midi_in.poll()
        if message is not None and message.type == "note_on":
            clock = time.time()
            print("[%f] %s (%d, %d)" %
                  (clock, message, message.note, message.velocity))