xiluoc un pc pour les unirs .... | jai creer une classe qui joue de snotes a partir de ca :
Code :
- /*
- FILE : Mucic.h
- AUTHOR : coulix, TAGMC21 v0.3 12/07/03
- PURPOSE : An easy way to translate music sheets into computer-speaker output sounds.
-
- ENLISH NOTE SYSTEM EQUIVALENCE
- ------------------------------
- DO -> C DO#/REb -> C#/Db
- RE -> D RE#/MIb -> D#/Eb
- MI -> E FA#/SOLb-> F#/Gb
- FA -> F SOL#/LAb-> G#/Ab
- SOL-> G LA#/SIb -> A#/Bb
- LA -> A
- SI -> B
-
- ENGLISH RYTHMIC SYSTEM EQUIVALENCE
- ----------------------------------
- On hold
- */
- #ifndef MUSIC_BEEP_H
- #define MUSIC_BEEP_H
- class Music
- {
- public :
- enum sound_freq //link a frequencie to a note
- {oDO=16 ,oRE=18 ,oMI=20 ,oFA=22 ,oSOL=24 ,oLA=27 ,oSI=31,
- oDOd=17 ,oREd=20 ,oFAd=23 ,oSOLd=26 ,oLAd=29,
- IDO=33 ,IRE=37 ,IMI=41 ,IFA=44 ,ISOL=49 ,ILA=55 ,ISI=62,
- IDOd=35 ,IREd=39 ,IFAd=46 ,ISOLd=52 ,ILAd=58,
- IIDO=65 ,IIRE=73 ,IIMI=82 ,IIFA=87 ,IISOL=98 ,IILA=110 ,IISI=123,
- IIDOd=69 ,IIREd=78 ,IIFAd=92 ,IISOLd=104,IILAd=117,
- IIIDO=131 ,IIIRE=147 ,IIIMI=165 ,IIIFA=175 ,IIISOL=196 ,IIILA=220 ,IIISI=247,
- IIIDOd=139 ,IIIREd=156 ,IIIFAd=185 ,IIISOLd=208 ,IIILAd=233,
- IVDO=262 ,IVRE=294 ,IVMI=329 ,IVFA=349 ,IVSOL=392 ,IVLA=440 ,IVSI=494,
- IVDOd=277 ,IVREd=311 ,IVFAd=370 ,IVSOLd=415 ,IVLAd=466,
- VDO=523 ,VRE=587 ,VMI=659 ,VFA=698 ,VSOL=784 ,VLA=880 ,VSI=988,
- VDOd=554 ,VREd=622 ,VFAd=740 ,VSOLd=831 ,VLAd=932,
- VIDO=1046 ,VIRE=1175 ,VIMI=1319 ,VIFA=1397 ,VISOL=1568 ,VILA=1760 ,VISI=1976,
- VIDOd=1109 ,VIREd=1245 ,VIFAd=1480 ,VISOLd=1661 ,VILAd=1865,
- VIIDO=2094 ,VIIRE=2349 ,VIIMI=2637 ,VIIFA=2793 ,VIISOL=3135 ,VIILA=3520 ,VIISI=3951,
- VIIDOd=2217 ,VIIREd=2489 ,VIIFAd=2959 ,VIISOLd=3322 ,VIILAd=3729,
- VIIIDO=4186 ,VIIIRE=4698,
- VIIIDOd=4434 ,VIIIREd=4978,};
-
- enum type //lenght of a note
- {ronde=32, blanche_pointe=24 ,blanche=16, noire_pointe=12,
- noire=8, croche_pointe=6 , croche=4, triolet=3, demi_croche=2,
- quart_croche=1 };
-
- enum stop //lenght of a pause
- {soupir=8 , demi_soupir= 4, pause=32 , demi_pause = 16, quart_soupir=2};
-
- void assign_tempo(int x); //Assign tempo for one "noire" (60 =1s )
- void note(sound_freq freq,type lenght); //play the wanted note
- void silence(stop stp);
- void sample(int var); //loop sound sanple
-
- //small created music
-
- void winner();
- void intro ();
- void error();
-
- private :
- int tempo;
-
- };
- #endif
|
Code :
- #include "MUSIC_BEEP.h"
- #include <cstdlib>
- using namespace std;
- void Music::assign_tempo(int x)
- {
- tempo=x;
- }
- void Music::error()
- {
- assign_tempo(100);
- note(Music::IIIDO, Music::croche);
- note(Music::IIRE, Music::croche);
- }
- void Music::note(sound_freq freq,type lenght)
- {
- _beep(freq,(7500/tempo*lenght));
- }
- void Music::silence(stop stp)
- {
- _sleep((7500/tempo)*stp);
- }
-
- void Music::sample(int var)
- {
- for (int i=1; i <var; i++) {
- _beep((5000/i), i*10);}
- }
- void Music::winner()
- {
- assign_tempo(130);
- note(Music::VSOL, Music::croche_pointe);
- note(Music::VSOL, Music::demi_croche);
- note(Music::VSOL, Music::demi_croche);
- note(Music::VLA, Music::croche);
- note(Music::VSOL, Music::croche);
- note(Music::VLA, Music::croche);
- note(Music::VSI, Music::blanche);
- }
- void Music::intro()
- {
- assign_tempo(200);
- note(Music::IVSOL, Music::croche);
- note(Music::IIIRE, Music::croche);
- note(Music::IIISI, Music::croche);
- note(Music::IIISOL, Music::croche);
-
- }
|
|