Sha256: 42439aac1a08a7de8ee3a35a148dc2ef7215bedf019c37066834e193cb3794e7

Contents?: true

Size: 599 Bytes

Versions: 9

Compression:

Stored size: 599 Bytes

Contents

# 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
class HeadMusic::Tuning
  attr_accessor :reference_pitch

  delegate :pitch, :frequency, to: :reference_pitch, prefix: true

  def initialize(reference_pitch: :a440)
    @reference_pitch = HeadMusic::ReferencePitch.get(reference_pitch)
  end

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

# TODO: other tunings

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
head_music-7.0.5 lib/head_music/tuning.rb
head_music-7.0.4 lib/head_music/tuning.rb
head_music-7.0.3 lib/head_music/tuning.rb
head_music-7.0.2 lib/head_music/tuning.rb
head_music-7.0.1 lib/head_music/tuning.rb
head_music-7.0.0 lib/head_music/tuning.rb
head_music-6.0.1 lib/head_music/tuning.rb
head_music-6.0.0 lib/head_music/tuning.rb
head_music-5.0.0 lib/head_music/tuning.rb