2017-04-08 00:34:45 +02:00
|
|
|
import bpy
|
2020-09-08 23:21:41 +02:00
|
|
|
|
2017-04-08 00:34:45 +02:00
|
|
|
from arm.logicnode.arm_nodes import *
|
|
|
|
|
2020-09-08 23:21:41 +02:00
|
|
|
|
2020-09-08 21:16:20 +02:00
|
|
|
class PlaySoundNode(ArmLogicTreeNode):
|
2020-10-05 19:55:56 +02:00
|
|
|
"""Plays the given sound.
|
2020-09-28 15:58:41 +02:00
|
|
|
|
|
|
|
@input Play: Plays the sound, or if paused, resumes the playback.
|
|
|
|
The exact behaviour depends on the Retrigger option (see below).
|
|
|
|
@input Pause: Pauses the playing sound. If no sound is playing,
|
|
|
|
nothing happens.
|
|
|
|
@input Stop: Stops the playing sound. If the playback is paused,
|
|
|
|
this will reset the playback position to the start of the sound.
|
|
|
|
|
|
|
|
@output Out: activated once when Play is activated.
|
|
|
|
@output Running: activated while the playback is active.
|
|
|
|
@output Done: activated when the playback has finished or was
|
|
|
|
stopped manually.
|
|
|
|
|
|
|
|
@option Sound: The sound that will be played.
|
|
|
|
@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
|
|
|
|
will continue at the current position.
|
|
|
|
@option Sample Rate: Manually override the sample rate of the sound
|
|
|
|
(this controls the pitch and the playback speed).
|
|
|
|
"""
|
2018-02-21 23:23:23 +01:00
|
|
|
bl_idname = 'LNPlaySoundRawNode'
|
2017-04-08 00:34:45 +02:00
|
|
|
bl_label = 'Play Sound'
|
2020-09-13 11:27:58 +02:00
|
|
|
arm_version = 1
|
2017-04-08 00:34:45 +02:00
|
|
|
|
2019-01-21 16:48:11 +01:00
|
|
|
property0: PointerProperty(name='', type=bpy.types.Sound)
|
2020-05-15 23:22:41 +02:00
|
|
|
property1: BoolProperty(
|
2020-05-15 23:32:48 +02:00
|
|
|
name='Loop',
|
|
|
|
description='Play the sound in a loop',
|
|
|
|
default=False)
|
|
|
|
property2: BoolProperty(
|
2020-05-16 00:28:52 +02:00
|
|
|
name='Retrigger',
|
2020-09-28 15:58:41 +02:00
|
|
|
description='Play the sound from the beginning every time',
|
2020-05-16 00:28:52 +02:00
|
|
|
default=False)
|
|
|
|
property3: BoolProperty(
|
2020-05-15 23:22:41 +02:00
|
|
|
name='Use Custom Sample Rate',
|
|
|
|
description='If enabled, override the default sample rate',
|
|
|
|
default=False)
|
2020-05-16 00:28:52 +02:00
|
|
|
property4: IntProperty(
|
2020-05-15 23:22:41 +02:00
|
|
|
name='Sample Rate',
|
|
|
|
description='Set the sample rate used to play this sound',
|
|
|
|
default=44100,
|
|
|
|
min=0)
|
2018-02-21 23:23:23 +01:00
|
|
|
|
2017-04-08 00:34:45 +02:00
|
|
|
def init(self, context):
|
2020-09-13 11:27:58 +02:00
|
|
|
super(PlaySoundNode, self).init(context)
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_input('ArmNodeSocketAction', 'Play')
|
|
|
|
self.add_input('ArmNodeSocketAction', 'Pause')
|
|
|
|
self.add_input('ArmNodeSocketAction', 'Stop')
|
|
|
|
self.add_output('ArmNodeSocketAction', 'Out')
|
2020-09-20 20:10:01 +02:00
|
|
|
self.add_output('ArmNodeSocketAction', 'Is Running')
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_output('ArmNodeSocketAction', 'Done')
|
2017-04-08 00:34:45 +02:00
|
|
|
|
2018-02-21 23:23:23 +01:00
|
|
|
def draw_buttons(self, context, layout):
|
|
|
|
layout.prop_search(self, 'property0', bpy.data, 'sounds', icon='NONE', text='')
|
|
|
|
|
2020-05-16 00:28:52 +02:00
|
|
|
col = layout.column(align=True)
|
|
|
|
col.prop(self, 'property1')
|
|
|
|
col.prop(self, 'property2')
|
2020-05-15 23:32:48 +02:00
|
|
|
|
2020-05-15 23:22:41 +02:00
|
|
|
layout.label(text="Overrides:")
|
|
|
|
# Sample rate
|
|
|
|
split = layout.split(factor=0.15, align=False)
|
2020-05-16 00:28:52 +02:00
|
|
|
split.prop(self, 'property3', text="")
|
2020-05-15 23:22:41 +02:00
|
|
|
row = split.row()
|
2020-05-16 00:28:52 +02:00
|
|
|
if not self.property3:
|
2020-05-15 23:22:41 +02:00
|
|
|
row.enabled = False
|
2020-05-16 00:28:52 +02:00
|
|
|
row.prop(self, 'property4')
|
2020-05-15 23:22:41 +02:00
|
|
|
|
2020-09-09 20:48:35 +02:00
|
|
|
add_node(PlaySoundNode, category=PKG_AS_CATEGORY)
|