Method: Beats::Pattern#initialize

Defined in:
lib/beats/pattern.rb

#initialize(name, tracks = []) ⇒ Pattern

Returns a new instance of Pattern.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/beats/pattern.rb', line 8

def initialize(name, tracks=[])
  @name = name
  @tracks = {}

  longest_track_length = tracks.map {|track| track.rhythm.length }.max

  tracks.each do |track|
    track_key = unique_track_name(track.name)
    new_track = Track.new(track.name, track.rhythm.ljust(longest_track_length, Track::REST))
    @tracks[track_key] = new_track
  end

  @tracks.freeze
end