Class: HeadMusic::Rudiment::Tuning

Inherits:
Base
  • Object
show all
Defined in:
lib/head_music/rudiment/tuning.rb

Overview

A tuning has a reference pitch and frequency and provides frequencies for all pitches The base class assumes equal temperament tuning. By default, A4 = 440.0 Hz

Direct Known Subclasses

JustIntonation, Meantone, Pythagorean

Defined Under Namespace

Classes: JustIntonation, Meantone, Pythagorean

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reference_pitch: :a440, tonal_center: nil) ⇒ Tuning

Returns a new instance of Tuning.



26
27
28
29
# File 'lib/head_music/rudiment/tuning.rb', line 26

def initialize(reference_pitch: :a440, tonal_center: nil)
  @reference_pitch = HeadMusic::Rudiment::ReferencePitch.get(reference_pitch)
  @tonal_center = tonal_center
end

Instance Attribute Details

#reference_pitchObject

Returns the value of attribute reference_pitch.



7
8
9
# File 'lib/head_music/rudiment/tuning.rb', line 7

def reference_pitch
  @reference_pitch
end

Class Method Details

.get(tuning_type = :equal_temperament, **options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/head_music/rudiment/tuning.rb', line 11

def self.get(tuning_type = :equal_temperament, **options)
  case tuning_type.to_s.downcase
  when "just_intonation", "just", "ji"
    HeadMusic::Rudiment::Tuning::JustIntonation.new(**options)
  when "pythagorean", "pythag"
    HeadMusic::Rudiment::Tuning::Pythagorean.new(**options)
  when "meantone", "quarter_comma_meantone", "1/4_comma"
    HeadMusic::Rudiment::Tuning::Meantone.new(**options)
  when "equal_temperament", "equal", "et", "12tet"
    new(**options)
  else
    new(**options)
  end
end

Instance Method Details

#frequency_for(pitch) ⇒ Object



31
32
33
34
# File 'lib/head_music/rudiment/tuning.rb', line 31

def frequency_for(pitch)
  pitch = HeadMusic::Rudiment::Pitch.get(pitch)
  reference_pitch_frequency * (2**(1.0 / 12))**(pitch - reference_pitch.pitch).semitones
end