From f890332656201a3482990ff86b5122173d4b748d Mon Sep 17 00:00:00 2001
From: Jean-Marie Favreau <jm.trivial@gmail.com>
Date: Mon, 21 Jan 2019 12:36:51 +0100
Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20de=20prise=20en=20charge=20des=20p?=
=?UTF-8?q?artitions=20graphiques?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
musique/exercice.py | 37 ++++++++++++++++++++++++++++++++++++-
musique/gamme.py | 16 ++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/musique/exercice.py b/musique/exercice.py
index 9ce1cf8..3ab4079 100644
--- a/musique/exercice.py
+++ b/musique/exercice.py
@@ -233,6 +233,39 @@ class GenerateurExercice(GammeTemperee):
result += "\\end{table}\n"
return result
+
+ def estDessinable(self, partitions):
+ if len(partitions) != 1:
+ print "plus d'une partition"
+ return False
+ if self.contientNoteAlteree(partitions):
+ print "note alteree"
+ return False
+
+ notes = [ self.getOctaveEtIDNote(p) for p in self.notesDansPartition(partitions) ]
+
+ minNote = min(notes)
+ maxNote = max(notes)
+
+ print notes
+ # si les notes sont dans une même gamme
+ # ou qu'elles sont sur deux gammes, avec le do dans la gamme suivante
+ return minNote[0] == maxNote[0] or (minNote[0] == maxNote[0] + 1 and maxNote[1] == 0)
+
+
+ def partitionGraphique(self, partitions):
+ result = ""
+
+ frequences = self.notesDansPartition(partitions)
+
+ if self.estDessinable(partitions):
+ p = partitions[0]
+ # TODO
+ result += "On peut la dessiner."
+ else:
+ result += "Cette partition n'est pas représentable sous forme de partition pour boomwhackers diatoniques."
+
+ return result
# cette fonction écrit la fin de l'exercice spectrogramme
def finExerciceSpectrogramme(self, partitions):
@@ -261,6 +294,9 @@ class GenerateurExercice(GammeTemperee):
# on écrit le tableau solution de l'exercice
result += self.tableauNotesBrutes(partitions, True)
+ result += "\\section{Partition graphique}\n"
+ # on écrit le tableau solution de l'exercice
+ result += self.partitionGraphique(partitions)
return result
@@ -288,7 +324,6 @@ class GenerateurExercice(GammeTemperee):
# à l'horodatage donné
def accordSpectrogrammePartition(self, accord, horodatage, couleur):
if isinstance(accord[0], float):
- print "duree", accord[1], self.nomDuree(accord[1])
return self.noteSpectrogrammePartition(accord[0], accord[1], horodatage, couleur)
else:
return ''.join([self.noteSpectrogrammePartition(note, accord[1], horodatage, couleur) for note in accord[0]])
diff --git a/musique/gamme.py b/musique/gamme.py
index 0681876..56938b7 100644
--- a/musique/gamme.py
+++ b/musique/gamme.py
@@ -125,6 +125,22 @@ class GammeTemperee:
l = [[ x for x in [note[0] if isinstance(note[0], float) else note[0] for note in partition] if x != 0.] for partition in partitions]
return list(set([ j for i in l for j in i ]))
+
+ def isNoteAlteree(self, frequence):
+ (o, i) = self.getOctaveEtIDNote(frequence)
+ return i in [ 1, 3, 6, 8, 10 ]
+
+ def contientNoteAlteree(self, partitions):
+ for partition in partitions:
+ for note in partition:
+ if isinstance(note[0], float):
+ if self.isNoteAlteree(note[0]):
+ return True
+ else:
+ for n in note:
+ if self.isNoteAlteree(n[0]):
+ return True
+ return False
# retourne la fréquence minimum utilisée dans les partitions
def minFrequence(self, partitions):
--
GitLab