From e3720758f1d5621c9b331044458d73fbdad86f53 Mon Sep 17 00:00:00 2001
From: Jean-Marie Favreau <jm.trivial@gmail.com>
Date: Tue, 29 Jan 2019 10:40:52 +0100
Subject: [PATCH] =?UTF-8?q?Suite=20d=C3=A9veloppement=20exercices=20(WIP)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 boomwhackers-8.json | 10 +++++++++
 happybirthday.py    | 49 +++++++++++++++++++++++----------------------
 musique/exercice.py | 13 +++++++-----
 musique/gamme.py    |  2 +-
 4 files changed, 44 insertions(+), 30 deletions(-)
 create mode 100644 boomwhackers-8.json

diff --git a/boomwhackers-8.json b/boomwhackers-8.json
new file mode 100644
index 0000000..475c890
--- /dev/null
+++ b/boomwhackers-8.json
@@ -0,0 +1,10 @@
+{
+  "do1": { "couleur": "#a73824", "capsule": "0" },
+  "re1": { "couleur": "#c56528", "capsule": "0" },
+  "mi1": { "couleur": "#f4e236", "capsule": "0" },
+  "fa1": { "couleur": "#f4e236", "capsule": "0" },
+  "sol1": { "couleur": "#27476d", "capsule": "0" },
+  "la1": { "couleur": "#413a88", "capsule": "0" },
+  "si1": { "couleur": "#682174", "capsule": "0" },
+  "do2": { "couleur": "#9c3922", "capsule": "0" }
+}
diff --git a/happybirthday.py b/happybirthday.py
index e99fc46..62e3513 100755
--- a/happybirthday.py
+++ b/happybirthday.py
@@ -16,32 +16,33 @@ gamme = GammeTemperee(117)
 
 
 happy = [ [ [gamme.do(4), gamme.crochepointee],
-[gamme.do(4), gamme.doublecroche],
-[gamme.re(4), gamme.noire],
-[gamme.do(4), gamme.noire],
-[gamme.fa(4), gamme.noire],
-[gamme.mi(4), gamme.blanche],
-[gamme.do(4), gamme.crochepointee],
-[gamme.do(4), gamme.doublecroche],
-[gamme.re(4), gamme.noire],
-[gamme.do(4), gamme.noire],
-[gamme.sol(4), gamme.noire],
-[gamme.fa(4), gamme.blanche],
-[gamme.do(4), gamme.crochepointee],
-[gamme.do(4), gamme.doublecroche],
-[gamme.do(5), gamme.noire],
-[gamme.la(4), gamme.noire],
-[gamme.fa(4), gamme.noire],
-[gamme.mi(4), gamme.noire],
-[gamme.re(4), gamme.noire],
-[gamme.sib(4), gamme.crochepointee],
-[gamme.sib(4), gamme.doublecroche],
-[gamme.la(4), gamme.noire],
-[gamme.fa(4), gamme.noire],
-[gamme.sol(4), gamme.noire],
-[gamme.fa(4), gamme.blanchepointee]
+            [gamme.do(4), gamme.doublecroche],
+            [gamme.re(4), gamme.noire],
+            [gamme.do(4), gamme.noire],
+            [gamme.fa(4), gamme.noire],
+            [gamme.mi(4), gamme.blanche],
+            [gamme.do(4), gamme.crochepointee],
+            [gamme.do(4), gamme.doublecroche],
+            [gamme.re(4), gamme.noire],
+            [gamme.do(4), gamme.noire],
+            [gamme.sol(4), gamme.noire],
+            [gamme.fa(4), gamme.blanche],
+            [gamme.do(4), gamme.crochepointee],
+            [gamme.do(4), gamme.doublecroche],
+            [gamme.do(5), gamme.noire],
+            [gamme.la(4), gamme.noire],
+            [gamme.fa(4), gamme.noire],
+            [gamme.mi(4), gamme.noire],
+            [gamme.re(4), gamme.noire],
+            [gamme.sib(4), gamme.crochepointee],
+            [gamme.sib(4), gamme.doublecroche],
+            [gamme.la(4), gamme.noire],
+            [gamme.fa(4), gamme.noire],
+            [gamme.sol(4), gamme.noire],
+            [gamme.fa(4), gamme.blanchepointee]
         ] ]
 
+
 if args.exerciceSpectrogramme:
   g = GenerateurExercice(gamme.bpm)
   g.genererExerciceSpectrogramme(happy, "exercices/ex-spec-happybirthday.tex", "thème joyeux anniversaire")
diff --git a/musique/exercice.py b/musique/exercice.py
index 3ab4079..3ad916c 100644
--- a/musique/exercice.py
+++ b/musique/exercice.py
@@ -13,7 +13,7 @@ class GenerateurExercice(GammeTemperee):
     # Paramètres:
     # * bpm: nombre de battements par minute (= nombre de noires par minute)
     # * dureeFrappe: duree de la frappe
-    def __init__(self, bpm = 120, dureeFrappe = 0.04):
+    def __init__(self, bpm = 120, dureeFrappe = 0.12):
         GammeTemperee.__init__(self, bpm)
         self.dureeFrappe = dureeFrappe
         self.margeDocument = 1.0
@@ -236,10 +236,10 @@ class GenerateurExercice(GammeTemperee):
     
     def estDessinable(self, partitions):
       if len(partitions) != 1:
-        print "plus d'une partition"
+        print "La partition contient plusieurs mains."
         return False
       if self.contientNoteAlteree(partitions):
-        print "note alteree"
+        print "La partition contient une alterée."
         return False
       
       notes = [ self.getOctaveEtIDNote(p) for p in self.notesDansPartition(partitions) ]
@@ -309,8 +309,11 @@ class GenerateurExercice(GammeTemperee):
     # dessine sur le spectrogramme l'accord donné en paramètre,
     # à l'horodatage donné
     def noteSpectrogrammePartition(self, frequence, duree, horodatage, couleur = "black"):
-      y = self.frequenceEnCm(frequence)
-      return self.noteGraphique(y, self.margeDureeDebut, duree, horodatage, couleur)
+      if frequence == 0:
+        return ''
+      else:
+        y = self.frequenceEnCm(frequence)
+        return self.noteGraphique(y, self.margeDureeDebut, duree, horodatage, couleur)
     
     def noteGraphique(self, y, decalageDuree, duree, horodatage, couleur = "black"):
       xmin = self.dureeEnCm(horodatage + decalageDuree)
diff --git a/musique/gamme.py b/musique/gamme.py
index 56938b7..e5d1a47 100644
--- a/musique/gamme.py
+++ b/musique/gamme.py
@@ -144,7 +144,7 @@ class GammeTemperee:
 
     # retourne la fréquence minimum utilisée dans les partitions
     def minFrequence(self, partitions):
-      return min([min([ x for x in [note[0] if isinstance(note[0], float) else min(note[0]) for note in partition] if x != 0.]) for partition in partitions])
+      return min([min([ x for x in [note[0] if isinstance(note[0], float) else min(note[0]) for note in partition] if x > 0]) for partition in partitions])
     # retourne la fréquence maximum utilisée dans les partitions
     def maxFrequence(self, partitions):
       return max([max([note[0] if isinstance(note[0], float) else max(note[0]) for note in partition]) for partition in partitions])
-- 
GitLab