diff --git a/admin/app/admin/jam_tracks.rb b/admin/app/admin/jam_tracks.rb index 8e62bbc85..6cfb6c1a3 100644 --- a/admin/app/admin/jam_tracks.rb +++ b/admin/app/admin/jam_tracks.rb @@ -26,6 +26,7 @@ ActiveAdmin.register JamRuby::JamTrack, :as => 'JamTracks' do column :id column :name column :description + column :version column :initial_play_silence column :time_signature column :status diff --git a/admin/app/views/admin/jam_tracks/_form.html.slim b/admin/app/views/admin/jam_tracks/_form.html.slim index 16e53837d..3950ee86f 100644 --- a/admin/app/views/admin/jam_tracks/_form.html.slim +++ b/admin/app/views/admin/jam_tracks/_form.html.slim @@ -7,6 +7,8 @@ | JamTrack should only be made available (to end users) if all its sub-component are in place: = f.input :available, as: :boolean = 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 :time_signature, collection: JamRuby::JamTrack::TIME_SIGNATURES, include_blank: false = f.input :status, collection: JamRuby::JamTrack::STATUS, include_blank: false @@ -24,7 +26,6 @@ = f.input :reproduction_royalty_amount, :required=>true, :input_html=>{type:'numeric'} = f.input :licensor_royalty_amount, :required=>true, :input_html=>{type:'numeric'} = f.input :pro_royalty_amount, :required=>true, :input_html=>{type:'numeric'} - = f.input :plan_code, :label=>'Recurly Plan Code', :required=>true = f.input :url, :as => :file, :label => 'Audio File' = f.semantic_fields_for :jam_track_tracks do |track| diff --git a/db/manifest b/db/manifest index 55f1373b5..9bb10cf65 100755 --- a/db/manifest +++ b/db/manifest @@ -252,4 +252,5 @@ metronome.sql recorded_backing_tracks.sql recorded_backing_tracks_add_filename.sql user_syncs_include_backing_tracks.sql -remove_bpm_from_jamtracks.sql \ No newline at end of file +remove_bpm_from_jamtracks.sql +jam_track_version.sql \ No newline at end of file diff --git a/db/up/jam_track_version.sql b/db/up/jam_track_version.sql new file mode 100644 index 000000000..7c1efff86 --- /dev/null +++ b/db/up/jam_track_version.sql @@ -0,0 +1 @@ +ALTER TABLE jam_tracks ADD COLUMN version VARCHAR NOT NULL DEFAULT 0; diff --git a/ruby/lib/jam_ruby/jam_tracks_manager.rb b/ruby/lib/jam_ruby/jam_tracks_manager.rb index a5c04cd61..9618ab3c4 100644 --- a/ruby/lib/jam_ruby/jam_tracks_manager.rb +++ b/ruby/lib/jam_ruby/jam_tracks_manager.rb @@ -42,10 +42,11 @@ module JamRuby title=jam_track.name output_jkz=File.join(tmp_dir, "#{title.parameterize}.jkz") py_file = File.join(py_root, "jkcreate.py") + version = jam_track.version @@log.info "Executing python source in #{py_file}, outputting to #{tmp_dir} (#{output_jkz})" # From http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby/5970819#5970819: - cli = "python #{py_file} -D -k #{sku} -p #{tmp_dir}/pkey.pem -s #{tmp_dir}/skey.pem #{jam_file_opts} -o #{output_jkz} -t '#{title}'" + cli = "python #{py_file} -D -k #{sku} -p #{tmp_dir}/pkey.pem -s #{tmp_dir}/skey.pem #{jam_file_opts} -o #{output_jkz} -t '#{title}' -V '#{version}'" Open3.popen3(cli) do |stdin, stdout, stderr, wait_thr| pid = wait_thr.pid exit_status = wait_thr.value diff --git a/ruby/lib/jam_ruby/models/jam_track.rb b/ruby/lib/jam_ruby/models/jam_track.rb index 3d884ca3a..552b4238b 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, as: :admin + :jam_track_tap_ins_attributes, :available, :version, as: :admin validates :name, presence: true, uniqueness: true, length: {maximum: 200} validates :description, length: {maximum: 1000} @@ -30,6 +30,7 @@ module JamRuby validates :sales_region, inclusion: {in: [nil] + SALES_REGION} validates_format_of :price, with: /^\d+\.*\d{0,2}$/ validates :initial_play_silence, numericality: true, :allow_nil => true + validates :version, presence: true validates :reproduction_royalty, inclusion: {in: [nil, true, false]} validates :public_performance_royalty, inclusion: {in: [nil, true, false]} diff --git a/web/app/assets/javascripts/download_jamtrack.js.coffee b/web/app/assets/javascripts/download_jamtrack.js.coffee index 77fa5aa34..162a1772a 100644 --- a/web/app/assets/javascripts/download_jamtrack.js.coffee +++ b/web/app/assets/javascripts/download_jamtrack.js.coffee @@ -51,6 +51,7 @@ context.JK.DownloadJamTrack = class DownloadJamTrack throw "no JamTrack specified" unless @jamTrack? throw "invalid size" if @size != 'large' && @size != 'small' + throw "no JamTrack version" unless @jamTrack.version? @path = [] @states = { @@ -342,6 +343,13 @@ context.JK.DownloadJamTrack = class DownloadJamTrack @logger.debug("DownloadJamTrack: JamTrackGetTrackDetail.key_state: " + @trackDetail.key_state) + # 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. Invalidating") + context.jamClient.InvalidateJamTrack(@jamTrack.id) + @trackDetail = context.jamClient.JamTrackGetTrackDetail (@jamTrack.id) + switch @trackDetail.key_state when 'pending' this.transition(@states.keying) diff --git a/web/app/views/api_jam_tracks/show.rabl b/web/app/views/api_jam_tracks/show.rabl index f9ea856db..cab264aa5 100644 --- a/web/app/views/api_jam_tracks/show.rabl +++ b/web/app/views/api_jam_tracks/show.rabl @@ -1,6 +1,6 @@ object @jam_track -attributes :id, :name, :description, :recording_type, :original_artist, :songwriter, :publisher, :sales_region, :price +attributes :id, :name, :description, :recording_type, :original_artist, :songwriter, :publisher, :sales_region, :price, :version node :genres do |item| [item.genre.description] # XXX: need to return single genre; not array 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 1b2db2fe6..7d2b38851 100644 --- a/web/app/views/api_jam_tracks/show_for_client.rabl +++ b/web/app/views/api_jam_tracks/show_for_client.rabl @@ -1,6 +1,6 @@ object @jam_track -attributes :id, :name, :description, :initial_play_silence, :original_artist +attributes :id, :name, :description, :initial_play_silence, :original_artist, :version node :jam_track_right_id do |jam_track| jam_track.right_for_user(current_user).id