Skip to content

Instantly share code, notes, and snippets.

@rixtox
Last active October 19, 2019 14:23
Show Gist options
  • Save rixtox/8c891d0ebf9f05481c96 to your computer and use it in GitHub Desktop.
Save rixtox/8c891d0ebf9f05481c96 to your computer and use it in GitHub Desktop.
Export REAPER Tempo Markers to osu! Timing Points
import sys, os, configparser, codecs, re
sys.argv=["Main"]
import tkinter as tk
from tkinter.filedialog import asksaveasfilename
root = tk.Tk()
root.withdraw()
proj = RPR_EnumProjects(-1, "", 512)[0]
(proj, project_dir, buf_sz) = RPR_GetProjectPathEx(proj, "", 255)
config_path = os.path.join(project_dir, "tempo_mapping.ini")
config = configparser.RawConfigParser()
config.read(config_path)
def update_osu_path():
file_path = asksaveasfilename(initialdir=project_dir,defaultextension=".osu", filetypes=[("osu! file",".osu")], title="Save Timing Points")
if not file_path:
RPR_ShowMessageBox("No file location provided!", "Export Error", 0)
return False
if not config.has_section('Export'):
config.add_section('Export')
config.set('Export', 'osu', file_path)
with codecs.open(config_path, 'w', encoding='utf8') as f:
config.write(f)
return True
if not config.has_option('Export', 'osu'):
update_osu_path()
def check_file_path():
file_path = config.get('Export', 'osu')
confirm = RPR_ShowMessageBox("Export to osu: \n" + file_path, "Export Confirm", 3)
if confirm == 7: # No
if update_osu_path():
export(config.get('Export', 'osu'))
elif confirm == 6: # Yes
export(config.get('Export', 'osu'))
def timing_points_lines():
global proj
tempo_c = RPR_CountTempoTimeSigMarkers(proj)
last_timesig_num = 0
last_timesig_denom = 0
timing_points = []
for ptidx in range(0, tempo_c):
(ok, proj, ptidx, timepos, measurepos, beatpos, bpm, timesig_num, timesig_denom, lineartempo) = RPR_GetTempoTimeSigMarker(proj, ptidx, 0, 0, 0, 0, 0, 0, 0)
if timesig_num == 0:
timesig_num = last_timesig_num
else:
last_timesig_num = timesig_num
if timesig_denom == 0:
timesig_denom = last_timesig_denom
else:
last_timesig_denom = timesig_denom
timing_points.append("%d,%s,%d,2,0,100,1,0\n" % (int(timepos * 1000), (60000 / bpm), timesig_denom))
return timing_points
def export(file_path):
with codecs.open(file_path, 'r', encoding='utf8') as f:
lines = f.readlines()
idxs = [ i for i, line in enumerate(lines) if line.startswith('[TimingPoints]') ]
if any(idxs):
first_part = lines[:idxs[0]+1]
second_part = lines[idxs[0]+1:]
idxs = [ i for i, line in enumerate(second_part) if re.search("^\[\w*\]", line) ]
if any(idxs):
second_part = second_part[idxs[0]:]
lines = first_part + timing_points_lines() + ['\r\n', '\r\n', '\r\n'] + second_part
with codecs.open(file_path, 'w', encoding='utf8') as f:
f.writelines(lines)
check_file_path()
import sys, os, configparser, codecs
sys.argv=["Main"]
import tkinter as tk
from tkinter.filedialog import asksaveasfilename
root = tk.Tk()
root.withdraw()
proj = RPR_EnumProjects(-1, "", 512)[0]
(proj, project_dir, buf_sz) = RPR_GetProjectPathEx(proj, "", 255)
config_path = os.path.join(project_dir, "tempo_mapping.ini")
config = configparser.RawConfigParser()
config.read(config_path)
def update_txt_path():
file_path = asksaveasfilename(initialdir=project_dir,defaultextension=".txt", filetypes=[("Text file",".txt")], title="Save Timing Points")
if not file_path:
RPR_ShowMessageBox("No file location provided!", "Export Error", 0)
return False
if not config.has_section('Export'):
config.add_section('Export')
config.set('Export', 'txt', file_path)
with codecs.open(config_path, 'w', encoding='utf8') as f:
config.write(f)
return True
if not config.has_option('Export', 'txt'):
update_txt_path()
def check_file_path():
file_path = config.get('Export', 'txt')
confirm = RPR_ShowMessageBox("Export to: \n" + file_path, "Export Confirm", 3)
if confirm == 7: # No
if update_txt_path():
export(config.get('Export', 'txt'))
elif confirm == 6: # Yes
export(config.get('Export', 'txt'))
def export(file_path):
global proj
f = open(file_path, 'w')
tempo_c = RPR_CountTempoTimeSigMarkers(proj)
last_timesig_num = 0
last_timesig_denom = 0
timing_points = []
for ptidx in range(0, tempo_c):
(ok, proj, ptidx, timepos, measurepos, beatpos, bpm, timesig_num, timesig_denom, lineartempo) = RPR_GetTempoTimeSigMarker(proj, ptidx, 0, 0, 0, 0, 0, 0, 0)
if timesig_num == 0:
timesig_num = last_timesig_num
else:
last_timesig_num = timesig_num
if timesig_denom == 0:
timesig_denom = last_timesig_denom
else:
last_timesig_denom = timesig_denom
timing_points.append("%d,%s,%d,2,0,100,1,0\n" % (int(timepos * 1000), (60000 / bpm), timesig_denom))
f.writelines(timing_points)
check_file_path()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment