Skip to content

Commit

Permalink
Support for non-individual audiowall (test)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie0 committed Jan 17, 2017
1 parent 8277491 commit faceeda
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--require spec_helper
1 change: 1 addition & 0 deletions Gemfile
@@ -1,6 +1,7 @@
source 'https://rubygems.org'
#ruby '>=2'

gem 'rspec'
gem 'oauth2'
gem 'sinatra', require: 'sinatra/base'
gem 'sinatra-reloader'
Expand Down
6 changes: 5 additions & 1 deletion jobs/transfer.rb
Expand Up @@ -36,7 +36,11 @@ def perform
track.status = 10
track.save

_run track
if options["force_cart_id"]
_run track, options["force_cart_id"].to_i
else
_run track
end

track.status = 5
track.save
Expand Down
53 changes: 44 additions & 9 deletions playout/audiowall.rb
Expand Up @@ -50,8 +50,8 @@ def self.from_data id, data, audiowall
# again, so three different lengths in total??
cart.length, length = data[282..289].unpack "ff"

cart.type = data[198]
cart.genre = data[199]
cart.type = data[198].unpack("c")[0]
cart.genre = data[199].unpack("c")[0]

cart

Expand Down Expand Up @@ -161,8 +161,6 @@ def load_settings
}


pp @settings

end


Expand Down Expand Up @@ -315,9 +313,11 @@ def load_cart id
file_name = get_full_path(id) + ".LST"
data = File.read(file_name, :encoding => "ASCII-8BIT")
else
fh = File.open(get_nearly_full_path(id) + "/Carts#{[11, ((id - 1) / 1000) + 1].min}.LST", "r")
file, offset = get_master_cart(id)

fh = File.open(file, "r")
i = id - 1
fh.seek(300 * (i > 10000 ? i - 10000 : (i % 1000)))
fh.seek(offset)
data = fh.read(300)
fh.close
end
Expand All @@ -326,15 +326,17 @@ def load_cart id

end


def load_all_carts

raise "Not yet supported" if @settings[:individual_carts]
carts = []

(1..11).each do | c |
(1..99).each do | c |

start_cart = ((c - 1) * 1000) + 1
fh = File.open(get_nearly_full_path(start_cart) + "/Carts#{c}.LST", "r")

fh = File.open(get_master_cart((c - 1) * 1000)[0], "r")
c = 0

while !fh.eof?
Expand All @@ -351,6 +353,40 @@ def load_all_carts

end

def save cart_id, cart

data = cart.to_data
if @settings[:individual_carts]
File.binwrite(@lst_path = prefix + ".LST", cart.to_data)
else
#file = get_nearly_full_path(id) + "/Carts#{[11, ((id - 1) / 1000) + 1].min}.LST"
file, index = get_master_cart(cart_id)

raise "Cart integrity error (#{data.length})" if data.length != 380
data = data[0..299]
puts "writing to #{file}, #{index}"
IO.binwrite(file, data, index)

end

end

# returns file, index
def get_master_cart id

i = id - 1
if @audiowall_root.length > 12 and id > 10000
file = get_nearly_full_path(id) + "Carts" + [100, ((id - 1) / 1000) + 1].min.to_s + ".LST"
index = 300 * (i > 99000 ? i - 99000 : (i % 1000))
return file, index
else
file = get_nearly_full_path(id) + "Carts" + [11, ((id - 1) / 1000) + 1].min.to_s + ".LST"
index = 300 * (i > 10000 ? i - 10000 : (i % 1000))
return file, index
end

end


def purge id

Expand Down Expand Up @@ -394,7 +430,6 @@ def fill_file
end

fh.seek(0)
p fh.read(10)
fh.close()


Expand Down
7 changes: 4 additions & 3 deletions playout/audiowall/export.rb
Expand Up @@ -45,7 +45,7 @@ def fade_end(input, output, extro)

end

def _run track
def _run track, cart_id = nil

@audiowall = Nerve::Playout::AudioWall.new
@audiowall.load_settings
Expand All @@ -59,7 +59,7 @@ def _run track
begin
#Dir::chdir $config["export"]["settings"]["path"] do

cart_id = @audiowall.get_cart_id(track)
cart_id = @audiowall.get_cart_id(track) unless cart_id
prefix = @audiowall.get_full_path(cart_id)

genres = $config["export"]["settings"]["genre"]
Expand All @@ -74,7 +74,8 @@ def _run track
# Lock the "cart_id". Only supported on Audio Walls with individual LSTs
# (do this by writing the LST file, prevents Myriad writing to it).
# binwrite allows us to actually export proper binary.
File.binwrite(@lst_path = prefix + ".LST", cart.to_data)

@audiowall.save cart_id, cart

# convert to the final wav and do the fade out ending, this is fast.
# the fade out in the future will be based on the end type
Expand Down
11 changes: 11 additions & 0 deletions playout/audiowall_test.rb
@@ -0,0 +1,11 @@
require './audiowall'

$config = YAML::load(File.read("../config.yml"))
$genres = YAML::load(File.read("../genres.yml"))
$env = {:slave => false}

aw = Nerve::Playout::AudioWall.new

aw.load_settings


