aboutsummaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/__init__.py7
-rw-r--r--helpers/action.py26
-rw-r--r--helpers/key.py4
-rw-r--r--helpers/music_file.py19
4 files changed, 43 insertions, 13 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py
index d0d3f46..b3ab1eb 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -41,7 +41,10 @@ def parse_config(mapping):
41 if argument == 'file': 41 if argument == 'file':
42 filename = action[action_name]['file'] 42 filename = action[action_name]['file']
43 if filename not in seen_files: 43 if filename not in seen_files:
44 seen_files[filename] = MusicFile(filename, file_lock, channel_id) 44 if 'name' in action[action_name]:
45 seen_files[filename] = MusicFile(filename, file_lock, channel_id, name = action[action_name]['name'])
46 else:
47 seen_files[filename] = MusicFile(filename, file_lock, channel_id)
45 channel_id = channel_id + 1 48 channel_id = channel_id + 1
46 49
47 action_args['music'] = seen_files[filename] 50 action_args['music'] = seen_files[filename]
@@ -62,4 +65,4 @@ def parse_config(mapping):
62 key.set_color(config['key_properties'][key_property]['color']) 65 key.set_color(config['key_properties'][key_property]['color'])
63 66
64 # Return the number of channels reserved 67 # Return the number of channels reserved
65 return channel_id + 1 68 return (channel_id + 1, seen_files)
diff --git a/helpers/action.py b/helpers/action.py
index 5afe437..1cb1686 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -8,6 +8,7 @@ class Action:
8 'play', 8 'play',
9 'stop', 9 'stop',
10 'stop_all_actions', 10 'stop_all_actions',
11 'unpause',
11 'volume', 12 'volume',
12 'wait', 13 'wait',
13 ] 14 ]
@@ -29,7 +30,8 @@ class Action:
29 30
30 def run(self): 31 def run(self):
31 print(self.description()) 32 print(self.description())
32 return getattr(self, self.action)(**self.arguments) 33 getattr(self, self.action)(**self.arguments)
34 pygame.event.post(pygame.event.Event(pygame.USEREVENT))
33 35
34 def description(self): 36 def description(self):
35 return getattr(self, self.action + "_print")(**self.arguments) 37 return getattr(self, self.action + "_print")(**self.arguments)
@@ -43,6 +45,12 @@ class Action:
43 else: 45 else:
44 pygame.mixer.pause() 46 pygame.mixer.pause()
45 47
48 def unpause(self, music = None, **kwargs):
49 if music is not None:
50 music.unpause()
51 else:
52 pygame.mixer.unpause()
53
46 def play(self, music = None, fade_in = 0, start_at = 0, 54 def play(self, music = None, fade_in = 0, start_at = 0,
47 restart_if_running = False, volume = 100, **kwargs): 55 restart_if_running = False, volume = 100, **kwargs):
48 if music is not None: 56 if music is not None:
@@ -88,15 +96,21 @@ class Action:
88 96
89 def pause_print(self, music = None, **kwargs): 97 def pause_print(self, music = None, **kwargs):
90 if music is not None: 98 if music is not None:
91 return "pausing {}".format(music.filename) 99 return "pausing « {} »".format(music.name)
92 else: 100 else:
93 return "pausing all musics" 101 return "pausing all musics"
94 102
103 def unpause_print(self, music = None, **kwargs):
104 if music is not None:
105 return "unpausing « {} »".format(music.name)
106 else:
107 return "unpausing all musics"
108
95 def play_print(self, music = None, fade_in = 0, start_at = 0, 109 def play_print(self, music = None, fade_in = 0, start_at = 0,
96 restart_if_running = False, volume = 100, **kwargs): 110 restart_if_running = False, volume = 100, **kwargs):
97 message = "starting " 111 message = "starting "
98 if music is not None: 112 if music is not None:
99 message += music.filename 113 message += "« {} »".format(music.name)
100 else: 114 else:
101 message += "music" 115 message += "music"
102 116
@@ -116,9 +130,9 @@ class Action:
116 def stop_print(self, music = None, fade_out = 0, **kwargs): 130 def stop_print(self, music = None, fade_out = 0, **kwargs):
117 if music is not None: 131 if music is not None:
118 if fade_out == 0: 132 if fade_out == 0:
119 return "stopping music {}".format(music.filename) 133 return "stopping music « {} »".format(music.name)
120 else: 134 else:
121 return "stopping music {} with {}s fadeout".format(music.filename, fade_out) 135 return "stopping music « {} » with {}s fadeout".format(music.name, fade_out)
122 else: 136 else:
123 if fade_out == 0: 137 if fade_out == 0:
124 return "stopping all musics" 138 return "stopping all musics"
@@ -130,7 +144,7 @@ class Action:
130 144
131 def volume_print(self, music = None, value = 100, **kwargs): 145 def volume_print(self, music = None, value = 100, **kwargs):
132 if music is not None: 146 if music is not None:
133 return "setting volume of {} to {}%".format(music.filename, value) 147 return "setting volume of « {} » to {}%".format(music.name, value)
134 else: 148 else:
135 return "setting volume to {}%".format(value) 149 return "setting volume to {}%".format(value)
136 150
diff --git a/helpers/key.py b/helpers/key.py
index 7b8051e..57fdef1 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -149,7 +149,7 @@ class Key:
149 #print("actions linked to key {}:".format(self.key_sym)) 149 #print("actions linked to key {}:".format(self.key_sym))
150 #print("\t" + "\n\t".join(action_descriptions)) 150 #print("\t" + "\n\t".join(action_descriptions))
151 self.draw_lock.acquire() 151 self.draw_lock.acquire()
152 surface = pygame.Surface((800, 250)).convert() 152 surface = pygame.Surface((690, 250)).convert()
153 surface.fill((250, 250, 250)) 153 surface.fill((250, 250, 250))
154 if getattr(sys, 'frozen', False): 154 if getattr(sys, 'frozen', False):
155 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14) 155 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
@@ -168,7 +168,7 @@ class Key:
168 surface.blit(text, (0, offset)) 168 surface.blit(text, (0, offset))
169 offset += police.get_linesize() 169 offset += police.get_linesize()
170 170
171 screen.blit(surface, (10, 330)) 171 screen.blit(surface, (5, 308))
172 pygame.display.flip() 172 pygame.display.flip()
173 self.draw_lock.release() 173 self.draw_lock.release()
174 174
diff --git a/helpers/music_file.py b/helpers/music_file.py
index f6b0117..d40a132 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -3,28 +3,35 @@ import pydub
3import pygame 3import pygame
4 4
5class MusicFile: 5class MusicFile:
6 def __init__(self, filename, lock, channel_id): 6 def __init__(self, filename, lock, channel_id, name = None):
7 self.filename = filename 7 self.filename = filename
8 self.channel_id = channel_id 8 self.channel_id = channel_id
9 self.name = name or filename
9 self.raw_data = None 10 self.raw_data = None
10 self.sound = None 11 self.sound = None
11 12
12 self.loaded = False 13 self.loaded = False
14 self.flag_paused = False
13 threading.Thread(name = "MSMusicLoad", target = self.load_sound, args = [lock]).start() 15 threading.Thread(name = "MSMusicLoad", target = self.load_sound, args = [lock]).start()
14 16
15 def load_sound(self, lock): 17 def load_sound(self, lock):
16 lock.acquire() 18 lock.acquire()
17 print("Loading {}".format(self.filename)) 19 print("Loading « {} »".format(self.name))
18 self.raw_data = pydub.AudioSegment.from_file(self.filename).raw_data 20 self.raw_data = pydub.AudioSegment.from_file(self.filename).raw_data
19 self.sound = pygame.mixer.Sound(self.raw_data) 21 self.sound = pygame.mixer.Sound(self.raw_data)
20 print("Loaded {}".format(self.filename)) 22 print("Loaded « {} »".format(self.name))
21 self.loaded = True 23 self.loaded = True
22 lock.release() 24 lock.release()
23 25
24 def is_playing(self): 26 def is_playing(self):
25 return self.channel().get_busy() 27 return self.channel().get_busy()
26 28
29 def is_paused(self):
30 return self.flag_paused
31
27 def play(self, fade_in = 0, volume = 100, start_at = 0): 32 def play(self, fade_in = 0, volume = 100, start_at = 0):
33 self.channel().set_endevent()
34 self.channel().set_endevent(pygame.USEREVENT)
28 self.set_volume(volume) 35 self.set_volume(volume)
29 36
30 if start_at > 0: 37 if start_at > 0:
@@ -37,9 +44,15 @@ class MusicFile:
37 self.sound = pygame.mixer.Sound(self.raw_data) 44 self.sound = pygame.mixer.Sound(self.raw_data)
38 45
39 self.channel().play(self.sound, fade_ms = fade_in * 1000) 46 self.channel().play(self.sound, fade_ms = fade_in * 1000)
47 self.flag_paused = False
40 48
41 def pause(self): 49 def pause(self):
42 self.channel().pause() 50 self.channel().pause()
51 self.flag_paused = True
52
53 def unpause(self):
54 self.channel().unpause()
55 self.flag_paused = False
43 56
44 def stop(self, fade_out = 0): 57 def stop(self, fade_out = 0):
45 if fade_out > 0: 58 if fade_out > 0: