Class: Lydown::Rendering::Command
- Inherits:
-
Base
- Object
- Base
- Lydown::Rendering::Command
show all
- Includes:
- Notes
- Defined in:
- lib/lydown/rendering/command.rb
Constant Summary
collapse
- COMMAND_ALIGNMENT =
{
'<' => '\\right-align',
'>' => '\\left-align',
'|' => '\\center-align'
}
Constants included
from Notes
Notes::ADD_LINK_COMMAND, Notes::DYNAMICS, Notes::LILYPOND_EXPRESSIONS, Notes::MARKUP_ALIGNMENT, Notes::TEXTMATE_URL, Notes::TRANSPARENT_NOTE, Notes::TRANSPARENT_TIE
Constants included
from Figures
Figures::ALTERATION, Figures::ALTERATION_RE, Figures::BLANK_EXTENDER, Figures::BLANK_EXTENDER_START, Figures::BLANK_EXTENDER_STOP, Figures::EXTENDERS_OFF, Figures::EXTENDERS_ON, Figures::HIDDEN_FORMAT
Instance Method Summary
collapse
Methods included from Notes
#add_chord, add_duration_macro_group, #add_macro_event, #add_macro_note, #add_note, cleanup_duration_macro, #cross_bar_dot_lilypond_note, #lilypond_chord, #lilypond_note, #lilypond_phrasing, #lydown_phrasing_close, #lydown_phrasing_open, #note_event_url_link, #translate_expressions, #translate_string_expression
Methods included from Figures
#add_figures, #add_stand_alone_figures, #check_tenues, #lilypond_figures, #next_figures_event, #translate_figures
Methods inherited from Base
#find_prev_event, #initialize, #next_event, #prev_event
Instance Method Details
#cmd_instr ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/lydown/rendering/command.rb', line 71
def cmd_instr
return unless (@context.render_mode == :score)
markup = Staff.inline_part_title(
@context,
part: @context[:part],
name: @event[:arguments] && @event[:arguments][0],
alignment: @event[:alignment]
)
@context.emit(:music, markup)
end
|
#cmd_partBreak ⇒ Object
97
98
99
|
# File 'lib/lydown/rendering/command.rb', line 97
def cmd_partBreak
@context.emit(:music, "\\break ") if (@context.render_mode == :part)
end
|
#cmd_partPageBreak ⇒ Object
105
106
107
|
# File 'lib/lydown/rendering/command.rb', line 105
def cmd_partPageBreak
@context.emit(:music, "\\pageBreak ") if (@context.render_mode == :part)
end
|
#cmd_scoreBreak ⇒ Object
101
102
103
|
# File 'lib/lydown/rendering/command.rb', line 101
def cmd_scoreBreak
@context.emit(:music, "\\break ") if (@context.render_mode == :score)
end
|
#cmd_scorePageBreak ⇒ Object
109
110
111
|
# File 'lib/lydown/rendering/command.rb', line 109
def cmd_scorePageBreak
@context.emit(:music, "\\pageBreak ") if (@context.render_mode == :score)
end
|
#cmd_sHLE ⇒ Object
height-limit + eccentricity
143
144
145
146
|
# File 'lib/lydown/rendering/command.rb', line 143
def cmd_sHLE
args = @event[:arguments]
@context.emit(:music, "\\sHL #{args[0]} \\sE #{args[1]} ")
end
|
#cmd_slur ⇒ Object
137
138
139
140
|
# File 'lib/lydown/rendering/command.rb', line 137
def cmd_slur
arguments = transform_slur_arguments(@event[:arguments])
@context.emit(:music, "\\sS #'(#{arguments}) ")
end
|
#cmd_sP ⇒ Object
149
150
151
152
|
# File 'lib/lydown/rendering/command.rb', line 149
def cmd_sP
args = @event[:arguments]
@context.emit(:music, "\\sP #{args.join(' ')} ")
end
|
#cmd_tempo ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/lydown/rendering/command.rb', line 82
def cmd_tempo
unless @event[:arguments] && @event[:arguments].size == 1
raise LydownError, "Invalid or missing tempo argument"
end
tempo = @event[:arguments].first
if tempo =~ /^\((.+)\)$/
format = @context['options/format']
return unless (format == :midi) || (format == :mp3)
tempo = $1
end
@context.emit(:music, "\\tempo #{tempo} ")
end
|
#cmd_to_lydown(event) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/lydown/rendering/command.rb', line 62
def cmd_to_lydown(event)
cmd = "\\#{event[:key]}"
if event[:arguments]
cmd << ":"
cmd << event[:arguments].map {|a| a.inspect}.join(':')
end
cmd
end
|
53
54
55
56
57
58
59
60
|
# File 'lib/lydown/rendering/command.rb', line 53
def format_argument(command_key, argument)
case command_key
when 'tempo', 'mark'
"\"#{argument}\""
else
argument
end
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/lydown/rendering/command.rb', line 38
def format_override_shorthand_command
key = @event[:key] =~ /^\\(.+)$/ && $1
arguments = @event[:arguments].map do |arg|
case arg
when /^[0-9\.]+$/
"##{arg}"
when /^[tf]$/
"###{arg}"
else
arg
end
end
"\\override #{key} = #{arguments.join(' ')} "
end
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/lydown/rendering/command.rb', line 113
def transform_slur_arguments(args)
case args.size
when 4
args = args.map do |a|
case a
when '_'
'#f'
when /\(([0-9\.\-]*),([0-9\.\-]*)\)/
"(#{$1.empty? ? '0' : $1} . #{$2.empty? ? '0' : $2})"
else
a
end
end
args.join(" ")
when 1
args[0].gsub(/_/, ' (0 . 0) ').
gsub (/\(([0-9\.\-]*),([0-9\.\-]*)\)/) do |m|
"(#{$1.empty? ? '0' : $1} . #{$2.empty? ? '0' : $2})"
end
else
raise "Invalid slur shape arguments (#{args.inspect})"
end
end
|
#translate ⇒ Object
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
|
# File 'lib/lydown/rendering/command.rb', line 11
def translate
key = @event[:key]
if key =~ /([\<\>\|])([a-zA-Z0-9]+)/
@event[:alignment] = COMMAND_ALIGNMENT[$1]
key = $2
end
if respond_to?("cmd_#{key}".to_sym)
return send("cmd_#{key}".to_sym)
end
if @context['process/duration_macro']
add_macro_event(@event[:raw] || cmd_to_lydown(@event))
else
arguments = (@event[:arguments] || []).map do |a|
format_argument(@event[:key], a)
end.join(' ')
if @event[:key] =~ /^\\/
cmd = format_override_shorthand_command
else
cmd = "\\#{@event[:key]} #{arguments} "
end
@context.emit(:music, '\once ') if @event[:once]
@context.emit(:music, cmd)
end
end
|