Module: Command
- Defined in:
- lib/command.rb
Class Method Summary collapse
- .build_patch_data_from_csv_file(path) ⇒ Object
- .build_patch_data_from_wav_file(path, title = nil, subtitle = nil) ⇒ Object
- .handle_base_options(options) ⇒ Object
- .normalize_coordinates(coordinates) ⇒ Object
- .parse_arguments!(argv) ⇒ Object
- .parse_midi_arguments!(argv) ⇒ Object
- .parse_spline_arguments!(argv) ⇒ Object
- .run_build_midi_node(argv) ⇒ Object
- .run_build_spline_node(argv) ⇒ Object
- .run_build_wavetable_node(argv) ⇒ Object
Class Method Details
.build_patch_data_from_csv_file(path) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/command.rb', line 34 def self.build_patch_data_from_csv_file(path) basename = File.basename(path, ".csv") audulus_patch_name = "#{basename}.audulus" coordinates = normalize_coordinates(CSV.readlines(path)) results = { :output_path => audulus_patch_name, :coordinates => coordinates } end |
.build_patch_data_from_wav_file(path, title = nil, subtitle = nil) ⇒ Object
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 12 def self.build_patch_data_from_wav_file(path, title=nil, subtitle=nil) # 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") 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 |
.handle_base_options(options) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/command.rb', line 165 def self.() if .has_key?(:help) puts [:help] exit(0) end path = [:input_filename] unless File.exist?(path) puts "Cannot find file at #{path}" exit(1) end end |
.normalize_coordinates(coordinates) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/command.rb', line 44 def self.normalize_coordinates(coordinates) floats = coordinates.map {|strings| strings.map(&:to_f)} sorted = floats.sort_by(&:first) min_x = sorted.map(&:first).min max_x = sorted.map(&:first).max min_y = sorted.map(&:last).min max_y = sorted.map(&:last).max sorted.map {|x, y| [(x - min_x)/(max_x - min_x), (y - min_y)/(max_y - min_y)] } end |
.parse_arguments!(argv) ⇒ Object
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 |
# File 'lib/command.rb', line 58 def self.parse_arguments!(argv) results = { :spline_only => false } option_parser = OptionParser.new do |opts| opts. = "#{$0} [OPTIONS] INPUT_FILE" opts.on("-h", "--help", "Prints this help") do results[:help] = opts.help 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 |
.parse_midi_arguments!(argv) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/command.rb', line 98 def self.parse_midi_arguments!(argv) results = {} option_parser = OptionParser.new do |opts| opts. = "#{$0} [OPTIONS] INPUT_FILE" opts.on("-h", "--help", "Prints this help") do results[:help] = opts.help end end option_parser.parse!(argv) if argv.count != 1 results = { :help => option_parser.help } end results[:input_filename] = argv[0] results end |
.parse_spline_arguments!(argv) ⇒ Object
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 |
# File 'lib/command.rb', line 127 def self.parse_spline_arguments!(argv) results = {} option_parser = OptionParser.new do |opts| opts. = "#{$0} [OPTIONS] INPUT_FILE" opts.on("-h", "--help", "Prints this help") do results[:help] = opts.help end opts.on("-c", "--csv", "Interpret the input file as CSV, not WAV") do results[:csv] = true end end option_parser.parse!(argv) if argv.count != 1 results = { :help => option_parser.help } end results[:input_filename] = argv[0] results end |
.run_build_midi_node(argv) ⇒ Object
121 122 123 124 125 |
# File 'lib/command.rb', line 121 def self.run_build_midi_node(argv) = parse_midi_arguments!(argv) () MidiPatch.build_patch([:input_filename]) end |
.run_build_spline_node(argv) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/command.rb', line 154 def self.run_build_spline_node(argv) = parse_spline_arguments!(argv) () if [:csv] patch_data = build_patch_data_from_csv_file([:input_filename]) else patch_data = build_patch_data_from_wav_file([:input_filename]) end SplinePatch.build_patch(patch_data) end |
.run_build_wavetable_node(argv) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/command.rb', line 90 def self.run_build_wavetable_node(argv) = parse_arguments!(argv) () patch_data = build_patch_data_from_wav_file([:input_filename], [:title], [:subtitle]) WavetablePatch.build_patch(patch_data) end |