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. :)
-
check out himera.herokuapp.com/synonym.htmledbond– edbond2013年11月20日 06:57:21 +00:00Commented Nov 20, 2013 at 6:57
-
I have created a repo github.com/edbond/cljs-metronome here is cljs file - github.com/edbond/cljs-metronome/blob/master/src/metronome/…edbond– edbond2013年11月20日 11:56:56 +00:00Commented Nov 20, 2013 at 11:56
-
1@edbond thank you very much for that! I will be studying that! If you want you can put this in an answer and I can accept it for you if you like. :)greduan– greduan2013年11月20日 12:31:06 +00:00Commented Nov 20, 2013 at 12:31
1 Answer 1
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.