def set_track_media(path_track, tidx, is_press=False): Reaper.CSurf_GoStart() set_current_track(tidx) if is_press: t = threading.Thread(target=click_window) t.start() Reaper.InsertMedia(path_track, 0)
def render_media( path_media, path_audio, bpm=None, is_press=False, track_idx=0): ''' function for rendering single track midi file or audio file the media will be inserted in the 1st track ''' clear_all() move_cursor_start() # set bpm if bpm: set_gobal_bpm(int(bpm)) # set media set_track_media(path_media, track_idx, is_press=is_press) # set audio filename filename = os.path.basename(path_audio) outdir = path_audio[:-len(filename)] print('filename:', filename) print('outdir:', outdir) Reaper.GetSetProjectInfo_String(0, "RENDER_FILE", outdir, True) Reaper.GetSetProjectInfo_String(0, "RENDER_PATTERN", filename, True) # save Reaper.Main_OnCommand(40296, 0) # select all Reaper.Main_OnCommand(41824, 0) # render project
def render_multi_media( mapping_dict, path_audio, bpm=None, is_press=None, ): clear_all() move_cursor_start() # set bpm if bpm: set_gobal_bpm(int(bpm)) # set media for idx, (track_idx, path_media) in enumerate(mapping_dict.items()): if isinstance(is_press, list): isp = is_press[idx] else: isp = is_press set_track_media(path_media, track_idx, is_press=is_press) # set audio filename filename = os.path.basename(path_audio) outdir = path_audio[:-len(filename)] print('filename:', filename) print('outdir:', outdir) Reaper.GetSetProjectInfo_String(0, "RENDER_FILE", outdir, True) Reaper.GetSetProjectInfo_String(0, "RENDER_PATTERN", filename, True) # save Reaper.Main_OnCommand(40296, 0) # select all Reaper.Main_OnCommand(41824, 0) # render project
def clear_all(): # delet items Reaper.Main_OnCommand(40035, 0) Reaper.Main_OnCommand(40006, 0) # got to start Reaper.CSurf_GoStart()
def drawMidi(self): Reaper.OnConnectExecute = "from sws_python import *" with Reaper: quartNoteLength = 960 self.msg('ReaChorder - drawMidi - Enter') p, bpm, bpi = Reaper.GetProjectTimeSignature2(0, 0, 0) bps = bpm / 60 beatsInBar = bpi barsPerSection = 4 RSMidi.selAllNotes() RSMidi.deleteSelectedNotes() sectionLength = quartNoteLength * beatsInBar * barsPerSection take = RSMidi.getActTakeInEditor() if take == "(MediaItem_Take*)0x00000000" or take == "(MediaItem_Take*)0x0000000000000000": Reaper.ShowConsoleMsg( "ReaChorder: Please open an item in the MIDI Editor first.\n" ) else: item = Item() # init Item class itemId = Reaper.GetMediaItemTake_Item(take) # get parent item songLength = sectionLength * len( self.song["Structure"]) # works (currently) :) item.setMidiItemLength(itemId, songLength, bps, quartNoteLength) item.setName(itemId, "ReaChorder Song") midiTake = RSMidi.allocateMIDITake(take) #go throught the sections, calling the draw() methods for obj in self.sections: self.msg("wtf3") p = obj.draw(midiTake, self.song, sectionLength) RSMidi.freeMIDITake(midiTake)
def update_controls(self): selectedTrack = Reaper.RPR_GetSelectedTrack(0, 0); # TODO add caching cursor_pos = Reaper.RPR_GetCursorPosition() for i in range(0, Reaper.RPR_CountTrackMediaItems(selectedTrack)): item_id = Reaper.RPR_GetTrackMediaItem(selectedTrack, i) take = Reaper.RPR_GetActiveTake(item_id); pos = Reaper.RPR_GetMediaItemInfo_Value(item_id, "D_POSITION"); length = Reaper.RPR_GetMediaItemInfo_Value(item_id, "D_LENGTH"); end_pos = pos + length current_pos_ppq = Reaper.RPR_MIDI_GetPPQPosFromProjTime(take, cursor_pos); if (cursor_pos >= pos + 0.001) and (cursor_pos <= end_pos + 0.001): # current_pos_ppq = Reaper.RPR_MIDI_GetPPQPosFromProjTime(take, cursor_pos); # iterate over Sysex events, get status num_sysex = Reaper.RPR_MIDI_CountEvts(take, 0, 0, 0)[0] print("Num sysex: " + str(num_sysex)) for j in range(0, num_sysex): # ta_ prefix for throw away (ta_retval, ta_take, ta_textsyxevtidx, ta_selectedOutOptional, ta_mutedOutOptional, current_evt_pos_ppq, current_evt_type, current_msg, msgOptional_sz) = Reaper.RPR_MIDI_GetTextSysexEvt(take, j, 0, 0, 0, 0, 0, 0) current_msg = Reaper.RPR_MIDI_GetTextSysexEvt(take, j, 0, 0, 0, 0, 0, 0)[7] if current_evt_type == -1: print("Sysex event number " + str(j)) # yes, this is a sysex message if current_pos_ppq == current_evt_pos_ppq: print("Sysex event is on cursor position") print("Sysex event data: %s" % ''.join('{:02X}'.format(int(a)) for a in current_msg)) # yes, it is on current cursor position # iterate over defined sysexes print("Configuration iteration") for conf_id in range(0, len(sysex)): print("Current configuration data: %s" % ''.join('{:02X}'.format(int(a)) for a in sysex[conf_id][1])) # print("Current configuration data: %s" % sysex[conf_id][1]) if current_msg == sysex[conf_id][1]: print("Found sysex event for button switching") self.buttons[conf_id].config(relief = "sunken") break
def __init__(self, master): """Init the Frame""" Frame.__init__(self,master) self.grid() for index in range(0, len(sysex)): button_states.append(tkinter.IntVar()) button_state_variable = button_states[index] button = Checkbutton(self, text = sysex[index][0], anchor = W, onvalue=1, offvalue=0, variable=button_state_variable , command = lambda index=index: self.access(index)) button.config(height = 3, width = 30) button.grid(column = 0, row = index, sticky = NW) self.buttons.append(button) self.last_pos = Reaper.RPR_GetCursorPosition() self.update_controls()
def ProjectSelected(o, p): A, _, F, _ = Reaper.EnumProjects(-1, "", 512) p.Value = Project(A) p.Value.File = File(F)
def _ReaperDisconnect(o): if o._UndoEventName != "": Reaper.Undo_EndBlock2(o.Address, o._UndoEventName, -1) o._UndoEventName = ""
def UndoEvent(o, Name): if o._UndoEventName == "": o._UndoEventName = Name Reaper.Undo_BeginBlock2(o.Address)
def set_current_track(tidx): Reaper.Main_OnCommand(40297, 0) # unselected all track Reaper.SetTrackSelected( # set selected track Reaper.GetTrack(0, tidx), True)
def move_cursor_start(): Reaper.CSurf_GoStart()
def set_gobal_bpm(bpm): retval, proj, ptidx, timeposOut, measureposOut, beatposOut, bpmOut, timesig_numOut, timesig_denomOut, lineartempoOut = Reaper.RPR_GetTempoTimeSigMarker(0, -1, 0, 0, 0, 0, 0, 0, 0) Reaper.SetTempoTimeSigMarker(0, ptidx, timeposOut, measureposOut, beatposOut, bpm, timesig_numOut, timesig_denomOut, lineartempoOut) Reaper.UpdateArrange() Reaper.UpdateTimeline()
import beyond.Reaper