* update how click track is determined for jamtracks

This commit is contained in:
Seth Call 2016-01-29 17:37:28 -06:00
parent 13b58dbaa4
commit 9e9c2819dd
3 changed files with 171 additions and 120 deletions

View File

@ -26,7 +26,7 @@ module JamRuby
connection.transaction do
yield manager
end
rescue Exception => e
rescue Exception => e
ActiveRecord::Base.connection.execute('ROLLBACK')
end
end

View File

@ -99,82 +99,99 @@ module JamRuby
end
def generate_jmep(jam_track)
if !jam_track.blank?
finish('success', 'jmep already exists')
# https://docs.google.com/spreadsheets/d/1dyUOjWkeU8BXwnJl-ws1Kvxq_twWEG7E78F29haYkLc/edit#gid=987457683
# cross-check against marks_approved
if JamTrackImporter.marks_approved.has_key?(jam_track.slug)
@@log.info("Found track in mark approved list. skipping")
finish('success', 'mark created')
return
end
# can we overwrite this one?
if jam_track.jmep_text.blank? || jam_track.jmep_text.include?('created via code')
@@log.info("This is a blank jmep or created earlier by code.")
else
# we need to download the click track, if it exists.
Dir.mktmpdir do |tmp_dir|
@@log.info("This a JMEP that was not created by code. Skip it.")
return
end
master_track = jam_track.master_track
# we need to download the click track, if it exists.
Dir.mktmpdir do |tmp_dir|
click_track = jam_track.click_track_file
master_track = jam_track.master_track
if master_track.nil?
finish('no_master_track', nil)
return
end
click_track = jam_track.click_track_file
master_track_file = File.join(tmp_dir, File.basename(master_track[:url_48]))
begin
JamTrackImporter.private_s3_manager.download(master_track.url_by_sample_rate(44), master_track_file)
rescue Exception => e
@@log.error("unable to download master track")
finish("no-download-master", master_track.url_by_sample_rate(44))
return
end
if master_track.nil?
finish('no_master_track', nil)
return
end
if click_track
click_track_file = File.join(tmp_dir, File.basename(click_track[:original_filename]))
JamTrackImporter.song_storage_manager.download(click_track[:original_filename], click_track_file)
else
# we'll use the master for click analysis. not ideal, but would work
click_track_file = master_track_file
end
master_track_file = File.join(tmp_dir, File.basename(master_track[:url_48]))
begin
JamTrackImporter.private_s3_manager.download(master_track.url_by_sample_rate(44), master_track_file)
rescue Exception => e
@@log.error("unable to download master track")
finish("no-download-master", master_track.url_by_sample_rate(44))
return
end
if click_track
click_track_file = File.join(tmp_dir, File.basename(click_track[:original_filename]))
JamTrackImporter.song_storage_manager.download(click_track[:original_filename], click_track_file)
else
# we'll use the master for click analysis. not ideal, but would work
click_track_file = master_track_file
end
if click_track
start_time = determine_start_time(click_track_file, tmp_dir, click_track[:original_filename])
else
start_time = determine_start_time(master_track_file, tmp_dir, master_track[:url])
end
# bpm comes from git clone http://www.pogo.org.uk/~mark/bpm-tools.git
# bpm comes from git clone http://www.pogo.org.uk/~mark/bpm-tools.git
sox="sox #{Shellwords.escape(click_track_file)} -t raw -r 44100 -e float -c 1 - | bpm"
cmd = "bash -c #{Shellwords.escape(sox)}"
@@log.debug("executing cmd #{cmd}")
output=`#{cmd}`
sox="sox #{Shellwords.escape(click_track_file)} -t raw -r 44100 -e float -c 1 - | bpm"
cmd = "bash -c #{Shellwords.escape(sox)}"
@@log.debug("executing cmd #{cmd}")
output=`#{cmd}`
result_code = $?.to_i
result_code = $?.to_i
if result_code == 0
bpm = output.to_f
if result_code == 0
bpm = output.to_f
@@log.debug("bpm: #{bpm} start_time: #{start_time}")
@@log.debug("bpm: #{bpm} start_time: #{start_time}")
metro_fin = "#{Time.at(start_time).utc.strftime("%H:%M:%S")}:#{((start_time - start_time.to_i) * 1000).round}"
metro_fin = "#{Time.at(start_time).utc.strftime("%H:%M:%S")}:#{((start_time - start_time.to_i) * 1000).round}"
jmep = ""
jmep << "# created via code using bpm/silence detection (bpm:#{bpm})\r\n"
jmep << "prelude@10.0 #number of seconds before music starts\r\n"
jmep << "metro_fin@#{metro_fin} bpm=#{bpm}, ticks=8, pmode=stream, name=Beep, play=mono"
jmep = ""
jmep << "# created via code using bpm/silence detection (bpm:#{bpm})\r\n"
jmep << "prelude@10.0 #number of seconds before music starts\r\n"
jmep << "metro_fin@#{metro_fin} bpm=#{bpm}, ticks=8, pmode=stream, name=Beep, play=mono"
@@log.info("jmep generated: #{jmep}")
@@log.info("jmep generated: #{jmep}")
jam_track.jmep_text = jmep
if jam_track.save
finish('success', nil)
else
@@log.error("jamtrack did not save. #{jam_track.errors.inspect}")
finish("no-save", "jamtrack did not save. #{jam_track.errors.inspect}")
return
end
jam_track.jmep_text = jmep
if jam_track.save
finish('success', nil)
else
finish("bpm-fail", "failed to run bpm: #{output}")
@@log.error("jamtrack did not save. #{jam_track.errors.inspect}")
finish("no-save", "jamtrack did not save. #{jam_track.errors.inspect}")
return
end
else
finish("bpm-fail", "failed to run bpm: #{output}")
return
end
end
end
def determine_start_time(audio_file, tmp_dir, original_filename)
burp_gaps = ['0.3', '0.2', '0.1', '0.05']
@ -824,7 +841,6 @@ module JamRuby
end
else
if !options[:resync_audio]
#@@log.debug("#{self.name} skipped because it already exists in database")
@ -1209,72 +1225,72 @@ module JamRuby
#if track.persisted?
# instrument_weight = track.position
#else
if track.instrument_id == 'voice'
if track.instrument_id == 'voice'
if track.part && track.part.start_with?('Lead')
instrument_weight = 100
elsif track.part && track.part.start_with?('Backing')
instrument_weight = 110
else
instrument_weight = 120
end
elsif track.instrument_id == 'drums'
if track.part && track.part == 'Drums'
instrument_weight = 150
elsif track.part && track.part == 'Percussion'
instrument_weight = 160
else
instrument_weight = 170
end
elsif track.instrument_id == 'percussion'
instrument_weight = 175
elsif track.instrument_id == 'bass guitar' && track.part && track.part == 'Bass'
instrument_weight = 180
elsif track.instrument_id == 'piano' && track.part && track.part == 'Piano'
instrument_weight = 250
elsif track.instrument_id == 'keyboard'
if track.part && track.part.start_with?('Synth')
instrument_weight = 260
elsif track.part && track.part.start_with?('Pads')
instrument_weight = 270
else
instrument_weight = 280
end
elsif track.instrument_id == 'acoustic guitar'
if track.part && track.part.start_with?('Lead')
instrument_weight = 300
elsif track.part && track.part.start_with?('Rhythm')
instrument_weight = 310
else
instrument_weight = 320
end
elsif track.instrument_id == 'electric guitar'
if track.part && track.part.start_with?('Lead')
instrument_weight = 400
elsif track.part && track.part.start_with?('Solo')
instrument_weight = 410
elsif track.part && track.part.start_with?('Rhythm')
instrument_weight = 420
else
instrument_weight = 440
end
if track.part && track.part.start_with?('Lead')
instrument_weight = 100
elsif track.part && track.part.start_with?('Backing')
instrument_weight = 110
else
instrument_weight = slop
instrument_weight = 120
end
if track.track_type == 'Master'
instrument_weight = 1000
elsif track.instrument_id == 'drums'
if track.part && track.part == 'Drums'
instrument_weight = 150
elsif track.part && track.part == 'Percussion'
instrument_weight = 160
else
instrument_weight = 170
end
elsif track.instrument_id == 'percussion'
instrument_weight = 175
elsif track.instrument_id == 'bass guitar' && track.part && track.part == 'Bass'
instrument_weight = 180
elsif track.instrument_id == 'piano' && track.part && track.part == 'Piano'
instrument_weight = 250
elsif track.instrument_id == 'keyboard'
if track.part && track.part.start_with?('Synth')
instrument_weight = 260
elsif track.part && track.part.start_with?('Pads')
instrument_weight = 270
else
instrument_weight = 280
end
if track.track_type == 'Click'
instrument_weight = 10000
elsif track.instrument_id == 'acoustic guitar'
if track.part && track.part.start_with?('Lead')
instrument_weight = 300
elsif track.part && track.part.start_with?('Rhythm')
instrument_weight = 310
else
instrument_weight = 320
end
elsif track.instrument_id == 'electric guitar'
if track.part && track.part.start_with?('Lead')
instrument_weight = 400
elsif track.part && track.part.start_with?('Solo')
instrument_weight = 410
elsif track.part && track.part.start_with?('Rhythm')
instrument_weight = 420
else
instrument_weight = 440
end
else
instrument_weight = slop
end
if track.track_type == 'Master'
instrument_weight = 1000
end
if track.track_type == 'Click'
instrument_weight = 10000
end
#end
@ -1525,7 +1541,7 @@ module JamRuby
raise "unable to locate jam track wit h#{wav_file} as original_filename"
end
track = matches[0]
track.original_audio_s3_path = wav_file
track.original_audio_s3_path = wav_file
file = nil
end
@ -2115,6 +2131,7 @@ module JamRuby
attr_accessor :paris_mapping
attr_accessor :paris_metadata
attr_accessor :summaries
attr_accessor :marks_approved
def report_summaries
@@log.debug("SUMMARIES DUMP")
@ -2150,7 +2167,7 @@ module JamRuby
end
def summaries
@summaries ||= {unknown_filetype: 0, no_instrument: 0, no_part: 0, total_tracks: 0, no_instrument_detail: {}, no_precount_num: 0, no_precount_detail: [], unique_artists: SortedSet.new, multiple_masters: 0, total:0}
@summaries ||= {unknown_filetype: 0, no_instrument: 0, no_part: 0, total_tracks: 0, no_instrument_detail: {}, no_precount_num: 0, no_precount_detail: [], unique_artists: SortedSet.new, multiple_masters: 0, total: 0}
end
def tency_s3_manager
@ -2313,11 +2330,11 @@ module JamRuby
if is_tency_storage?
iterate_tency_song_storage do |metadata, metalocation|
blk.call(metadata, metalocation)
end
end
elsif is_paris_storage?
iterate_paris_song_storage do |metadata, metalocation|
blk.call(metadata, metalocation)
end
iterate_paris_song_storage do |metadata, metalocation|
blk.call(metadata, metalocation)
end
elsif is_tim_tracks_storage?
iterate_tim_tracks_song_storage do |metadata, metalocation|
blk.call(metadata, metalocation)
@ -2549,6 +2566,7 @@ module JamRuby
importer
end
def generate_jmep(jam_track)
importer = JamTrackImporter.new
importer.name = jam_track.name
@ -2561,7 +2579,7 @@ module JamRuby
importers = []
JamTrack.all.each do |jam_track|
#jam_track = JamTrack.find('126')
#jam_track = JamTrack.find('126')
importers << import_click_track(jam_track)
end
@ -2807,7 +2825,7 @@ module JamRuby
jam_tracks = JamTrack.where(licensor_id: paris.id)
elsif is_default_storage?
# XXX IF WE ADD ANOTHER STORAGE, UPDATE THE WHERE TO EXCLUDE IT AS WELL
jam_tracks = JamTrack.where('licensor_id is null OR licensor_id != ?', tency.id )
jam_tracks = JamTrack.where('licensor_id is null OR licensor_id != ?', tency.id)
else
raise 'unknown storage format!'
end
@ -3010,7 +3028,7 @@ module JamRuby
jam_track.original_artist = metadata[:original_artist]
jam_track.name = metadata[:name]
if jam_track.changed?
puts "ARTIST/NAME CHANGE: #{jam_track.changes.inspect}"
puts "ARTIST/NAME CHANGE: #{jam_track.changes.inspect}"
end
if !jam_track.save
@ -3078,6 +3096,32 @@ module JamRuby
end
end
def load_marks_approved
@marks_approved = {}
Dir.mktmpdir do |tmp_dir|
mapping_file = 'marks_approved.csv'
mapping_csv = CSV.read(mapping_file, headers: true, return_headers: false)
mapping_csv.each do |line|
approved = line[3]
track_url = line[2]
comments = line[7]
approved.strip! if approved
track_url.strip! if track_url
comments.strip! if comments
if approved == 'MJ'
prefix = 'https://www.jamkazam.com/landing/jamtracks/'.length
slug = track_url[prefix..-1]
puts "MARKS APPROVED #{slug} #{comments}"
@marks_approved[slug] = comments
end
end
end
end
def load_paris_mappings
Dir.mktmpdir do |tmp_dir|
mapping_file = File.join(tmp_dir, 'mapping.csv')

View File

@ -7,6 +7,13 @@ namespace :jam_tracks do
task generate_jmep: :environment do |task, args|
JamTrackImporter.storage_format = 'Tency'
JamTrackImporter.load_marks_approved
JamTrackImporter.generate_jmeps
end
task generate_jmep_paris: :environment do |task, args|
JamTrackImporter.storage_format = 'Paris'
JamTrackImporter.load_marks_approved
JamTrackImporter.generate_jmeps
end