-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheq2eq.py
More file actions
executable file
·195 lines (180 loc) · 6.32 KB
/
eq2eq.py
File metadata and controls
executable file
·195 lines (180 loc) · 6.32 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import pathlib
import sys
from converter import (
file2iir,
iir2aupreset,
PRESET_DIR,
iir2rme_totalmix_channel,
iir2rme_totalmix_room,
)
def usage():
print(
"Usage: {} -input *infiles* -format *format* [-output *outfile*] [-install]".format(
sys.argv[0]
)
)
print("Parameters")
print(" *infile* the name of your eq files separated by comma.")
print(" *format* can be one of aupreset, apo, rmetmeq, rmetmreq.")
print(
" *outfile* the name of the generated eq file, if not specified stdout will be used."
)
print(
" -install if the specified format as a specific directory the EQ will be copied in it"
)
print("")
print("Examples")
print(
"{} -input eq.txt -format aupreset -output eq.aupreset".format(
sys.argv[0]
)
)
print("{} -input eq.txt -output eq.aupreset -install".format(sys.argv[0]))
print(
" It will copy output to ~/Library/Audio/Presets/Apple/AUNBandEQ/eq.aupreset"
)
print(
"{} -input eq.txt -format rmetmeq -output eq.tmeq".format(sys.argv[0])
)
print(
"{} -input left.txt,rigt.txt -format rmetmreq -output eq.tmreq".format(
sys.argv[0]
)
)
print("")
def main():
# Show help if no arguments provided or --help flag used
if len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help")):
usage()
sys.exit(0)
cond_too_short = len(sys.argv) < 5
cond_too_long = len(sys.argv) > 8
cond_no_input = sys.argv[1] != "-input"
input_arg = sys.argv[2]
# Check if input exists as-is (single file with possible commas in name)
# or check first part if it contains comma separator
if os.path.exists(input_arg):
# File exists as-is, likely a single file with commas in name
cond_input_exists = False
cond_input_file = not os.path.isfile(input_arg)
else:
# Might be comma-separated list, check first file
first_file = input_arg.split(",")[0]
cond_input_exists = not os.path.exists(first_file)
cond_input_file = not os.path.isfile(first_file)
cond_no_format = sys.argv[3] != "-format"
cond_unknown_format = sys.argv[4] not in (
"apo",
"aupreset",
"rmetmeq",
"rmetmreq",
)
cond_output = len(sys.argv) > 5 and sys.argv[5] != "-output"
if (
cond_too_short
or cond_too_long
or cond_no_input
or cond_no_format
or cond_no_input
or cond_unknown_format
or cond_output
or cond_input_exists
or cond_input_file
):
usage()
if cond_too_short:
print("Error: not enough arguments {}".format(len(sys.argv)))
if cond_too_long:
print("Error: too manyarguments {}".format(len(sys.argv)))
if cond_no_input:
print("Error: argument 1 {} must be -input".format(sys.argv[1]))
if cond_input_exists:
print("Error: argument 2 {} does not exist".format(sys.argv[2]))
if cond_input_file:
print("Error: argument 2 {} is not a file".format(sys.argv[2]))
if cond_no_format:
print("Error: argument 3 {} must be -format".format(sys.argv[3]))
if cond_unknown_format:
print(
"Error: argument 4 {} must be a known format".format(
sys.argv[4]
)
)
if cond_output:
print("Error: argument 5 {} must be -output".format(sys.argv[5]))
sys.exit(-1)
output_format = sys.argv[4]
# Split by comma only for formats that support multiple files
files = input_arg.split(",") if output_format == "rmetmreq" else [input_arg]
rew_filename = files[0]
rew_base = rew_filename
dotpos = rew_filename.rfind(".")
if dotpos != -1:
rew_base = rew_filename[:dotpos]
preset_name = pathlib.Path(rew_base).name
success, iir = file2iir(rew_filename)
if not success or len(iir) == 0:
print("Parsing failed! for {}".format(rew_filename))
return 1
success = True
result = ""
output = ""
if output_format == "aupreset":
success, result = iir2aupreset(iir, preset_name)
if not success:
print("Generation failed! for {}".format(rew_filename))
return success
output = "{}.aupreset".format(rew_base)
elif output_format == "rmetmeq":
success, result = iir2rme_totalmix_channel(iir)
if not success:
print("Generation failed! for {}".format(rew_filename))
return success
output = "{}.tmeq".format(rew_base)
elif output_format == "rmetmreq":
if len(files) == 1:
success, result = iir2rme_totalmix_room(iir, [])
if not success:
print("Converting to RME room eq failed {}".format(files[0]))
return 1
output = "{}.tmreq".format(rew_base)
elif len(files) == 2:
iir_left = iir
success, iir_right = file2iir(files[1])
if not success or len(iir_right) == 0:
print("Parsing failed! for {}".format(files[1]))
return 1
success, result = iir2rme_totalmix_room(iir_left, iir_right)
if not success:
print(
"Converting to RME room eq failed for {} and {}".format(
files[0], files[1]
)
)
return 1
output = "{}.tmreq".format(rew_base)
else:
print(
"Warning: RME TotalMix Room EQ takes at most 2 EQs (left, right)"
)
if not success:
print("Generation failed! for {}".format(rew_filename))
return success
if len(sys.argv) == 5:
print("Generated file:")
print(result)
return 0
if output_format == "aupreset" and sys.argv[-1] == "-install":
PRESET_DIR.mkdir(mode=0o755, parents=True, exist_ok=True)
output = "{}/{}.aupreset".format(PRESET_DIR, preset_name)
try:
with open(output, "w", encoding="ascii") as fd:
fd.write(result)
except FileNotFoundError:
return 1
return 0
if __name__ == "__main__":
sys.exit(main())