aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helpers/key.py3
-rw-r--r--helpers/mapping.py50
-rw-r--r--helpers/music_file.py25
3 files changed, 67 insertions, 11 deletions
diff --git a/helpers/key.py b/helpers/key.py
index 363e9ce..4ec08d1 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -70,7 +70,7 @@ class Key(ButtonBehavior, Widget):
70 }, 70 },
71 { 71 {
72 'trigger': 'reload', 72 'trigger': 'reload',
73 'source': 'loaded', 73 'source': ['loaded','failed'],
74 'dest': 'configuring', 74 'dest': 'configuring',
75 'after': 'key_loaded_callback' 75 'after': 'key_loaded_callback'
76 }, 76 },
@@ -190,6 +190,7 @@ class Key(ButtonBehavior, Widget):
190 def set_description(self, description): 190 def set_description(self, description):
191 if description[0] is not None: 191 if description[0] is not None:
192 self.description_title = str(description[0]) 192 self.description_title = str(description[0])
193 self.description = []
193 for desc in description[1 :]: 194 for desc in description[1 :]:
194 if desc is None: 195 if desc is None:
195 self.description.append("") 196 self.description.append("")
diff --git a/helpers/mapping.py b/helpers/mapping.py
index 864afbe..1256696 100644
--- a/helpers/mapping.py
+++ b/helpers/mapping.py
@@ -1,5 +1,5 @@
1from kivy.uix.relativelayout import RelativeLayout 1from kivy.uix.relativelayout import RelativeLayout
2from kivy.properties import NumericProperty, ListProperty 2from kivy.properties import NumericProperty, ListProperty, StringProperty
3from kivy.core.window import Window 3from kivy.core.window import Window
4from kivy.clock import Clock 4from kivy.clock import Clock
5 5
@@ -56,13 +56,34 @@ class Mapping(RelativeLayout):
56 'trigger': 'success', 56 'trigger': 'success',
57 'source': 'loading', 57 'source': 'loading',
58 'dest': 'loaded' 58 'dest': 'loaded'
59 },
60 {
61 'trigger': 'reload',
62 'source': 'loaded',
63 'dest': 'configuring'
59 } 64 }
60 ] 65 ]
61 66
62 master_volume = NumericProperty(100) 67 master_volume = NumericProperty(100)
63 ready_color = ListProperty([1, 165/255, 0, 1]) 68 ready_color = ListProperty([1, 165/255, 0, 1])
69 state = StringProperty("")
64 70
65 def __init__(self, **kwargs): 71 def __init__(self, **kwargs):
72 self.keys = []
73 self.running = []
74 self.wait_ids = {}
75 self.open_files = {}
76
77 Machine(model=self, states=self.STATES,
78 transitions=self.TRANSITIONS, initial='initial',
79 ignore_invalid_triggers=True, queued=True)
80 super(Mapping, self).__init__(**kwargs)
81 self.keyboard = Window.request_keyboard(self.on_keyboard_closed, self)
82 self.keyboard.bind(on_key_down=self.on_keyboard_down)
83
84 self.configure()
85
86 def on_enter_configuring(self):
66 if Config.builtin_mixing: 87 if Config.builtin_mixing:
67 self.mixer = Mixer() 88 self.mixer = Mixer()
68 else: 89 else:
@@ -74,14 +95,13 @@ class Mapping(RelativeLayout):
74 error_print("Error while loading configuration: {}".format(e), 95 error_print("Error while loading configuration: {}".format(e),
75 with_trace=True) 96 with_trace=True)
76 sys.exit() 97 sys.exit()
98 else:
99 self.success()
77 100
78 self.keys = [] 101 def on_enter_loading(self):
79 self.running = [] 102 for key in self.keys:
80 self.wait_ids = {} 103 key.reload()
81 104 self.success()
82 super(Mapping, self).__init__(**kwargs)
83 self.keyboard = Window.request_keyboard(self.on_keyboard_closed, self)
84 self.keyboard.bind(on_key_down=self.on_keyboard_down)
85 105
86 # Kivy events 106 # Kivy events
87 def add_widget(self, widget, index=0): 107 def add_widget(self, widget, index=0):
@@ -112,6 +132,8 @@ class Mapping(RelativeLayout):
112 thread.join() 132 thread.join()
113 133
114 sys.exit() 134 sys.exit()
135 elif 'ctrl' in modifiers and keycode[0] == 114:
136 threading.Thread(name="MSReload", target=self.reload).start()
115 return True 137 return True
116 138
117 # Helpers 139 # Helpers
@@ -143,6 +165,8 @@ class Mapping(RelativeLayout):
143 self.ready_color = [0, 1, 0, 1] 165 self.ready_color = [0, 1, 0, 1]
144 elif result == "partial": 166 elif result == "partial":
145 self.ready_color = [1, 0, 0, 1] 167 self.ready_color = [1, 0, 0, 1]
168 else:
169 self.ready_color = [1, 165/255, 0, 1]
146 170
147 ## Some global actions 171 ## Some global actions
148 def stop_all_running(self): 172 def stop_all_running(self):
@@ -347,8 +371,14 @@ class Mapping(RelativeLayout):
347 music_properties[filename], 371 music_properties[filename],
348 filename) 372 filename)
349 373
350 seen_files[filename] = MusicFile( 374 if filename in self.open_files:
351 filename, self, **music_property) 375 self.open_files[filename]\
376 .reload_properties(**music_property)
377
378 seen_files[filename] = self.open_files[filename]
379 else:
380 seen_files[filename] = MusicFile(
381 filename, self, **music_property)
352 382
353 if filename not in key_properties[mapped_key]['files']: 383 if filename not in key_properties[mapped_key]['files']:
354 key_properties[mapped_key]['files'] \ 384 key_properties[mapped_key]['files'] \
diff --git a/helpers/music_file.py b/helpers/music_file.py
index 9976306..ba86142 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -92,6 +92,31 @@ class MusicFile:
92 92
93 threading.Thread(name="MSMusicLoad", target=self.load).start() 93 threading.Thread(name="MSMusicLoad", target=self.load).start()
94 94
95 def reload_properties(self, name=None, gain=1):
96 self.name = name or self.filename
97 if gain != self.initial_volume_factor:
98 self.initial_volume_factor = gain
99 self.reload_music_file()
100
101 def reload_music_file(self):
102 with file_lock:
103 try:
104 debug_print("Reloading « {} »".format(self.name))
105 initial_db_gain = gain(self.initial_volume_factor * 100)
106 self.audio_segment = pydub.AudioSegment \
107 .from_file(self.filename) \
108 .set_frame_rate(Config.frame_rate) \
109 .set_channels(Config.channels) \
110 .set_sample_width(Config.sample_width) \
111 .apply_gain(initial_db_gain)
112 except Exception as e:
113 error_print("failed to reload « {} »: {}"\
114 .format(self.name, e))
115 self.loading_error = e
116 self.to_failed()
117 else:
118 debug_print("Reloaded « {} »".format(self.name))
119
95 # Machine related events 120 # Machine related events
96 def on_enter_loading(self): 121 def on_enter_loading(self):
97 with file_lock: 122 with file_lock: