rosetta-code.metronome: simplify stack shuffling
parent
939395ac13
commit
ccf1b82882
|
@ -2,9 +2,8 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: accessors calendar circular colors.constants colors.hsv
|
||||
concurrency.semaphores generalizations kernel math
|
||||
openal.example threads timers ui ui.gadgets ui.gadgets.worlds
|
||||
ui.pens.solid ;
|
||||
concurrency.semaphores kernel math openal.example threads timers
|
||||
ui ui.gadgets ui.gadgets.worlds ui.pens.solid ;
|
||||
IN: rosetta-code.metronome
|
||||
|
||||
: bpm>duration ( bpm -- duration ) 60 swap / seconds ;
|
||||
|
@ -27,16 +26,15 @@ IN: rosetta-code.metronome
|
|||
acquire [ play-note ] [ drop find-world handle>> ] 2bi
|
||||
] curry with circular-loop ;
|
||||
|
||||
: start-metronome-timer ( bpm semaphore -- timer )
|
||||
: (start-metronome-timer) ( bpm semaphore -- timer )
|
||||
[ release ] curry swap bpm>duration every ;
|
||||
|
||||
: start-metronome-timer ( bpm -- timer semaphore )
|
||||
0 <semaphore> [ (start-metronome-timer) ] keep ;
|
||||
|
||||
: metronome ( bpm notes -- )
|
||||
<circular> open-metronome-window
|
||||
swap 0 <semaphore>
|
||||
{
|
||||
[ 2nip start-metronome-timer ]
|
||||
[ metronome-loop drop ]
|
||||
} 4 ncleave
|
||||
[ start-metronome-timer ] dip
|
||||
[ open-metronome-window ] 2dip <circular> swap metronome-loop
|
||||
stop-timer ;
|
||||
|
||||
! example usage: 60 { 440 220 330 } metronome
|
||||
|
|
Loading…
Reference in New Issue