Last active
July 8, 2020 20:36
-
-
Save manualbashing/17eccaad39cfca8b5d3f2538eff1843d to your computer and use it in GitHub Desktop.
Midi Logger for #SonicPi
This file contains hidden or 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
key_pressed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
key_released_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
amp = 0.5 | |
key_pressed_in_chord = false | |
midi_device = "/midi/digital_piano/0/1/note_on" | |
log_file_path = "C:\\Users\\Manuel\\Documents\\sonicpi\\logger.log" | |
live_loop :midi_logger do | |
note, velocity = sync midi_device | |
# File.write(log_file_path, "# debug >> [%d,%d]\n" % [note, velocity], mode: "a") | |
if velocity != 0 | |
key_pressed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
timespan_between_notes = key_pressed_time - key_released_time | |
sleep_cmd = "sleep %0.3f\n" % timespan_between_notes | |
File.write(log_file_path, sleep_cmd, mode: "a") if key_pressed_in_chord == false | |
amp = velocity / 127.0 | |
key_pressed_in_chord = true | |
else | |
key_pressed_in_chord = false | |
key_released_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
timespan_key_was_pressed = key_released_time - key_pressed_time | |
played_note_cmd = "play %d, amp: %0.2f, sustain: %0.3f\n" % [note, | |
amp, | |
timespan_key_was_pressed] | |
File.write(log_file_path, played_note_cmd, mode: "a") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment