Class: HeadMusic::ReferencePitch

Inherits:
Object
  • Object
show all
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

Attributes included from Named

#alias_name_keys, #name_key

Class Method Summary collapse

Instance Method Summary collapse

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.



84
85
86
87
88
89
# File 'lib/head_music/reference_pitch.rb', line 84

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

#frequencyObject (readonly)

Returns the value of attribute frequency.



77
78
79
# File 'lib/head_music/reference_pitch.rb', line 77

def frequency
  @frequency
end

#pitchObject (readonly)

Returns the value of attribute pitch.



77
78
79
# File 'lib/head_music/reference_pitch.rb', line 77

def pitch
  @pitch
end

Class Method Details

.get(name) ⇒ Object



79
80
81
82
# File 'lib/head_music/reference_pitch.rb', line 79

def self.get(name)
  return name if name.is_a?(self)
  get_by_name(name)
end

Instance Method Details

#descriptionObject



91
92
93
94
95
96
97
98
99
# File 'lib/head_music/reference_pitch.rb', line 91

def description
  [
    pitch.letter_name,
    format(
      "%<with_digits>g",
      with_digits: format("%.2<frequency>f", frequency: frequency)
    )
  ].join("=")
end

#to_sObject



101
102
103
# File 'lib/head_music/reference_pitch.rb', line 101

def to_s
  description
end