diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-08-11 16:52:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-08-11 16:52:21 +0200 |
| commit | 2b4057ef612cac821def7dff666d66e6a8b96c74 (patch) | |
| tree | 3590f63f98a1110bae479c46eac51b6ff2951d4f /client/index.js | |
| parent | 795e1064ed498457dfc122b5ef91f4b2496a62e1 (diff) | |
export pitchbend FWIW
Diffstat (limited to 'client/index.js')
| -rw-r--r-- | client/index.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/client/index.js b/client/index.js index da07d12..476c8e3 100644 --- a/client/index.js +++ b/client/index.js @@ -30,6 +30,13 @@ function midi_ready(err) { console.log(WebMidi.outputs) midi = WebMidi.outputs[0] } +function ftom(f) { + // return (Math.log(f) - Math.log(261.626)) / Math.log(2) + 4.0 + return 69 + 12 * Math.log2(f / 440) +} +function mtof(m) { + return 440 * Math.pow(2, (m - 69) / 12) +} var loop = new Tone.Sequence(function(time, col){ var column = grid.matrix[col] @@ -38,11 +45,22 @@ var loop = new Tone.Sequence(function(time, col){ if (column[i] === 1){ const index = noteCount - i - baseTone const freq = scales.current().index(index) - const midi_note = Tone.Frequency.ftom(freq) - const midi_freq = Tone.Frequency.mtof(midi_note) - console.log(midi_note, freq, midi_freq, freq - midi_freq) + // const midi_note = Tone.Frequency.ftom(freq) + // const midi_freq = Tone.Frequency.mtof(midi_note) + // console.log(midi_note, freq, midi_freq, freq - midi_freq) + let midi_note = ftom(freq) + let cents = midi_note % 1 + if (cents > 0.5) { + midi_note += 1 + cents -= 1 + } + cents *= 2 + midi_note = Math.floor(midi_note) + // console.log(freq, midi_note, cents.foFixed(1)) if (midi) { - midi.playNote(Tone.Frequency(midi_note, "midi").toNote(), 3, { duration: 90000 / Tone.Transport.bpm.value }) + midi.playNote(Tone.Frequency(Math.floor(midi_note), "midi").toNote(), "all", { duration: 90000 / Tone.Transport.bpm.value }) + // cents + midi.sendPitchBend(cents, "all") } else { kalimba.play(freq) } |
