サンプルを見たところ、USB MIDIを使うことで、MIDIのNoteOn/NoteOffを送ることが簡単にできることが分かった。そこで、、ドミソの和音からランダムに音を選択して自動演奏するソフトを作ってみた。以下のアプリを走らせて、FL StudioのMIDI INに設定すると、勝手に、延々と、ドミソドの中から音を拾って再生する。ドミソの和音から選んでいるのでメロディーの破綻はない。アルゴリズムが超簡単なので、問題は聴いていて飽きないかどうか。。
# # test for USB MIDI # # import time import random import usb_midi import adafruit_midi from adafruit_midi.note_off import NoteOff from adafruit_midi.note_on import NoteOn scale = { 'C5' : 60, 'D5' : 62, 'E5' : 64, 'F5' : 65, 'G5' : 67, 'A5' : 69, 'B5' : 71, 'C6' : 72, 'D6' : 74, 'E6' : 76, } CC = ('C5', 'E5', 'G5', 'C6', 'E6') USB_MIDI_channel = 1 usb_midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=USB_MIDI_channel - 1) VELOCITY=64 def auto_play(code,velocity=VELOCITY): while True: note = code[int(random.random()*len(code))] usb_midi.send(NoteOn(scale[note], velocity)) print("{:s} ".format(note),end="") time.sleep(0.5) usb_midi.send(NoteOff(scale[note], velocity)) def all_off(): global VELOCITY for note in scale.values(): usb_midi.send(NoteOff(note, velocity))
FL Studioとソフトシンセを使って、USB MIDIが出力するランダムなNoteを再生する
自動再生している音楽(単にドミソドのランダムです。シンセのアルペジェータが動いているので多少はそれらしくなっていますが)
https://soundcloud.com/dune-geek/automatic-composition-test001
こんな感じで最終的にはIBIZA風のハウスを自動で延々と流したいのだが・・・
30分程度で、USB MIDIで自動再生する試作アプリが作れた。他人の褌状態だけど、、CircuitPythonのバンドルライブラリの威力はすごい。。