]> gitweb.factorcode.org Git - factor.git/commitdiff
rosetta-code.metronome: use openAL to play sound
authorJon Harper <jon.harper87@gmail.com>
Sun, 29 Sep 2013 17:00:57 +0000 (19:00 +0200)
committerJon Harper <jon.harper87@gmail.com>
Sun, 29 Sep 2013 17:00:57 +0000 (19:00 +0200)
This brings cross-platform compatibility

extra/rosetta-code/metronome/metronome.factor

index 67744e668c5110af540240c9fa9619dc13203fb5..eb452025b8c7c6a6c113e7f91552e21fb5ebaeea 100644 (file)
@@ -2,16 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 
 USING: accessors calendar circular colors.constants colors.hsv
-concurrency.semaphores continuations formatting fry
-generalizations io.launcher kernel math sequences threads timers
-ui ui.gadgets ui.gadgets.worlds ui.pens.solid ;
+concurrency.semaphores generalizations kernel math
+openal.example threads timers ui ui.gadgets ui.gadgets.worlds
+ui.pens.solid ;
 IN: rosetta-code.metronome
 
-! linux alsa..
-! For debian, in package alsa-utils
-: <wave-process> ( freq -- process )
-    "speaker-test -t sine -f %d -p 20000" sprintf ;
-
 : bpm>duration ( bpm -- duration ) 60 swap / seconds ;
 
 : blink-gadget ( gadget freq -- )
@@ -21,9 +16,7 @@ IN: rosetta-code.metronome
     COLOR: white <solid> >>interior relayout-1 ;
 
 : play-note ( gadget freq -- )
-    [ dupd blink-gadget ] [ <wave-process> run-detached ] bi
-    [ [ kill-process blank-gadget ] 2curry 300 milliseconds later drop ]
-    [ [ wait-for-process ] ignore-errors drop ] bi ;
+    [ blink-gadget ] [ 0.3 play-sine blank-gadget ] 2bi ;
 
 : open-metronome-window ( -- gadget )
     gadget new { 200 200 } >>pref-dim