-
Notifications
You must be signed in to change notification settings - Fork 4
/
ft_preset_convert.py
executable file
·168 lines (124 loc) · 5.92 KB
/
ft_preset_convert.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
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
#!/usr/bin/env python
# this script converts old (before 0.5.0) FreqTweak presets into
# the new format in place. (the original preset files are left for backward
# compatibility
import sys,os,shutil,string
def write_channel_node(wfile, info, pos):
# writes out entire channel node with
# known fixed modules and order
wfile.write(' <Channel pos="%s" input_gain="%s" mix_ratio="%s" bypassed="%s" muted="%s">\n' % \
(pos, info['input_gain'], info['mix_ratio'], info['bypassed'], info['muted']))
wfile.write(' <ProcMods>\n')
wfile.write(' <ProcMod pos="0" name="EQ">\n')
wfile.write(' <Filter pos="0" name="freq" linked="%s" bypassed="%s" file="0_0_freq.filter">\n' % \
(info['freq_bypassed'], info['freq_linked']))
wfile.write(' <Extra height="68" minimized="0" xscale="0" gridsnap="0" grid="2" gridlines="0"/>\n')
wfile.write(' </Filter>\n')
wfile.write(' </ProcMod>\n')
wfile.write(' <ProcMod pos="1" name="Pitch">\n')
wfile.write(' <Filter pos="0" name="scale" linked="%s" bypassed="%s" file="0_1_scale.filter">\n' % \
(info['scale_bypassed'], info['scale_linked']))
wfile.write(' <Extra height="68" minimized="0" xscale="0" gridsnap="0" grid="1" gridlines="0"/>\n')
wfile.write(' </Filter>\n')
wfile.write(' </ProcMod>\n')
wfile.write(' <ProcMod pos="2" name="Gate">\n')
wfile.write(' <Filter pos="0" name="inverse_gate" linked="%s" bypassed="%s" file="0_2_inverse_gate.filter">\n' % \
(info['inverse_gate_bypassed'], info['inverse_gate_linked']))
wfile.write(' <Extra height="68" minimized="0" xscale="0" gridsnap="0" grid="2" gridlines="0"/>\n')
wfile.write(' </Filter>\n')
wfile.write(' <Filter pos="1" name="gate" linked="%s" bypassed="%s" file="0_2_gate.filter">\n' % \
(info['gate_bypassed'], info['gate_linked']))
wfile.write(' <Extra/>\n')
wfile.write(' </Filter>\n')
wfile.write(' </ProcMod>\n')
wfile.write(' <ProcMod pos="3" name="Delay">\n')
wfile.write(' <Filter pos="0" name="delay" linked="%s" bypassed="%s" file="0_3_delay.filter">\n' % \
(info['delay_bypassed'], info['delay_linked']))
wfile.write(' <Extra height="68" minimized="0" xscale="0" gridsnap="0" grid="2" gridlines="0"/>\n')
wfile.write(' </Filter>\n')
wfile.write(' <Filter pos="1" name="feedback" linked="%s" bypassed="%s" file="0_3_feedback.filter">\n' % \
(info['feedback_bypassed'], info['feedback_linked']))
wfile.write(' <Extra height="68" minimized="0" xscale="0" gridsnap="0" grid="3" gridlines="0"/>\n')
wfile.write(' </Filter>\n')
wfile.write(' </ProcMod>\n')
wfile.write(' </ProcMods>\n')
wfile.write(' <Inputs>\n')
for port in string.split(info['input_ports'], ','):
wfile.write(' <Port name="%s"/>\n' % port)
wfile.write(' </Inputs>\n')
wfile.write(' <Outputs>\n')
for port in string.split(info['output_ports'], ','):
wfile.write(' <Port name="%s"/>\n' % port)
wfile.write(' </Outputs>\n')
wfile.write(' </Channel>\n')
# the main script follows
preset_dir = os.path.join(os.getenv('HOME', '.'), '.freqtweak', 'presets')
if len(sys.argv) > 1:
preset_dir = sys.argv[1]
try:
os.chdir(preset_dir)
except OSError, ex:
print 'Error accessing preset directory %s' % preset_dir
sys.exit(2)
# each directory in the presets dir is a preset
preset_names = os.listdir(preset_dir)
for pname in preset_names:
dirname = os.path.join(preset_dir, pname)
if not os.path.isdir(dirname):
continue
os.chdir(dirname)
if os.path.exists('config.xml'):
print 'Already converted: %s' % pname
continue
elif not os.path.exists('config.0'):
print 'No old preset in %s' % dirname
continue
orig_info = []
wfile = None
try:
wfile = open('config.xml', 'w+')
except IOError:
print 'error opening new %s/config.xml' % pname
continue
# write xml initial stuff
wfile.write('<?xml version="1.0"?>\n')
wfile.write('<Preset version="0.5.0">\n')
for chan in range(4):
if not os.path.exists('config.%d' % chan):
break
# copy filter files to new names
shutil.copy('freq.%d.filter' % chan, '%d_0_freq.filter' % chan)
shutil.copy('scale.%d.filter' % chan, '%d_1_scale.filter' % chan)
shutil.copy('gate.%d.filter' % chan, '%d_2_gate.filter' % chan)
shutil.copy('inverse_gate.%d.filter' % chan, '%d_2_inverse_gate.filter' % chan)
shutil.copy('delay.%d.filter' % chan, '%d_3_delay.filter' % chan)
shutil.copy('feedback.%d.filter' % chan, '%d_3_feedback.filter' % chan)
# now parse config
info = {}
cfile = None
try:
cfile = open('config.%d' % chan, 'r')
except IOError,ex:
print "error opening config.%d" % chan
continue
lines = cfile.readlines()
for line in lines:
line = string.strip(line)
if not line or line[0] == '#':
continue
try:
key,val = string.split(line, '=', 1)
except:
continue
info[key] = val
if chan==0:
# write params
wfile.write(' <Params fft_size="%s" windowing="%s" update_speed="%s" oversamp="%s" tempo="%s" max_delay="%s" />\n' % \
(info['fft_size'], info['windowing'], info['update_speed'], info['oversamp'], info['tempo'], info['max_delay']))
wfile.write(' <Channels>\n')
# write Channel node
write_channel_node(wfile, info, chan)
wfile.write(' </Channels>\n')
wfile.write('</Preset>\n')
wfile.close()
print 'Converted: %s' % pname