I'm finding two problems with the script I wrote below. (1) the MIDI notes are not added to the take until I manually double-click on the take to open it, see the MIDI notes, and then click one of the MIDI notes. Then, suddenly they all appear in the main Reaper window. (2) action 41824 (render project) requires a confirm button be pressed in the GUI, which freezes Python. Is there a way to automate the whole rendering process from Python?
Code:
#load Reaper library/API
import reapy
from random import randint as r, choice
class note():
def __init__(self,pitch,start,end,velocity):
self.pitch = pitch
self.start = start
self.end = end
self.velocity = velocity
def add_pattern_Reaper(pattern,channel=1):
for n in range(len(pattern)):
note = pattern[n]
take.add_note(start=note.start,end=note.end,pitch=note.pitch,velocity=note.velocity,channel=channel,unit="beats")
project = reapy.Project()
track = project.add_track(name="synth")
track.add_fx("Ultra Analog Session 2")
item = track.add_midi_item(start=0,end=12)
take = item.active_take
# (created pitches, durations, velocities, and spacings here)
pattern_01=create_pattern(0,pitches,durations,velocities,spacings,32
add_pattern_Reaper(pattern_01)
project.perform_action(41824)