lib/beats/song_optimizer.rb
def determine_pattern_replacements(patterns)
      seen_patterns = []
      replacements = {}

      # Pattern names are sorted to ensure predictable pattern replacement. Makes tests easier to write.
      pattern_names = patterns.keys.sort

      # Detect duplicates
      pattern_names.each do |pattern_name|
        pattern = patterns[pattern_name]
        found_duplicate = false
        seen_patterns.each do |seen_pattern|
          if !found_duplicate && pattern.same_tracks_as?(seen_pattern)
            replacements[pattern.name.to_sym] = seen_pattern.name.to_sym
            found_duplicate = true
          end
        end

        if !found_duplicate
          seen_patterns << pattern
        end
      end

      replacements
    end
# Examines a set of patterns definitions, determining which ones have the same tracks with the same
# rhythms. Then constructs a hash of pattern => pattern indicating that all occurances in the flow
# of the key should be replaced with the value, so that the other equivalent definitions can be pruned
# from the song (and hence their sample data doesn't need to be generated).
Examines a set of patterns definitions, determining which ones have the same tracks with the same
rhythms. Then constructs a hash of pattern => pattern indicating that all occurances in the flow
of the key should be replaced with the value, so that the other equivalent definitions can be pruned
from the song (and hence their sample data doesn't need to be generated).
Examines a set of patterns definitions determining which ones have the same tracks with the same rhythms . Then constructs a hash of pattern = > pattern indicating that all occurances in the flow of the key should be replaced with the value so that the other equivalent definitions can be pruned from the song ( and hence their sample data doesn ' t need to be generated ) .
def determine_pattern_replacements(patterns)
      seen_patterns = []
      replacements = {}
      pattern_names = patterns.keys.sort
      pattern_names.each do |pattern_name|
        pattern = patterns[pattern_name]
        found_duplicate = false
        seen_patterns.each do |seen_pattern|
          if !found_duplicate && pattern.same_tracks_as?(seen_pattern)
            replacements[pattern.name.to_sym] = seen_pattern.name.to_sym
            found_duplicate = true
          end
        end
        if !found_duplicate
          seen_patterns << pattern
        end
      end
      replacements
    end
def determine_pattern_replacements ( patterns ) seen_patterns = [ ] replacements = { } pattern_names = patterns . keys . sort pattern_names . each do | pattern_name | pattern = patterns [ pattern_name ] found_duplicate = false seen_patterns . each do | seen_pattern | if ! found_duplicate && pattern . same_tracks_as? ( seen_pattern ) replacements [ pattern . name . to_sym ] = seen_pattern . name . to_sym found_duplicate = true end end if ! found_duplicate seen_patterns << pattern end end replacements end
Examines a set of patterns definitions, determining which ones have the same tracks with the same
rhythms.
Examines a set of patterns definitions determining which ones have the same tracks with the same rhythms .
# Pattern names are sorted to ensure predictable pattern replacement. Makes tests easier to write. # Detect duplicates
patterns