SHOW:
|
|
- or go back to the newest paste.
1 | % Alexandre JADIN - Frederic KACZYNSKI | |
2 | % ----------- | |
3 | % Version 2.0.0.0.1-prealpha-b10056 pa | |
4 | ||
5 | - | local Mix Interprete Projet CWD ToNote ToDuree Bourdon Etirer Duree Transpose in |
5 | + | local Mix Interprete Projet CWD ToNote ToDuree Bourdon Etirer Duree Transpose GetH in |
6 | % CWD contient le chemin complet vers le dossier contenant le fichier 'code.oz' | |
7 | % modifiez sa valeur pour correspondre à votre système. | |
8 | CWD = {Property.condGet 'testcwd' '/home/justice/Documents/Projet2014/'} | |
9 | ||
10 | % Si vous utilisez Mozart 1.4, remplacez la ligne précédente par celle-ci : | |
11 | % [Projet] = {Link ['Projet2014_mozart1.4.ozf']} | |
12 | % | |
13 | % Projet fournit quatre fonctions : | |
14 | % {Projet.run Interprete Mix Music 'out.wav'} = ok OR error(...) | |
15 | % {Projet.readFile FileName} = AudioVector OR error(...) | |
16 | % {Projet.writeFile FileName AudioVector} = ok OR error(...) | |
17 | % {Projet.load 'music_file.dj.oz'} = La valeur oz contenue dans le fichier chargé (normalement une <musique>). | |
18 | % | |
19 | % et une constante : | |
20 | % Projet.hz = 44100, la fréquence d'échantilonnage (nombre de données par seconde) | |
21 | [Projet] = {Link [CWD#'Projet2014_mozart2.ozf']} | |
22 | ||
23 | local | |
24 | Audio = {Projet.readFile CWD#'wave/animaux/cow.wav'} | |
25 | in | |
26 | % Mix prends une musique et doit retourner un vecteur audio. | |
27 | fun {Mix Interprete Music} | |
28 | local Result in | |
29 | Result = {Interprete Music.1.1} | |
30 | ||
31 | {Browse Result} | |
32 | Audio | |
33 | end | |
34 | end % fun | |
35 | ||
36 | ||
37 | fun{GetH Note} | |
38 | H=0 in | |
39 | case Note of note(nom:Nom octave:Octave alteration:none) then | |
40 | case Nom of a then H=0 | |
41 | [] b then H=2 | |
42 | [] c then H=~8 | |
43 | [] d then H=~6 | |
44 | [] e then H=~4 | |
45 | [] f then H=~3 | |
46 | [] g then H=~2 | |
47 | end | |
48 | []note(nom:Nom octave:Octave alteration:'# ') then | |
49 | case Nom of c then H=~7 | |
50 | [] d then H=~5 | |
51 | [] f then H=~3 | |
52 | [] g then H=~1 | |
53 | [] a then H=1 | |
54 | end | |
55 | end %case | |
56 | H+48-12*Octave | |
57 | end %fun | |
58 | ||
59 | fun {Bourdon ListEchants Note} | |
60 | case ListEchants | |
61 | of echantillon(hauteur:Hauteur duree:Duree instrument:Instrument)|T then | |
62 | case Note | |
63 | of silence then | |
64 | silence(duree:Duree)|{Bourdon T Note} | |
65 | else | |
66 | % TODO Appliquer ToHauteur à Note | |
67 | echantillon(hauteur:Hauteur-2 duree:Duree instrument:Instrument)|{Bourdon T Note} | |
68 | end | |
69 | [] silence(duree:Duree)|T then | |
70 | silence(duree:Duree)|{Bourdon T Note} | |
71 | [] nil then | |
72 | nil | |
73 | end | |
74 | end | |
75 | ||
76 | fun {Etirer L Facteur} | |
77 | case L | |
78 | of echantillon(hauteur:Hauteur duree:Duree instrument:Instrument)|T then | |
79 | echantillon(hauteur:Hauteur duree:(Duree*Facteur) instrument:Instrument)|{Etirer T Facteur} | |
80 | [] silence(duree:Duree)|T then | |
81 | silence(duree:(Duree*Facteur))|{Etirer T Facteur} | |
82 | [] nil then | |
83 | nil | |
84 | end % case | |
85 | end % fun | |
86 | ||
87 | fun {Duree L Secondes DureeTotale} | |
88 | case L of echantillon(hauteur:Hauteur duree:DureeEchant instrument:Instrument)|T then | |
89 | echantillon(hauteur:Hauteur duree:(DureeEchant*Secondes/DureeTotale) instrument:Instrument)|{Duree T Secondes DureeTotale} | |
90 | [] nil then | |
91 | nil | |
92 | [] silence(duree:DureeSilence)|T then | |
93 | silence(duree:(DureeSilence*Secondes/DureeTotale))|{Duree T Secondes DureeTotale} | |
94 | [] E then | |
95 | {Duree [E] Secondes DureeTotale} % TODO | |
96 | end | |
97 | end | |
98 | ||
99 | fun {ToNote Note} | |
100 | case Note | |
101 | of Nom#Octave then | |
102 | note(nom:Nom octave:Octave alteration:'# ') | |
103 | [] Atom then | |
104 | case {AtomToString Atom} | |
105 | of [ N ] then | |
106 | note(nom:Atom octave:4 alteration:none) | |
107 | [] [N O] then | |
108 | note(nom:{StringToAtom [N]} octave:{StringToInt [O]} alteration:none) | |
109 | end | |
110 | end | |
111 | end | |
112 | ||
113 | fun{ToDuree EchList} | |
114 | local ToDuree2 in | |
115 | fun{ToDuree2 EchantList Acc} | |
116 | case EchantList of H|T then | |
117 | Acc=Acc+H.duree | |
118 | {ToDuree T} | |
119 | [] nil then | |
120 | Acc | |
121 | end %case | |
122 | end %fun | |
123 | {ToDuree2 EchList 0} | |
124 | end %local | |
125 | end %fun | |
126 | ||
127 | fun{Transpose EchList DemiTons} | |
128 | case EchList | |
129 | of echantillon(hauteur:Hauteur duree:Duree instrument:Instrument)|T then | |
130 | echantillon(hauteur:Hauteur+DemiTons duree:Duree instrument:Instrument)|{Transpose T DemiTons} | |
131 | [] silence(duree:Duree)|T then | |
132 | silence(duree:Duree)|{Transpose T DemiTons} | |
133 | [] nil then | |
134 | nil | |
135 | end | |
136 | end | |
137 | ||
138 | ||
139 | ||
140 | % Interprete doit interpréter une partition | |
141 | fun {Interprete Partition} | |
142 | case Partition | |
143 | of H|T then | |
144 | {Append {Interprete H} {Interprete T}} | |
145 | [] etirer(1:PartitionIn facteur:Facteur) then | |
146 | {Etirer {Interprete PartitionIn} Facteur} | |
147 | [] muet(1:PartitionIn) then | |
148 | {Bourdon {Interprete PartitionIn} silence} | |
149 | [] duree(1:PartitionIn secondes:Secondes) then | |
150 | local | |
151 | ListEchants = {Interprete PartitionIn} | |
152 | DureeTotale = {ToDuree ListEchants} | |
153 | in | |
154 | {Duree ListEchants Secondes DureeTotale} | |
155 | end | |
156 | [] bourdon(1:PartitionIn note:Note) then | |
157 | {Bourdon {Interprete PartitionIn} Note} | |
158 | [] transpose(1:PartitionIn demitons:Demitons) then | |
159 | {Transpose {Interprete PartitionIn} Demitons} | |
160 | [] nil then | |
161 | nil | |
162 | [] E then | |
163 | % TODO Appliquer ToHauteur | |
164 | [echantillon(hauteur:{ToNote E} duree:1.0 instrument: none)] | |
165 | end % case | |
166 | end % fun | |
167 | ||
168 | local | |
169 | Music = {Projet.load CWD#'joie.dj.oz'} | |
170 | in | |
171 | % Votre code DOIT appeler Projet.run UNE SEULE fois. Lors de cet appel, | |
172 | % vous devez mixer une musique qui démontre les fonctionalités de votre | |
173 | % programme. | |
174 | % | |
175 | % Si votre code devait ne pas passer nos tests, cet exemple serait le | |
176 | % seul qui ateste de la validité de votre implémentation. | |
177 | {Browse {Projet.run Mix Interprete Music CWD#'out.wav'}} | |
178 | end | |
179 | end | |
180 | end |