]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Fix threading problems with ipython
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 19 Jun 2016 20:44:54 +0000 (22:44 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 19 Jun 2016 20:44:54 +0000 (22:44 +0200)
config.yml
helpers/key.py
helpers/mapping.py
helpers/music_file.py
music_sampler.py

index ca6c3991ad383c68d3a15c20f18f73078b1882c2..bd674965761e0865f08811d374f2f95f22025051 100644 (file)
@@ -35,124 +35,140 @@ aliases:
 key_properties:
   'a':
     description:
-      - Chloé
+      -  # Chloé
       - Jonglacro
-    color: [255, 0, 0]
+    color: [73, 221, 226]
   'z':
     description:
-      - Chloé
-      - Jonglacro 2
-    color: [255, 0, 0]
+      -  #Chloé
+      - Jonglacro
+      - 2
+    color: [73, 221, 226]
   'e':
     description:
-      - Chloé
-      - Stop jonglacro 2
-    color: [255, 0, 0]
+      -   #Chloé
+      - Fin
+      - jonglacro
+    color: [73, 221, 226]
   'r':
     description:
-      - Chloé
-      - Lancer prisonnière
-    color: [255, 0, 0]
+      -   #Chloé
+      - Lancer 
+      - prisonnière
+    color: [73, 221, 226]
   't':
     description:
-      - Chloé
-      - Stop lancer prisonnière
-    color: [255, 0, 0]
+      -  #Chloé
+      - Fin
+      - lancer
+    color: [73, 221, 226]
   'y':
     description:
-      - Chloé
+      -  #Chloé
       - Quête
-    color: [255, 0, 0]
+    color: [73, 221, 226]
   'u':
     description:
-      - Chloé
-      - Grrr
-    color: [255, 0, 0]
+      -  #Chloé
+      - Monstre
+    color: [73, 221, 226]
   'i':
     description:
-      - Chloé
-      - Transition -> entrée ondine
-    color: [255, 0, 0]
+      -  #Chloé
+      - Fin quête
+      - Entrée ondine
+    color: [73, 221, 226]
   'o':
     description:
-      - Denise
+      -   #Denise
+      - Fin ondine
       - Cour ondine
-    color: [0, 255, 0]
+    color: [190, 110, 236]
   'p':
     description:
-      - Denise
-      - Stop cour ondine
-    color: [0, 255, 0]
+      -   #Denise
+      - Fin 
+      - cour ondine
+    color: [190, 110, 236]
   'q':
     description:
-      - Chloé
-      - Fouille jonglage
-    color: [255, 0, 0]
+      -  #Chloé
+      - Fouille 
+      - Jonglage
+    color: [73, 221, 226]
   's':
     description:
-      - Denise
-      - Stop fouille jonglage
-    color: [0, 255, 0]
+      -   #Denise
+      - Fin
+      - Jonglage
+    color: [190, 110, 236]
   'd':
     description:
-      - Denise
-      - Libération prisonnière
-    color: [0, 255, 0]
+      -   #Denise
+      - Libération 
+      - Prisonnière
+    color: [190, 110, 236]
   'f':
     description:
-      - Denise
-      - Paf + baisser musique
-    color: [0, 255, 0]
+      -   #Denise
+      - Paf
+      - Baisser musique
+    color: [190, 110, 236]
   'g':
     description:
-      - Denise
-      - Stop musique
-    color: [0, 255, 0]
+      -   #Denise
+      - Stop 
+      - libération
+    color: [190, 110, 236]
   'h':
     description:
-      - Denise
-      - Duos
-    color: [0, 255, 0]
+      -   #Denise
+      - Duo
+    color: [190, 110, 236]
   'j':
     description:
-      - Jérôme
-      - Transition trios
-    color: [0, 0, 255]
+      -   #Jérôme
+      - Fin duo
+      - Trio
+    color: [240, 158, 0]
   'k':
     description:
-      - Jérôme
-      - Stop trios
-    color: [0, 0, 255]
+      -   #Jérôme
+      - Fin trio
+    color: [240, 158, 0]
   'l':
     description:
-      - Jérôme
-      - Jeu à 2-4
-    color: [0, 0, 255]
+      -   #Jérôme
+      - Jeu à 
+      - 2 4
+    color: [240, 158, 0]
   'm':
     description:
-      - Chloé
+      -  #Chloé
+      - Fin jeu
       - Début baston
-    color: [255, 0, 0]
+    color: [73, 221, 226]
   'w':
     description:
-      - Christophe
-      - Transition ralenti
+      -  #Christophe
+      - Fin baston
+      - Ralenti
     color: [255, 255, 0]
   'x':
     description:
-      - Christophe
-      - Stop ralenti
+      -  #Christophe
+      - Fin ralenti
     color: [255, 255, 0]
   'c':
     description:
-      - Christophe
-      - Début baston 2
+      -  #Christophe
+      - Baston 2
     color: [255, 255, 0]
   'v':
     description:
-      - Auréliane
-      - Stop baston 2
-    color: [0, 255, 255]
+      -  #Auréliane
+      - Fin baston 2
+    color: [0, 190, 27]
 
 
 keys:
index 9a6cb3b29f2a1b0270a1081490eab4efdc90f844..e9e485d11d52d45a61c0d73060aa66895f611a7a 100644 (file)
@@ -72,7 +72,7 @@ class Key:
                 )
 
     def set_description(self, description):
-        self.description = description
+        self.description = [str(desc) for desc in description]
 
     def set_color(self, color):
         self.custom_color = tuple(color)
@@ -97,7 +97,7 @@ class Key:
         self.surface.blit(text, (5,5))
 
         is_first_line = True
-        offset = 11 + text_police.get_linesize()
+        offset = 11 + text_police.get_linesize() - 4
         first_line_offset = 18
         for description in self.description:
             text = text_police.render(description, True, (0,0,0))
@@ -105,8 +105,8 @@ class Key:
                 self.surface.blit(text, (first_line_offset, 9))
                 is_first_line = False
             else:
-                self.surface.blit(text, (5, offset))
-                offset += text_police.get_linesize()
+                self.surface.blit(text, (3, offset))
+                offset += text_police.get_linesize() - 4
 
         background_surface.blit(self.surface, self.position)
         self.draw_lock.release()
index ee5623a9843f503b2f034d7fa6e8794c483ba208..84e99410874a979b7252329c245f152877582586 100644 (file)
@@ -130,7 +130,7 @@ class Mapping:
             should_redraw_key = key.draw(self.background)
 
             if should_redraw_key:
-                threading.Thread(target = key.poll_redraw, args = [self.background]).start()
+                threading.Thread(name = "MSPollRedraw", target = key.poll_redraw, args = [self.background]).start()
         self.blit()
 
     def blit(self):
index b834104fe6b01d95930d4ea1e23bc8f108747015..5101f7f4c7232175a243d5445e8c9551bc58e950 100644 (file)
@@ -10,7 +10,7 @@ class MusicFile:
         self.sound = None
 
         self.loaded = False
-        threading.Thread(target = self.load_sound, args = [lock]).start()
+        threading.Thread(name = "MSMusicLoad", target = self.load_sound, args = [lock]).start()
 
     def load_sound(self, lock):
         lock.acquire()
index fd03009495f72cddfaa635558190d70badeb05ae..d4fc2a726ee6923772bfd36d782ca5ff0014fc9f 100644 (file)
@@ -27,6 +27,7 @@ contexts = [
 
 context = 'normal'
 
+#### Normal workflow ####
 while 1:
     event = pygame.event.wait()
 
@@ -35,7 +36,7 @@ while 1:
             event.mod  == 4160 and
             event.key  == pygame.K_c):
         for thread in threading.enumerate():
-            if thread is threading.current_thread():
+            if thread.getName()[0:2] != "MS":
                 continue
             thread.join()
 
@@ -46,13 +47,18 @@ while 1:
         if event.type == pygame.KEYDOWN:
             key = mapping.find_by_key_num(event.key)
             if key is not None:
-                threading.Thread(target=key.do_actions).start()
+                threading.Thread(name = "MSKeyAction", target=key.do_actions).start()
         elif event.type == pygame.MOUSEBUTTONUP:
             key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
             if key is not None:
-                threading.Thread(target=key.list_actions, args = [screen]).start()
+                threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
 
     draw_lock.acquire()
     pygame.display.flip()
     draw_lock.release()
 
+#### In Ipython ####
+# for thread in threading.enumerate():
+#     if thread.getName()[0:2] != "MS":
+#         continue
+#     thread.join()