Class: Musicality::RhythmClass
- Inherits:
-
Object
- Object
- Musicality::RhythmClass
- Defined in:
- lib/musicality/composition/model/rhythm_class.rb
Overview
Note:
Rests are represented by neagtive portions.
A rhythm pattern based on an array of “portions”. These portions encode an array of fractions that sum to 1 (each portion would be numerator and the sum of all portions would be the denominator). These fractions can be applied to a total duration to form a rhythm (an array of durations).
Instance Attribute Summary collapse
-
#portions ⇒ Object
readonly
Returns the value of attribute portions.
-
#portions_sum ⇒ Object
readonly
Returns the value of attribute portions_sum.
Instance Method Summary collapse
-
#initialize(portions) ⇒ RhythmClass
constructor
A new instance of RhythmClass.
-
#to_rhythm(total_dur) ⇒ Object
Use the rhythm class to generate a rhtyhm.
Constructor Details
#initialize(portions) ⇒ RhythmClass
Returns a new instance of RhythmClass.
10 11 12 13 14 15 16 |
# File 'lib/musicality/composition/model/rhythm_class.rb', line 10 def initialize portions if portions.find {|x| x.zero? } raise ArgumentError, "rhythm class contains portion(s) that are zero" end @portions = portions.clone.freeze @portions_sum = @portions.inject(0) {|sum,x| sum + x.abs} end |
Instance Attribute Details
#portions ⇒ Object (readonly)
Returns the value of attribute portions.
9 10 11 |
# File 'lib/musicality/composition/model/rhythm_class.rb', line 9 def portions @portions end |
#portions_sum ⇒ Object (readonly)
Returns the value of attribute portions_sum.
9 10 11 |
# File 'lib/musicality/composition/model/rhythm_class.rb', line 9 def portions_sum @portions_sum end |