Class: Clef::Parser::DSL::VoiceBuilder
- Inherits:
-
Object
- Object
- Clef::Parser::DSL::VoiceBuilder
show all
- Includes:
- BlockEvaluation
- Defined in:
- lib/clef/parser/dsl.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of VoiceBuilder.
212
213
214
215
216
217
218
219
220
|
# File 'lib/clef/parser/dsl.rb', line 212
def initialize(voice)
@voice = voice
@last_duration = Clef::Core::Duration.quarter
@pending_tie = false
@pending_articulations = []
@open_slur = false
@open_beam = false
@last_note = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Clef::Parser::DSL::BlockEvaluation
Instance Method Details
#chord(pitch_strs, duration_sym, **opts) ⇒ Object
249
250
251
252
253
|
# File 'lib/clef/parser/dsl.rb', line 249
def chord(pitch_strs, duration_sym, **opts)
duration = Clef::Core::Duration.new(duration_sym, dots: opts.fetch(:dots, 0))
pitches = pitch_strs.map { |pitch| parse_pitch(pitch) }
@voice.add(Clef::Core::Chord.new(pitches, duration))
end
|
#dynamic(type) ⇒ Object
256
257
258
|
# File 'lib/clef/parser/dsl.rb', line 256
def dynamic(type)
@voice.add(Clef::Notation::Dynamic.new(type))
end
|
#note(pitch_str, duration_sym, **opts) ⇒ Object
232
233
234
235
236
237
|
# File 'lib/clef/parser/dsl.rb', line 232
def note(pitch_str, duration_sym, **opts)
pitch = parse_pitch(pitch_str)
duration = Clef::Core::Duration.new(duration_sym, dots: opts.fetch(:dots, 0))
articulations = Array(opts.fetch(:articulations, []))
@voice.add(Clef::Core::Note.new(pitch, duration, articulations: articulations, tied: opts[:tied]))
end
|
#notes(lilypond_string) ⇒ Object
268
269
270
|
# File 'lib/clef/parser/dsl.rb', line 268
def notes(lilypond_string)
parse_tokens(lilypond_string).each { |token| add_token(token) }
end
|
#rest(duration_sym, **opts) ⇒ Object
241
242
243
244
|
# File 'lib/clef/parser/dsl.rb', line 241
def rest(duration_sym, **opts)
duration = Clef::Core::Duration.new(duration_sym, dots: opts.fetch(:dots, 0))
@voice.add(Clef::Core::Rest.new(duration, kind: opts.fetch(:kind, :visible), measures: opts.fetch(:measures, 1)))
end
|
#tempo(beat_unit:, bpm:) ⇒ Object
#tuplet(actual, normal, &block) ⇒ Object
274
275
276
277
278
279
280
281
|
# File 'lib/clef/parser/dsl.rb', line 274
def tuplet(actual, normal, &block)
raise ArgumentError, "tuplet values must be positive" unless actual.positive? && normal.positive?
return unless block_given?
voice = Clef::Core::Voice.new(id: @voice.id)
evaluate_block(self.class.new(voice), &block)
@voice.add(Clef::Core::Tuplet.new(actual, normal, voice.elements))
end
|
224
225
226
227
|
# File 'lib/clef/parser/dsl.rb', line 224
def use_voice(voice)
@voice = voice
self
end
|