def Main(bpm): bps = bpm / 60 time_per_beat = 1.0 / bps interval = time_per_beat / 24.0 print('BPM: %d sleep interval: %f' % (bpm, interval)) start_time = time.time() i = 0 while True: next_time = start_time + i * interval delta = next_time - time.time() if delta > 0: time.sleep(delta) simplecoremidi.send_midi([0xf8]) i += 1
def play_a_scale(): root_note = 60 # This is middle C channel = 1 # This is MIDI channel 1 note_on_action = 0x90 major_steps = [2, 2, 1, 2, 2, 2, 1, 0] velocity = 127 note = root_note for step in major_steps: send_midi((note_on_action | channel, note, velocity)) sleep(0.1) send_midi((note_on_action | channel, note, 0)) # A note-off is just a note-on with velocity 0 note += step sleep(0.2)
def emit_midi(midi_numbers, note_duration=500, velocity=64, channel=0): for midi_number in midi_numbers: send_midi((144 + channel, midi_number, velocity)) try: time.sleep(note_duration / 1000) except KeyboardInterrupt: for midi_number in midi_numbers: send_midi((128 + channel, midi_number, velocity)) raise for midi_number in midi_numbers: send_midi((128 + channel, midi_number, velocity))
def result(): note = int(request.form['note']) velocity = int(request.form['velocity']) send_midi((0xb0, note, velocity)) print(note, velocity) return '{},{}'.format(note, velocity)
def play_note(n, c, l, v): send_midi((0x90|(c-1), n, v)) gevent.sleep(l) send_midi((0x90|(c-1), n, 0))
def send_midi(self): # this is a simple wrapper function to send a MIDI event out immediately # note: has nothing to do with pos simplecoremidi.send_midi(self.msg.bytes())
def test_can_send_midi(): scm.send_midi(midion) scm.send_midi(midioff)
def test_can_send_midi_as_list(): midion = [0x91, 0x3C, 0x7f] midioff = [0x91, 0x3C, 0x00] scm.send_midi(midion) scm.send_midi(midioff)
def send_midi(self, sensor, value): simplecoremidi.send_midi((STATUS_BYTE, self.sensor_config[sensor]["cc"], value))
def midi(x): #print(repr(x)) send_midi(x)
def playSound(name): note = beatNames.index(name) print(note) send_midi((note_on_action | channel, note+1, 127))
from simplecoremidi import send_midi import sys import time import sched import os beatNames = ['P', 'S', 'K'] channel = 1 # This is MIDI channel 1 note_on_action = 0x90 schedule = sched.scheduler(time.time, time.sleep) send_midi((note_on_action | channel, 0, 127)) # warm up the channel def parseLabel(f): sounds = {} for line in f: startStr, endStr, name, prob = line.split() start = float(startStr)/10000000.0 if name in beatNames: sounds[start] = name return sounds def scheduleSounds(sounds): for start, sound in sounds.items(): schedule.enter(start, 1, playSound, sound) schedule.run() def playSound(name): note = beatNames.index(name) print(note) send_midi((note_on_action | channel, note+1, 127))
def play_note(n, c, l, v): send_midi((0x90 | (c - 1), n, v)) gevent.sleep(l) send_midi((0x90 | (c - 1), n, 0))