Class: HeadMusic::Rudiment::Tuning::Pythagorean

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

Overview

Pythagorean tuning system based on stacking perfect fifths (3:2 ratio)

Constant Summary collapse

INTERVAL_RATIOS =

Frequency ratios for intervals in Pythagorean tuning (relative to tonic) Generated by stacking perfect fifths and reducing to within one octave

{
  unison: Rational(1, 1),
  minor_second: Rational(256, 243),        # Pythagorean minor second
  major_second: Rational(9, 8),            # Pythagorean major second
  minor_third: Rational(32, 27),           # Pythagorean minor third
  major_third: Rational(81, 64),           # Pythagorean major third (ditone)
  perfect_fourth: Rational(4, 3),          # Perfect fourth
  tritone: Rational(729, 512),             # Pythagorean tritone (augmented fourth)
  perfect_fifth: Rational(3, 2),           # Perfect fifth
  minor_sixth: Rational(128, 81),          # Pythagorean minor sixth
  major_sixth: Rational(27, 16),           # Pythagorean major sixth
  minor_seventh: Rational(16, 9),          # Pythagorean minor seventh
  major_seventh: Rational(243, 128),       # Pythagorean major seventh
  octave: Rational(2, 1)                   # Octave
}.freeze
CHROMATIC_RATIOS =

Additional chromatic intervals for enharmonic equivalents

{
  augmented_unison: Rational(2187, 2048),   # Pythagorean augmented unison (sharp)
  diminished_second: Rational(256, 243)     # Same as minor second in Pythagorean
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Pythagorean.



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

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.



30
31
32
# File 'lib/head_music/rudiment/tuning/pythagorean.rb', line 30

def tonal_center
  @tonal_center
end

Instance Method Details

#calculate_tonal_center_frequencyObject (private)



55
56
57
58
59
# File 'lib/head_music/rudiment/tuning/pythagorean.rb', line 55

def calculate_tonal_center_frequency
  # Use equal temperament to get the tonal center frequency from the reference pitch
  interval_to_tonal_center = (tonal_center - reference_pitch.pitch).semitones
  reference_pitch_frequency * (2**(interval_to_tonal_center / 12.0))
end

#frequency_for(pitch) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/head_music/rudiment/tuning/pythagorean.rb', line 37

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 Pythagorean ratio for this interval
  ratio = ratio_for_interval(interval_from_tonal_center)

  # Calculate the frequency
  tonal_center_frequency * ratio
end

#ratio_for_interval(semitones) ⇒ Object (private)



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/head_music/rudiment/tuning/pythagorean.rb', line 61

def ratio_for_interval(semitones)
  # Handle octaves
  octaves = semitones / 12
  interval_within_octave = semitones % 12

  # Make sure we handle negative intervals
  if interval_within_octave < 0
    interval_within_octave += 12
    octaves -= 1
  end

  # Get the base ratio
  base_ratio = case interval_within_octave
  when 0 then INTERVAL_RATIOS[:unison]
  when 1 then INTERVAL_RATIOS[:minor_second]
  when 2 then INTERVAL_RATIOS[:major_second]
  when 3 then INTERVAL_RATIOS[:minor_third]
  when 4 then INTERVAL_RATIOS[:major_third]
  when 5 then INTERVAL_RATIOS[:perfect_fourth]
  when 6 then INTERVAL_RATIOS[:tritone]
  when 7 then INTERVAL_RATIOS[:perfect_fifth]
  when 8 then INTERVAL_RATIOS[:minor_sixth]
  when 9 then INTERVAL_RATIOS[:major_sixth]
  when 10 then INTERVAL_RATIOS[:minor_seventh]
  when 11 then INTERVAL_RATIOS[:major_seventh]
  end

  # Apply octave adjustments
  base_ratio * (2**octaves)
end