package leenkx.logicnode; class PlaySoundRawNode extends LogicNode { /** The name of the sound */ public var property0: String; /** Whether to loop the playback */ public var property1: Bool; /** Retrigger */ public var property2: Bool; /** Override sample rate */ public var property3: Bool; /** Playback sample rate */ public var property4: Int; /** Whether to stream the sound from disk **/ public var property5: Bool; public var property6: String; #if lnx_audio var sound: kha.Sound = null; var channel: kha.audio1.AudioChannel = null; #end public function new(tree: LogicTree) { super(tree); } override function run(from: Int) { #if lnx_audio switch (from) { case Play: if (property6 == 'Sound' ? sound == null : true) { iron.data.Data.getSound(property6 == 'Sound' ? property0 : inputs[5].get(), function(s: kha.Sound) { this.sound = s; }); } // Resume if (channel != null) { if (property2) channel.stop(); if (property6 == 'Sound Name') channel = iron.system.Audio.play(sound, property1, property5); channel.play(); channel.volume = inputs[4].get(); } // Start else if (sound != null) { if (property3) sound.sampleRate = property4; channel = iron.system.Audio.play(sound, property1, property5); channel.volume = inputs[4].get(); } 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); runOutput(2); case UpdateVolume: if (channel != null) channel.volume = inputs[4].get(); } #end #if !lnx_audio runOutput(0); #end } 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; var UpdateVolume = 3; }