* VRFS-2841 - load jmep into the backend

This commit is contained in:
Seth Call 2015-02-27 08:37:12 -06:00
parent a02f7c2dfb
commit 8205b5ea58
16 changed files with 134 additions and 13 deletions

View File

@ -9,7 +9,7 @@
= f.input :description, :input_html => { :rows=>5, :maxlength=>1000 }
= f.input :plan_code, :label=>'Recurly Plan Code', :required=>true, :hint => 'Must match plan code in Recurly'
= f.input :version, :label => 'Version', :hint => 'Increment this value whenever you invalidate (update) the definition of this JamTrack'
= f.input :initial_play_silence, :label => 'Initial Play Silence (seconds)'
//= f.input :initial_play_silence, :label => 'Initial Play Silence (seconds)'
= f.input :time_signature, collection: JamRuby::JamTrack::TIME_SIGNATURES, include_blank: false
= f.input :status, collection: JamRuby::JamTrack::STATUS, include_blank: false
= f.input :recording_type, collection: JamRuby::JamTrack::RECORDING_TYPE, include_blank: false
@ -27,6 +27,8 @@
= f.input :licensor_royalty_amount, :required=>true, :input_html=>{type:'numeric'}
= f.input :pro_royalty_amount, :required=>true, :input_html=>{type:'numeric'}
= f.input :url, :as => :file, :label => 'Audio File'
= f.input :jmep_text, :as => :text, :label => "JMEP Text", :input_html => {:rows => 5 }
= f.input :jmep_json, :as => :text, :label => "JMEP Json", :input_html => {:rows => 5, :readonly=>true }, :hint => 'readonly'
= f.semantic_fields_for :jam_track_tracks do |track|
= render 'jam_track_track_fields', f: track

View File

@ -147,5 +147,8 @@ module JamAdmin
config.influxdb_hosts = ["localhost"]
config.influxdb_port = 8086
config.influxdb_ignored_environments = ENV["INFLUXDB_ENABLED"] == '1' ? ['test', 'cucumber'] : ['test', 'cucumber', 'development']
config.jamtracks_dir = ENV['JAMTRACKS_DIR'] || File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "jamtracks"))
config.jmep_dir = ENV['JMEP_DIR'] || File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "jmep"))
end
end

View File

@ -0,0 +1,25 @@
class JamRuby::JamTrack
# add a custom validation
before_save :jmep_json_generate
validate :jmep_text_validate
def jmep_text_validate
begin
JmepManager.execute(self.jmep_text)
rescue ArgumentError => err
errors.add(:jmep_text, err.to_s)
end
end
def jmep_json_generate
begin
self[:jmep_json] = JmepManager.execute(self.jmep_text)
rescue ArgumentError => err
#errors.add(:jmep_text, err.to_s)
end
end
end

View File

@ -254,4 +254,5 @@ recorded_backing_tracks_add_filename.sql
user_syncs_include_backing_tracks.sql
remove_bpm_from_jamtracks.sql
jam_track_version.sql
recorded_jam_track_tracks.sql
recorded_jam_track_tracks.sql
jam_track_jmep_data.sql

View File

@ -0,0 +1,2 @@
ALTER TABLE jam_tracks ADD COLUMN jmep_text VARCHAR;
ALTER TABLE jam_tracks ADD COLUMN jmep_json JSON;

View File

@ -204,6 +204,7 @@ require "jam_ruby/models/user_sync"
require "jam_ruby/models/video_source"
require "jam_ruby/models/text_message"
require "jam_ruby/jam_tracks_manager"
require "jam_ruby/jmep_manager"
include Jampb

View File

@ -20,7 +20,6 @@ module JamRuby
def save_jam_track_right_jkz(jam_track_right)
jam_track = jam_track_right.jam_track
#py_root = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "jamtracks"))
py_root = APP_CONFIG.jamtracks_dir
Dir.mktmpdir do |tmp_dir|
jam_file_opts=""

View File

@ -0,0 +1,55 @@
require 'json'
require 'tempfile'
require 'open3'
require 'fileutils'
require 'open-uri'
module JamRuby
# Interact with external python tools to create jmep json
class JmepManager
@@log = Logging.logger[JmepManager]
class << self
def execute(jmep_text)
json = nil
if jmep_text.blank?
return nil
end
py_root = APP_CONFIG.jmep_dir
Dir.mktmpdir do |tmp_dir|
output_json = File.join(tmp_dir, "jmep.json")
input_text = File.join(tmp_dir, "jmep.txt")
# put JMEP text into input file
File.open(input_text, 'w') { |file| file.write(jmep_text) }
py_file = File.join(py_root, "jmepgen.py")
@@log.info "Executing python source in #{py_file}, outputting to #{output_json})"
# From http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby/5970819#5970819:
cli = "python #{py_file} -i '#{input_text}' -o '#{output_json}'"
Open3.popen3(cli) do |stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid
exit_status = wait_thr.value
err = stderr.read(1000)
out = stdout.read(1000)
raise ArgumentError, "#{out} #{err}" if exit_status != 0
json = File.read(output_json)
end
end
json
end
end
end
end

