Module: Lydown::Rendering::Figures
- Included in:
- Notes
- Defined in:
- lib/lydown/rendering/figures.rb
Constant Summary collapse
- BLANK_EXTENDER_START =
'<->'
- BLANK_EXTENDER_STOP =
'<.>'
- BLANK_EXTENDER =
'<_>'
- EXTENDERS_ON =
"\\bassFigureExtendersOn "
- EXTENDERS_OFF =
"\\bassFigureExtendersOff "
- ALTERATION_RE =
/[#bh`']/
- ALTERATION =
{ '#' => '_+', 'b' => '_-', 'h' => '_!', '`' => '\\\\', "'" => "/" }
- HIDDEN_FORMAT =
"\\once \\override BassFigure #'implicit = ##t"
Instance Method Summary collapse
- #add_figures(figures, value) ⇒ Object
- #add_stand_alone_figures(figures) ⇒ Object
- #check_tenues(figures) ⇒ Object
- #lilypond_figures(figures) ⇒ Object
- #next_figures_event ⇒ Object
- #translate_figures(figures) ⇒ Object
Instance Method Details
#add_figures(figures, value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lydown/rendering/figures.rb', line 10 def add_figures(figures, value) # Add fill-in silences to catch up with music stream if @context['process/running_values'] silence_figures = @event[:tenue] ? @context['process/last_figures'] : (@context['process/blank_extender_mode'] ? '<_>' : 's') @context['process/running_values'].each do |v| silence = silence_figures if v != @context['process/last_figures_value'] silence = silence + v @context['process/last_figures_value'] = v end @context.emit(:figures, "#{silence} ") end @context['process/running_values'] = nil end figures = lilypond_figures(figures) if figures == BLANK_EXTENDER_START @context['process/blank_extender_mode'] = true figures = BLANK_EXTENDER @context.emit(:figures, EXTENDERS_ON) elsif figures == BLANK_EXTENDER_STOP @context['process/blank_extender_mode'] = false figures = BLANK_EXTENDER @event[:figure_extenders_off] = true else @context['process/last_figures'] = figures end if value != @context['process/last_figures_value'] figures = figures + value @context['process/last_figures_value'] = value end @context.emit(:figures, "#{figures} ") @context.emit(:figures, EXTENDERS_ON) if @event[:figure_extenders_on] @context.emit(:figures, EXTENDERS_OFF) if @event[:figure_extenders_off] end |
#add_stand_alone_figures(figures) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lydown/rendering/figures.rb', line 51 def add_stand_alone_figures(figures) if @context['process/running_values'] # for stand alone figures, we regard the stand alone figure as being # aligned to the last note. Therefore we pop its value from # running_values array. @context['process/running_values'].pop end value = @context['process/figures_duration_value'] || @context['process/last_value'] add_figures(figures, value) end |
#check_tenues(figures) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/lydown/rendering/figures.rb', line 71 def check_tenues(figures) next_event = next_figures_event unless next_event # if next figures event is not found, check if there is a tenue, and # add extenders off flag @event[:figure_extenders_off] = @event[:tenue] return end if next_event[:figures] next_event[:tenue] = next_event[:figures].include?('_') if next_event[:tenue] && !@event[:tenue] @event[:figure_extenders_on] = true elsif !next_event[:tenue] && @event[:tenue] @event[:figure_extenders_off] = true end # transform underscores into figure components next_event[:figures].each_with_index do |component, idx| next_event[:figures][idx] = @event[:figures][idx] if component == '_' end end end |
#lilypond_figures(figures) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/lydown/rendering/figures.rb', line 62 def lilypond_figures(figures) if figures check_tenues(figures) "<#{translate_figures(figures)}>" else "s" end end |
#next_figures_event ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lydown/rendering/figures.rb', line 109 def next_figures_event idx = @idx + 1 while idx < @stream.size event = @stream[idx] case event[:type] when :setting if ['part', 'movement'].include? event[:key] return nil end when :note return event if event[:figures] when :stand_alone_figures return event end idx += 1 end end |
#translate_figures(figures) ⇒ Object
95 96 97 |
# File 'lib/lydown/rendering/figures.rb', line 95 def translate_figures(figures) figures.map {|n| n.gsub(ALTERATION_RE) {|a| ALTERATION[a]}}.join(' ') end |