Module: Command
- Defined in:
- lib/command.rb
Class Method Summary collapse
- .build_patch_data(path, title, subtitle) ⇒ Object
- .parse_arguments!(argv) ⇒ Object
- .run(argv) ⇒ Object
Class Method Details
.build_patch_data(path, title, subtitle) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/command.rb', line 11 def self.build_patch_data(path, title, subtitle) # break the path into directory and path so we can build the audulus file's name parent, file = path.split("/")[-2..-1] # load the samples from the WAV file samples = Sox.load_samples(path) # build the audulus patch name from the WAV file name basename = File.basename(file, ".wav") puts "building #{basename}.audulus" audulus_patch_name = "#{basename}.audulus" results = { :output_path => audulus_patch_name, :samples => samples, :title => title, :subtitle => subtitle, } results[:title] ||= parent results[:subtitle] ||= basename results end |
.parse_arguments!(argv) ⇒ Object
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 |
# File 'lib/command.rb', line 34 def self.parse_arguments!(argv) results = { :spline_only => false } option_parser = OptionParser.new do |opts| opts. = "build_audulus_wavetable_node [OPTIONS] INPUT_FILE" opts.on("-h", "--help", "Prints this help") do results[:help] = opts.help end opts.on("-s", "--spline", "generate a patch containing only a spline corresponding to the samples in the provided WAV file") do results[:spline_only] = true end opts.on("-m", "--midi", "generate a patch containing two splines based on the provided MIDI file") do |t| results[:midi] = true end opts.on("-tTITLE", "--title=TITLE", "provide a title for the patch (defaults to parent directory)") do |t| results[:title] = t end opts.on("-uSUBTITLE", "--subtitle=SUBTITLE", "provide a subtitle for the patch (defaults to file name, minus .wav)") do |u| results[:subtitle] = u end end option_parser.parse!(argv) if argv.count != 1 results = { :help => option_parser.help } end results[:input_filename] = argv[0] results end |
.run(argv) ⇒ Object
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 |
# File 'lib/command.rb', line 74 def self.run(argv) arguments = argv.dup = parse_arguments!(arguments) if .has_key?(:help) puts [:help] exit(0) end path = [:input_filename] unless File.exist?(path) puts "Cannot find WAV file at #{path}" exit(1) end if [:spline_only] patch_data = build_patch_data(path, [:title], [:subtitle]) SplinePatch.build_patch(patch_data) elsif [:midi] MidiPatch.build_patch(path) else patch_data = build_patch_data(path, [:title], [:subtitle]) WavetablePatch.build_patch(patch_data) end end |