-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dumbest mixdown full of assumptions.
- Loading branch information
1 parent
8c218eb
commit a954d56
Showing
6 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.