Class: Archaeopteryx::Drum

Inherits:
Object
  • Object
show all
Defined in:
lib/drum.rb

Direct Known Subclasses

Fx

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Drum



4
5
6
7
8
9
10
# File 'lib/drum.rb', line 4

def initialize(attributes)
  %w{note probabilities when next number_generator}.each do |attribute|
    eval("@#{attribute} = attributes[:#{attribute}]")
  end
  @queue = [attributes[:when]]
  generate
end

Instance Attribute Details

#nextObject

Returns the value of attribute next



3
4
5
# File 'lib/drum.rb', line 3

def next
  @next
end

#noteObject

Returns the value of attribute note



3
4
5
# File 'lib/drum.rb', line 3

def note
  @note
end

#number_generatorObject

Returns the value of attribute number_generator



3
4
5
# File 'lib/drum.rb', line 3

def number_generator
  @number_generator
end

#probabilitiesObject

Returns the value of attribute probabilities



3
4
5
# File 'lib/drum.rb', line 3

def probabilities
  @probabilities
end

#whenObject

Returns the value of attribute when



3
4
5
# File 'lib/drum.rb', line 3

def when
  @when
end

Instance Method Details

#generateObject Also known as: mutate



14
15
16
17
18
19
20
21
# File 'lib/drum.rb', line 14

def generate
  beats_on_which_to_play = []
  @probabilities.each_with_index do |probability, index|
    beats_on_which_to_play << index if @number_generator[] <= probability
  end
  @queue << L{|beat| beats_on_which_to_play.include? beat}
  @when = @next[@queue]
end

#play?(beat) ⇒ Boolean



11
12
13
# File 'lib/drum.rb', line 11

def play?(beat)
  @when[beat]
end