]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - music_sampler.py
enhancing locks
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
index 6cc49dff4884a7f0391f796ddd097321afe146b0..fd03009495f72cddfaa635558190d70badeb05ae 100644 (file)
@@ -7,23 +7,19 @@ pygame.mixer.pre_init(frequency = 44100)
 pygame.init()
 
 size = width, height = 1024, 600
-
-helpers.draw_lock.acquire()
 screen = pygame.display.set_mode(size)
-mapping = helpers.Mapping(screen)
+screen.fill((250, 250, 250))
+
+draw_lock = helpers.Lock("draw")
 
-action_surface = pygame.Surface((600, 250)).convert()
-action_surface.fill((0,0,0))
+mapping = helpers.Mapping(screen, draw_lock)
 helpers.parse_config(mapping)
-helpers.draw_lock.release()
 
 mapping.draw()
 
-helpers.draw_lock.acquire()
-screen.blit(action_surface, (10, 330))
-
+draw_lock.acquire()
 pygame.display.flip()
-helpers.draw_lock.release()
+draw_lock.release()
 
 contexts = [
     'normal'
@@ -38,6 +34,11 @@ while 1:
             event.type == pygame.KEYDOWN and 
             event.mod  == 4160 and
             event.key  == pygame.K_c):
+        for thread in threading.enumerate():
+            if thread is threading.current_thread():
+                continue
+            thread.join()
+
         pygame.quit()
         sys.exit()
 
@@ -49,7 +50,9 @@ while 1:
         elif event.type == pygame.MOUSEBUTTONUP:
             key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
             if key is not None:
-                key.list_actions(action_surface)
+                threading.Thread(target=key.list_actions, args = [screen]).start()
 
+    draw_lock.acquire()
     pygame.display.flip()
+    draw_lock.release()