Class: HeadMusic::Content::StaffSystem
- Inherits:
-
Object
- Object
- HeadMusic::Content::StaffSystem
- Defined in:
- lib/head_music/content/staff_system.rb
Overview
An ordered set of staves joined by a brace or a bracket: a piano's two, a harp's two, an organ's three, or the single staff most parts use.
Constant Summary collapse
- BRACKETS =
%i[brace bracket none].freeze
Instance Attribute Summary collapse
-
#bracket ⇒ Object
readonly
Returns the value of attribute bracket.
-
#staves ⇒ Object
readonly
Returns the value of attribute staves.
Class Method Summary collapse
-
.grand_staff ⇒ Object
A grand staff, treble over bass, as a piano or harp uses.
-
.single_staff(clef: nil) ⇒ Object
The one-staff system a part falls back to when nothing has said otherwise.
Instance Method Summary collapse
- #first_staff ⇒ Object
- #include?(staff) ⇒ Boolean
-
#initialize(staves: nil, bracket: :none) ⇒ StaffSystem
constructor
A new instance of StaffSystem.
- #length ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(staves: nil, bracket: :none) ⇒ StaffSystem
Returns a new instance of StaffSystem.
11 12 13 14 15 16 17 |
# File 'lib/head_music/content/staff_system.rb', line 11 def initialize(staves: nil, bracket: :none) raise ArgumentError, "bracket must be one of: #{BRACKETS.join(", ")}" unless BRACKETS.include?(bracket) @staves = Array(staves) @staves = [HeadMusic::Content::Staff.new] if @staves.empty? @bracket = bracket end |
Instance Attribute Details
#bracket ⇒ Object (readonly)
Returns the value of attribute bracket.
9 10 11 |
# File 'lib/head_music/content/staff_system.rb', line 9 def bracket @bracket end |
#staves ⇒ Object (readonly)
Returns the value of attribute staves.
9 10 11 |
# File 'lib/head_music/content/staff_system.rb', line 9 def staves @staves end |
Class Method Details
.grand_staff ⇒ Object
A grand staff, treble over bass, as a piano or harp uses.
25 26 27 28 |
# File 'lib/head_music/content/staff_system.rb', line 25 def self.grand_staff new(staves: [HeadMusic::Content::Staff.new(clef: :treble_clef), HeadMusic::Content::Staff.new(clef: :bass_clef)], bracket: :brace) end |
Instance Method Details
#first_staff ⇒ Object
30 31 32 |
# File 'lib/head_music/content/staff_system.rb', line 30 def first_staff staves.first end |
#include?(staff) ⇒ Boolean
34 35 36 |
# File 'lib/head_music/content/staff_system.rb', line 34 def include?(staff) staves.any? { |candidate| candidate.equal?(staff) } end |
#length ⇒ Object
38 39 40 |
# File 'lib/head_music/content/staff_system.rb', line 38 def length staves.length end |
#to_h ⇒ Object
46 47 48 |
# File 'lib/head_music/content/staff_system.rb', line 46 def to_h {"bracket" => bracket.to_s, "staves" => staves.map(&:to_h)} end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/head_music/content/staff_system.rb', line 42 def to_s "#{length}-staff #{bracket}" end |