Question

I have developed a simple metronome in JS as a JS exercise and also out of need. It can be found here: https://github.com/Greduan/js-metronome/blob/master/js/main.js

I have translated it to a certain extent to CLJS:

(ns mies-2.core
  (:use 'createjs.Sound))

(def assetsPath "assets/")
(def manifest [{:src "Click1.ogg|Click1.mp3" :id 1} {:src "Click2.ogg|Click2.mp3" :id 2}])

(.registerManifest createjs/Sound [manifest assetsPath])

(defn stop []
  ((js/clearInterva(intervalID))
   (.stop createjs/Sound [])
   (.log js/console "Stopped sound(s).")))

(defn playSound [target]
  ;                                           v FIX
  ((def instance (.play createjs/Sound [target.id (.INTERRUPT_NONE createjs/Sound []) 0 0 false 1]))
  ;                                 v FIX
  (or (== instance nil) (== instance.playState (.PLAY_FAILED createjs/Sound)) nil)
  (.log js/console ["Played sound ID:" target.id])))

(defn soundLoop [soundID]
  ;                                                             v FIX
  ((def bpmInput (.querySelector js/document ["[name=\"bpm\"]"] .value))
   (def bpm (/ 60000 bpmInput))
   (.log js/console ["Input:" bpmInput "Delay:" bpm])
   (def intervalID (js/setInterval [fn [] (playSound [soundID]) bpm]))))

I pointed out what I need help with in comments saying FIX. :)

Basically diong a system of thing.function.value or something like that, specifically translating document.querySelector('[name="bpm"]').value to CLJS.

And the variables, having a variable.value system, how could I achieve that with CLJS?

Pointing me in the right direction is more than enough and appreciated very much. :)

Was it helpful?

Solution

I have converted your js app to cljs and created a repository: https://github.com/edbond/cljs-metronome Let me know if it doesn't works for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top