* deal with duplicate instrument/parts better than failing

This commit is contained in:
Seth Call 2015-08-12 09:36:42 -05:00
parent 96fa38f611
commit 03f5407727
1 changed files with 32 additions and 0 deletions

View File

@ -774,6 +774,36 @@ module JamRuby
instrument_weight
end
def deduplicate_parts(tracks)
unique_instruments = {}
tracks.each do |track|
found = unique_instruments[[track.instrument_id, track.part]]
if !found
found = []
end
found << track
end
unique_instruments.each do |key, value|
if value.length > 1
count = 0
value.each do |track|
if track.part.nil?
track.part = (count + 1).to_s
else
track.part = "#{track.part} #{count + 1}"
end
end
count += 1
end
end
end
def sort_tracks(tracks)
sorted_tracks = tracks.sort do |a, b|
@ -914,6 +944,8 @@ module JamRuby
@@log.info("sorting tracks")
tracks = sort_tracks(tracks)
deduplicate_parts(tracks)
jam_track.jam_track_tracks = tracks
jam_track.jam_track_files = addt_files