aboutsummaryrefslogtreecommitdiff
path: root/music_sampler
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2017-06-26 17:36:40 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2017-06-26 17:36:40 +0200
commitb798117bb79038ae7495ea4fdb5254d15c7e4b63 (patch)
tree0d10041b953ac1918f2cf95b4ddb371a377f5b1f /music_sampler
parentd028768179d4fd1555831e26daaa9aae9ac94e85 (diff)
downloadMusicSampler-b798117bb79038ae7495ea4fdb5254d15c7e4b63.tar.gz
MusicSampler-b798117bb79038ae7495ea4fdb5254d15c7e4b63.tar.zst
MusicSampler-b798117bb79038ae7495ea4fdb5254d15c7e4b63.zip
Change "keys" hash to "key_properties" in config.yml1.4.0
Diffstat (limited to 'music_sampler')
-rw-r--r--music_sampler/mapping.py100
1 files changed, 53 insertions, 47 deletions
diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py
index a526ad2..193f5e5 100644
--- a/music_sampler/mapping.py
+++ b/music_sampler/mapping.py
@@ -320,13 +320,60 @@ class Mapping(RelativeLayout):
320 else: 320 else:
321 return {} 321 return {}
322 322
323 def check_mapped_key(mapped_keys, key): 323 def check_mapped_key(actions, key):
324 if not isinstance(mapped_keys[key], list): 324 if not isinstance(actions, list):
325 warn_print("key config '{}' is not an array, ignored" 325 warn_print("key config '{}' is not an array, ignored"
326 .format(key)) 326 .format(key))
327 return [] 327 return []
328 else: 328 else:
329 return mapped_keys[key] 329 return actions
330
331 def append_actions_to_key(mapped_key, actions, aliases, seen_files, music_properties, key_properties):
332 for index, action in enumerate(check_mapped_key(actions, mapped_key)):
333 if not isinstance(action, dict) or\
334 not len(action) == 1 or\
335 not isinstance(list(action.values())[0] or {}, dict):
336 warn_print("action number {} of key '{}' is invalid, "
337 "ignored".format(index + 1, mapped_key))
338 continue
339 append_action_to_key(action, mapped_key, aliases, seen_files, music_properties, key_properties)
340
341 def append_action_to_key(action, mapped_key, aliases, seen_files, music_properties, key_properties):
342 action_name = list(action)[0]
343 action_args = {}
344 if action[action_name] is None:
345 action[action_name] = {}
346
347 include_aliases(action[action_name], aliases)
348
349 for argument in action[action_name]:
350 if argument == 'file':
351 filename = str(action[action_name]['file'])
352 if filename not in seen_files:
353 music_property = check_music_property(
354 music_properties[filename],
355 filename)
356
357 if filename in self.open_files:
358 self.open_files[filename]\
359 .reload_properties(**music_property)
360
361 seen_files[filename] =\
362 self.open_files[filename]
363 else:
364 seen_files[filename] = MusicFile(
365 filename, self, **music_property)
366
367 if filename not in key_properties[mapped_key]['files']:
368 key_properties[mapped_key]['files'] \
369 .append(seen_files[filename])
370
371 action_args['music'] = seen_files[filename]
372 else:
373 action_args[argument] = action[action_name][argument]
374
375 key_properties[mapped_key]['actions'] \
376 .append([action_name, action_args])
330 377
331 def check_music_property(music_property, filename): 378 def check_music_property(music_property, filename):
332 if not isinstance(music_property, dict): 379 if not isinstance(music_property, dict):
@@ -400,52 +447,11 @@ class Mapping(RelativeLayout):
400 check_key_property(key_prop, key) 447 check_key_property(key_prop, key)
401 448
402 key_properties[key]["properties"].update(key_prop) 449 key_properties[key]["properties"].update(key_prop)
450 if 'actions' in key_prop:
451 append_actions_to_key(key, key_prop['actions'], aliases, seen_files, music_properties, key_properties)
403 452
404 for mapped_key in check_mapped_keys(config): 453 for mapped_key in check_mapped_keys(config):
405 for index, action in enumerate(check_mapped_key( 454 append_actions_to_key(mapped_key, config['keys'][mapped_key], aliases, seen_files, music_properties, key_properties)
406 config['keys'], mapped_key)):
407 if not isinstance(action, dict) or\
408 not len(action) == 1 or\
409 not isinstance(list(action.values())[0] or {}, dict):
410 warn_print("action number {} of key '{}' is invalid, "
411 "ignored".format(index + 1, mapped_key))
412 continue
413
414 action_name = list(action)[0]
415 action_args = {}
416 if action[action_name] is None:
417 action[action_name] = {}
418
419 include_aliases(action[action_name], aliases)
420
421 for argument in action[action_name]:
422 if argument == 'file':
423 filename = str(action[action_name]['file'])
424 if filename not in seen_files:
425 music_property = check_music_property(
426 music_properties[filename],
427 filename)
428
429 if filename in self.open_files:
430 self.open_files[filename]\
431 .reload_properties(**music_property)
432
433 seen_files[filename] =\
434 self.open_files[filename]
435 else:
436 seen_files[filename] = MusicFile(
437 filename, self, **music_property)
438
439 if filename not in key_properties[mapped_key]['files']:
440 key_properties[mapped_key]['files'] \
441 .append(seen_files[filename])
442
443 action_args['music'] = seen_files[filename]
444 else:
445 action_args[argument] = action[action_name][argument]
446
447 key_properties[mapped_key]['actions'] \
448 .append([action_name, action_args])
449 455
450 return (key_properties, seen_files) 456 return (key_properties, seen_files)
451 457