18 changes: 17 additions & 1 deletion public/js/views.js
Expand Up @@ -490,11 +490,27 @@ var Upload2Page = (function (_super) {
}
this.view.set("status", this.track.title + " - " + this.track.artist + "; ready for upload");
};
Upload2Page.prototype.abort = function () {
Pages.show("uploadCopy");
};
Upload2Page.prototype.go = function () {
var _this = this;
if (this.uploading)
return;
var track = this.track;
this.upload(null, this.track.cart_id);
// We only care if it exists to be honest
var data = {
title: track.title,
artist: track.artist,
album: track.album
};
GlobalLibrary.match(data, function (result) {
if (result.exists && !confirm("This already seems to exist on the system! Do you really want to (re-)upload it?"))
return _this.abort();
if (result.explicit && !confirm("This song might be explicit. Are you sure it's safe to upload?"))
return _this.abort();
_this.upload(null, _this.track.cart_id);
});
};
Upload2Page.prototype.upload = function (file, cart_id) {
var _this = this;
Expand Down
22 changes: 21 additions & 1 deletion public/js/views.ts
Expand Up @@ -721,13 +721,33 @@ class Upload2Page extends UploadPage {

}

abort() {
Pages.show("uploadCopy");
}

go():void {

if(this.uploading)
return;
var track = this.track;

this.upload(null, this.track.cart_id);
// We only care if it exists to be honest
var data = {
title: track.title,
artist: track.artist,
album: track.album
}
GlobalLibrary.match(data, (result:any) => {

if(result.exists && !confirm("This already seems to exist on the system! Do you really want to (re-)upload it?"))
return this.abort();

if(result.explicit && !confirm("This song might be explicit. Are you sure it's safe to upload?"))
return this.abort();

this.upload(null, this.track.cart_id);

});

}

Expand Down
101 changes: 101 additions & 0 deletions spec/audiowall.rb
@@ -0,0 +1,101 @@
# these tests work on the Insanity config (sorry!)

describe Nerve::Playout::AudioWall do

before do

$config = YAML::load(File.read("./config.yml"))
$genres = YAML::load(File.read("./genres.yml"))
$env = {:slave => false}


@aw = Nerve::Playout::AudioWall.new
@aw.load_settings

end

describe "get_full_path" do
it "returns the right path" do

@aw.get_full_path(1).should eq("/audiowall/1/MYR00001")
@aw.get_full_path(100).should eq("/audiowall/1/MYR00100")

@aw.get_full_path(1000).should eq("/audiowall/1/MYR01000")
@aw.get_full_path(1001).should eq("/audiowall/1001/MYR01001")

@aw.get_full_path(10000).should eq("/audiowall/9001/MYR10000")
@aw.get_full_path(10001).should eq("/audiowall/10001/MYR10001")

@aw.get_full_path(90000).should eq("/audiowall/80001/MYR90000")
@aw.get_full_path(90001).should eq("/audiowall/90001/MYR90001")

@aw.get_full_path(140000).should eq("/audiowall/90001/MY140000")

end
end

describe "get_master_cart" do
it "returns the right file" do

@aw.get_master_cart(1)[0].should eq("/audiowall/1/Carts1.LST")
@aw.get_master_cart(100)[0].should eq("/audiowall/1/Carts1.LST")

@aw.get_master_cart(1000)[0].should eq("/audiowall/1/Carts1.LST")
@aw.get_master_cart(1001)[0].should eq("/audiowall/1001/Carts2.LST")

@aw.get_master_cart(10000)[0].should eq("/audiowall/9001/Carts10.LST")
@aw.get_master_cart(10001)[0].should eq("/audiowall/10001/Carts11.LST")

@aw.get_master_cart(90000)[0].should eq("/audiowall/80001/Carts90.LST")
@aw.get_master_cart(90001)[0].should eq("/audiowall/90001/Carts91.LST")

@aw.get_master_cart(140000)[0].should eq("/audiowall/90001/Carts100.LST")

end

it "returns the right index" do

@aw.get_master_cart(1)[1].should eq(0)
@aw.get_master_cart(100)[1].should eq(29700)

@aw.get_master_cart(1000)[1].should eq(299700)
@aw.get_master_cart(1001)[1].should eq(0)

@aw.get_master_cart(10000)[1].should eq(299700)
@aw.get_master_cart(10001)[1].should eq(0)

@aw.get_master_cart(20000)[1].should eq(299700)
@aw.get_master_cart(20001)[1].should eq(0)

@aw.get_master_cart(90000)[1].should eq(299700)
@aw.get_master_cart(90001)[1].should eq(0)

@aw.get_master_cart(140000)[1].should eq(12299700)
@aw.get_master_cart(140001)[1].should eq(12300000)

end

it "reads the right data" do

cart = @aw.load_cart(140000)
cart.title.should eq("")

cart = @aw.load_cart(140001)
cart.title.should eq("Dreams")

end

it "writes to the right cart" do

cart = @aw.load_cart(140001)

@aw.save 140000, cart

cart2 = @aw.load_cart(140000)
cart2.title.should eq("Dreams")

end

end

end

0 comments on commit faceeda

Please sign in to comment.