View File

@ -16,7 +16,7 @@ module JamRuby
:original_artist, :songwriter, :publisher, :licensor, :licensor_id, :pro, :genre, :genre_id, :sales_region, :price,
:reproduction_royalty, :public_performance_royalty, :reproduction_royalty_amount,
:licensor_royalty_amount, :pro_royalty_amount, :plan_code, :initial_play_silence, :jam_track_tracks_attributes,
:jam_track_tap_ins_attributes, :available, :version, as: :admin
:jam_track_tap_ins_attributes, :available, :version, :jmep_json, :jmep_text, as: :admin
validates :name, presence: true, uniqueness: true, length: {maximum: 200}
validates :description, length: {maximum: 1000}
@ -152,6 +152,7 @@ module JamRuby
def sanitize_active_admin
self.genre_id = nil if self.genre_id == ''
self.licensor_id = nil if self.licensor_id == ''
self.jmep_json = nil if self.jmep_json = ''
end
end
end

View File

@ -345,14 +345,15 @@ context.JK.DownloadJamTrack = class DownloadJamTrack
# first check if the version is not the same; if so, invalidate.
if @jamTrack.version != @trackDetail.version
@logger.info("DownloadJamTrack: JamTrack on disk is different version (stored: #{@trackDetail.version}, server: #{@jamTrack.version}. Invalidating")
context.jamClient.InvalidateJamTrack(@jamTrack.id)
@trackDetail = context.jamClient.JamTrackGetTrackDetail (@jamTrack.id)
if @trackDetail.version?
if @jamTrack.version != @trackDetail.version
@logger.error("after invalidating package, the version is still wrong!")
throw "after invalidating package, the version is still wrong!"
@logger.info("DownloadJamTrack: JamTrack on disk is different version (stored: #{@trackDetail.version}, server: #{@jamTrack.version}. Invalidating")
context.jamClient.InvalidateJamTrack(@jamTrack.id)
@trackDetail = context.jamClient.JamTrackGetTrackDetail (@jamTrack.id)
if @trackDetail.version?
@logger.error("after invalidating package, the version is still wrong!")
throw "after invalidating package, the version is still wrong!"
switch @trackDetail.key_state
when 'pending'

View File

@ -162,6 +162,7 @@
var duration = context.jamClient.SessionGetJamTracksPlayDurationMs();
var durationMs = duration.media_len;
var start = duration.start; // needed to understand start offset, and prevent slider from moving in tapins
console.log("JamTrack start: " + start)
}
else {
var positionMs = context.jamClient.SessionCurrrentPlayPosMs();

View File

@ -307,7 +307,7 @@
unlockControlsforJamTrackRecording();
if(sessionModel.selfOpenedJamTracks()) {
var timeline = context.jamClient.getJamTrackTimeline();
var timeline = context.jamClient.GetJamTrackTimeline();
rest.addRecordingTimeline(data.recordingId, timeline)
.fail(function(){
@ -2415,6 +2415,15 @@
// XXX: test with this removed; it should be unnecessary
context.jamClient.JamTrackStopPlay();
if(jamTrack.jmep)
{
logger.debug("setting jmep data")
context.jamClient.JamTrackLoadJmep(jamTrack.id, jamTrack.jmep)
}
else {
logger.debug("no jmep data for jamtrack")
}
// JamTrackPlay means 'load'
var result = context.jamClient.JamTrackPlay(jamTrack.id);

View File

@ -21,7 +21,15 @@ end
child(:recording => :recording) {
attributes :id, :created_at, :duration, :comment_count, :like_count, :play_count, :jam_track_id, :jam_track_initiator_id
child(:jam_track => :jam_track) {
attributes :id
node :jmep do |jam_track|
jam_track.jmep_json ? JSON.parse(jam_track.jmep_json) : nil
end
}
child(:band => :band) {
attributes :id, :name, :location, :photo_url
}

View File

@ -2,6 +2,10 @@ object @jam_track
attributes :id, :name, :description, :initial_play_silence, :original_artist, :version
node :jmep do |jam_track|
jam_track.jmep_json ? JSON.parse(jam_track.jmep_json) : nil
end
node :jam_track_right_id do |jam_track|
jam_track.right_for_user(current_user).id
end

View File

@ -12,6 +12,13 @@ node :mix do |recording|
end
end
child(:jam_track => :jam_track) {
attributes :id
node :jmep do |jam_track|
jam_track.jmep_json ? JSON.parse(jam_track.jmep_json) : nil
end
}
child(:band => :band) {
attributes :id, :name, :location, :photo_url

View File

@ -209,6 +209,8 @@ if defined?(Bundler)
# Location of jamtracks python tool:
config.jamtracks_dir = ENV['JAMTRACKS_DIR'] || File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "jamtracks"))
config.jmep_dir = ENV['JMEP_DIR'] || File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "jmep"))
# amount of time before we think packaging job is broken
config.signing_job_run_max_time = 60 # 1 minute
# amount of time before we think the queue is stuck