Microtuning Function

Hi,

I’m experimenting with microtuning and have the following code: [Update, I think I got it working!]

define :microTune do |note, isSample|
  # Bohlen–Pierce
  cents = (map a: 1316.74,
           as: 1463.05,
           b: 1609.35,  #! unmapped h: 1755.66 , j: 1901.96
           c: 0,
           cs: 146.30,
           d: 292.61,
           ds: 438.91,
           e: 585.22,
           f: 731.52,
           fs: 877.83,
           g: 1024.13,
           gs: 1170.44)[note]
  
  # 10 out of 13-tET
  cents2 = (map a: 1107.69,
            as: nil,
            b: nil,
            c: 0,
            cs: 184.61,
            d: 276.92,
            ds: 369.23,
            e: 553.84,
            f: 646.15,
            fs: 738.46,
            g: 923.07,
            gs: 1015.38)[note]
  
  # 12 out of 17-tET, chain of fifths
  cents3 = (map a: 847.05,
            as: 988.23,
            b: 1058.82,
            c: 0,
            cs: 70.58,
            d: 141.17,
            ds: 282.35,
            e: 352.94,
            f: 494.11,
            fs: 564.70,
            g: 635.29,
            gs: 776.47)[note]
  
  if isSample
    return (cents / 100) # Return pitch adjustment
  else
    return note + (cents / 100) # Return note with adjustment
  end
end

define :getPitchFromNote do |note, sampleBaseNote, fineTune|
  return note - sampleBaseNote + fineTune
end


live_loop :testNote do
  notes = (ring :c, :cs, :d, :ds, :e, :f, :fs, :g, :gs, :a) #, :as, :b)
  
  with_synth :chiplead do
    with_octave -1 do
      play microTune(notes.tick, false), amp: 1
    end
  end
  
  sleep 0.5
end


live_loop :testSample do
  s = :bass_dnb_f
  notes = (ring :c, :cs, :d, :ds, :e, :f, :fs, :g, :gs, :a) #, :as, :b)
  
  sample s, rpitch: (getPitchFromNote notes.tick, :f3, microTune(notes.look, true)), amp: 1
  
  sleep 0.5
end

Thanks,
Lee.

I’ve been studying this again recently and found out the above code is actually incorrect. The below appears to work correctly (if I compare it to the build-in meantone tuning).

define :micro_tune do |note, is_sample|
  # Meantone
  cents = (map c: 0,
           cs: 76.0-100,
           d: 193.2-200,
           ds: 310.3-300,
           eb: 310.3-300,
           e: 386.3-400,
           f: 503.4-500,
           fs: 579.5-600,
           g: 696.6-700,
           gs: 772.6-800,
           a: 889.7-900,
           as: 1006.8-1000,
           bb: 1006.8-1000,
           b: 1082.9-1100,
           r: 0)
  
  tuned_notes = []
  note_map = ""
  
  if !note.kind_of?(Array)
    note = [note]
  end
  
  note.each { |n|
    if n.length > 1
      chars = n.to_s.split("")
      chars.each { |c|
        if !(true if Float(c) rescue false)
          note_map += c.downcase
        end
      }
      
      note_map = note_map.to_s.to_sym
    else
      note_map = n.downcase.to_sym
    end
    
    tuned_notes.push(n + cents[note_map] / 100)
    if !is_sample
      note_map = ""
    end
  }
  
  if is_sample
    return cents[note_map] / 100
  else
    return tuned_notes
  end
end

12.times do
  notes = (ring :c4, :cs4, :d4, :ds4, :e4, :f4, :fs4, :g4, :gs4, :a4, :as4, :b4) 
  play micro_tune(notes.tick, false)  
  sleep 0.5
end
1 Like