1

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. :)

asked Nov 19, 2013 at 22:19
3

1 Answer 1

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.

answered Nov 20, 2013 at 12:40
Sign up to request clarification or add additional context in comments.

1 Comment

I tested the code and it works fine. Thanks! I'll be studying it today, thanks a lot! :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.