Class: HeadMusic::Rudiment::Tuning::JustIntonation

Inherits:
HeadMusic::Rudiment::Tuning show all
Defined in:
lib/head_music/rudiment/tuning/just_intonation.rb

Overview

Just Intonation tuning system based on whole number frequency ratios

Constant Summary collapse

INTERVAL_RATIOS =

Frequency ratios for intervals in just intonation (relative to tonic) Based on the major scale with pure intervals

{
  unison: Rational(1, 1),
  minor_second: Rational(16, 15),
  major_second: Rational(9, 8),
  minor_third: Rational(6, 5),
  major_third: Rational(5, 4),
  perfect_fourth: Rational(4, 3),
  tritone: Rational(45, 32),
  perfect_fifth: Rational(3, 2),
  minor_sixth: Rational(8, 5),
  major_sixth: Rational(5, 3),
  minor_seventh: Rational(16, 9),
  major_seventh: Rational(15, 8),
  octave: Rational(2, 1)
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of JustIntonation.



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

def initialize(reference_pitch: :a440, tonal_center: nil)
  super
  @tonal_center = HeadMusic::Rudiment::Pitch.get(tonal_center || "C4")
end

Instance Attribute Details

#tonal_centerObject (readonly)

Returns the value of attribute tonal_center.



24
25
26
# File 'lib/head_music/rudiment/tuning/just_intonation.rb', line 24

def tonal_center
  @tonal_center
end

Instance Method Details

#frequency_for(pitch) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/head_music/rudiment/tuning/just_intonation.rb', line 31

def frequency_for(pitch)
  pitch = HeadMusic::Rudiment::Pitch.get(pitch)

  # Calculate the frequency of the tonal center using equal temperament from reference pitch
  tonal_center_frequency = calculate_tonal_center_frequency

  # Calculate the interval from the tonal center to the requested pitch
  interval_from_tonal_center = (pitch - tonal_center).semitones

  # Get the just intonation ratio for this interval
  ratio = ratio_for_interval(interval_from_tonal_center)

  # Calculate the frequency
  tonal_center_frequency * ratio
end