-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
129 lines (113 loc) · 4.13 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import config
from reaper_python import *
def render_action(dir = "", file = "test.wav", track = "mix"):
RPR_GetSetProjectInfo_String(0, "RENDER_FILE", dir, True)
RPR_GetSetProjectInfo_String(0, "RENDER_PATTERN", file , True)
RPR_Main_OnCommand(40340, 0)
if track == "tenor":
command = 40940
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "bass":
command = 40941
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "soprano":
command = 40942
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "alto":
command = 40943
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "girl":
command = 40942
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
command = 40943
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "boya":
command = 40940
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
command = 40941
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "hidis":
command = 40941
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
command = 40942
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "lowdis":
command = 40940
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
command = 40943
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "diff":
command = 40940
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
command = 40942
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
elif track == "zick":
command = 40941
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
command = 40943
RPR_Main_OnCommand(command, 0)
RPR_Main_OnCommand(40728, 0)
RPR_Main_OnCommand(42230, 0)
def create_folder(folder_name):
if not os.path.exists(folder_name):
os.mkdir(folder_name)
def render_project(midi_file, tonality_index, output_path, output_name, override = True):
output_file = os.path.join(output_path, output_name)
track_name = config.global_config["track_name"]
render_name = config.global_config["render_name"]
for t in render_name:
if os.path.exists(output_file + "_" + t + "_" + str(tonality_index) + ".wav"):
if override:
os.remove(output_file + "_" + t + "_" + str(tonality_index) + ".wav")
else:
RPR_ShowConsoleMsg("The file ", output_file + "_" + t + "_" + str(tonality_index) + ".wav"," already exist but the override option is False")
return
# erase previous midi tracks
num_item = RPR_CountMediaItems(0)
for i in range(num_item):
mi = RPR_GetMediaItem(0, 0)
track = RPR_GetMediaItem_Track(mi)
k = RPR_DeleteTrackMediaItem(track, mi)
# insert new tracks
for i in range(len(track_name)):
file = midi_file + "_" + track_name[i] + "_" + str(tonality_index) + ".mid"
track = RPR_GetTrack(0, i + 1)
RPR_SetOnlyTrackSelected(track)
RPR_SetEditCurPos(0, True, False)
RPR_InsertMedia(file, 0)
for i in range(len(render_name)):
solo_name = output_name + "_" + render_name[i] + "_" + str(tonality_index) + ".wav"
render_action(output_path, solo_name, render_name[i])
# render different tracks
# render_action(output_path, output_name + "_" + str(tonality_index) + ".wav", -1)
render_path = config.render_path
project_name = RPR_GetSetProjectInfo_String(0, "PROJECT_NAME", "", False)[3]
project_name = project_name[:-4]
dataset_path = os.path.join(config.dataset_path, config.type_path, project_name)
render_path = os.path.join(config.render_path, config.type_path, project_name)
create_folder(render_path)
midi_files = list(set(d[:config.global_config["general_name_length"]] for d in os.listdir(dataset_path)))
midi_files.sort()
for midi_file in midi_files:
for i in range(0, 12):
path_tidx = os.path.join(dataset_path, midi_file + "_alto_" + str(i) + ".mid")
if os.path.exists(path_tidx):
render_project(os.path.join(dataset_path, midi_file), i, render_path, midi_file)
else:
break