Last active
September 29, 2016 00:40
-
-
Save rianhunter/627fdfb6913563d35a5a79f01b3b9ed8 to your computer and use it in GitHub Desktop.
Hemiola
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
import asyncio | |
import anushri | |
OUTPUT_CLIENT = 20 | |
BPM = 70 | |
BEAT_LENGTH = 60 / BPM | |
WHOLE_LENGTH = BEAT_LENGTH * 4 | |
NOTE_16 = WHOLE_LENGTH / 16 | |
NOTE_32 = WHOLE_LENGTH / 32 | |
VELOCITY = 127 | |
DRUM_VELOCITY = VELOCITY | |
MIDI_ROOT = 48 | |
MAJOR_SCALE = [0, 2, 4, 5, 7, 9, 11] | |
MINOR_SCALE = [0, 2, 3, 5, 7, 8, 10] | |
@asyncio.coroutine | |
def sequence(*a): | |
for c in a: | |
yield from c | |
def scale_map(midi_root, scale, scale_offsets): | |
toret = [] | |
for offset in scale_offsets: | |
midi_root_ = midi_root | |
while offset >= len(scale): | |
offset -= len(scale) | |
midi_root_ += 12 | |
toret.append(midi_root_ + scale[offset]) | |
return toret | |
@asyncio.coroutine | |
def main(anu): | |
yield from anu.reset_all_controllers() | |
yield from anu.set_parameters( | |
**{ | |
"vco_detune": 0.38, | |
"pw_env_amount": 0.0, | |
"vco_dco_range": 0.40234375, | |
"pw_lfo_amount": 0.15, | |
"env_vca_morph": 0.0, | |
"env_sustain": 0.9921875, | |
"cutoff_lfo_amount": 0.53125, | |
"cutoff_tracking": 0.703125, | |
"vca_velocity_amount": 0.0, | |
"lfo_rate": 0.6484375, | |
"glide": 0.203125, | |
"vco_dco_fine": 0.5, | |
"vcf_velocity_amount": 0.0, | |
"env_legato_mode": 0.0, | |
"vibrato_destination": 0.0, | |
"vco_env_amount": 0.0, | |
"vco_lfo_amount": 0.0, | |
"env_release": 0.5703125, | |
"cutoff_env_amount": 0.0, | |
"vco_fine": 0.49609375, | |
"lfo_shape": 0.0, | |
"cutoff_bias": 0.75, | |
"env_attack": 0.0078125, | |
"env_decay": 0.5703125, | |
"vibrato_rate": 0.625 | |
}) | |
@asyncio.coroutine | |
def sixteenth_triplets(): | |
num_notes = 8 * 3 | |
for i in range(num_notes): | |
yield from anu.trigger_hh(DRUM_VELOCITY * 70 // 100) | |
yield from asyncio.sleep(WHOLE_LENGTH / num_notes) | |
@asyncio.coroutine | |
def bd(): | |
DIV = 8 | |
for i in range(DIV): | |
if not (i % 2): | |
if i == 0: | |
yield from anu.trigger_bd(DRUM_VELOCITY) | |
else: | |
yield from anu.trigger_bd(DRUM_VELOCITY * 75 // 100) | |
if not ((i + 1) % 2): | |
yield from anu.trigger_sd(DRUM_VELOCITY * 75 // 100) | |
yield from asyncio.sleep(WHOLE_LENGTH / DIV) | |
@asyncio.coroutine | |
def note(note, velocity, duration): | |
yield from anu.note_on(note, velocity) | |
yield from asyncio.sleep(duration) | |
yield from anu.note_off(note) | |
@asyncio.coroutine | |
def one_two(notes): | |
yield from note(notes[0], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from note(notes[1], VELOCITY, NOTE_32) | |
yield from note(notes[2], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from note(notes[3], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_32) | |
yield from asyncio.sleep(NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from note(notes[2], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from asyncio.sleep(NOTE_32) | |
@asyncio.coroutine | |
def one_two_swung(notes): | |
yield from asyncio.sleep(NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from note(notes[0], VELOCITY, NOTE_32) | |
yield from note(notes[1], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from note(notes[2], VELOCITY, NOTE_32) | |
yield from note(notes[3], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
yield from note(notes[2], VELOCITY, NOTE_32) | |
yield from asyncio.sleep(NOTE_32) | |
yield from asyncio.sleep(NOTE_16) | |
for _ in range(2): | |
for scale in [MAJOR_SCALE, MINOR_SCALE]: | |
for (first_motive, first_root, second_root) in [[one_two_swung, 0, 3], | |
[one_two_swung, 0, 3], | |
[one_two, 1, 4], | |
[one_two, 0, 3]]: | |
to_wait = [] | |
to_wait.append(asyncio.ensure_future(sixteenth_triplets())) | |
to_wait.append(asyncio.ensure_future(bd())) | |
first_arpeggio = scale_map(MIDI_ROOT, scale, | |
[first_root, first_root + 2, | |
first_root + 4, first_root + 6]) | |
second_arpeggio = scale_map(MIDI_ROOT, scale, | |
[second_root, second_root + 2, | |
second_root + 4, second_root + 6]) | |
to_wait.append(asyncio.ensure_future(sequence(first_motive(first_arpeggio), | |
one_two(second_arpeggio)))) | |
yield from asyncio.wait(to_wait) | |
anushri.run_async(OUTPUT_CLIENT, 0, main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment