Class: Musa::MusicXML::Builder::Internal::PartGroup Private

Inherits:
Object
  • Object
show all
Includes:
Helper, Helper::HeaderToXML
Defined in:
lib/musa-dsl/musicxml/builder/part-group.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.

Part group for bracketing multiple parts together.

PartGroup represents the <part-group> element in the MusicXML part-list section. Part groups visually bracket or brace related parts together (e.g., string sections, choir SATB, piano grand staff).

Usage

Part groups are defined by matching start/stop pairs with the same number:

<part-group number="1" type="start">
  <group-name>Strings</group-name>
  <group-symbol>bracket</group-symbol>
</part-group>
<score-part id="p1">...</score-part>
<score-part id="p2">...</score-part>
<part-group number="1" type="stop" />

Nesting

Groups can be nested using different numbers:

<part-group number="1" type="start" name="Orchestra" />
<part-group number="2" type="start" name="Strings" />
<score-part id="vln1" />
<score-part id="vln2" />
<part-group number="2" type="stop" />
<part-group number="1" type="stop" />

Symbols

Common bracket symbols:

  • bracket: Standard square bracket
  • brace: Curly brace (for piano, organ)
  • line: Simple vertical line
  • square: Square bracket (rare)

Examples:

String quartet grouping

group_start = PartGroup.new(1,
  type: 'start',
  name: "String Quartet",
  symbol: 'bracket'
)
# ... add parts vln1, vln2, vla, vlc ...
group_stop = PartGroup.new(1, type: 'stop')

Piano grand staff

PartGroup.new(1,
  type: 'start',
  symbol: 'brace',
  group_barline: true
)
# ... add parts for right hand and left hand ...
PartGroup.new(1, type: 'stop')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number = nil, type:, name: nil, abbreviation: nil, symbol: nil, group_barline: nil, group_time: nil) ⇒ PartGroup

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 part group declaration.

Examples:

Start a bracket group

PartGroup.new(1,
  type: 'start',
  name: "Woodwinds",
  symbol: 'bracket'
)

Stop a group

PartGroup.new(1, type: 'stop')

Parameters:

  • number (Integer, nil) (defaults to: nil)

    group number for matching start/stop pairs

  • type (String)

    'start' or 'stop'

  • name (String, nil) (defaults to: nil)

    group name displayed on bracket

  • abbreviation (String, nil) (defaults to: nil)

    abbreviated group name

  • symbol (String, nil) (defaults to: nil)

    bracket type: 'bracket', 'brace', 'line', 'square'

  • group_barline (Boolean, String, nil) (defaults to: nil)

    whether barlines connect across group

  • group_time (Boolean, String, nil) (defaults to: nil)

    whether time signatures are shared



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 84

def initialize(number = nil, # number
               type:,
               name: nil,
               abbreviation: nil,
               symbol: nil,
               group_barline: nil, # true
               group_time: nil) # true
  @number = number
  @type = type
  @name = name
  @abbreviation = abbreviation
  @symbol = symbol
  @group_barline = group_barline
  @group_time = group_time
end

Instance Attribute Details

#abbreviationString?

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.

Abbreviated group name.

Returns:



114
115
116
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 114

def abbreviation
  @abbreviation
end

#group_barlineBoolean, ...

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.

Whether barlines connect across the group.

Returns:



122
123
124
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 122

def group_barline
  @group_barline
end

#group_timeBoolean, ...

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.

Whether time signatures are shared.

Returns:



126
127
128
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 126

def group_time
  @group_time
end

#nameString?

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.

Group name displayed on bracket.

Returns:



110
111
112
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 110

def name
  @name
end

#numberInteger?

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.

Group number (for matching start/stop pairs).

Returns:

  • (Integer, nil)


102
103
104
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 102

def number
  @number
end

#symbolString?

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.

Bracket symbol type.

Returns:



118
119
120
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 118

def symbol
  @symbol
end

#typeString

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.

Type: 'start' or 'stop'.

Returns:



106
107
108
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 106

def type
  @type
end

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-group XML element for the part-list section.

Parameters:

  • io (IO)

    output stream

  • indent (Integer)

    indentation level

  • tabs (String)

    tab string



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/musa-dsl/musicxml/builder/part-group.rb', line 136

def _header_to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<part-group#{ decode_bool_or_string_attribute(@number&.to_i, 'number') } type=\"#{@type}\">"

  io.puts "#{tabs}\t<group-name>#{@name}</group-name>" if @name
  io.puts "#{tabs}\t<group-abbreviation>#{@abbreviation}</group-abbreviation>" if @abbreviation
  io.puts "#{tabs}\t<group-symbol>#{@symbol}</group-symbol>" if @symbol
  io.puts "#{tabs}\t<group-barline>#{decode_bool_or_string_value(@group_barline, 'yes', 'no')}</group-barline>" if @group_barline
  io.puts "#{tabs}\t<group-time>#{decode_bool_or_string_value(@group_time, 'yes', 'no')}</group-time>" if @group_time

  io.puts "#{tabs}</part-group>"
end

#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.

Parameters:

  • io (IO, StringIO, nil) (defaults to: nil)

    output stream (creates StringIO if nil)

  • indent (Integer, nil) (defaults to: nil)

    indentation level (default: 0)

Returns:

  • (IO, StringIO)

    the io parameter, containing the XML output