Class: HeadMusic::ReferencePitch
- Inherits:
-
Object
- Object
- HeadMusic::ReferencePitch
- Includes:
- Named
- Defined in:
- lib/head_music/reference_pitch.rb
Overview
A reference pitch has a pitch and a frequency With no arguments, it assumes that A4 = 440.0 Hz
Constant Summary collapse
- DEFAULT_PITCH_NAME =
"A4"- DEFAULT_FREQUENCY =
440.0- DEFAULT_REFERENCE_PITCH_NAME =
"A440"- NAMED_REFERENCE_PITCHES =
{ frequency: 415.0, key: :baroque, alias_keys: %i[chamber_tone] }, { frequency: 430.0, key: :classical, alias_keys: %i[haydn mozart] }, { pitch: "C4", frequency: 256.0, key: :scientific, alias_keys: %i[philosophical sauveur] }, { frequency: 432.0, tuning: "Pythagorean", key: :verdi }, { frequency: 435.0, key: :french, alias_keys: %i[continental international] }, { frequency: 439.0, key: :new_philharmonic, alias_keys: %i[low] }, { frequency: 440.0, key: :a440, alias_keys: %i[concert stuttgart scheibler iso_16] }, { frequency: 441.0, key: :sydney_symphony_orchestra }, { frequency: 442.0, key: :new_york_philharmonic }, { frequency: 443.0, key: :berlin_philharmonic }, { frequency: 444.0, key: :boston_symphony_orchestra }, { frequency: 452.4, key: :old_philharmonic, alias_keys: %i[high] }, { frequency: 466.0, key: :chorton, alias_keys: %i[choir] } ].freeze
Instance Attribute Summary collapse
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
Attributes included from Named
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(name = DEFAULT_REFERENCE_PITCH_NAME) ⇒ ReferencePitch
constructor
A new instance of ReferencePitch.
- #to_s ⇒ Object
Methods included from Named
#ensure_localized_name, included, #localized_name, #localized_names, #name, #name=
Constructor Details
#initialize(name = DEFAULT_REFERENCE_PITCH_NAME) ⇒ ReferencePitch
Returns a new instance of ReferencePitch.
82 83 84 85 86 87 |
# File 'lib/head_music/reference_pitch.rb', line 82 def initialize(name = DEFAULT_REFERENCE_PITCH_NAME) record = named_reference_pitch_record_for_name(name) @pitch = HeadMusic::Pitch.get(record.fetch(:pitch, DEFAULT_PITCH_NAME)) @frequency = record.fetch(:frequency, DEFAULT_FREQUENCY) initialize_keys_from_record(record) end |
Instance Attribute Details
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
75 76 77 |
# File 'lib/head_music/reference_pitch.rb', line 75 def frequency @frequency end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
75 76 77 |
# File 'lib/head_music/reference_pitch.rb', line 75 def pitch @pitch end |
Class Method Details
.get(name) ⇒ Object
77 78 79 80 |
# File 'lib/head_music/reference_pitch.rb', line 77 def self.get(name) return name if name.is_a?(self) get_by_name(name) end |
Instance Method Details
#description ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/head_music/reference_pitch.rb', line 89 def description [ pitch.letter_name, format( "%<with_digits>g", with_digits: format("%.2<frequency>f", frequency: frequency) ) ].join("=") end |
#to_s ⇒ Object
99 100 101 |
# File 'lib/head_music/reference_pitch.rb', line 99 def to_s description end |