Class: Musa::MusicXML::Builder::Internal::Clef 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.
Clef specification.
Clef represents musical clefs that determine the pitch range displayed on a staff. MusicXML supports standard clefs (treble, bass, alto, tenor), percussion clefs, and tablature clefs.
For multi-staff parts (like piano), the number attribute specifies which staff the clef applies to.
Common Clefs
Standard clefs are defined by a sign and staff line number:
- Treble (G clef): sign='G', line=2
- Bass (F clef): sign='F', line=4
- Alto (C clef): sign='C', line=3
- Tenor (C clef): sign='C', line=4
- Percussion: sign='percussion'
- Tablature: sign='TAB'
Clef Signs
The sign parameter determines the clef type:
- G: Treble clef family
- F: Bass clef family
- C: Alto/tenor clef family (movable C clef)
- percussion: For unpitched percussion
- TAB: For guitar/bass tablature
Staff Lines
The line parameter indicates which staff line the clef sign sits on:
- Lines are numbered 1-5 from bottom to top
- Treble clef (G) typically on line 2
- Bass clef (F) typically on line 4
- Alto clef (C) on line 3, Tenor clef (C) on line 4
Octave Transposition
The octave_change parameter transposes notation by octaves:
- -2: 15ma basso (two octaves down)
- -1: 8va basso (one octave down)
- 0: No transposition (default)
- +1: 8va alta (one octave up)
- +2: 15ma alta (two octaves up)
Common for tenor voice (treble clef 8va basso) and piccolo (treble 8va alta).
Reaching it
Clefs are written through the attributes DSL. The examples below are
against measure = Measure.new(1, divisions: 2).
line: is optional, as it is in MusicXML: a clef that sits on no line
simply leaves it out, and no <line> element is written.
Instance Attribute Summary collapse
-
#line ⇒ Integer
private
Staff line number (1-5).
-
#number ⇒ Integer?
readonly
private
Staff number (for multi-staff instruments).
-
#octave_change ⇒ Integer?
private
Octave transposition (-2 to +2).
-
#sign ⇒ String
private
Clef sign (G, F, C, percussion, TAB).
Instance Method Summary collapse
-
#_to_xml(io, indent:, tabs:) ⇒ void
private
Generates the clef XML element.
-
#initialize(number = nil, sign:, line: nil, octave_change: nil, &block) ⇒ Clef
constructor
private
Creates a clef.
-
#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, sign:, line: nil, octave_change: nil, &block) ⇒ Clef
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 clef.
388 389 390 391 392 393 394 395 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 388 def initialize(number = nil, sign:, line: nil, octave_change: nil, &block) @number = number @sign = sign @line = line @octave_change = octave_change with &block if block_given? end |
Instance Attribute Details
#line ⇒ 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.
Staff line number (1-5).
407 408 409 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 407 def line @line 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).
399 400 401 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 399 def number @number end |
#octave_change ⇒ 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.
Octave transposition (-2 to +2).
411 412 413 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 411 def octave_change @octave_change end |
#sign ⇒ 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.
Clef sign (G, F, C, percussion, TAB).
403 404 405 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 403 def sign @sign 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 clef XML element.
421 422 423 424 425 426 427 428 429 |
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 421 def _to_xml(io, indent:, tabs:) io.puts "#{tabs}<clef#{" number=\"#{@number.to_i}\"" if @number}>" io.puts "#{tabs}\t<sign>#{@sign}</sign>" io.puts "#{tabs}\t<line>#{@line.to_i}</line>" if @line io.puts "#{tabs}\t<clef-octave-change>#{@octave_change.to_i}</clef-octave-change>" if @octave_change io.puts "#{tabs}</clef>" 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.