Class: Wavify::Sequencer::Pattern
- Inherits:
-
Object
- Object
- Wavify::Sequencer::Pattern
- Includes:
- Enumerable, Enumerable[Step]
- Defined in:
- lib/wavify/sequencer/pattern.rb,
sig/sequencer.rbs
Overview
Step-pattern parser (x, X, x0.7, x?50, x:3, -, .) for trigger sequencing.
Defined Under Namespace
Classes: Step
Constant Summary collapse
- MAX_RESOLUTION =
Highest supported step-grid resolution per bar.
4_096- MAX_RATCHET =
Highest supported retrigger count for one pattern step.
64
Instance Attribute Summary collapse
-
#notation ⇒ String
readonly
Returns the value of attribute notation.
-
#resolution ⇒ Integer
readonly
Returns the value of attribute resolution.
-
#steps ⇒ Array[Step]
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#[](index) ⇒ Step?
Returns a step at the given index.
-
#accented_indices ⇒ Array<Integer>
Indices for accented trigger steps.
-
#each {|step| ... } ⇒ Enumerator
Enumerates parsed steps.
-
#initialize(notation, resolution: 16) ⇒ Pattern
constructor
A new instance of Pattern.
-
#length ⇒ Integer
(also: #size)
Number of steps.
-
#to_a ⇒ Array<Step>
Copy of parsed steps.
-
#trigger_indices ⇒ Array<Integer>
Indices for trigger steps.
Constructor Details
#initialize(notation, resolution: 16) ⇒ Pattern
Returns a new instance of Pattern.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wavify/sequencer/pattern.rb', line 31 def initialize(notation, resolution: 16) raise InvalidPatternError, "pattern notation must be String" unless notation.is_a?(String) @notation = notation.dup.freeze @resolution = validate_resolution!(resolution) @steps = parse_steps(@notation).freeze if @steps.length > @resolution raise InvalidPatternError, "pattern has #{@steps.length} steps but resolution is #{@resolution}" end freeze end |
Instance Attribute Details
#notation ⇒ String (readonly)
Returns the value of attribute notation.
29 30 31 |
# File 'lib/wavify/sequencer/pattern.rb', line 29 def notation @notation end |
#resolution ⇒ Integer (readonly)
Returns the value of attribute resolution.
29 30 31 |
# File 'lib/wavify/sequencer/pattern.rb', line 29 def resolution @resolution end |
#steps ⇒ Array[Step] (readonly)
Returns the value of attribute steps.
29 30 31 |
# File 'lib/wavify/sequencer/pattern.rb', line 29 def steps @steps end |
Instance Method Details
#[](index) ⇒ Step?
Returns a step at the given index.
58 59 60 |
# File 'lib/wavify/sequencer/pattern.rb', line 58 def [](index) @steps[index] end |
#accented_indices ⇒ Array<Integer>
Returns indices for accented trigger steps.
75 76 77 |
# File 'lib/wavify/sequencer/pattern.rb', line 75 def accented_indices @steps.select(&:accent?).map(&:index) end |
#each ⇒ Pattern #each ⇒ Enumerator[Step, Pattern]
Enumerates parsed steps.
48 49 50 51 52 |
# File 'lib/wavify/sequencer/pattern.rb', line 48 def each(&) return enum_for(:each) unless block_given? @steps.each(&) end |
#length ⇒ Integer Also known as: size
Returns number of steps.
63 64 65 |
# File 'lib/wavify/sequencer/pattern.rb', line 63 def length @steps.length end |
#to_a ⇒ Array<Step>
Returns copy of parsed steps.
80 81 82 |
# File 'lib/wavify/sequencer/pattern.rb', line 80 def to_a @steps.dup end |
#trigger_indices ⇒ Array<Integer>
Returns indices for trigger steps.
70 71 72 |
# File 'lib/wavify/sequencer/pattern.rb', line 70 def trigger_indices @steps.select(&:trigger?).map(&:index) end |