def save(selected_track = None): """Save. Saves a preset from selected track in Reaper Parameters ---------- presetname: Name of preset to be used Returns ------- return_chunk: chunk that can be stored in preset manager """ #get references project = reapy.Project() if selected_track == None: selected_track = project.get_selected_track(0) else: selected_track = selected_track logging.debug('Storing preset from: ' + selected_track.name + "|" + project.name) #load configuration from selected track vst_track_chunk = reapy.reascript_api.GetTrackStateChunk(selected_track.id,"",10000000,False) #parse track state chnk with RPP vst_track_chunk_parsed = rpp.loads(vst_track_chunk[2]) #search for VST plugin data preset_chunk = vst_track_chunk_parsed.find("FXCHAIN").find("VST") #create new chunk return_chunk = reaper_preset_chunk() return_chunk.from_element(preset_chunk, vst_track_chunk) init_name = selected_track.name return return_chunk, init_name
def set_output_path(folder: str): """Set Render Path. Changes current project render path Parameters ---------- folder: folder where to render audio """ logging.debug('Setting Render Path: ' + folder) #open project file project_file_path = os.path.join(glob.data_folder, "renderproject.rpp") project_file = open(project_file_path, "r+") file_content = rpp.loads(project_file.read()) #change render file setting render_file = file_content.find("RENDER_FILE") render_file[1] = folder #empty file project_file.seek(0) project_file.truncate() #write new content rpp.dump(file_content,project_file) project_file.close() #reopen project to make changes effective reapy.open_project(project_file_path)
def test_conversion(filename): DIR = path.dirname(__file__) with open(path.join(DIR, 'data', filename)) as fp: raw_proj = fp.read() # Allow some differences raw_proj = (raw_proj.replace('"4.32"', '4.32').replace( '"5.50c"', '5.50c').replace('"audio/"', 'audio/').replace( "'{1EB4F5A8-25D1-43CA-91D1-F1CA4ED005ED}'", '{1EB4F5A8-25D1-43CA-91D1-F1CA4ED005ED}').replace( "'{35FAE399-C558-4F4A-903F-4FF6F0470B4D}'", '{35FAE399-C558-4F4A-903F-4FF6F0470B4D}').replace( '"Trackk"', 'Trackk').replace("''", '""').replace('- \n', '-\n')) proj = loads(raw_proj) raw_proj2 = dumps(proj) assert raw_proj2 == raw_proj assert loads(raw_proj2) == proj
def load(chunk: reaper_preset_chunk, selected_track=None, new_track=False): """Load. Loads a preset into Reaper Parameters ---------- chunk: Chunk to be loaded """ #get references project = reapy.Project() #check if a track is selected, otherwise create new track if new_track == False: if selected_track == None: if project.n_selected_tracks == 0: selected_track = project.add_track(project.n_tracks + 1, "New Track") else: selected_track = project.get_selected_track(0) else: selected_track = project.add_track(project.n_tracks + 1, "New Track") #chekc if tracks has already an instrument. If so replace if different if selected_track.instrument == None: selected_track.add_fx(chunk.plugin_dll) elif selected_track.instrument.name != chunk.plugin_name: selected_track.instrument.delete() selected_track.add_fx(chunk.plugin_dll) #read track state from selected track vst_track_chunk = reapy.reascript_api.GetTrackStateChunk(selected_track.id,"",10000000,False) #parse data with RPP vst_track_chunk_parsed = rpp.loads(vst_track_chunk[2]) #add new preset configuration, by replacing portion of the track state vst_track_chunk_parsed.find("FXCHAIN").find("VST").children = chunk.vst_chunk #convert to writeable chunk new_chunk = rpp.dumps(vst_track_chunk_parsed) #set new chunk to track success = reapy.reascript_api.SetTrackStateChunk(selected_track.id, new_chunk,False) if success == 1: logging.debug('Setting preset to: ' + selected_track.name + "|" + project.name) else: logging.error('Setting preset to: ' + selected_track.name + "|" + project.name)
import json, sys, rpp def getSecondsFromPPQ(tempo, ppq, offset): microseconds_per_tick = (60000 / tempo * 1000) / ppq seconds_per_tick = microseconds_per_tick / 1000000 seconds = offset * seconds_per_tick return seconds try: with open(sys.argv[1], "rb") as f: data = f.read().decode("utf-8") r = rpp.loads(data) tempo = float(next(r.iterfind(".//TEMPO"))[1]) trackList = {} for item in r.iterfind(".//TRACK"): trackName = item.find(".//NAME")[1] if (trackName.startswith("!")): if not trackName in trackList: trackList[trackName] = [] for pos in item.iterfind(".//POSITION"): itemType = item.find(".//SOURCE").attrib itemPos = float(pos[1]) if (itemType[0] == "MIDI"): ppq = 960 tick_offset = 0 for midiData in item.find(".//SOURCE").children: if midiData[0] == 'HASDATA': ppq = int(midiData[2])
float(hop), float(frame)) np.save(euFramesFile, guideTrackUtterance, allow_pickle=True) # Save guide track .npy with name, hop, frame #Process print('\nComparing Utterance from Speakers to Guide Track...') resultExclusive = CompareUtteranceExclusive(speakersUtterance, guideTrackUtterance, float(tr)) if config['overlapitems'] == 'True': duration = frame else: duration = hop with open(projectFile, "r") as file: r = rpp.loads(file.read()) for i in range(len(dxList)): result = resultExclusive[np.where(resultExclusive[:, 2] == int(i))] ReaPush(r, result, float(hop), float(duration), guideTrack['path'], dxList[i]) with open(outputFile, "w+") as file: file.write(rpp.dumps(r)) print('\nDone.') try: os.system('cd /') os.system('open ' + str(outputFile).replace(' ', '\\ ')) except:
def test_loads(): src = """\ <REAPER_PROJECT 0.1 "4.32" 1372525904 RIPPLE 0 GROUPOVERRIDE 0 0 0 AUTOXFADE 1 <RECORD_CFG Y2FsZhAAAAAIAAAA > <RECORD_CFG > <VST "VST: ReaComp (Cockos)" reacomp.dll 0 "" 1919247213 bWNlcu9e7f4EAAAAAQAAAAAAAAACAAAAAAAAAAQAAAAAAAAACAAAAAAAAAACAAAAAQAAAAAAAAACAAAAAAAAAFQAAAAAAAAAAAAQAA== 776t3g3wrd7L/6o+AAAAAKabxDsK16M8AAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAnNEHMwAAgD8AAAAAzcxMPQAAAAAAAAAAAAAAAAAAAAAAAAAA AAAQAAAA > <SOURCE MIDI E 3840 b0 7b 00 e 3840 b0 7b 00 > <JS loser/3BandEQ "" 0.000000 200.000000 0.000000 2000.000000 0.000000 0.000000 - - - - - > NAME 09azAZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ NAME `09 azAZ!"#$%&'()*+,-./:;<=>?@[\]^_'{|}~` NAME < NAME > NAME <> VERSION 4.32 >""" expected = Element('REAPER_PROJECT', ['0.1', '4.32', '1372525904'], [ ['RIPPLE', '0'], ['GROUPOVERRIDE', '0', '0', '0'], ['AUTOXFADE', '1'], Element('RECORD_CFG', [], ['Y2FsZhAAAAAIAAAA']), Element('RECORD_CFG', [], []), Element('VST', [ 'VST: ReaComp (Cockos)', 'reacomp.dll', '0', '', '1919247213' ], [ 'bWNlcu9e7f4EAAAAAQAAAAAAAAACAAAAAAAAAAQAAAAAAAAACAAAAAAAAAACAAAAAQAAAAAAAAACAAAAAAAAAFQAAAAAAAAAAAAQAA==', '776t3g3wrd7L/6o+AAAAAKabxDsK16M8AAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAnNEHMwAAgD8AAAAAzcxMPQAAAAAAAAAAAAAAAAAAAAAAAAAA', 'AAAQAAAA', ]), Element('SOURCE', ['MIDI'], [ ['E', '3840', 'b0', '7b', '00'], ['e', '3840', 'b0', '7b', '00'], ]), Element('JS', ['loser/3BandEQ', ''], [ [ '0.000000', '200.000000', '0.000000', '2000.000000', '0.000000', '0.000000', '-', '-', '-', '-', '-' ], ]), ['NAME', '09azAZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'], ['NAME', '09 azAZ!"#$%&\'()*+,-./:;<=>?@[\\]^_\'{|}~'], ['NAME', '<'], ['NAME', '>'], ['NAME', '<>'], ['VERSION', '4.32'], ]) actual = loads(src) assert attr.asdict(actual) == attr.asdict(expected)