diff --git a/musique/exercice.py b/musique/exercice.py index d10f6c30d313d38842026c9580d8d83d509f25fb..211833b168870ad2bdf4f357cf1f5f710b993168 100644 --- a/musique/exercice.py +++ b/musique/exercice.py @@ -179,16 +179,23 @@ class GenerateurExercice(GammeTemperee): # retourne un tableau des durées des notes possibles dans la partition - def tableauDurees(self, partitions): + def tableauDurees(self, partitions, beamer = False): result = "\n" - if not self.tableauSimplifie: - result += "Cette partition est proposée à une fréquence de " + str(self.bpm) + " noires par minute, ce qui donne les durées suivantes." - else: - result += "Les durées traits sur le graphique peuvent être traduites en durée musicale" + + if not beamer: + if not self.tableauSimplifie: + result += "Cette partition est proposée à une fréquence de " + str(self.bpm) + " noires par minute, ce qui donne les durées suivantes." + else: + result += "Les durées traits sur le graphique peuvent être traduites en durée musicale" ds = self.durees(partitions) - result += "\\begin{table}[H]\n\centering\n" + + + if beamer: + result += '\\resizebox{1\\textwidth}{!}{%\n' + else: + result += "\\begin{table}[H]\n\centering\n" result += "\\begin{tabular}{|l" + "".join(["|c" for d in ds ]) + "|}\n" result += "\\hline\n" @@ -201,7 +208,7 @@ class GenerateurExercice(GammeTemperee): result += "\\\\ \n" result += "\\hline\n" - if not self.tableauSimplifie: + if not self.tableauSimplifie and not beamer: result += "\\textbf{Longueur} (cm) " for duree in ds: result += "& " + '{0:.2f}'.format(self.dureeEnCm(duree)).replace(".", ",") @@ -222,8 +229,12 @@ class GenerateurExercice(GammeTemperee): result += "\\end{tabular}\n" - result += "\\caption{Table des durées}\n" - result += "\\end{table}\n" + if beamer: + result += "}\n" + else: + result += "\\caption{Table des durées}\n" + result += "\\end{table}\n" + return result @@ -233,6 +244,8 @@ class GenerateurExercice(GammeTemperee): # on ne va utiliser que la première partition partition = partitions[0] + self.setShiftOctave(partitions) + result = "\\renewcommand{\\arraystretch}{1.3}" result += "\\begin{table}[H]\n\centering\n" if len(partition) > 30: @@ -248,7 +261,19 @@ class GenerateurExercice(GammeTemperee): if isinstance(note[0], float): if note[0] > 0: result += self.frequenceToLaTeX(note[0], - self.minOctave, self.maxOctave) + "& " + self.nomDuree(note[1]) + " & \\\\\n" + self.minOctave, self.maxOctave) + "& " + self.nomDuree(note[1]) + " & " + + # ajout note graphique + result += "\\begin{tikzpicture}[]" + nid = self.shiftNote(self.getOctaveEtIDNote(note[0]), self.shiftOctave) + mw = self.boomwhackers[nid] + if len(partition) > 30: + result += self.pointColore(mw, 0, 0, 0.15) + else: + result += self.pointColore(mw, 0, 0, 0.2) + result += "\\end{tikzpicture}" + + result += " \\\\\n" result += "\\hline\n" else: result += " & " + self.nomDuree(note[1]) + " & \\\\\n" @@ -272,14 +297,19 @@ class GenerateurExercice(GammeTemperee): return result - def tableauFrequences(self, partitions): + def tableauFrequences(self, partitions, beamer = False): result = "" notes = self.getOctaveEtIDNoteDansIntervalle(self.minFrequence(partitions), self.maxFrequence(partitions)) - result += "Fréquences de chacune des notes utilisées sur la partition (arrondies à l'entier le plus proche):" - result += "\\begin{table}[H]\n\centering\n" + if not beamer: + result += "Fréquences de chacune des notes utilisées sur la partition (arrondies à l'entier le plus proche):" + + if beamer: + result += "{\\footnotesize\n \\begin{center}\n" + else: + result += "\\begin{table}[H]\n\\centering\n" result += "\\begin{tabular}{|c|c|}\n" result += "\\hline\n" result += "\\textbf{Fréquence} (Hz) & \\textbf{Note} \\\\ \n" @@ -291,11 +321,15 @@ class GenerateurExercice(GammeTemperee): result += "\\hline\n" result += "\\end{tabular}\n" - result += "\\caption{Table des fréquences de la gamme tempérée}\n" - result += "\\end{table}\n" + if not beamer: + result += "\\caption{Table des fréquences de la gamme tempérée}\n" + result += "\\end{table}\n" - if self.contientSilences(partitions): + if self.contientSilences(partitions) and not beamer: result += "Attention, la partition peut également contenir des silences, dont on peut mesurer la longueur, comme les notes" + + if beamer: + result += "\\end{center}}\n" return result # retourne la translation d'octave nécessaire pour jouer avec @@ -311,15 +345,11 @@ class GenerateurExercice(GammeTemperee): nN = self.shiftNote(note, shiftOctave) return nN in self.boomwhackers - def estDessinable(self, partitions): - if len(partitions) != 1: - print "La partition contient plusieurs mains." - return False - + def setShiftOctave(self, partitions): notes = [ self.getOctaveEtIDNote(p) for p in self.notesDansPartition(partitions) ] minNote = min(notes) - + self.shiftOctave = self.getTranslationOctaveBoomwhackers(minNote) if self.shiftOctave > 100: @@ -335,10 +365,18 @@ class GenerateurExercice(GammeTemperee): if not self.estJouable(n, self.shiftOctave): self.shiftOctave -= 1 break - - return True + + def estDessinable(self, partitions): + if len(partitions) != 1: + print "La partition contient plusieurs mains." + return False + + return self.setShiftOctave(partitions) + + + def couleurBoomwhackerToTikz(self, mw): return "\\definecolor{tempcolor}{rgb}{ "+ \ str(mw["couleur"][0] / 255.) + ", " + \ @@ -372,50 +410,52 @@ class GenerateurExercice(GammeTemperee): notesTotales = sorted(list(set(frequences))) - result += "\\begin{table}[H]\n\centering\n" + result += "\\begin{table}[H]\centering\n" if len(notesTotales) > 12: n = [ notesTotales[:12], notesTotales[12:] ] + else: + n = [notesTotales] - for notes in n: - result += '\\resizebox{1\\textwidth}{!}{%\n' - if not beamer: - result += "\\begin{tabular}{|r|" + "".join(["c|"] * len(notes)) + "}\n" - else: - result += "\\begin{tabular}{r|" + "".join(["c"] * len(notes)) + "}\n" - if not beamer: - result += "\\hline\n" - - result += "Notes" - for n in notes: - result += "&" - if beamer: - result += "\\hspace*{.2cm}" - result += self.frequenceToLaTeX(n, self.minOctave, self.maxOctave) - if beamer: - result += "\\hspace*{.2cm}" - result += "\\\\ \n" - result += "Forme" + for notes in n: + result += '\\resizebox{1\\textwidth}{!}{%\n' + if not beamer: + result += "\\begin{tabular}{|r|" + "".join(["c|"] * len(notes)) + "}\n" + else: + result += "\\begin{tabular}{r|" + "".join(["c"] * len(notes)) + "}\n" + if not beamer: + result += "\\hline\n" + + result += "Notes" + for n in notes: + result += "&" + if beamer: + result += "\\hspace*{.2cm}" + result += self.frequenceToLaTeX(n, self.minOctave, self.maxOctave) + if beamer: + result += "\\hspace*{.2cm}" + result += "\\\\ \n" + result += "Forme" + for n in notes: + result += "&" + result += "\\begin{tikzpicture}[]" + nid = self.shiftNote(self.getOctaveEtIDNote(n), self.shiftOctave) + mw = self.boomwhackers[nid] + result += self.pointColore(mw, 0, 0, radius) + + result += "\\end{tikzpicture}" + result += "\\\\ \n" + if not beamer: + result += "Prénom" for n in notes: result += "&" - result += "\\begin{tikzpicture}[]" - nid = self.shiftNote(self.getOctaveEtIDNote(n), self.shiftOctave) - mw = self.boomwhackers[nid] - result += self.pointColore(mw, 0, 0, radius) - - result += "\\end{tikzpicture}" + result += "\\hspace*{2cm}" result += "\\\\ \n" - if not beamer: - result += "Prénom" - for n in notes: - result += "&" - result += "\\hspace*{2cm}" - result += "\\\\ \n" - if not beamer: - result += "\\hline\n" - result += "\\end{tabular}\n" - result += "}\n" - result += " \\newline \n \\ \n" + if not beamer: + result += "\\hline\n" + result += "\\end{tabular}\n" + result += "}\n" + #result += " \\newline \n" result += "\\caption{Représentation colorée des notes}\n" result += "\\end{table}\n" @@ -428,7 +468,7 @@ class GenerateurExercice(GammeTemperee): if beamer: result += "\\frame{" - result += "\\frametitle{Représentation graphique}" + result += "\\frametitle{Représentation graphique}\n" frequences = self.notesDansPartition(partitions) @@ -458,9 +498,9 @@ class GenerateurExercice(GammeTemperee): if beamer: result += self.ensembleDesNotesGraphiques(frequences, radius, beamer) - result += "}" - result += "\\frame{" - result += "\\frametitle{Représentation graphique}" + result += "}\n" + result += "\\frame{\n" + result += "\\frametitle{Représentation graphique}\n" result += self.ensembleDesNotesGraphiques(frequences, radius, beamer) @@ -497,7 +537,7 @@ class GenerateurExercice(GammeTemperee): result += "Cette partition n'est pas représentable sous forme de partition pour boomwhackers diatoniques." if beamer: - result += "}" + result += "}\n" return result def partitionMusicale(self, partitions, beamer = False): @@ -539,7 +579,7 @@ class GenerateurExercice(GammeTemperee): if note[0] != 0: result += self.dureeToMusicTex(note[1]) + "{" result += self.frequenceToMusicTeX(note[0], midOctave) - result += "}" + result += "}\n" longueurCourante += note[1] else: # TODO @@ -561,7 +601,7 @@ class GenerateurExercice(GammeTemperee): result += "Le générateur d'exercice ne prend pas en charge cette partition." if beamer: - result += "}" + result += "}\n" return result @@ -783,7 +823,7 @@ class GenerateurExercice(GammeTemperee): result += "\\end{tikzpicture}" if beamer: - result += "}" + result += "}\n" return result @@ -853,15 +893,24 @@ class GenerateurExercice(GammeTemperee): l_fichier.write(self.spectrogramme(partitions, True)) + l_fichier.write("\\frame{\n") + l_fichier.write("\\frametitle{Durées et notes}\n") + # on écrit le tableau de durées + l_fichier.write(self.tableauDurees(partitions, True)) + # on écrit le tableau des fréquences + l_fichier.write(self.tableauFrequences(partitions, True)) + l_fichier.write("}\n") + + l_fichier.write(self.partitionGraphique(partitions, True)) l_fichier.write(self.partitionMusicale(partitions, True)) if nomSolution != "": - result = "\\frame{" + result = "\\frame{\n" result += "\\frametitle{Solution}\n" result += "\\begin{center}\Large Cette mélodie s'appelle " + nomSolution + "\\end{center}" - result += "}" + result += "}\n" l_fichier.write(result)