PlaySoundRawNode: add pause/stop functionality
This commit is contained in:
parent
49c5b1b129
commit
18ebd3444f
|
@ -11,15 +11,68 @@ class PlaySoundRawNode extends LogicNode {
|
|||
/** Playback sample rate */
|
||||
public var property3: Int;
|
||||
|
||||
var sound: kha.Sound = null;
|
||||
var channel: kha.audio1.AudioChannel = null;
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
}
|
||||
|
||||
override function run(from: Int) {
|
||||
iron.data.Data.getSound(property0, function(sound: kha.Sound) {
|
||||
if (property2) sound.sampleRate = property3;
|
||||
iron.system.Audio.play(sound, property1);
|
||||
});
|
||||
runOutput(0);
|
||||
switch (from) {
|
||||
case Play:
|
||||
if (sound == null) {
|
||||
iron.data.Data.getSound(property0, function(s: kha.Sound) {
|
||||
this.sound = s;
|
||||
});
|
||||
}
|
||||
|
||||
// Resume
|
||||
if (channel != null) {
|
||||
channel.play();
|
||||
}
|
||||
// Start
|
||||
else if (sound != null) {
|
||||
if (property2) sound.sampleRate = property3;
|
||||
channel = iron.system.Audio.play(sound, property1);
|
||||
}
|
||||
|
||||
tree.notifyOnUpdate(this.onUpdate);
|
||||
runOutput(0);
|
||||
|
||||
case Pause:
|
||||
if (channel != null) {
|
||||
channel.pause();
|
||||
}
|
||||
|
||||
tree.removeUpdate(this.onUpdate);
|
||||
|
||||
case Stop:
|
||||
if (channel != null) {
|
||||
channel.stop();
|
||||
}
|
||||
|
||||
tree.removeUpdate(this.onUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
function onUpdate() {
|
||||
if (channel != null) {
|
||||
// Done
|
||||
if (channel.finished) {
|
||||
channel = null;
|
||||
runOutput(2);
|
||||
}
|
||||
// Running
|
||||
else {
|
||||
runOutput(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum abstract PlayState(Int) from Int to Int {
|
||||
var Play = 0;
|
||||
var Pause = 1;
|
||||
var Stop = 2;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,12 @@ class PlaySoundNode(Node, ArmLogicTreeNode):
|
|||
min=0)
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAction', 'In')
|
||||
self.inputs.new('ArmNodeSocketAction', 'Play')
|
||||
self.inputs.new('ArmNodeSocketAction', 'Pause')
|
||||
self.inputs.new('ArmNodeSocketAction', 'Stop')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Running')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Done')
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.prop_search(self, 'property0', bpy.data, 'sounds', icon='NONE', text='')
|
||||
|
|
Loading…
Reference in a new issue