Skip to content

Commit

Permalink
Add dumbest mixdown full of assumptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dodecaphonic committed Mar 14, 2014
1 parent 8c218eb commit a954d56
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/balladina.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
require_relative "balladina/control_socket_listener"
require_relative "balladina/track_coordinator"
require_relative "balladina/board"
require_relative "balladina/mixdown"
58 changes: 58 additions & 0 deletions lib/balladina/mixdown.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module Balladina
class Mixdown
def initialize(name, options = {})
@name = name
@target_path = options.fetch(:target_path) { Configuration.mixdowns_path }
end

attr_reader :name, :target_path

def perform_on(tracks_clips)
create_temp_mixdown_path

tracks_clips.map { |track_name, clips|
join_clips track_name, clips
}.each { |track_path|
compress_track track_path
}

zip_tracks
ensure
FileUtils.rm_rf temp_mixdown_path
end

def join_clips(track_name, clips)
track_path = File.join(temp_mixdown_path, "#{track_name}.wav")
clip_paths = clips.join(" ")

`sox #{clip_paths} #{track_path}`

track_path
end

def compress_track(track_path)
mp3_path = track_path.sub(/\.wav$/, ".mp3")
`lame -V2 --quiet #{track_path} #{mp3_path}`
mp3_path
ensure
File.delete track_path
end

def zip_tracks
`cd #{temp_mixdown_path}/../; zip -r #{mixdown_zipfile_path} #{name}`
mixdown_zipfile_path
end

def create_temp_mixdown_path
FileUtils.mkdir_p temp_mixdown_path
end

def temp_mixdown_path
File.join Dir.tmpdir, "balladina-mixdowns", name
end

def mixdown_zipfile_path
File.join target_path, "#{name}.zip"
end
end
end
33 changes: 33 additions & 0 deletions spec/balladina/mixdown_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative "../spec_helper"
require "digest/md5"

describe Balladina::Mixdown do
let(:clip_paths) {
Dir[File.expand_path("../fixtures/clips/*.wav", __dir__)]
}
let(:mixdown) {
File.expand_path("../fixtures/clips/mixdowns/my-crazy-mixdown.zip", __dir__)
}

let(:clips) { Hamster.set(clip_paths) }
let(:tmp_mixdowns) { Dir.tmpdir + "/balladina-mixdowns" }

subject { Balladina::Mixdown.new("my-crazy-mixdown", target_path: tmp_mixdowns) }

before do
FileUtils.mkdir_p tmp_mixdowns
end

after do
FileUtils.rm_rf tmp_mixdowns
end

it "joins a set of Tracks into a zipfile" do
zipped_path = subject.perform_on("track-1" => clips, "track-2" => clips)
expect(File.size(zipped_path)).to eq(File.size(mixdown))
end

def digest(path)
Digest::MD5.file path
end
end
Binary file added spec/fixtures/clips/1394802617.wav
Binary file not shown.
Binary file added spec/fixtures/clips/1394802618.wav
Binary file not shown.
Binary file not shown.

0 comments on commit a954d56

Please sign in to comment.