Sha256: 560941a7354899514317f2d100e0e231531cbc6851e45e2635f773b199ae43e7

Contents?: true

Size: 630 Bytes

Versions: 21

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

# 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

21 entries across 21 versions & 1 rubygems

Version Path
head_music-4.0.1 lib/head_music/tuning.rb
head_music-4.0.0 lib/head_music/tuning.rb
head_music-3.0.1 lib/head_music/tuning.rb
head_music-3.0.0 lib/head_music/tuning.rb
head_music-2.0.1 lib/head_music/tuning.rb
head_music-2.0.0 lib/head_music/tuning.rb
head_music-1.0.0 lib/head_music/tuning.rb
head_music-0.29.0 lib/head_music/tuning.rb
head_music-0.28.0 lib/head_music/tuning.rb
head_music-0.27.0 lib/head_music/tuning.rb
head_music-0.26.3 lib/head_music/tuning.rb
head_music-0.26.2 lib/head_music/tuning.rb
head_music-0.26.1 lib/head_music/tuning.rb
head_music-0.26.0 lib/head_music/tuning.rb
head_music-0.25.0 lib/head_music/tuning.rb
head_music-0.24.5 lib/head_music/tuning.rb
head_music-0.24.4 lib/head_music/tuning.rb
head_music-0.24.3 lib/head_music/tuning.rb
head_music-0.24.2 lib/head_music/tuning.rb
head_music-0.24.1 lib/head_music/tuning.rb