Skip to content

Commit

Permalink
Merge pull request #2981 from t3du/sound
Browse files Browse the repository at this point in the history
Play Sound Node: add option for sound/sound name
  • Loading branch information
luboslenco committed Dec 18, 2023
2 parents 495cbb3 + 12562d8 commit d5dfd84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Sources/armory/logicnode/PlaySoundRawNode.hx
Expand Up @@ -15,6 +15,8 @@ class PlaySoundRawNode extends LogicNode {
/** Whether to stream the sound from disk **/
public var property5: Bool;

public var property6: String;

var sound: kha.Sound = null;
var channel: kha.audio1.AudioChannel = null;

Expand All @@ -26,7 +28,7 @@ class PlaySoundRawNode extends LogicNode {
switch (from) {
case Play:
if (sound == null) {
iron.data.Data.getSound(property0, function(s: kha.Sound) {
iron.data.Data.getSound(property6 == 'Sound' ? property0 : inputs[5].get(), function(s: kha.Sound) {
this.sound = s;
});
}
Expand Down
25 changes: 23 additions & 2 deletions blender/arm/logicnode/sound/LN_play_sound.py
Expand Up @@ -20,7 +20,9 @@ class PlaySoundNode(ArmLogicTreeNode):
@output Done: activated when the playback has finished or was
stopped manually.
@option Sound/Sound Name: specify a sound by a resource or a string name
@option Sound: The sound that will be played.
@option Stream: Stream the sound from disk.
@option Loop: Whether to loop the playback.
@option Retrigger: If true, the playback position will be reset to
the beginning on each activation of Play. If false, the playback
Expand All @@ -31,9 +33,16 @@ class PlaySoundNode(ArmLogicTreeNode):
bl_idname = 'LNPlaySoundRawNode'
bl_label = 'Play Sound'
bl_width_default = 200
arm_version = 2
arm_version = 3

def remove_extra_inputs(self, context):
while len(self.inputs) > 5:
self.inputs.remove(self.inputs[-1])
if self.property6 == 'Sound Name':
self.add_input('ArmStringSocket', 'Sound Name')

property0: HaxePointerProperty('property0', name='', type=bpy.types.Sound)

property1: HaxeBoolProperty(
'property1',
name='Loop',
Expand Down Expand Up @@ -62,7 +71,14 @@ class PlaySoundNode(ArmLogicTreeNode):
default=False
)

property6: HaxeEnumProperty(
'property6',
items = [('Sound', 'Sound', 'Sound'),
('Sound Name', 'Sound Name', 'Sound Name')],
name='', default='Sound', update=remove_extra_inputs)

def arm_init(self, context):

self.add_input('ArmNodeSocketAction', 'Play')
self.add_input('ArmNodeSocketAction', 'Pause')
self.add_input('ArmNodeSocketAction', 'Stop')
Expand All @@ -74,9 +90,14 @@ def arm_init(self, context):
self.add_output('ArmNodeSocketAction', 'Done')

def draw_buttons(self, context, layout):
layout.prop_search(self, 'property0', bpy.data, 'sounds', icon='NONE', text='')

layout.prop(self, 'property6')

col = layout.column(align=True)

if self.property6 == 'Sound':
col.prop_search(self, 'property0', bpy.data, 'sounds', icon='NONE', text='')

col.prop(self, 'property5')
col.prop(self, 'property1')
col.prop(self, 'property2')
Expand Down

0 comments on commit d5dfd84

Please sign in to comment.