- zavai.log.debug("Stop noise for alarm");
- if (zavai.led.vibrator != null)
- zavai.led.vibrator.pop_state("alarm");
- soundplayer.stop();
+ slave = player;
+ slave.master = this;
+ }
+
+ public bool playing()
+ {
+ return states != null;
+ }
+
+ protected void stop_playing()
+ {
+ if (slave_was_playing)
+ slave.resume();
+ }
+
+ public void push_state(PlayerState state)
+ {
+ // Save current playing position
+ if (states == null)
+ {
+ // We start playing: see about preempting slave
+ slave_was_playing = (slave != null && slave.playing);
+ if (slave_was_playing)
+ slave.pause();
+ } else
+ // We were playing: pause previous sound
+ states.data.pause();
+ state.register(this);
+ states.prepend(state);
+ states.data.resume();
+ }
+
+ public void pop_state(string owner)
+ {
+ // Handle empty list
+ if (states == null) return;
+
+ // Track if the list head changed
+ weak List<PlayerState> old_top = states;
+
+ // Remove state "name" from the stack
+ for (weak List<PlayerState> i = states; i != null; i = i.next)
+ if (i.data.owner == owner)
+ {
+ i.data.stop();
+ states.delete_link(i);
+ break;
+ }
+
+ // If the list head changed, put into action the new top state
+ if (states != old_top)
+ {
+ if (states == null)
+ stop_playing();
+ else
+ states.data.resume();
+ }
+ }
+
+ public void shutdown()
+ {
+ while (states != null)
+ {
+ states.data.stop();
+ states.delete_link(states);
+ }
+ stop_playing();