Anonymous user
Musical scale: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, use a better format of alternating literal strings.
m (→{{header|REXX}}: added/changed whitespace and comments, use a better format of alternating literal strings.) |
|||
Line 733:
{{works with|Personal REXX}}
{{works with|Regina}}
<lang rexx>/*REXX program sounds eight notes of the C major natural diatonic music scale.
parse arg ! /*obtain optional arguments from the CL*/
/* [↓] invoke boilerplate REXX code. */
if !all( arg() ) then exit /*determine which REXX is running, if */
/* any form of help requested, exit.*/
if \!regina & \!pcrexx then do
say "***error*** this program can't execute under:" !ver
exit 13
end
$ = 'do ra me fa so la te do' /*the words for music scale sounding. */
dur = 1/4 /*define duration as a quarter second. */
do j=1 for words($) /*sound each "note" in the string. */
call notes word($, j),
end /*j*/ /* [↑] sound each of the words. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
notes: procedure expose !regina !pcrexx; arg note,dur /*obtain the arguments from list. */
@.=
@.la= 220; @.si= 246.94; @.te= @.si; @.ta= @.te; @.ti= @.te
@.do= 261.6256; @.ut= @.do; @.re= 293.66; @.ra= @.re; @.mi= 329.63
@.ma= @.mi; @.fa= 349.23; @.so= 392; @.sol= @.so
if @.note==0 then return /*if frequency is zero, skip it. */
if !pcrexx then call sound @.note,dur
if !regina then do
ms= format(dur*1000, , 0)
intN= format(@.note, , 0)
call beep intN,
end
return
/*─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
!all: !!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1
!cal: if symbol('!CALL')\=="VAR" then !call=; return !call
!env: !env= 'ENVIRONMENT'; if !sys==
!fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .; call !sys; if !dos then do; _= lastpos('\',!fn); !fm= left(!fn,_); !fn= substr(!fn,_+1); parse var !fn !fn
!rex: parse upper version !ver !vernum !verdate .; !brexx= 'BY'==!vernum;
!sys: !cms= !sys=='CMS'; !os2= !sys==
!var: call !fid; if !kexx then return space( dosenv( arg(1) ) ); return space( value( arg(1), , !env) )</lang>
Programming note:
|