Class: HeadMusic::Notation::LilyPond::PitchReaderStack

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/notation/lily_pond/pitch_reader_stack.rb

Overview

The pitch readers in scope. \relative and \absolute each push a reader for the music they wrap, so the notes inside are read by the innermost one and the notes after it by whichever reader was in force before.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ PitchReaderStack

Returns a new instance of PitchReaderStack.



7
8
9
# File 'lib/head_music/notation/lily_pond/pitch_reader_stack.rb', line 7

def initialize
  @readers = [PitchReader.absolute]
end

Instance Method Details

#absolute(&block) ⇒ Object



19
20
21
# File 'lib/head_music/notation/lily_pond/pitch_reader_stack.rb', line 19

def absolute(&block)
  scoped(PitchReader.absolute, &block)
end

#current ⇒ Object



11
12
13
# File 'lib/head_music/notation/lily_pond/pitch_reader_stack.rb', line 11

def current
  @readers.last
end

#relative(reference, &block) ⇒ Object



15
16
17
# File 'lib/head_music/notation/lily_pond/pitch_reader_stack.rb', line 15

def relative(reference, &block)
  scoped(PitchReader.relative(reference), &block)
end

#scoped(reader) ⇒ Object (private)



25
26
27
28
29
# File 'lib/head_music/notation/lily_pond/pitch_reader_stack.rb', line 25

def scoped(reader)
  @readers.push(reader)
  yield
  @readers.pop
end