sklflsjflksjdf sklflsjflksjdf
关注数: 15 粉丝数: 55 发帖数: 1,029 关注贴吧数: 28
wxWidgets使用技巧(二)——直接载入将文件编入exe程序 本方法理论上也适用于其他的C和C++程序 对于windows资源文件中的 图标、位图和对话框,按照wxWidgets和技巧一中的问题已经解决,这里介绍如何直接将一个文件编写进入exe。 其实方法就是将文件转换成char数组。 举个例子,比如一个小程序,你要使用word,你可以使用3种方法: 1、先调用word,然后用代码调用com在word中生成想要的格式,很麻烦,不建议使用 2、先做好一个word模板,定义书签,然后调用com,替换书签内容,这种比较方便,而且实现了视图和数据、模型的分离,但是由于word版本的问题,可能出现不兼容。 3、使用rtf。做一个word文件,定义好标志词组,比如$(var)保,存成rtf格式。由于rtf是文本格式,直接使用txt的读取方式或者直接编译进exe中。这就涉及到了资源文件中的自定义。 我说一下第3种,很简单,把rtf转换成 static char 数组,然后变成头文件,使用wxString.FromUTF8转化为字符串,替换掉标志词组,写入文件。 这只是一个思路,如果你能解决文件格式的读取问题,你可以随意定义文件的数组格式。 对于文本类这种方法很好用。具体到生成 static char 数组,我使用的 python ,也可以使用其他的方法。 with open("dddd.txt",'rb') as file: temp=[] ch=file.read(1) while len(ch)!=0: temp+=ch ch=file.read(1) with open('test.txt','w') as file: file.write(str(temp)) 很简单。 分享一下,如果还有好办法请告诉我。
MATLAB演奏国歌,除乐理知识基本抛弃卡农代码,未参照前国歌.... 最近很无聊,想起卡农代码,很是佩服,原卡农代码为小提琴三重奏,本人音乐修养不行,做不出来,在此感谢卡农大神代码的启发指点,并无多少相同 本帖第一部分为思路,第二部分为代码,第三部分为失败了的自动筛选代码,为省内存基本都是single数据 思路:先建立三个库矩阵,分别为标准音符、连音符、附点音符的89*8矩阵,sound1,、sound0_6,sound1.5,行表示钢琴的88键+空音键,列为全音符,2分符,4分符,8分符,16分符,32,64,128分符,理论上可扩展。按此思路可以囊括所有曲目。本希望抛弃单个取值赋变量的方法,奈何识别程序有问题,我也没找出来哪里出错了,所以后面又是手动赋值。切记可以实现自动筛选匹配音符的功能 %沈阳化工大学 %马红越 %不留联系方式了,太乱 %matlab版本2012b fs=single(44100);%采样频率 dt=single(1/fs); %速度 temp=90;%拍速 %四分符为基准,一拍时值 t4=60/temp; t1=4*t4; t2=2*t4; t8=0.5*t4; t16=0.25*t4; t32=0.125*t4; t64=t32/2; t128=t64/2; t=single([t1,t2,t4,t8,t16,t32,t64,t128]); clear t1 t2 t4 t8 t16 t32 t64 t128; %调幅函数 t1_5=t*1.5; t0_6=t*2/3; for j=1:length(t) %标准音 temp=single(0:dt:t(j)); mod1{j}=single(sin(pi*temp/temp(end)));%标准音调幅函数 T1{j}=temp;%T1为标准音时值矩阵, %1个点的附点长音 temp=single(0:dt:t1_5(j)); mod1_5{j}=single(sin(pi*temp/temp(end)));%附点音调幅函数 T1_5{j}=temp;%附点音时值 %三连音 temp=single(0:dt:t0_6(j)); mod0_6{j}=single(sin(pi*temp/temp(end)));%标准音调幅函数 T0_6{j}=temp;%T1为标准音时值矩阵, %两个点 %t=t*1.5*1.5; %for j=1:length(t); % tem1=0:dt:t(j); % k=length(tem1); % mod1_25{j}=[mod256(temp),ones(1,k-i),mod256(tem)];%附点音调幅函数 % T1_25{j}=tem1;%附点音时值 end clear dt t0_6 t1_5 t %以A为基准,f=440hz %中央区 c=261.63; cp=277.18;ds=cp; d=293.66; dp=311.13;es=dp; e=329.63; f=349.23; fp=369.99;gs=fp; g=392.00; gp=415.30;as=gp; a=440.00; ap=466.16;bs=ap; b=493.88; center4=single([c,cp,d,dp,e,f,fp,g,gp,a,ap,b]); clear c cp ds d dp es e f fp gs g gp as a ap bs b %全部音区,%88键 keys=center4; for i=1:4 temp=center4/2^i; tem=center4*2^i; if i==4 temp(1:9)=[]; tem(2:end)=[]; end keys=[temp,keys,tem]; end clear center4 %国歌 1=G 2/4拍 %标准音长 for j=1:length(T1) temp=cos(2*pi*keys'*T1{j}); temp(89,:)=single(0);%休止符 for i=1:89 sound1{i,j}=single(mod1{j}.*temp(i,:)); end %cell sound1中j=1-8为 全音符,2分符,4分符,8分符,16分符,32分符,64分符,128分符 %i=1-88个音符 temp=cos(2*pi*keys'*T1_5{j}); temp(89,:)=single(0);%休止符 for i=1:89 sound1_5{i,j}=single(mod1_5{j}.*temp(i,:)); end %cell sound1_5中j为 1附点的 全音符,2分符,4分符,8分符,16分符,32分符,64分符,128分符 %i=1-88个音符 temp=cos(2*pi*keys'*T0_6{j}); temp(89,:)=single(0);%休止符 for i=1:89 sound0_6{i,j}=single(mod0_6{j}.*temp(i,:)); end %cell sound0_6中为三连音的 全音符,2分符,4分符,8分符,16分符,32分符,64分符,128分符 %i=1-88个音符 end clear i j k temp tem T1_5 T1 T0_6 keys do1_5f8=sound1_5{47,4}; mi1f16=sound1{51,5}; so1f8=sound1{54,4}; section1=[do1_5f8,mi1f16,so1f8,so1f8]; la1f4=sound1{56,3}; so1f4=sound1{54,3}; section2=[la1f4,so1f4]; mi1_5f8=sound1_5{51,4}; do1f16=sound1{47,5}; so0_6f8=sound0_6{54,4}; section3=[mi1_5f8,do1f16,so0_6f8,so0_6f8,so0_6f8]; mi1f4=sound1{51,3}; do1f4=sound1{47,3}; section4=[mi1f4,do1f4]; so0_6f8d=sound0_6{42,4}; section5=[so0_6f8d,so0_6f8d,so0_6f8d,so0_6f8d,so0_6f8d,so0_6f8d]; section=[section1,section2,section3,section4,section5]; clear section1 section2 section3 section4 section5 emf8=sound1{89,4}; so1f8d=sound1{42,4}; section6=[do1f4,emf8,so1f8d]; do1_5f4=sound1_5{47,3}; do1f8=sound1{47,4}; section7=[do1_5f4,do1f8]; la1f16d=sound1{44,5}; ti1f16d=sound1{46,5}; section8=[do1_5f8,do1f16,so1f8d,la1f16d,ti1f16d]; section9=[do1f4,do1f4]; mi1f8=sound1{51,4}; re1f16=sound1{49,5}; section10=[emf8,mi1f8,do1f8,re1f16,mi1f16]; section=[section,section6,section7,section8,section9,section10]; clear section6 section7 section8 section9 section10 section11=[so1f4,so1f4]; section12=[mi1_5f8,mi1f16,do1_5f8,mi1f16]; so1_5f8=sound1_5{54,4}; re1f4=sound1{49,3}; section13=[so1_5f8,mi1f16,re1f4]; re1f2=sound1{49,2}; section14=re1f2; section15=[la1f4,so1f4]; section=[section,section11,section12,section13,section14,section15]; clear section11 section12 section13 section14 section15 section16=[re1f4,mi1f4]; section17=[so1f8,mi1f8,emf8,so1f8]; section18=[mi1f8,re1f16,mi1f16,do1f4]; emf4=sound1{89,3}; section19=[mi1f4,emf4]; so1_5f8d=sound1_5{42,4}; section20=[so1_5f8d,la1f16d,do1f8,do1f8]; section=[section,section16,section17,section18,section19,section20]; clear section16 section17 section18 section19 section20 section21=[mi1_5f8,mi1f16,so1f8,so1f8]; re1f8=sound1{49,4}; la1f4d=sound1{44,3}; section22=[re1f8,re1f16,re1f16,la1f4d]; re1_5f4=sound1_5{49,3}; section23=[re1_5f4,so1f8d]; section24=[do1_5f4,do1f8]; mi1_5f4=sound1_5{51,3}; section25=[mi1_5f4,mi1f8]; section=[section,section21,section22,section23,section24,section25]; clear section21 section22 section23 section24 section25 so1f2=sound1{54,2}; section26=so1f2; section27=[do1_5f8,mi1f16,so1f8,so1f8]; section28=[la1f4,so1f4]; section29=[mi1_5f8,do1f16,so0_6f8,so0_6f8,so0_6f8]; section30=[mi1f8,emf8,do1f8,emf8]; section=[section,section26,section27,section28,section29,section30]; clear section26 section27 section28 section29 section30 sof4d=sound1{42,3}; section31=[sof4d,do1f4]; section32=[mi1_5f8,do1f16,so0_6f8,so0_6f8,so0_6f8]; section33=[mi1f8,emf8,do1f8,emf8]; section34=[sof4d,do1f4]; section35=[sof4d,do1f4]; section36=[sof4d,do1f4]; section37=[do1f4,emf4]; section=[section,section31,section32,section33,... section34,section35,section36,section37]; clear section31 section32 section33 section34 section35 section36 section37 sound(section,fs);
1 下一页