%let pc=0.75;/*调节曲速,越小越快*/
%macro df3(note,octave,length);
select(¬e);
when("A") call sound(55*(2**&octave.),&length.*160*&pc.);
when("A#") call sound(58*(2**&octave.),&length.*160*&pc.);
when("Bb") call sound(58*(2**&octave.),&length.*160*&pc.);
when("B") call sound(62*(2**&octave.),&length.*160*&pc.);
when("C") call sound(65*(2**&octave.),&length.*160*&pc.);
when("C#") call sound(69*(2**&octave.),&length.*160*&pc.);
when("Db") call sound(69*(2**&octave.),&length.*160*&pc.);
when("D") call sound(73.5*(2**&octave.),&length.*160*&pc.);
when("D#") call sound(73.5*(2**&octave.),&length.*160*&pc.);
when("Eb") call sound(78*(2**&octave.),&length.*160*&pc.);
when("E") call sound(82*(2**&octave.),&length.*160*&pc.);
when("F") call sound(87*(2**&octave.),&length.*160*&pc.);
when("F#") call sound(92.5*(2**&octave.),&length.*160*&pc.);
when("Gb") call sound(92.5*(2**&octave.),&length.*160*&pc.);
when("G") call sound(98*(2**&octave.),&length.*160*&pc.);
when("G#") call sound(104*(2**&octave.),&length.*160*&pc.);
when("Ab") call sound(104*(2**&octave.),&length.*160*&pc.);
when("R") call sleep((&length./3)*&pc.,1);
otherwise;
end;
%mend;
/*创建简谱*/
data jianpu;
input x $ @@;/*输入简谱,半拍为单位,-为下面加点,+为上面加点,可以加多个点*/
note=translate(compress(x,,'kd'),'CDEFGABR','12345670');
octave=3;
octave=octave+(note in ('A','B'))+count(compress(x,,'d'),'+')-count(compress(x,,'d'),'-');
cards;
5 6 5 4 3 2 1 1 1 5- 5- 5- 1 3 1+ 7 6 3 5 5 5 5 5 5
6 7 6 5 4 3 2 2 2 6- 6- 6- 7- 6- 5- 5 1 2 3 3 3 3 3 3
5 6 5 4 3 2 1 1 1 5- 5- 5- 1 3 1+ 7 2+ 1+ 6 6 6 6 6 6
1+ 7 6 5 5 5 6 5 4 3 3 3 7- 6- 5- 2 2 2 1 1 1 1 1 1
1+ 2+ 3+ 2+ 1+ 6 7 6 3 5 5 5 5 5 5 1+ 2+ 3+ 2+ 1+ 6
7 5 3 6 6 6 6 6 6 5 4 3 2 2 2 7- 6- 5- 3 3 3 4 4 4 2 2 1 1 1 1 1 1 0
1+ 2+ 3+ 2+ 1+ 6 7 6 3 5 5 5 1+ 2+ 3+ 2+ 1+ 6 7 5 3 6 6 6
5 4 3 2 2 2 7 6 5 3 3 3 5 5 5 2+ 2+ 1+ 1+ 1+ 1+ 1+ 1+ 1+
;
run;
/*创建宏变量¬e.和&octave.用于存储简谱中所有的note和对应的octave*/
proc sql noprint;
select note, octave into : note separated by '*', : octave separated by '*'
from jianpu;
quit;
/*播放*/
proc printto log=_null_;run;
%macro music;
data want;
call execute('data _null_;');
%do i=1 %to %sysfunc(countw(¬e,'*'));
%df3("%scan(¬e,&i,'*')",%scan(&octave,&i,'*'),1);
%end;
call execute('run;');
run;
%mend;
%music
proc printto log=log;run;