Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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)
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:
def midi():
import mido
return set(mido.get_input_names()) - MIDI_PORTS_TO_REMOVE
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])]
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
def test_decode_sysex():
assert Message.from_str('sysex data=(1,2,3)').data == (1, 2, 3)
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