Last active
May 8, 2020 17:15
-
-
Save tabascoterrier/6bc0334298c9e056880d9774021550af to your computer and use it in GitHub Desktop.
audiater.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import mido | |
import time | |
import random | |
import hashlib | |
# pip install mido rtmidi | |
# Enable a virtual MIDI bus: https://help.ableton.com/hc/en-us/articles/209774225-Using-virtual-MIDI-buses | |
# tail -f somelog | ./audiater.py | |
# Major: A, C, D, E, G | |
maj_pentatonic = [57, 60, 62, 64, 67] | |
sleeps = [0, 0.5, 1, 2] | |
scale = maj_pentatonic | |
outport = mido.open_output("IAC Driver Bus 1") | |
for line in sys.stdin: | |
# Map a line to a note | |
note = int(hashlib.md5(line.rstrip().encode('utf-8')).hexdigest(), 16) % 5 | |
# Send the occasional "bass" note to channel 1 | |
if random.randint(0, 99) < 12: | |
channel = 1 | |
length = random.randint(3, 9) | |
velocity = random.randint(90, 100) | |
else: | |
channel = 0 | |
length = random.randint(1, 3) | |
velocity = random.randint(50, 100) | |
msg = mido.Message( | |
'note_on', | |
note=scale[note-1], | |
velocity=velocity, | |
time=length, | |
channel=channel | |
) | |
outport.send(msg) | |
print('{0}\r'.format(msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment