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

- (Drum) initialize(attributes)



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

- (Object) next

Returns the value of attribute next



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

def next
  @next
end

- (Object) note

Returns the value of attribute note



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

def note
  @note
end

- (Object) number_generator

Returns the value of attribute number_generator



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

def number_generator
  @number_generator
end

- (Object) probabilities

Returns the value of attribute probabilities



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

def probabilities
  @probabilities
end

- (Object) when

Returns the value of attribute when



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

def when
  @when
end

Instance Method Details

- (Object) generate 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

- (Boolean) play?(beat)



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

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