rosetta-code.metronome: correct disposal of timer
							parent
							
								
									ccf1b82882
								
							
						
					
					
						commit
						d04bf5c10a
					
				| 
						 | 
				
			
			@ -2,8 +2,8 @@
 | 
			
		|||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
 | 
			
		||||
USING: accessors calendar circular colors.constants colors.hsv
 | 
			
		||||
concurrency.semaphores kernel math openal.example threads timers
 | 
			
		||||
ui ui.gadgets ui.gadgets.worlds ui.pens.solid ;
 | 
			
		||||
concurrency.semaphores continuations 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 ;
 | 
			
		||||
| 
						 | 
				
			
			@ -32,9 +32,11 @@ IN: rosetta-code.metronome
 | 
			
		|||
: start-metronome-timer ( bpm -- timer semaphore )
 | 
			
		||||
    0 <semaphore> [ (start-metronome-timer) ] keep ;
 | 
			
		||||
 | 
			
		||||
: run-metronome ( semaphore notes -- )
 | 
			
		||||
    [ open-metronome-window ] 2dip <circular> swap metronome-loop ;
 | 
			
		||||
 | 
			
		||||
: metronome ( bpm notes -- )
 | 
			
		||||
    [ start-metronome-timer ] dip
 | 
			
		||||
    [ open-metronome-window ] 2dip <circular> swap metronome-loop
 | 
			
		||||
    stop-timer ;
 | 
			
		||||
    [ run-metronome ] curry [ stop-timer ] [ ] cleanup ;
 | 
			
		||||
 | 
			
		||||
! example usage: 60 { 440 220 330 } metronome
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue