module Serinette::SoxWrapper

Provides Sox helper functions

Public Class Methods

generate(options = {}) click to toggle source

Takes options and generates a configured Sox::Cmd

@params [Hash] options hash @returns [Sox::Cmd] Sox commands with all configurations

# File lib/utils/sox_wrapper.rb, line 16
def self.generate(options = {})
  setup(options, false)
end
generate_and_run(options = {}) click to toggle source

Takes options, generates a configured Sox::Cmd, and runs

@params [Hash] options hash @returns [Sox::Cmd] Sox command with all configurations

# File lib/utils/sox_wrapper.rb, line 8
def self.generate_and_run(options = {})
  setup(options, true)
end

Private Class Methods

setup(options, should_run) click to toggle source

Internal function for setting up and running (if should_run) sox command

# File lib/utils/sox_wrapper.rb, line 23
def self.setup(options, should_run)
  options[:global_options] ||= {}
  options[:input] ||= '-n'
  options[:output] ||= FileName.generate
  options[:effects] ||= {}

  options[:effects].merge! Song::default_effects

  sox = Sox::Cmd.new options[:global_options]

  sox.add_input(options[:input])
  sox.set_effects(options[:effects])
  sox.set_output(options[:output])

  sox.run if should_run
  sox
end