Class: Archaeopteryx::Drum
- Inherits:
-
Object
- Object
- Archaeopteryx::Drum
- Defined in:
- lib/drum.rb
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) next
Returns the value of attribute next.
-
- (Object) note
Returns the value of attribute note.
-
- (Object) number_generator
Returns the value of attribute number_generator.
-
- (Object) probabilities
Returns the value of attribute probabilities.
-
- (Object) when
Returns the value of attribute when.
Instance Method Summary (collapse)
- - (Object) generate (also: #mutate)
-
- (Drum) initialize(attributes)
constructor
A new instance of Drum.
- - (Boolean) play?(beat)
Constructor Details
- (Drum) initialize(attributes)
A new instance of 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
- (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 |