diff options
Diffstat (limited to 'client/lib/organ.js')
| -rw-r--r-- | client/lib/organ.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/client/lib/organ.js b/client/lib/organ.js index f67a3e8..9d0ac90 100644 --- a/client/lib/organ.js +++ b/client/lib/organ.js @@ -1,4 +1,5 @@ import Tone from "tone"; +import { roundFreq } from "./util"; const oscillators = {}; @@ -8,11 +9,17 @@ let lastPlayed; function load(out) { output = out; } + +function isPlaying(freq) { + const rounded = roundFreq(freq); + const osc = oscillators[rounded]; + return osc && osc.playing; +} function play(freq) { if (!output) { return; } - const rounded = Math.floor(freq); + const rounded = roundFreq(freq); const osc = (oscillators[rounded] = oscillators[rounded] || {}); if (!osc.el) { osc.el = new Tone.Oscillator(freq, "sine"); @@ -25,7 +32,7 @@ function play(freq) { } function pause(freq) { - const rounded = Math.floor(freq); + const rounded = roundFreq(freq); if (!oscillators[rounded]) return; const osc = (oscillators[rounded] = oscillators[rounded] || {}); if (osc.el) osc.el.stop(); @@ -33,4 +40,4 @@ function pause(freq) { return osc; } -export default { load, play, pause, oscillators }; +export default { load, isPlaying, play, pause, oscillators }; |
