diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-06-19 22:44:54 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-06-19 22:44:54 +0200 |
commit | 23b7e0e5daf024e87d967ede3dfe6777a07e7469 (patch) | |
tree | 066f4d4c1678ac4ce4f441d042b36b30818c9597 | |
parent | b86db9f1679c855c2d39a0b116f846d271271a2c (diff) | |
download | MusicSampler-23b7e0e5daf024e87d967ede3dfe6777a07e7469.tar.gz MusicSampler-23b7e0e5daf024e87d967ede3dfe6777a07e7469.tar.zst MusicSampler-23b7e0e5daf024e87d967ede3dfe6777a07e7469.zip |
Fix threading problems with ipython
-rw-r--r-- | config.yml | 146 | ||||
-rw-r--r-- | helpers/key.py | 8 | ||||
-rw-r--r-- | helpers/mapping.py | 2 | ||||
-rw-r--r-- | helpers/music_file.py | 2 | ||||
-rw-r--r-- | music_sampler.py | 12 |
5 files changed, 96 insertions, 74 deletions
@@ -35,124 +35,140 @@ aliases: | |||
35 | key_properties: | 35 | key_properties: |
36 | 'a': | 36 | 'a': |
37 | description: | 37 | description: |
38 | - Chloé | 38 | - # Chloé |
39 | - Jonglacro | 39 | - Jonglacro |
40 | color: [255, 0, 0] | 40 | color: [73, 221, 226] |
41 | 'z': | 41 | 'z': |
42 | description: | 42 | description: |
43 | - Chloé | 43 | - #Chloé |
44 | - Jonglacro 2 | 44 | - Jonglacro |
45 | color: [255, 0, 0] | 45 | - 2 |
46 | color: [73, 221, 226] | ||
46 | 'e': | 47 | 'e': |
47 | description: | 48 | description: |
48 | - Chloé | 49 | - #Chloé |
49 | - Stop jonglacro 2 | 50 | - Fin |
50 | color: [255, 0, 0] | 51 | - jonglacro |
52 | color: [73, 221, 226] | ||
51 | 'r': | 53 | 'r': |
52 | description: | 54 | description: |
53 | - Chloé | 55 | - #Chloé |
54 | - Lancer prisonnière | 56 | - Lancer |
55 | color: [255, 0, 0] | 57 | - prisonnière |
58 | color: [73, 221, 226] | ||
56 | 't': | 59 | 't': |
57 | description: | 60 | description: |
58 | - Chloé | 61 | - #Chloé |
59 | - Stop lancer prisonnière | 62 | - Fin |
60 | color: [255, 0, 0] | 63 | - lancer |
64 | color: [73, 221, 226] | ||
61 | 'y': | 65 | 'y': |
62 | description: | 66 | description: |
63 | - Chloé | 67 | - #Chloé |
64 | - Quête | 68 | - Quête |
65 | color: [255, 0, 0] | 69 | color: [73, 221, 226] |
66 | 'u': | 70 | 'u': |
67 | description: | 71 | description: |
68 | - Chloé | 72 | - #Chloé |
69 | - Grrr | 73 | - Monstre |
70 | color: [255, 0, 0] | 74 | color: [73, 221, 226] |
71 | 'i': | 75 | 'i': |
72 | description: | 76 | description: |
73 | - Chloé | 77 | - #Chloé |
74 | - Transition -> entrée ondine | 78 | - Fin quête |
75 | color: [255, 0, 0] | 79 | - Entrée ondine |
80 | color: [73, 221, 226] | ||
76 | 'o': | 81 | 'o': |
77 | description: | 82 | description: |
78 | - Denise | 83 | - #Denise |
84 | - Fin ondine | ||
79 | - Cour ondine | 85 | - Cour ondine |
80 | color: [0, 255, 0] | 86 | color: [190, 110, 236] |
81 | 'p': | 87 | 'p': |
82 | description: | 88 | description: |
83 | - Denise | 89 | - #Denise |
84 | - Stop cour ondine | 90 | - Fin |
85 | color: [0, 255, 0] | 91 | - cour ondine |
92 | color: [190, 110, 236] | ||
86 | 'q': | 93 | 'q': |
87 | description: | 94 | description: |
88 | - Chloé | 95 | - #Chloé |
89 | - Fouille jonglage | 96 | - Fouille |
90 | color: [255, 0, 0] | 97 | - Jonglage |
98 | color: [73, 221, 226] | ||
91 | 's': | 99 | 's': |
92 | description: | 100 | description: |
93 | - Denise | 101 | - #Denise |
94 | - Stop fouille jonglage | 102 | - Fin |
95 | color: [0, 255, 0] | 103 | - Jonglage |
104 | color: [190, 110, 236] | ||
96 | 'd': | 105 | 'd': |
97 | description: | 106 | description: |
98 | - Denise | 107 | - #Denise |
99 | - Libération prisonnière | 108 | - Libération |
100 | color: [0, 255, 0] | 109 | - Prisonnière |
110 | color: [190, 110, 236] | ||
101 | 'f': | 111 | 'f': |
102 | description: | 112 | description: |
103 | - Denise | 113 | - #Denise |
104 | - Paf + baisser musique | 114 | - Paf |
105 | color: [0, 255, 0] | 115 | - Baisser musique |
116 | color: [190, 110, 236] | ||
106 | 'g': | 117 | 'g': |
107 | description: | 118 | description: |
108 | - Denise | 119 | - #Denise |
109 | - Stop musique | 120 | - Stop |
110 | color: [0, 255, 0] | 121 | - libération |
122 | color: [190, 110, 236] | ||
111 | 'h': | 123 | 'h': |
112 | description: | 124 | description: |
113 | - Denise | 125 | - #Denise |
114 | - Duos | 126 | - Duo |
115 | color: [0, 255, 0] | 127 | color: [190, 110, 236] |
116 | 'j': | 128 | 'j': |
117 | description: | 129 | description: |
118 | - Jérôme | 130 | - #Jérôme |
119 | - Transition trios | 131 | - Fin duo |
120 | color: [0, 0, 255] | 132 | - Trio |
133 | color: [240, 158, 0] | ||
121 | 'k': | 134 | 'k': |
122 | description: | 135 | description: |
123 | - Jérôme | 136 | - #Jérôme |
124 | - Stop trios | 137 | - Fin trio |
125 | color: [0, 0, 255] | 138 | color: [240, 158, 0] |
126 | 'l': | 139 | 'l': |
127 | description: | 140 | description: |
128 | - Jérôme | 141 | - #Jérôme |
129 | - Jeu à 2-4 | 142 | - Jeu à |
130 | color: [0, 0, 255] | 143 | - 2 4 |
144 | color: [240, 158, 0] | ||
131 | 'm': | 145 | 'm': |
132 | description: | 146 | description: |
133 | - Chloé | 147 | - #Chloé |
148 | - Fin jeu | ||
134 | - Début baston | 149 | - Début baston |
135 | color: [255, 0, 0] | 150 | color: [73, 221, 226] |
136 | 'w': | 151 | 'w': |
137 | description: | 152 | description: |
138 | - Christophe | 153 | - #Christophe |
139 | - Transition ralenti | 154 | - Fin baston |
155 | - Ralenti | ||
140 | color: [255, 255, 0] | 156 | color: [255, 255, 0] |
141 | 'x': | 157 | 'x': |
142 | description: | 158 | description: |
143 | - Christophe | 159 | - #Christophe |
144 | - Stop ralenti | 160 | - Fin ralenti |
145 | color: [255, 255, 0] | 161 | color: [255, 255, 0] |
146 | 'c': | 162 | 'c': |
147 | description: | 163 | description: |
148 | - Christophe | 164 | - #Christophe |
149 | - Début baston 2 | 165 | - Baston 2 |
150 | color: [255, 255, 0] | 166 | color: [255, 255, 0] |
151 | 'v': | 167 | 'v': |
152 | description: | 168 | description: |
153 | - Auréliane | 169 | - #Auréliane |
154 | - Stop baston 2 | 170 | - Fin baston 2 |
155 | color: [0, 255, 255] | 171 | color: [0, 190, 27] |
156 | 172 | ||
157 | 173 | ||
158 | keys: | 174 | keys: |
diff --git a/helpers/key.py b/helpers/key.py index 9a6cb3b..e9e485d 100644 --- a/helpers/key.py +++ b/helpers/key.py | |||
@@ -72,7 +72,7 @@ class Key: | |||
72 | ) | 72 | ) |
73 | 73 | ||
74 | def set_description(self, description): | 74 | def set_description(self, description): |
75 | self.description = description | 75 | self.description = [str(desc) for desc in description] |
76 | 76 | ||
77 | def set_color(self, color): | 77 | def set_color(self, color): |
78 | self.custom_color = tuple(color) | 78 | self.custom_color = tuple(color) |
@@ -97,7 +97,7 @@ class Key: | |||
97 | self.surface.blit(text, (5,5)) | 97 | self.surface.blit(text, (5,5)) |
98 | 98 | ||
99 | is_first_line = True | 99 | is_first_line = True |
100 | offset = 11 + text_police.get_linesize() | 100 | offset = 11 + text_police.get_linesize() - 4 |
101 | first_line_offset = 18 | 101 | first_line_offset = 18 |
102 | for description in self.description: | 102 | for description in self.description: |
103 | text = text_police.render(description, True, (0,0,0)) | 103 | text = text_police.render(description, True, (0,0,0)) |
@@ -105,8 +105,8 @@ class Key: | |||
105 | self.surface.blit(text, (first_line_offset, 9)) | 105 | self.surface.blit(text, (first_line_offset, 9)) |
106 | is_first_line = False | 106 | is_first_line = False |
107 | else: | 107 | else: |
108 | self.surface.blit(text, (5, offset)) | 108 | self.surface.blit(text, (3, offset)) |
109 | offset += text_police.get_linesize() | 109 | offset += text_police.get_linesize() - 4 |
110 | 110 | ||
111 | background_surface.blit(self.surface, self.position) | 111 | background_surface.blit(self.surface, self.position) |
112 | self.draw_lock.release() | 112 | self.draw_lock.release() |
diff --git a/helpers/mapping.py b/helpers/mapping.py index ee5623a..84e9941 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py | |||
@@ -130,7 +130,7 @@ class Mapping: | |||
130 | should_redraw_key = key.draw(self.background) | 130 | should_redraw_key = key.draw(self.background) |
131 | 131 | ||
132 | if should_redraw_key: | 132 | if should_redraw_key: |
133 | threading.Thread(target = key.poll_redraw, args = [self.background]).start() | 133 | threading.Thread(name = "MSPollRedraw", target = key.poll_redraw, args = [self.background]).start() |
134 | self.blit() | 134 | self.blit() |
135 | 135 | ||
136 | def blit(self): | 136 | def blit(self): |
diff --git a/helpers/music_file.py b/helpers/music_file.py index b834104..5101f7f 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py | |||
@@ -10,7 +10,7 @@ class MusicFile: | |||
10 | self.sound = None | 10 | self.sound = None |
11 | 11 | ||
12 | self.loaded = False | 12 | self.loaded = False |
13 | threading.Thread(target = self.load_sound, args = [lock]).start() | 13 | threading.Thread(name = "MSMusicLoad", target = self.load_sound, args = [lock]).start() |
14 | 14 | ||
15 | def load_sound(self, lock): | 15 | def load_sound(self, lock): |
16 | lock.acquire() | 16 | lock.acquire() |
diff --git a/music_sampler.py b/music_sampler.py index fd03009..d4fc2a7 100644 --- a/music_sampler.py +++ b/music_sampler.py | |||
@@ -27,6 +27,7 @@ contexts = [ | |||
27 | 27 | ||
28 | context = 'normal' | 28 | context = 'normal' |
29 | 29 | ||
30 | #### Normal workflow #### | ||
30 | while 1: | 31 | while 1: |
31 | event = pygame.event.wait() | 32 | event = pygame.event.wait() |
32 | 33 | ||
@@ -35,7 +36,7 @@ while 1: | |||
35 | event.mod == 4160 and | 36 | event.mod == 4160 and |
36 | event.key == pygame.K_c): | 37 | event.key == pygame.K_c): |
37 | for thread in threading.enumerate(): | 38 | for thread in threading.enumerate(): |
38 | if thread is threading.current_thread(): | 39 | if thread.getName()[0:2] != "MS": |
39 | continue | 40 | continue |
40 | thread.join() | 41 | thread.join() |
41 | 42 | ||
@@ -46,13 +47,18 @@ while 1: | |||
46 | if event.type == pygame.KEYDOWN: | 47 | if event.type == pygame.KEYDOWN: |
47 | key = mapping.find_by_key_num(event.key) | 48 | key = mapping.find_by_key_num(event.key) |
48 | if key is not None: | 49 | if key is not None: |
49 | threading.Thread(target=key.do_actions).start() | 50 | threading.Thread(name = "MSKeyAction", target=key.do_actions).start() |
50 | elif event.type == pygame.MOUSEBUTTONUP: | 51 | elif event.type == pygame.MOUSEBUTTONUP: |
51 | key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) | 52 | key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) |
52 | if key is not None: | 53 | if key is not None: |
53 | threading.Thread(target=key.list_actions, args = [screen]).start() | 54 | threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() |
54 | 55 | ||
55 | draw_lock.acquire() | 56 | draw_lock.acquire() |
56 | pygame.display.flip() | 57 | pygame.display.flip() |
57 | draw_lock.release() | 58 | draw_lock.release() |
58 | 59 | ||
60 | #### In Ipython #### | ||
61 | # for thread in threading.enumerate(): | ||
62 | # if thread.getName()[0:2] != "MS": | ||
63 | # continue | ||
64 | # thread.join() | ||