+import math
+import time
+from transitions.extensions import HierarchicalMachine as Machine
+
+class MusicFile(Machine):
+ def __init__(self, filename, lock, channel_id, name = None, gain = 1):
+ states = [
+ 'initial',
+ 'loading',
+ 'failed',
+ { 'name': 'loaded', 'children': ['stopped', 'playing', 'paused'] }
+ ]
+ transitions = [
+ { 'trigger': 'load', 'source': 'initial', 'dest': 'loading'},
+ { 'trigger': 'fail', 'source': 'loading', 'dest': 'failed'},
+ { 'trigger': 'success', 'source': 'loading', 'dest': 'loaded_stopped'},
+ #{ 'trigger': 'play', 'source': 'loaded_stopped', 'dest': 'loaded_playing'},
+ #{ 'trigger': 'pause', 'source': 'loaded_playing', 'dest': 'loaded_paused'},
+ #{ 'trigger': 'stop', 'source': ['loaded_playing','loaded_paused'], 'dest': 'loaded_stopped'}
+ ]
+
+ Machine.__init__(self, states=states, transitions=transitions, initial='initial')