Class: Musa::MusicXML::Builder::Internal::Part
- Extended by:
- Extension::AttributeBuilder
- Includes:
- Extension::With, Helper::HeaderToXML, Helper::ToXML
- Defined in:
- lib/musa-dsl/musicxml/builder/part.rb
Overview
Individual part (instrument/voice) in a score.
Part represents a single instrument or voice in the score, containing a sequence of measures with musical content. Each part has a unique identifier, full name, and optional abbreviation.
Structure
A part contains:
- Header: Declared in
<part-list>with<score-part> - Content: Sequence of
<measure>elements with notes, dynamics, etc.
Usage
Parts are typically created via ScorePartwise#part or ScorePartwise#add_part. Measures are added sequentially, automatically numbered starting from 1.
Class Method Summary collapse
-
.attr_complex_adder_to_array(name, klass, plural: nil, variable: nil) ⇒ Object
extended
from Extension::AttributeBuilder
Creates methods for adding complex objects (with multiple parameters) to an array.
-
.attr_complex_adder_to_custom(name, plural: nil, variable: nil) { ... } ⇒ Object
extended
from Extension::AttributeBuilder
Creates methods for adding complex objects with custom construction logic.
-
.attr_complex_builder(name, klass, variable: nil, first_parameter: nil) ⇒ Object
extended
from Extension::AttributeBuilder
Creates a getter/setter DSL method for complex objects with multiple parameters.
-
.attr_simple_builder(name, klass = nil, variable: nil) ⇒ Object
extended
from Extension::AttributeBuilder
Creates a simple getter/setter DSL method for a single value.
-
.attr_tuple_adder_to_array(name, klass, plural: nil, variable: nil) ⇒ Object
extended
from Extension::AttributeBuilder
Creates methods for adding id/value tuples to an array collection.
-
.attr_tuple_adder_to_hash(name, klass, plural: nil, variable: nil) ⇒ Object
extended
from Extension::AttributeBuilder
Creates methods for adding id/value tuples to a hash collection.
-
.attr_tuple_builder(name, klass, variable: nil) ⇒ Object
extended
from Extension::AttributeBuilder
Creates a getter/setter DSL method for a single id/value tuple.
Instance Method Summary collapse
-
#_header_to_xml(io, indent:, tabs:) ⇒ void
private
Generates the part declaration for the part-list section.
-
#_to_xml(io, indent:, tabs:) ⇒ void
private
Generates the part content with all measures.
-
#abbreviation ⇒ Object
Part abbreviation builder/setter.
-
#header_to_xml(io = nil, indent: nil) ⇒ IO, StringIO
included
from Helper::HeaderToXML
private
Converts the object's header representation to MusicXML.
-
#id ⇒ Object
Part ID builder/setter.
-
#initialize(id, name:, abbreviation: nil, **first_measure_attributes) { ... } ⇒ Part
constructor
Creates a new part.
-
#measure { ... } ⇒ Measure
Adds a measure to the part.
-
#name ⇒ Object
Part name builder/setter.
-
#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(id, name:, abbreviation: nil, **first_measure_attributes) { ... } ⇒ Part
Creates a new part.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 80 def initialize(id, name:, abbreviation: nil, **first_measure_attributes, &block) @id = id @name = name @abbreviation = abbreviation @measures = [] unless first_measure_attributes.empty? add_measure **first_measure_attributes end with &block if block_given? end |
Class Method Details
.attr_complex_adder_to_array(name, klass, plural: nil, variable: nil) ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates methods for adding complex objects (with multiple parameters) to an array.
Supports both positional and keyword arguments when creating instances.
.attr_complex_adder_to_custom(name, plural: nil, variable: nil) { ... } ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates methods for adding complex objects with custom construction logic.
The block receives parameters and should construct and add the object.
.attr_complex_builder(name, klass, variable: nil, first_parameter: nil) ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates a getter/setter DSL method for complex objects with multiple parameters.
Supports optional first_parameter that's automatically prepended when constructing.
.attr_simple_builder(name, klass = nil, variable: nil) ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates a simple getter/setter DSL method for a single value.
.attr_tuple_adder_to_array(name, klass, plural: nil, variable: nil) ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates methods for adding id/value tuples to an array collection.
Similar to attr_tuple_adder_to_hash but stores items in an array instead of hash. Useful when order matters or duplicates are allowed.
.attr_tuple_adder_to_hash(name, klass, plural: nil, variable: nil) ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates methods for adding id/value tuples to a hash collection.
Generates:
add_#{name}(id, parameter)→ creates instance and adds to hash#{plural}(**parameters)→ batch add or retrieve hash
.attr_tuple_builder(name, klass, variable: nil) ⇒ Object Originally defined in module Extension::AttributeBuilder
Creates a getter/setter DSL method for a single id/value tuple.
Instance Method Details
#_header_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 part declaration for the part-list section.
Creates a <score-part> element with part name and optional abbreviation.
178 179 180 181 182 183 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 178 def _header_to_xml(io, indent:, tabs:) io.puts "#{tabs}<score-part id=\"#{@id}\">" io.puts "#{tabs}\t<part-name>#{@name}</part-name>" io.puts "#{tabs}\t<part-abbreviation>#{@abbreviation}</part-abbreviation>" if @abbreviation io.puts "#{tabs}</score-part>" end |
#_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 part content with all measures.
Creates a <part> element containing all measures in sequence.
195 196 197 198 199 200 201 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 195 def _to_xml(io, indent:, tabs:) io.puts "#{tabs}<part id=\"#{@id}\">" @measures.each do |measure| measure.to_xml(io, indent: indent + 1) end io.puts "#{tabs}</part>" end |
#abbreviation(value) ⇒ Object #abbreviation=(value) ⇒ Object
Part abbreviation builder/setter.
122 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 122 attr_simple_builder :abbreviation |
#header_to_xml(io = nil, indent: nil) ⇒ IO, StringIO Originally defined in module Helper::HeaderToXML
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's header representation to MusicXML.
Used for elements that appear in the <part-list> section, such as
<score-part> and <part-group> declarations.
#id(value) ⇒ Object #id=(value) ⇒ Object
Part ID builder/setter.
102 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 102 attr_simple_builder :id |
#measure { ... } ⇒ Measure
Adds a measure to the part.
Measures are automatically numbered sequentially starting from 1. The first measure typically contains attributes (key, time, clef, divisions).
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 155 attr_complex_adder_to_custom :measure, variable: :@measures do | 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 | Measure.new(@measures.size + 1, divisions: divisions, key_cancel: key_cancel, key_fifths: key_fifths, key_mode: key_mode, time_senza_misura: time_senza_misura, time_beats: time_beats, time_beat_type: time_beat_type, clef_sign: clef_sign, clef_line: clef_line, clef_octave_change: clef_octave_change).tap { |measure| @measures << measure } end |
#name(value) ⇒ Object #name=(value) ⇒ Object
Part name builder/setter.
112 |
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 112 attr_simple_builder :name |
#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.