Class: Wavify::Sequencer::Pattern

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(notation, resolution: 16) ⇒ Pattern

Returns a new instance of Pattern.

Parameters:

  • notation (String)
  • resolution: (Integer) (defaults to: 16)

Raises:



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

#notationString (readonly)

Returns the value of attribute notation.

Returns:

  • (String)


29
30
31
# File 'lib/wavify/sequencer/pattern.rb', line 29

def notation
  @notation
end

#resolutionInteger (readonly)

Returns the value of attribute resolution.

Returns:

  • (Integer)


29
30
31
# File 'lib/wavify/sequencer/pattern.rb', line 29

def resolution
  @resolution
end

#stepsArray[Step] (readonly)

Returns the value of attribute steps.

Returns:



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.

Parameters:

  • index (Integer)

Returns:



58
59
60
# File 'lib/wavify/sequencer/pattern.rb', line 58

def [](index)
  @steps[index]
end

#accented_indicesArray<Integer>

Returns indices for accented trigger steps.

Returns:

  • (Array<Integer>)

    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

#eachPattern #eachEnumerator[Step, Pattern]

Enumerates parsed steps.

Overloads:

Yields:

  • (step)

Yield Parameters:

Returns:

  • (Enumerator)


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

#lengthInteger Also known as: size

Returns number of steps.

Returns:

  • (Integer)

    number of steps



63
64
65
# File 'lib/wavify/sequencer/pattern.rb', line 63

def length
  @steps.length
end

#to_aArray<Step>

Returns copy of parsed steps.

Returns:

  • (Array<Step>)

    copy of parsed steps



80
81
82
# File 'lib/wavify/sequencer/pattern.rb', line 80

def to_a
  @steps.dup
end

#trigger_indicesArray<Integer>

Returns indices for trigger steps.

Returns:

  • (Array<Integer>)

    indices for trigger steps



70
71
72
# File 'lib/wavify/sequencer/pattern.rb', line 70

def trigger_indices
  @steps.select(&:trigger?).map(&:index)
end