Class: SynthBlocks::Sequencer::SequencerDSL::Song
- Inherits:
-
Object
- Object
- SynthBlocks::Sequencer::SequencerDSL::Song
- Defined in:
- lib/synth_blocks/sequencer/sequencer_dsl.rb
Overview
A
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
:nodoc:.
-
#per_bar ⇒ Object
readonly
:nodoc:.
-
#per_beat ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(bpm, patterns) ⇒ Song
constructor
:nodoc:.
-
#length ⇒ Object
Returns the length of the song in seconds plus 2 seconds to allow for reverb tails etc.
-
#pattern(name, at: 0, repeat: 1, length: nil) ⇒ Object
inserts a pattern into the song [name] pattern needs to be defined by
def_pattern[at] Position in bars to insert the pattern to [repeat] number of times the pattern should repeat [length] if you want to only use part of the pattern. -
#play ⇒ Object
Sends all scheduled events to the instruments.
-
#run(block) ⇒ Object
:nodoc:.
Constructor Details
#initialize(bpm, patterns) ⇒ Song
:nodoc:
123 124 125 126 127 128 129 130 131 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 123 def initialize(bpm, patterns) # :nodoc: @tempo = bpm @events = [] @per_beat = 60.0 / @tempo.to_f @per_bar = @per_beat * 4.0 @per_step = @per_beat / 4.0 @patterns = patterns @latest_time = 0 end |
Instance Attribute Details
#events ⇒ Object (readonly)
:nodoc:
122 123 124 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 122 def events @events end |
#per_bar ⇒ Object (readonly)
:nodoc:
122 123 124 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 122 def @per_bar end |
#per_beat ⇒ Object (readonly)
:nodoc:
122 123 124 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 122 def per_beat @per_beat end |
Instance Method Details
#length ⇒ Object
Returns the length of the song in seconds plus 2 seconds to allow for reverb tails etc.
169 170 171 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 169 def length (@latest_time + 2.0).ceil end |
#pattern(name, at: 0, repeat: 1, length: nil) ⇒ Object
inserts a pattern into the song
- name
-
pattern needs to be defined by
def_pattern - at
-
Position in bars to insert the pattern to
- repeat
-
number of times the pattern should repeat
- length
-
if you want to only use part of the pattern
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 145 def pattern(name, at: 0, repeat: 1, length: nil) p = @patterns[name] pattern_length = length || p.steps start = at.to_f * @per_bar p.sounds.each do |sound, events| repeat.times do |rep| events.each do |event| step, data = event next if step > pattern_length time = start + (rep.to_f * pattern_length.to_f * @per_step.to_f) + step.to_f * @per_step @latest_time = time if time > @latest_time type, *rest = data @events << [sound, [type, time, *rest]] end end end end |
#play ⇒ Object
Sends all scheduled events to the instruments
175 176 177 178 179 180 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 175 def play @events.each do |event| instrument, data = event instrument.send(*data) end end |
#run(block) ⇒ Object
:nodoc:
133 134 135 |
# File 'lib/synth_blocks/sequencer/sequencer_dsl.rb', line 133 def run(block) # :nodoc: instance_eval(&block) end |