Class: HeadMusic::Instruments::StaffProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/instruments/staff_profile.rb

Overview

The properties an instrument derives from its default notation staves: how many staves it uses, their clefs, whether it transposes, and whether it is pitched. These are a projection of the notation layer (a StaffScheme built from the default NotationStyle), separated from the instrument’s identity so Instrument can delegate to one place rather than carry the staff logic itself.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instrument) ⇒ StaffProfile

Returns a new instance of StaffProfile.



12
13
14
# File 'lib/head_music/instruments/staff_profile.rb', line 12

def initialize(instrument)
  @instrument = instrument
end

Instance Attribute Details

#instrumentObject (readonly)

Returns the value of attribute instrument.



10
11
12
# File 'lib/head_music/instruments/staff_profile.rb', line 10

def instrument
  @instrument
end

Instance Method Details

#default_clefsObject



32
33
34
# File 'lib/head_music/instruments/staff_profile.rb', line 32

def default_clefs
  default_staves&.map(&:clef) || []
end

#default_notation_staves_dataObject (private)

The raw staff-attribute list for this instrument’s default notation, resolved from the default NotationStyle. Referenced only inside a method body, because the Notation module loads after Instruments.



67
68
69
70
# File 'lib/head_music/instruments/staff_profile.rb', line 67

def default_notation_staves_data
  notation = HeadMusic::Notation::NotationStyle.default.notation_for(instrument)
  (notation&.staves || []).map(&:attributes)
end

#default_staff_schemeObject



20
21
22
23
24
25
26
# File 'lib/head_music/instruments/staff_profile.rb', line 20

def default_staff_scheme
  @default_staff_scheme ||= HeadMusic::Instruments::StaffScheme.new(
    key: "default",
    instrument: instrument,
    list: default_notation_staves_data
  )
end

#default_stavesObject



28
29
30
# File 'lib/head_music/instruments/staff_profile.rb', line 28

def default_staves
  default_staff_scheme.staves
end

#multiple_staves?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/head_music/instruments/staff_profile.rb', line 52

def multiple_staves?
  default_staves.length > 1
end

#pitched?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/head_music/instruments/staff_profile.rb', line 56

def pitched?
  return false if default_clefs.compact.uniq == [HeadMusic::Rudiment::Clef.get("neutral_clef")]

  default_clefs.any?
end

#single_staff?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/head_music/instruments/staff_profile.rb', line 48

def single_staff?
  default_staves.length == 1
end

#sounding_transpositionObject



36
37
38
# File 'lib/head_music/instruments/staff_profile.rb', line 36

def sounding_transposition
  default_staves&.first&.sounding_transposition || 0
end

#staff_schemesObject



16
17
18
# File 'lib/head_music/instruments/staff_profile.rb', line 16

def staff_schemes
  [default_staff_scheme]
end

#transposing?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/head_music/instruments/staff_profile.rb', line 40

def transposing?
  sounding_transposition != 0
end

#transposing_at_the_octave?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/head_music/instruments/staff_profile.rb', line 44

def transposing_at_the_octave?
  transposing? && sounding_transposition % 12 == 0
end