-class MusicFile(Machine):
- def __init__(self, filename, mapping, name = None, gain = 1):
- states = [
- 'initial',
- 'loading',
- 'failed',
- { 'name': 'loaded', 'children': ['stopped', 'playing', 'paused', 'stopping'] }
- ]
- transitions = [
- { 'trigger': 'load', 'source': 'initial', 'dest': 'loading'},
- { 'trigger': 'fail', 'source': 'loading', 'dest': 'failed'},
- { 'trigger': 'success', 'source': 'loading', 'dest': 'loaded_stopped'},
- { 'trigger': 'start_playing', 'source': 'loaded_stopped', 'dest': 'loaded_playing'},
- { 'trigger': 'pause', 'source': 'loaded_playing', 'dest': 'loaded_paused'},
- { 'trigger': 'unpause', 'source': 'loaded_paused', 'dest': 'loaded_playing'},
- { 'trigger': 'stop_playing', 'source': ['loaded_playing','loaded_paused'], 'dest': 'loaded_stopping'},
- { 'trigger': 'stopped', 'source': 'loaded_stopping', 'dest': 'loaded_stopped', 'after': 'trigger_stopped_events'}
- ]
-
- Machine.__init__(self, states=states, transitions=transitions, initial='initial')
-
- self.mixer = mapping.mixer or Mixer()
- self.volume = 100
+class MusicFile:
+ STATES = [
+ 'initial',
+ 'loading',
+ 'failed',
+ {
+ 'name': 'loaded',
+ 'children': [
+ 'playing',
+ 'paused',
+ 'stopping'
+ ]
+ }
+ ]
+ TRANSITIONS = [
+ {
+ 'trigger': 'load',
+ 'source': 'initial',
+ 'dest': 'loading',
+ 'after': 'poll_loaded'
+ },
+ {
+ 'trigger': 'fail',
+ 'source': 'loading',
+ 'dest': 'failed'
+ },
+ {
+ 'trigger': 'success',
+ 'source': 'loading',
+ 'dest': 'loaded'
+ },
+ {
+ 'trigger': 'start_playing',
+ 'source': 'loaded',
+ 'dest': 'loaded_playing',
+ # if a child has no transitions, then it is bubbled to the parent,
+ # and we don't want that. Not useful in that machine precisely.
+ 'conditions': ['is_loaded']
+ },
+ {
+ 'trigger': 'pause',
+ 'source': 'loaded_playing',
+ 'dest': 'loaded_paused'
+ },
+ {
+ 'trigger': 'unpause',
+ 'source': 'loaded_paused',
+ 'dest': 'loaded_playing'
+ },
+ {
+ 'trigger': 'stop_playing',
+ 'source': ['loaded_playing','loaded_paused'],
+ 'dest': 'loaded_stopping'
+ },
+ {
+ 'trigger': 'stopped',
+ 'source': '*',
+ 'dest': 'loaded',
+ 'before': 'trigger_stopped_events',
+ 'conditions': ['is_in_use']
+ }
+ ]
+
+ def __init__(self, filename, mapping, name=None, gain=1):
+ Machine(model=self, states=self.STATES,
+ transitions=self.TRANSITIONS, initial='initial',
+ ignore_invalid_triggers=True)
+
+ self.loaded_callbacks = []