class SynthBlocks::Sequencer::SequencerDSL::Pattern

The Pattern class is instantiated by the def_pattern helper

Public Instance Methods

drum_pattern(sound, pattern) click to toggle source

Define a drum pattern

  • sound is the sound generator object

  • pattern is a pattern in the form of a string

Defining patterns

drum_pattern bass_drum, '*---*---*---!---'
  • * represents a normal drum hit (velocity: 0.5)

  • ! represents an accented drum hit (velocity 1.0)

  • - represents a pause (no hit)

# File lib/synth_blocks/sequencer/sequencer_dsl.rb, line 53
def drum_pattern(sound, pattern)
  events = []
  @steps.times do |i|
    if pattern.chars[i] == '*'
      events << [i, [:start, 36, 0.5]]
    elsif pattern.chars[i] == '!'
      events << [i, [:start, 36, 1.0]]
    end
  end
  @sounds.push([sound, events])
end
note_pattern(sound, pattern) click to toggle source

Define a note pattern

sound

sound generator base class

pattern

a note pattern

Defining a note pattern

note_pattern monosynth, [
  ['C4, D#4, G4', 2], P, P, P,
  P, P, P, P,
  P, P, P, P,
  P, P, P, P
]
  • P is a pause

  • a note step in the pattern is an array containing the note and the length of the note in steps

  • a note is a note name as a string, which consists of the note and the octave. To play chords, concatenate notes with commas

# File lib/synth_blocks/sequencer/sequencer_dsl.rb, line 94
def note_pattern(sound, pattern)
  events = []
  @steps.times do |i|
    if pattern[i]
      notes, len = pattern[i]
      notes.split(',').each do |note|
        note_num = str2note(note)
        events << [i, [:start, note_num, 1.0]]
        events << [i + len, [:stop, note_num]]
      end
    end
  end
  @sounds.push([sound, events])
end