Class: Musa::MusicXML::Builder::Internal::Time Private
- Includes:
- Helper::ToXML
- Defined in:
- lib/musa-dsl/musicxml/builder/attributes.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Time signature specification.
Time represents time signatures in MusicXML. It supports simple meters (4/4, 3/4), compound meters (6/8), complex meters (5/4), and compound time signatures with multiple beat groups. Also supports unmeasured time (senza misura) for cadenzas and free-form sections.
For multi-staff parts (like piano), the number attribute specifies which staff the time signature applies to.
Simple Time Signatures
Most common meters use a single beats/beat_type pair:
- 4/4 (common time): beats=4, beat_type=4
- 3/4 (waltz): beats=3, beat_type=4
- 6/8 (compound): beats=6, beat_type=8
- 2/2 (cut time): beats=2, beat_type=2
Compound Time Signatures
Some meters combine multiple beat groups (e.g., 3+2+3/8):
Time.new do |t|
t.add_beats beats: 3, beat_type: 8
t.add_beats beats: 2, beat_type: 8
t.add_beats beats: 3, beat_type: 8
end
Senza Misura (Unmeasured Time)
For cadenzas and free-form sections without strict meter:
Time.new(senza_misura: '')
Instance Attribute Summary collapse
-
#beats ⇒ Array<Hash>
readonly
private
Array of beat groups for compound time signatures.
-
#number ⇒ Integer?
readonly
private
Staff number (for multi-staff instruments).
-
#senza_misura ⇒ String?
private
Senza misura indicator for unmeasured time.
Instance Method Summary collapse
-
#_to_xml(io, indent:, tabs:) ⇒ void
private
Generates the time signature XML element.
-
#add_beats(beats:, beat_type:) ⇒ void
private
Adds a beat group to the time signature.
-
#initialize(number = nil, senza_misura: nil, beats: nil, beat_type: nil) ⇒ Time
constructor
private
Creates a time signature.
-
#to_xml(io = nil, indent: nil) ⇒ IO, StringIO
included
from Helper::ToXML
private
Converts the object to MusicXML format.
Constructor Details
#initialize(number = nil, senza_misura: nil, beats: nil, beat_type: nil) ⇒ Time
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a time signature.
183 184 185 186 187 188 189 190 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 183 def initialize(number = nil, senza_misura: nil, beats: nil, beat_type: nil) @number = number @senza_misura = senza_misura unless beats && beat_type @beats = [] add_beats beats: beats, beat_type: beat_type if beats && beat_type end |
Instance Attribute Details
#beats ⇒ Array<Hash> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Array of beat groups for compound time signatures.
202 203 204 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 202 def beats @beats end |
#number ⇒ Integer? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Staff number (for multi-staff instruments).
194 195 196 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 194 def number @number end |
#senza_misura ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Senza misura indicator for unmeasured time.
198 199 200 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 198 def senza_misura @senza_misura end |
Instance Method Details
#_to_xml(io, indent:, tabs:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Generates the time signature XML element.
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 230 def _to_xml(io, indent:, tabs:) io.puts "#{tabs}<time#{" number=\"#{@number.to_i}\"" if @number}>" io.puts "#{tabs}\t<senza-misura>#{@senza_misura}</senza-misura>" if @senza_misura @beats.each do |beats| io.puts "#{tabs}\t<beats>#{beats[:beats].to_i}</beats>" io.puts "#{tabs}\t<beat-type>#{beats[:beat_type].to_i}</beat-type>" end io.puts "#{tabs}</time>" end |
#add_beats(beats:, beat_type:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Adds a beat group to the time signature.
Used for compound time signatures that combine multiple beat groups (e.g., 3+2+3/8 or 2+2+3/4).
218 219 220 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 218 def add_beats(beats:, beat_type:) @beats << { beats: beats, beat_type: beat_type } end |
#to_xml(io = nil, indent: nil) ⇒ IO, StringIO Originally defined in module Helper::ToXML
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the object to MusicXML format.
This method sets up the IO stream and indentation, then delegates to
the private _to_xml method for actual XML generation.