class Mass::Pattern
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.
Attributes
Public Class Methods
Create a new pattern and immediately play it.
@param [String] name @param [Integer] bars @param block
# File lib/mass/pattern.rb, line 28 def self.create( name: '', bars: 4, repeat: false, sequence: nil, &block ) pattern = new(name: name, bars: bars, sequence: sequence, &block) pattern.play in_loop: repeat if pattern.notes.any? pattern end
@param [String] name @param [Integer] bars @param block
# File lib/mass/pattern.rb, line 15 def initialize(name: '', bars: 4, sequence: nil) @name = name @bars = bars @notes = [] @sequence = sequence yield if block_given? end
Public Instance Methods
Tests equivilance bases on name
@return [Boolean] whether both patterns have the same name
# File lib/mass/pattern.rb, line 48 def ==(other) other.name == name end
Play the instantiated pattern once, or in a loop if opted into it.
@param [Boolean] in_loop - defaults to false
.
# File lib/mass/pattern.rb, line 40 def play(in_loop: false) return _play_once unless in_loop _play_in_loop end
Protected Instance Methods
Part of the DSL, the note
method instantiates a new Note
object with the given parameters and pushes it into the pattern’s notes collection.
@private @param [Integer] value - Value of each note @param [String] pitch - String representation
of MIDI note, e.g. 'c4'
@param [Symbol] expression - Symbolic representation
of MIDI velocity, e.g. ':ff'
# File lib/mass/pattern.rb, line 64 def note(value, pitch: nil, expression: nil) @notes << Note.new( value: value, pitch: pitch, exp: expression, midi: sequence._midi, bpm: sequence._bpm ) end
# File lib/mass/pattern.rb, line 74 def rest(value) note value end
Private Instance Methods
# File lib/mass/pattern.rb, line 84 def _play_in_loop loop { _play_once } end
# File lib/mass/pattern.rb, line 80 def _play_once notes.all?(&:play) end