class PicoTune::Instrument
Attributes
length[R]
name[R]
pan[R]
phrase[RW]
reverb[R]
tone[R]
volume[R]
Public Class Methods
new(name, tone, length, volume, pan, reverb)
click to toggle source
# File lib/picotune.rb, line 311 def initialize name, tone, length, volume, pan, reverb @name = name @tone = tone @length = length @volume = volume @pan = pan @reverb = reverb end
Public Instance Methods
decay()
click to toggle source
# File lib/picotune.rb, line 375 def decay case @reverb when 'none' 0.0 when 'some' 0.1 when 'more' 0.3 when 'lots' 0.5 else 0.0 end end
delay()
click to toggle source
# File lib/picotune.rb, line 371 def delay @reverb == 'none' ? 0.0 : 0.08 end
frequency_for_note(note)
click to toggle source
# File lib/picotune.rb, line 418 def frequency_for_note note parts = note.split '' octave = parts.pop.to_i name = parts.join.to_sym freq = PicoTune::FREQUENCIES[name] raise "Bad note: #{name} from #{note}. Valid note names are <C, C# or Db, D, D# or Eb, E, F, F# or Gb, G, G# or Ab, A, A# or Bb, B>" unless freq raise "Bad octave: #{octave} from #{note}. Valid octave number is 1..8" unless (1..8).include?(octave) octave_shift = PicoTune::TONE_CONSTANT ** 12 (octave - 1).times { freq = freq * octave_shift } freq end
length_value()
click to toggle source
# File lib/picotune.rb, line 320 def length_value case @length when 'none' 0.0 when 'quarter' 0.25 when 'half' 0.5 when 'threequarters' 0.75 when 'full' 1.0 else 1.0 end end
pan_value()
click to toggle source
# File lib/picotune.rb, line 354 def pan_value case @pan when 'left' 0 when 'centerleft' 1 when 'center' 2 when 'centerright' 3 when 'right' 4 else 2 end end
reverb?()
click to toggle source
# File lib/picotune.rb, line 394 def reverb? %w(some more lots).include? @reverb end
reverb_offset()
click to toggle source
# File lib/picotune.rb, line 390 def reverb_offset (PicoTune::SAMPLE_RATE * delay).floor end
samples_per_wave(note)
click to toggle source
# File lib/picotune.rb, line 413 def samples_per_wave note frequency = frequency_for_note note (PicoTune::SAMPLE_RATE / frequency).to_i end
volume_value()
click to toggle source
# File lib/picotune.rb, line 337 def volume_value case @volume when 'none' 0.0 when 'quarter' 0.25 when 'half' 0.5 when 'threequarters' 0.75 when 'full' 1.0 else 1.0 end end
wave(wave_index, note)
click to toggle source
# File lib/picotune.rb, line 398 def wave wave_index, note frequency = frequency_for_note note samples_per_wave = (PicoTune::SAMPLE_RATE / frequency).to_i sample = PicoTune::WaveSample.new(@tone, samples_per_wave).sample wave_index sample.modify_left :*, volume_value * (1 - pan_value / 4.0) sample.modify_right :*, volume_value * (pan_value / 4.0) if v = phrase&.tune&.volume_factor_for_simultaneous_melodies sample.modify_left :*, v sample.modify_right :*, v end sample end