enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
243 stars 33 forks source link

LIVENODING 796 / Blender - Mido - Sonic Pi #181

Open enzyme69 opened 7 years ago

enzyme69 commented 7 years ago

BLEND ZIP midi_message_read_016_2017_10_30_10_07.zip

PYTHON CODE / SCRIPT NODE:

import mido
from time import sleep

# REQUIRE MIDO MODULE AND RTMIDI

#mido.set_backend('mido.backends.rtmidi')
port = mido.open_output('Network Session 2')

#mynotes = [65, 77, 44, 56, 34, 67]

msg = mido.Message('note_on', note=notes)
port.send(msg)

sleep(sleep)

#sleep(0.01)

# quick loading MIDI -- will play whole MIDI to Sonic Pi
#mid = mido.MidiFile('DuckTales2017.mid')
#for msg in mid.play():
#    port.send(msg)

#    if msg.type == 'note_on' and msg.channel == 0:
#        bpy.data.objects['Suzanne'].location.x = msg.note

    #bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
    #sleep (0.01) #insert 1 divided by (framerate)
enzyme69 commented 7 years ago

BLEND ZIP: Simpler setup: AN_Mido_SonicPi_001_2017_10_30_10_09.zip

screen shot 2017-10-30 at 21 09 09

enzyme69 commented 7 years ago

SONIC PI LIVE LOOP example:

live_loop :midi_piano1 do
  note, velocity = sync "/midi/network_session_2/0/1/note_on"
  synth :piano, note: note, amp: velocity / 127.0, sustain: 0.05, decay: 0.15, attack: 0.02, release: 0.3

end

##| live_loop :midi_piano2 do
##|   note, velocity = sync "/midi/network_session_2/0/2/note_on"
##|   synth :fm, note: note, amp: velocity / 127.0
##| end

##| live_loop :midi_piano3 do
##|   note, velocity = sync "/midi/network_session_2/0/3/note_on"
##|   synth :chiplead, note: note, amp: velocity / 127.0
##| end

##| live_loop :midi_piano4 do
##|   note, velocity = sync "/midi/network_session_2/0/4/note_on"
##|   synth :piano, note: note, amp: velocity / 127.0
##| end

##| live_loop :midi_piano5 do
##|   note, velocity = sync "/midi/network_session_2/0/5/note_on"
##|   synth :sine, note: note, amp: velocity / 127.0
##| end

##| live_loop :midi_piano6 do
##|   note, velocity = sync "/midi/network_session_2/0/6/note_on"
##|   synth :pluck, note: note, amp: velocity / 127.0
##| end
enzyme69 commented 7 years ago

With MIDI messages, there are some theories you need to think:

The cool thing with the setup is that you can use Sonic Pi to use all kind of Synth, and with Blender controlling Sonic Pi, you can also make procedural animation, to visualize the MIDI.

I am still studying and exploring this idea with 'Clockmender'.