Class: HeadMusic::Notation::NotationStyle
- Inherits:
-
Object
- Object
- HeadMusic::Notation::NotationStyle
- Defined in:
- lib/head_music/notation/notation_style.rb
Overview
A named notation tradition: how instruments are notated (clef, sounding transposition, staff structure) for a given context.
default lists every instrument. Named styles (british_brass_band,
concert_pitch, german, italian) are sparse OVERLAYS: they list only the
instruments whose notation differs, and any instrument they don’t mention
falls back to default.
HeadMusic::Notation::NotationStyle.get(:british_brass_band) .notation_for(“euphonium”) #=> treble clef, sounding transposition -14
Uses a lightweight registry rather than the Named mixin: style keys are internal identifiers with no translation surface.
Constant Summary collapse
- STYLES =
YAML.load_file(File.("notation_styles.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#instrument_notations ⇒ Object
readonly
protected
Returns the value of attribute instrument_notations.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#default_data(name_key) ⇒ Object
private
-
#initialize(hash_key) ⇒ NotationStyle
constructor
private
A new instance of NotationStyle.
-
#memo ⇒ Object
private
-
#notation_for(instrument) ⇒ Object
Resolve an instrument’s notation in this style, falling back to
default.
Constructor Details
#initialize(hash_key) ⇒ NotationStyle (private)
Returns a new instance of NotationStyle.
61 62 63 64 65 66 67 68 |
# File 'lib/head_music/notation/notation_style.rb', line 61 def initialize(hash_key) @key = hash_key.to_sym record = STYLES[@key.to_s] raise KeyError, "Unknown notation style: #{@key}" unless record @name = record["name"] @instrument_notations = record["instrument_notations"] || {} end |
Instance Attribute Details
#instrument_notations ⇒ Object (readonly, protected)
Returns the value of attribute instrument_notations.
57 58 59 |
# File 'lib/head_music/notation/notation_style.rb', line 57 def instrument_notations @instrument_notations end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
19 20 21 |
# File 'lib/head_music/notation/notation_style.rb', line 19 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/head_music/notation/notation_style.rb', line 19 def name @name end |
Class Method Details
.all ⇒ Object
34 35 36 |
# File 'lib/head_music/notation/notation_style.rb', line 34 def all STYLES.keys.map { |style_key| get(style_key) } end |
.default ⇒ Object
30 31 32 |
# File 'lib/head_music/notation/notation_style.rb', line 30 def default get(:default) end |
Instance Method Details
#default_data(name_key) ⇒ Object (private)
70 71 72 73 74 |
# File 'lib/head_music/notation/notation_style.rb', line 70 def default_data(name_key) return nil if @key == :default self.class.default.instrument_notations[name_key] end |
#memo ⇒ Object (private)
76 77 78 |
# File 'lib/head_music/notation/notation_style.rb', line 76 def memo @memo ||= {} end |
#notation_for(instrument) ⇒ Object
Resolve an instrument’s notation in this style, falling back to default.
Accepts an Instrument or any key/name Instrument.get understands.
Returns an InstrumentNotation, or nil if the instrument is unknown.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/head_music/notation/notation_style.rb', line 44 def notation_for(instrument) instrument = HeadMusic::Instruments::Instrument.get(instrument) return nil unless instrument&.name_key name_key = instrument.name_key.to_s data = instrument_notations[name_key] || default_data(name_key) return nil unless data memo[name_key] ||= HeadMusic::Notation::InstrumentNotation.new(instrument: instrument, data: data) end |