diff --git a/admin/app/views/admin/jam_tracks/_form.html.slim b/admin/app/views/admin/jam_tracks/_form.html.slim index 3950ee86f..9ec25ffcf 100644 --- a/admin/app/views/admin/jam_tracks/_form.html.slim +++ b/admin/app/views/admin/jam_tracks/_form.html.slim @@ -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 diff --git a/admin/config/application.rb b/admin/config/application.rb index 684f30d7e..102a03176 100644 --- a/admin/config/application.rb +++ b/admin/config/application.rb @@ -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 diff --git a/admin/config/initializers/jam_tracks.rb b/admin/config/initializers/jam_tracks.rb new file mode 100644 index 000000000..c88fc6a2c --- /dev/null +++ b/admin/config/initializers/jam_tracks.rb @@ -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 diff --git a/db/manifest b/db/manifest index fbdb8d856..2cafa6501 100755 --- a/db/manifest +++ b/db/manifest @@ -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 \ No newline at end of file +recorded_jam_track_tracks.sql +jam_track_jmep_data.sql \ No newline at end of file diff --git a/db/up/jam_track_jmep_data.sql b/db/up/jam_track_jmep_data.sql new file mode 100644 index 000000000..46c6e67b5 --- /dev/null +++ b/db/up/jam_track_jmep_data.sql @@ -0,0 +1,2 @@ +ALTER TABLE jam_tracks ADD COLUMN jmep_text VARCHAR; +ALTER TABLE jam_tracks ADD COLUMN jmep_json JSON; \ No newline at end of file diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index f878bac21..a2dc1f4e7 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -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 diff --git a/ruby/lib/jam_ruby/jam_tracks_manager.rb b/ruby/lib/jam_ruby/jam_tracks_manager.rb index 9618ab3c4..37003d115 100644 --- a/ruby/lib/jam_ruby/jam_tracks_manager.rb +++ b/ruby/lib/jam_ruby/jam_tracks_manager.rb @@ -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="" diff --git a/ruby/lib/jam_ruby/jmep_manager.rb b/ruby/lib/jam_ruby/jmep_manager.rb new file mode 100644 index 000000000..a4d0215bc --- /dev/null +++ b/ruby/lib/jam_ruby/jmep_manager.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/jam_track.rb b/ruby/lib/jam_ruby/models/jam_track.rb index 18f8e77a5..fa57b623f 100644 --- a/ruby/lib/jam_ruby/models/jam_track.rb +++ b/ruby/lib/jam_ruby/models/jam_track.rb @@ -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 diff --git a/web/app/assets/javascripts/download_jamtrack.js.coffee b/web/app/assets/javascripts/download_jamtrack.js.coffee index 244466b83..6e09d8bc5 100644 --- a/web/app/assets/javascripts/download_jamtrack.js.coffee +++ b/web/app/assets/javascripts/download_jamtrack.js.coffee @@ -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' diff --git a/web/app/assets/javascripts/playbackControls.js b/web/app/assets/javascripts/playbackControls.js index f88d541c6..4489f0c71 100644 --- a/web/app/assets/javascripts/playbackControls.js +++ b/web/app/assets/javascripts/playbackControls.js @@ -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(); diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index b4195a9ce..75d427266 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -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); diff --git a/web/app/views/api_claimed_recordings/show.rabl b/web/app/views/api_claimed_recordings/show.rabl index 5803d4da4..91174f87b 100644 --- a/web/app/views/api_claimed_recordings/show.rabl +++ b/web/app/views/api_claimed_recordings/show.rabl @@ -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 } diff --git a/web/app/views/api_jam_tracks/show_for_client.rabl b/web/app/views/api_jam_tracks/show_for_client.rabl index 7d2b38851..364b13031 100644 --- a/web/app/views/api_jam_tracks/show_for_client.rabl +++ b/web/app/views/api_jam_tracks/show_for_client.rabl @@ -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 diff --git a/web/app/views/api_recordings/show.rabl b/web/app/views/api_recordings/show.rabl index cda9e1251..a717a6bfb 100644 --- a/web/app/views/api_recordings/show.rabl +++ b/web/app/views/api_recordings/show.rabl @@ -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 diff --git a/web/config/application.rb b/web/config/application.rb index b2fd02ae1..2ec535647 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -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