Module: Lydown::Rendering::Staff

Defined in:
lib/lydown/rendering/staff.rb

Constant Summary collapse

VOCAL_GROUP_SPAN_BAR_OVERRIDE =
"\\override SpanBar #'break-visibility = #'#( #t #f #t )"
VOCAL_PARTS =
%w{
  soprano alto tenore basso soprano1 soprano2 alto1 alto2 tenore1 tenore2
  basso1 basso2 1soprano 2soprano 1alto 2alto 1tenore 2tenore 1basso 2basso
  1soprano1 1soprano2 2soprano1 2soprano2 1alto1 1alto2 2alto1 2alto2
  1tenore1 1tenore2 2tenore1 2tenore2 1basso1 1basso2 2basso1 2basso2
}

Class Method Summary collapse

Class Method Details

.beaming_mode(context, opts) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/lydown/rendering/staff.rb', line 83

def self.beaming_mode(context, opts)
  beaming = context.get_setting(:beaming, opts)
  return nil if beaming.nil?
  
  case beaming
  when 'auto'
    '\\set Staff.autoBeaming = ##t'
  when 'manual'
    '\\set Staff.autoBeaming = ##f'
  else
    raise LydownError, "Invalid beaming mode (#{beaming.inspect})"
  end
end

.clef(context, opts) ⇒ Object



65
66
67
68
# File 'lib/lydown/rendering/staff.rb', line 65

def self.clef(context, opts)
  !context.get_setting(:inhibit_first_clef, opts) &&
    context.get_setting(:clef, opts)
end

.end_barline(context, opts) ⇒ Object



143
144
145
146
147
148
# File 'lib/lydown/rendering/staff.rb', line 143

def self.end_barline(context, opts)
  return nil if context['global/settings/inhibit_end_barline']
  
  barline = context.get_setting('end_barline', opts)
  barline == 'none' ? nil : barline
end

.heading_part_title(context, opts) ⇒ Object



108
109
110
111
112
113
# File 'lib/lydown/rendering/staff.rb', line 108

def self.heading_part_title(context, opts)
  title = context.get_setting("parts/#{opts[:part]}/heading_title", opts) ||
          context.get_setting("parts/#{opts[:part]}/title", opts) ||
          Lydown::Rendering.default_part_title(opts[:part])
  title.strip
end

.inline_part_title(context, opts) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/lydown/rendering/staff.rb', line 129

def self.inline_part_title(context, opts)
  title = qualified_part_title(context, opts)

  if title.empty?
    "#\"\""
  else
    if context.get_setting('instrument_name_style', opts) == 'smallcaps'
      "<>^\\markup { #{opts[:alignment]} \\smallCaps { #{title} } } "
    else
      "<>^\\markup { #{opts[:alignment]} { #{title} } } "
    end
  end
end

.is_vocal_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/lydown/rendering/staff.rb', line 61

def self.is_vocal_group?(group)
  !!group.find {|part| VOCAL_PARTS.include? part }
end

.midi_instrument(context, opts) ⇒ Object



79
80
81
# File 'lib/lydown/rendering/staff.rb', line 79

def self.midi_instrument(context, opts)
  context.get_setting(:midi_instrument, opts)
end

.part_title(context, opts) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/lydown/rendering/staff.rb', line 115

def self.part_title(context, opts)
  title = qualified_part_title(context, opts)

  if title.empty?
    "#\"\" "
  else
    if context.get_setting('instrument_name_style', opts) == 'smallcaps'
      "\\markup { \\smallCaps { #{title} } } "
    else
      "#\"#{title}\" "
    end
  end
end

.prevent_remove_empty(context, opts) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/lydown/rendering/staff.rb', line 70

def self.prevent_remove_empty(context, opts)
  case context.get_setting(:remove_empty, opts)
  when false, 'false'
    true
  else
    false
  end
end

.qualified_part_title(context, opts) ⇒ Object



102
103
104
105
106
# File 'lib/lydown/rendering/staff.rb', line 102

def self.qualified_part_title(context, opts)
  title = context.get_setting("parts/#{opts[:part]}/title", opts) ||
          Lydown::Rendering.default_part_title(opts[:part])
  title.strip
end

.staff_group_config(context, group) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/lydown/rendering/staff.rb', line 46

def self.staff_group_config(context, group)
  if is_vocal_group?(group)
    VOCAL_GROUP_SPAN_BAR_OVERRIDE
  else
    ''
  end
end

.staff_group_hierarchy(context, staff_groups) ⇒ Object

returns a hierarchy of staffgroups, each containing group configuration and a list of parts



33
34
35
36
37
38
39
40
41
# File 'lib/lydown/rendering/staff.rb', line 33

def self.staff_group_hierarchy(context, staff_groups)
  staff_groups.map {|group|
    {
      class: 'StaffGroup',
      config: staff_group_config(context, group),
      parts:  group
    }
  }
end

.staff_groups(context, opts, parts) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lydown/rendering/staff.rb', line 3

def self.staff_groups(context, opts, parts)
  if context.render_mode == :part
    opts = opts.merge(part: context['render_opts/parts'])
  end
  
  model = context.get_setting('score/order', opts)
  
  parts_copy = parts.clone
  
  groups = []
  
  model.each do |group|
    group = [group] unless group.is_a?(Array)
    filtered = group.select do |p|
      if parts_copy.include?(p)
        parts_copy.delete(p)
        true
      end
    end
    groups << filtered unless filtered.empty?
  end
  
  # add any remaining unknown parts, in their original order
  parts_copy.each {|p| groups << [p]}
  
  groups
end

.staff_id(part) ⇒ Object



97
98
99
100
# File 'lib/lydown/rendering/staff.rb', line 97

def self.staff_id(part)
  title = Lydown::Rendering.default_part_title(part).gsub(/\s+/, '')
  "#{title}Staff"
end