Metronome: Difference between revisions

1,327 bytes added ,  8 years ago
→‎{{header|REXX}}: added output to the 1st REXX program, changed/added comments, whitespace, and indentations.
m (→‎with sound, REGINA only: added a comment to a REXX section header.)
(→‎{{header|REXX}}: added output to the 1st REXX program, changed/added comments, whitespace, and indentations.)
Line 1,019:
These REXX program examples are modeled after the Perl 6 example.
===textual visual, no sound===
<lang rexx>/*REXX program simulates a visual (textual) metronome (with no sound). */
parse arg bpm bpb dur . /*obtain optional arguments from the CL*/
if bpm=='' | bpm=='",'" then bpm=72 /*the number of beats per minute. */
if bpb=='' | bpb=='",'" then bpb= 4 /*number of" " " " " beats per bar. */
if dur=='' | dur=='",'" then dur= 5 /*duration of the run in seconds. */
call time 'RReset' /*reset the REXX elapsed timer. */
bt=1/bpb /*calculate a tock-time interval. */
 
do until et>=dur; et=time('EElasped') /*process tick-tocks for the duration*/
say; call charout ,'TICK' /*show the first tick for the period. */
es=et+1 /*bump the elapsed time "limiter". */
ee$t=et+bt
do until time('E')e>=es; e=time('EElapsed')
if e<ee$t then iterate /*time for tock? */
call charout , ' tock' /*show a "tock". */
ee$t=ee$t+bt /*bump tockthe TOCK time.*/
end /*until time('E')≥es···*/
end /*until et≥duret···*/</lang>
/*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; when using the default inputs:
<per>
TICK tock tock tock tock
TICK tock tock tock tock
TICK tock tock tock tock
TICK tock tock tock tock
TICK tock tock tock tock
TICK tock tock tock tock
</langpre>
 
===with sound, REGINA only===
This REXX version &nbsp; ''only'' &nbsp; executes when using the Regina REXX interpreter.
<lang rexx>/*REXX program simulates a metronome (with sound),. Regina REXX only. */
parse arg bpm bpb dur tockf tockd tickf tickd . /*obtain optional arguments from the CL*/
if bpm=='' | bpm=='",'" then bpm= 72 /*the number of beats per minute. */
if bpb=='' | bpb=='",'" then bpb= 4 /*number of" " " " " beats per bar. */
if dur=='' | dur=='",'" then dur= 5 /*duration of the run in seconds. in secs*/
if tockf=='' | tockf=='",'" then tockf=400 /*frequency of " " tock sound in " HZ. */
if tockd=='' | tockd=='",'" then tockd= 20 /*duration of tock" " " " sound in" msec*/
if tickf=='' | tickf=='",'" then tickf=600 /*frequency of " " tick sound in " " HZ. */
if tickd=='' | tickd=='",'" then tickd= 10 /*duration of tick" " " " sound in" msec*/
call time 'RReset' /*reset the REXX elapsed timer. */
bt=1/bpb /*calculate a tock-time tock─time interval. */
 
do until et>=dur; et=time('EElasped') /*process tick-tocks for the duration*/
call beep tockf, tockd /*sound a beep for the "TOCK". */
es=et+1 /*bump the elapsed time "limiter". */
ee$t=et+bt
do until time('E')e>=es; e=time('EElapsed')
if e<ee$t then iterate /*time for tock? */
call beep tickf, tickd /*sound a "tick". */
ee$t=ee$t+bt /*bump tockthe TOCK time.*/
end /*until time('E')≥ese···*/
end /*until et≥duret···*/
/*stick a fork in it, we're all done. */</lang>
</lang>
 
===with sound, PC/REXX only===
<lang rexx>/*REXX program simulates a metronome (with sound),. PC/REXX only. or Personal REXX only.*/
parse arg bpm bpb dur tockf tockd tickf tickd . /*obtain optional arguments from the CL*/
if bpm=='' | bpm=='",'" then bpm= 72 /*the number of beats per minute. */
if bpb=='' | bpb=='",'" then bpb= 4 /*number of" " " " " beats per bar. */
if dur=='' | dur=='",'" then dur= 5 /*duration of the run in seconds. in secs*/
if tockf=='' | tockf=='",'" then tockf=400 /*frequency of " " tock sound in " HZ. */
if tockd=='' | tockd=='",'" then tockd= .02 /*duration of tock" sound in" secs " " " sec.*/
if tickf=='' | tickf=='",'" then tickf=600 /*frequency of " " tick sound in " " HZ. */
if tickd=='' | tickd=='",'" then tickd= .01 /*duration of tick" sound in" secs " " " sec.*/
call time 'RReset' /*reset the REXX elapsed timer. */
bt=1/bpb /*calculate a tock-time tock─time interval. */
 
do until et>=dur; et=time('EElasped') /*process tick-tocks for the duration*/
call sound tockf, tockd /*sound a beep for the "TOCK". */
es=et+1 /*bump the elapsed time "limiter". */
ee$t=et+bt
do until time('E')e>=es; e=time('EElapsed')
if e<ee$t then iterate /*time for tock? */
call sound tickf, tickd /*sound a tick. */
ee$t=ee$t+bt /*bump tockthe TOCK time.*/
end /*until time('E')≥es···*/
end /*until et≥duret···*/</lang>
/*stick a fork in it, we're all done. */</lang>
 
=={{header|Tcl}}==