Class: Musa::MusicXML::Builder::Internal::Key Private
- Includes:
- Extension::With, 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.
Key signature specification.
Key represents a key signature in terms of the circle of fifths and mode. For multi-staff parts (like piano), the number attribute specifies which staff the key signature applies to.
Circle of Fifths
The fifths attribute uses the circle of fifths representation:
- Negative values: flats (C♭ major = -7, F major = -1)
- Zero: C major / A minor
- Positive values: sharps (G major = +1, C♯ major = +7)
Common keys:
- -7: C♭, -6: G♭, -5: D♭, -4: A♭, -3: E♭, -2: B♭, -1: F
- 0: C (major) / A (minor)
- +1: G, +2: D, +3: A, +4: E, +5: B, +6: F♯, +7: C♯
Instance Attribute Summary collapse
-
#cancel ⇒ Integer?
private
Number of accidentals to cancel.
-
#fifths ⇒ Integer
private
Circle of fifths position (-7 to +7).
-
#mode ⇒ String?
private
Mode ('major' or 'minor').
-
#number ⇒ Integer?
readonly
private
Staff number (for multi-staff instruments).
Instance Method Summary collapse
-
#_to_xml(io, indent:, tabs:) ⇒ void
private
Generates the key signature XML element.
-
#initialize(number = nil, cancel: nil, fifths:, mode: nil, &block) ⇒ Key
constructor
private
Creates a key signature.
-
#to_xml(io = nil, indent: nil) ⇒ IO, StringIO
included
from Helper::ToXML
private
Converts the object to MusicXML format.
-
#with(*value_parameters, keep_block_context: nil, **key_parameters, &block) ⇒ Object
included
from Extension::With
Executes a block with flexible context and parameter handling.
Constructor Details
#initialize(number = nil, cancel: nil, fifths:, mode: nil, &block) ⇒ Key
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 key signature.
58 59 60 61 62 63 64 65 66 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 58 def initialize(number = nil, cancel: nil, fifths:, mode: nil, &block) @number = number @cancel = cancel @fifths = fifths @mode = mode with &block if block_given? end |
Instance Attribute Details
#cancel ⇒ Integer?
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.
Number of accidentals to cancel.
74 75 76 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 74 def cancel @cancel end |
#fifths ⇒ Integer
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.
Circle of fifths position (-7 to +7).
78 79 80 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 78 def fifths @fifths end |
#mode ⇒ 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.
Mode ('major' or 'minor').
82 83 84 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 82 def mode @mode 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).
70 71 72 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 70 def number @number 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 key signature XML element.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 92 def _to_xml(io, indent:, tabs:) io ||= StringIO.new indent ||= 0 tabs = "\t" * indent io.puts "#{tabs}<key#{" number=\"#{@number.to_i}\"" if @number}>" io.puts "#{tabs}\t<cancel>#{@cancel}</cancel>" if @cancel io.puts "#{tabs}\t<fifths>#{@fifths.to_i}</fifths>" io.puts "#{tabs}\t<mode>#{@mode}</mode>" if @mode io.puts "#{tabs}</key>" io 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.
#with(*value_parameters, keep_block_context: nil, **key_parameters, &block) ⇒ Object Originally defined in module Extension::With
The _ parameter is special: when present, it signals "keep caller's context"
and receives self (the object) as its value.
Uses SmartProcBinder internally to handle parameter matching.
Executes a block with flexible context and parameter handling.