Class: Musa::MusicXML::Builder::Internal::Attributes

Inherits:
Object
  • Object
show all
Extended by:
Extension::AttributeBuilder
Includes:
Extension::With, Helper::ToXML
Defined in:
lib/musa-dsl/musicxml/builder/attributes.rb

Instance Method Summary collapse

Methods included from Extension::AttributeBuilder

attr_complex_adder_to_array, attr_complex_adder_to_custom, attr_complex_builder, attr_simple_builder, attr_tuple_adder_to_array, attr_tuple_adder_to_hash, attr_tuple_builder

Methods included from Helper::ToXML

#to_xml

Methods included from Extension::With

#with

Constructor Details

#initialize(divisions: nil, key_cancel: nil, key_fifths: nil, key_mode: nil, time_senza_misura: nil, time_beats: nil, time_beat_type: nil, clef_sign: nil, clef_line: nil, clef_octave_change: nil, &block) ⇒ Attributes

Returns a new instance of Attributes.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 104

def initialize(divisions: nil,
               key_cancel: nil, key_fifths: nil, key_mode: nil,
               time_senza_misura: nil, time_beats: nil, time_beat_type: nil,
               clef_sign: nil, clef_line: nil, clef_octave_change: nil,
               &block)

  @divisions = divisions

  @keys = []
  @times = []
  @clefs = []

  add_key cancel: key_cancel, fifths: key_fifths, mode: key_mode if key_fifths
  add_time senza_misura: time_senza_misura, beats: time_beats, beat_type: time_beat_type if time_senza_misura || (time_beats && time_beat_type)
  add_clef sign: clef_sign, line: clef_line, octave_change: clef_octave_change if clef_sign

  with &block if block_given?
end

Instance Method Details

#_to_xml(io, indent:, tabs:) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 129

def _to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<attributes>"

  io.puts "#{tabs}\t<divisions>#{@divisions.to_i}</divisions>" if @divisions

  @keys.each do |key|
    key.to_xml(io, indent: indent + 1)
  end

  @times.each do |time|
    time.to_xml(io, indent: indent + 1)
  end

  staves = [@keys.size, @times.size, @clefs.size].max
  io.puts "#{tabs}\t<staves>#{staves}</staves>" if staves > 1

  @clefs.each do |clef|
    clef.to_xml(io, indent: indent + 1)
  end

  io.puts "#{tabs}</attributes>"
end