Class: Mass::Pattern
- Inherits:
-
Object
- Object
- Mass::Pattern
- Defined in:
- lib/mass/pattern.rb
Overview
A single pattern written using the Mass DSL. This is the “collection”-style object which holds each Note and plays them in sequence, but has no control over their durations or pitches.
Instance Attribute Summary collapse
-
#bars ⇒ Object
readonly
Returns the value of attribute bars.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
Class Method Summary collapse
-
.create(name: '', bars: 4, repeat: false, sequence: nil, &block) ⇒ Object
Create a new pattern and immediately play it.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Tests equivilance bases on name.
-
#initialize(name: '', bars: 4, sequence: nil) ⇒ Pattern
constructor
A new instance of Pattern.
-
#play(in_loop: false) ⇒ Object
Play the instantiated pattern once, or in a loop if opted into it.
Constructor Details
#initialize(name: '', bars: 4, sequence: nil) ⇒ Pattern
Returns a new instance of Pattern.
15 16 17 18 19 20 21 |
# File 'lib/mass/pattern.rb', line 15 def initialize(name: '', bars: 4, sequence: nil) @name = name = @notes = [] @sequence = sequence yield if block_given? end |
Instance Attribute Details
#bars ⇒ Object (readonly)
Returns the value of attribute bars.
10 11 12 |
# File 'lib/mass/pattern.rb', line 10 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/mass/pattern.rb', line 10 def name @name end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
10 11 12 |
# File 'lib/mass/pattern.rb', line 10 def notes @notes end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
10 11 12 |
# File 'lib/mass/pattern.rb', line 10 def sequence @sequence end |
Class Method Details
.create(name: '', bars: 4, repeat: false, sequence: nil, &block) ⇒ Object
Create a new pattern and immediately play it.
28 29 30 31 32 33 34 |
# File 'lib/mass/pattern.rb', line 28 def self.create( name: '', bars: 4, repeat: false, sequence: nil, &block ) pattern = new(name: name, bars: , sequence: sequence, &block) pattern.play in_loop: repeat if pattern.notes.any? pattern end |
Instance Method Details
#==(other) ⇒ Boolean
Tests equivilance bases on name
48 49 50 |
# File 'lib/mass/pattern.rb', line 48 def ==(other) other.name == name end |
#play(in_loop: false) ⇒ Object
Play the instantiated pattern once, or in a loop if opted into it.
40 41 42 43 |
# File 'lib/mass/pattern.rb', line 40 def play(in_loop: false) return _play_once unless in_loop _play_in_loop end |