build_audulus_wavetable_node 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/build_audulus_wavetable_node.rb +90 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d02df36b06e903541294901c553cef80d7830f41
|
4
|
+
data.tar.gz: 281c8617db7cbd34ece938b92fb0a9f20acf3e43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23714863dca46f257e47356b52b58af7a48038c4ab5ee93e631ec226e7c12bd74d585a30c2ffb222d62157a5e0fc6e183150fe0faa0bf496db8168ad0edb1ec
|
7
|
+
data.tar.gz: ed944ee19c0ee119dda2429b62a9be2245037a6ad70e205c3b9604cc82313f7d061f85bdd30253b992829867ed85244867c07d64b88aea47b067a40c85178c18
|
@@ -45,7 +45,7 @@ class Sox
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
class
|
48
|
+
class WavetablePatch
|
49
49
|
# Take a list of samples corresponding to a single cycle wave form
|
50
50
|
# and generate an Audulus patch with a single wavetable node that
|
51
51
|
# has title1 and title2 as title and subtitle
|
@@ -113,13 +113,7 @@ class Patch
|
|
113
113
|
# generate the actual spline nodes corresponding to each wavetable
|
114
114
|
spline_nodes =
|
115
115
|
normalized_sample_sets.each_with_index.map {|samples, i|
|
116
|
-
spline_node =
|
117
|
-
spline_node["controlPoints"] = samples.each_with_index.map {|sample, i|
|
118
|
-
{
|
119
|
-
"x" => i.to_f/(samples.count-1).to_f,
|
120
|
-
"y" => (sample+1)/2,
|
121
|
-
}
|
122
|
-
}
|
116
|
+
spline_node = build_spline_node_from_samples(samples)
|
123
117
|
move_node(spline_node, -100, i*200)
|
124
118
|
spline_node
|
125
119
|
}
|
@@ -164,6 +158,18 @@ class Patch
|
|
164
158
|
doc
|
165
159
|
end
|
166
160
|
|
161
|
+
def self.build_spline_node_from_samples(samples)
|
162
|
+
spline_node = build_simple_node("Spline")
|
163
|
+
spline_node["controlPoints"] = samples.each_with_index.map {|sample, i|
|
164
|
+
{
|
165
|
+
"x" => i.to_f/(samples.count-1).to_f,
|
166
|
+
"y" => (sample+1)/2,
|
167
|
+
}
|
168
|
+
}
|
169
|
+
# move_node(spline_node, -100, i*200)
|
170
|
+
spline_node
|
171
|
+
end
|
172
|
+
|
167
173
|
XMUX_NODE = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'xmux.audulus')))['patch']['nodes'][0]
|
168
174
|
def self.build_xmux_node
|
169
175
|
clone_node(XMUX_NODE)
|
@@ -213,7 +219,33 @@ end
|
|
213
219
|
|
214
220
|
# Given a path to a single-cycle-waveform wav file, generate an Audulus wavetable
|
215
221
|
# node
|
216
|
-
def
|
222
|
+
def build_wavetable_patch_from_wav_file(path)
|
223
|
+
patch_data = build_patch_data(path)
|
224
|
+
|
225
|
+
# build the patch as a full patch
|
226
|
+
base_patch = WavetablePatch.build_patch(patch_data[:samples], patch_data[:title1], patch_data[:title2])['patch']
|
227
|
+
|
228
|
+
# wrap it up as a subpatch
|
229
|
+
final_patch = make_subpatch(base_patch)
|
230
|
+
|
231
|
+
# write the patch to a file as JSON (the format Audulus uses)
|
232
|
+
File.write(patch_data[:output_path], JSON.generate(final_patch))
|
233
|
+
end
|
234
|
+
|
235
|
+
# Build just a spline from the given samples. Intended for automation rather than
|
236
|
+
# for wavetables.
|
237
|
+
def build_spline_patch_from_wav_file(path)
|
238
|
+
patch_data = build_patch_data(path)
|
239
|
+
|
240
|
+
doc = build_init_doc
|
241
|
+
patch = doc['patch']
|
242
|
+
spline_node = WavetablePatch.build_spline_node_from_samples(patch_data[:samples])
|
243
|
+
add_node(patch, spline_node)
|
244
|
+
|
245
|
+
File.write(patch_data[:output_path], JSON.generate(doc))
|
246
|
+
end
|
247
|
+
|
248
|
+
def build_patch_data(path)
|
217
249
|
# break the path into directory and path so we can build the audulus file's name
|
218
250
|
parent, file = path.split("/")[-2..-1]
|
219
251
|
|
@@ -225,14 +257,11 @@ def build_patch_from_wav_file(path)
|
|
225
257
|
puts "building #{basename}.audulus"
|
226
258
|
audulus_patch_name = "#{basename}.audulus"
|
227
259
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
# write the patch to a file as JSON (the format Audulus uses)
|
235
|
-
File.write(audulus_patch_name, JSON.generate(final_patch))
|
260
|
+
{ :output_path => audulus_patch_name,
|
261
|
+
:samples => samples,
|
262
|
+
:title1 => parent,
|
263
|
+
:title2 => basename,
|
264
|
+
}
|
236
265
|
end
|
237
266
|
|
238
267
|
# Make a set of random samples. Useful for generating a cyclic
|
@@ -258,28 +287,57 @@ end
|
|
258
287
|
# Given a set of samples, build the Audulus wavetable node
|
259
288
|
def build_patch_from_samples(samples, title1, title2, output_path)
|
260
289
|
puts "building #{output_path}"
|
261
|
-
File.write(output_path, JSON.generate(make_subpatch(
|
290
|
+
File.write(output_path, JSON.generate(make_subpatch(WavetablePatch.build_patch(samples, title1, title2)['patch'])))
|
262
291
|
end
|
263
292
|
|
264
|
-
|
265
|
-
|
266
|
-
|
293
|
+
require 'optparse'
|
294
|
+
|
295
|
+
def parse_arguments!(argv)
|
296
|
+
results = {
|
297
|
+
:spline_only => false
|
298
|
+
}
|
299
|
+
option_parser = OptionParser.new do |opts|
|
300
|
+
opts.banner = "build_audulus_wavetable_node [OPTIONS] WAV_FILE"
|
301
|
+
|
302
|
+
opts.on("-h", "--help", "Prints this help") do
|
303
|
+
results[:help] = opts.help
|
304
|
+
end
|
267
305
|
|
268
|
-
|
269
|
-
|
306
|
+
opts.on("-s", "--spline-only", "generate a patch containing only a spline corresponding to the samples in the provided WAV file") do
|
307
|
+
results[:spline_only] = true
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
option_parser.parse!(argv)
|
312
|
+
if argv.count != 1
|
313
|
+
results = {
|
314
|
+
:help => option_parser.help
|
315
|
+
}
|
316
|
+
end
|
317
|
+
|
318
|
+
results[:input_filename] = argv[0]
|
319
|
+
|
320
|
+
results
|
270
321
|
end
|
271
322
|
|
272
323
|
def command(argv)
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
exit(1)
|
280
|
-
end
|
324
|
+
arguments = argv.dup
|
325
|
+
options = parse_arguments!(arguments)
|
326
|
+
if options.has_key?(:help)
|
327
|
+
puts options[:help]
|
328
|
+
exit(0)
|
329
|
+
end
|
281
330
|
|
282
|
-
|
331
|
+
path = options[:input_filename]
|
332
|
+
unless File.exist?(path)
|
333
|
+
puts "Cannot find WAV file at #{path}"
|
334
|
+
exit(1)
|
335
|
+
end
|
336
|
+
|
337
|
+
if options[:spline_only]
|
338
|
+
build_spline_patch_from_wav_file(path)
|
339
|
+
else
|
340
|
+
build_wavetable_patch_from_wav_file(path)
|
283
341
|
end
|
284
342
|
end
|
285
343
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build_audulus_wavetable_node
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Thrasher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fftw3
|