-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
desc="Get selected items weighted BPM" | ||
by="junh1024" | ||
|
||
from reaper_python import * | ||
from contextlib import contextmanager | ||
|
||
global total_lengths, BPM_file | ||
total_lengths=0 | ||
global total_rates | ||
total_rate=0 | ||
|
||
@contextmanager | ||
def undoable(message): | ||
RPR_Undo_BeginBlock2(0) | ||
try: | ||
yield | ||
finally: | ||
RPR_Undo_EndBlock2(0, message, -1) | ||
|
||
debug = True | ||
|
||
def msg(m): | ||
if 'debug' in globals(): | ||
RPR_ShowConsoleMsg(m) | ||
|
||
# msg(RPR_CountSelectedMediaItems(0)) | ||
|
||
with undoable(desc): | ||
#get project BPM | ||
|
||
# https://forum.cockos.com/showthread.php?t=46432 | ||
# https://github.com/metalmike/ReaScoreMusicXML/blob/master/reascoremusicxml/reascoremusicxml.py | ||
BPM_proj=RPR_GetProjectTimeSignature2(-1,0,0)[1] | ||
# RPR_ShowConsoleMsg(BPM_proj) | ||
|
||
#get file BPM | ||
# BPM_file = RPR_GetUserInputs("BPM",1,"What is the BPM of this item?","",64)[4] | ||
# BPM_file = float(BPM_file.strip()) | ||
# RPR_ShowConsoleMsg(BPM_file) | ||
|
||
#get items | ||
for i in range (RPR_CountSelectedMediaItems( 0)): | ||
MI=RPR_GetSelectedMediaItem(0,i) | ||
|
||
|
||
# get length | ||
item_len = RPR_GetMediaItemInfo_Value(MI, "D_LENGTH") | ||
length_file=item_len | ||
# compute length | ||
# adjusted_length=item_len*1/ | ||
|
||
# set length | ||
# RPR_SetMediaItemInfo_Value(MI, "D_LENGTH", item_len*BPM_file/BPM_proj) | ||
# set playrate | ||
# MediaItem_Take* RPR_GetMediaItemTakeInfo_Value( take, parmname )(MediaItem* item, int tk ) | ||
take=RPR_GetActiveTake(MI) | ||
# RPR_ShowConsoleMsg(RPR_GetMediaItemTakeInfo_Value( MI, "B_MUTE")) | ||
if (RPR_GetMediaItemInfo_Value( MI, "B_MUTE"))== False : | ||
#calculate weighted BPM | ||
|
||
|
||
rate_file=RPR_GetMediaItemTakeInfo_Value( take, "D_RATE" ) | ||
if rate_file == 0: | ||
continue | ||
# length_file=RPR_GetMediaItemTakeInfo_Value( take, "D_LENGTH" ) | ||
pitch_file=RPR_GetMediaItemTakeInfo_Value( take, "D_PITCH" ) | ||
|
||
BPM_file=BPM_proj/rate_file | ||
|
||
total_pitches+=pitch_file*length_file | ||
total_lengths+=length_file | ||
avg_pitch=total_pitches/total_lengths | ||
ideal_rate=1+(1.06^avg_pitch) # 12th root of 2 | ||
ideal_bpm=BPM_file*ideal_rate | ||
RPR_ShowConsoleMsg(str(ideal_bpm) + "\n") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# junh1024 and AI to make codes | ||
# external python script to turn a VideoReDo project file to a markers file for REAPER DAW | ||
# of selected video scenes | ||
|
||
import sys | ||
|
||
|
||
|
||
import xml.etree.ElementTree as ET | ||
from datetime import datetime | ||
|
||
divisor=10000000 | ||
|
||
def parse_xml(file_path): | ||
tree = ET.parse(file_path) | ||
root = tree.getroot() | ||
|
||
times = [] | ||
|
||
First=True | ||
|
||
for cut in root.findall('.//cut'): | ||
|
||
# VRD vprj format stores the timecodes of the cuts we don't want, so we ignore the 1st timecode | ||
if First == False: | ||
CutTimeStart = float(cut.find('CutTimeStart').text)/divisor | ||
times.append(CutTimeStart) | ||
# print('start\n') | ||
|
||
# Thereafter, we put the timecodes in a list | ||
CutTimeEnd = float(cut.find('CutTimeEnd').text)/divisor | ||
times.append(CutTimeEnd) | ||
# print('end\n') | ||
First = False | ||
|
||
return times | ||
|
||
def calculate_time_differences(times): | ||
differences = [] | ||
|
||
|
||
the_range= int ( ( len(times)-1 ) /2 ) | ||
# print(type(the_range)) | ||
|
||
i=0 | ||
for i in range(0, the_range ): | ||
|
||
# pairs of times form scenes, of which we are interested in the length | ||
time_difference = times[i*2+1]-times[i*2] | ||
|
||
if i>0: | ||
cumulative_time_difference=time_difference+differences[i-1] | ||
else: | ||
cumulative_time_difference=time_difference | ||
|
||
differences.append(cumulative_time_difference) | ||
|
||
i+=1 | ||
|
||
return differences | ||
|
||
if __name__ == "__main__": | ||
file = sys.argv[1] | ||
times = parse_xml(file) | ||
differences = calculate_time_differences(times) | ||
|
||
# Finally, write the times to a file | ||
csv_file = open(file[0:-5]+'_cuts.csv', 'w') | ||
csv_file.write('#,Name,Start,End,Length\r\n') | ||
|
||
|
||
i=2 | ||
for diff in differences: | ||
|
||
print(diff) | ||
csv_file.write('M'+str(i) +',,'+str(diff)+'\n') | ||
i+=1 | ||
|
||
csv_file.close() | ||
|
||
|