@ -733,6 +733,7 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
subtype = " PERCENTAGE " )
subtype = " PERCENTAGE " )
def convert_callback_message ( self , exporter , so , msg , target , wait ) :
def convert_callback_message ( self , exporter , so , msg , target , wait ) :
assert not self . is_random_sound , " Callbacks are not available for random sounds "
cb = plEventCallbackMsg ( )
cb = plEventCallbackMsg ( )
cb . addReceiver ( target )
cb . addReceiver ( target )
cb . event = kEnd
cb . event = kEnd
@ -747,6 +748,33 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
if not soundemit . enabled :
if not soundemit . enabled :
self . raise_error ( " ' {} ' is not a valid Sound Emitter " . format ( self . emitter_object . name ) )
self . raise_error ( " ' {} ' is not a valid Sound Emitter " . format ( self . emitter_object . name ) )
if self . is_random_sound :
yield from self . _convert_random_sound_msg ( exporter , so )
else :
yield from self . _convert_sound_emitter_msg ( exporter , so )
def _convert_random_sound_msg ( self , exporter , so ) :
# Yas, plAnimCmdMsg
msg = plAnimCmdMsg ( )
msg . addReceiver ( exporter . mgr . find_key ( plRandomSoundMod , bl = self . emitter_object ) )
if self . action == " kPlay " :
msg . setCmd ( plAnimCmdMsg . kContinue , True )
elif self . action == " kStop " :
msg . setCmd ( plAnimCmdMsg . kStop , True )
elif self . action == " kToggleState " :
msg . setCmd ( plAnimCmdMsg . kToggleState , True )
if self . volume != " CURRENT " :
# No, you are not imagining things...
msg . setCmd ( plAnimCmdMsg . kSetSpeed , True )
msg . speed = self . volume_pct / 100.0 if self . volume == " CUSTOM " else 0.0
yield msg
def _convert_sound_emitter_msg ( self , exporter , so ) :
soundemit = self . emitter_object . plasma_modifiers . soundemit
# Always test the specified audible for validity
# Always test the specified audible for validity
if self . sound_name and soundemit . sounds . get ( self . sound_name , None ) is None :
if self . sound_name and soundemit . sounds . get ( self . sound_name , None ) is None :
self . raise_error ( " Invalid Sound ' {} ' requested from Sound Emitter ' {} ' " . format ( self . sound_name , self . emitter_object . name ) )
self . raise_error ( " Invalid Sound ' {} ' requested from Sound Emitter ' {} ' " . format ( self . sound_name , self . emitter_object . name ) )
@ -787,26 +815,43 @@ class PlasmaSoundMsgNode(idprops.IDPropObjectMixin, PlasmaMessageWithCallbacksNo
def draw_buttons ( self , context , layout ) :
def draw_buttons ( self , context , layout ) :
layout . prop ( self , " emitter_object " )
layout . prop ( self , " emitter_object " )
if self . emitter_object is not None :
soundemit = self . emitter_object . plasma_modifiers . soundemit
if soundemit . enabled :
layout . prop_search ( self , " sound_name " , soundemit , " sounds " , icon = " SOUND " )
else :
layout . label ( " Not a Sound Emitter " , icon = " ERROR " )
layout . prop ( self , " go_to " )
# Random Sound emitters can only control the entire emitter object, not the
if self . go_to == " TIME " :
# individual sounds.
layout . prop ( self , " time " )
random = self . is_random_sound
if not random :
if self . emitter_object is not None :
soundemit = self . emitter_object . plasma_modifiers . soundemit
if soundemit . enabled :
layout . prop_search ( self , " sound_name " , soundemit , " sounds " , icon = " SOUND " )
else :
layout . label ( " Not a Sound Emitter " , icon = " ERROR " )
layout . prop ( self , " go_to " )
if self . go_to == " TIME " :
layout . prop ( self , " time " )
layout . prop ( self , " action " )
layout . prop ( self , " action " )
if self . volume == " CUSTOM " :
if self . volume == " CUSTOM " :
layout . prop ( self , " volume_pct " )
layout . prop ( self , " volume_pct " )
layout . prop ( self , " looping " )
if not random :
layout . prop ( self , " looping " )
layout . prop ( self , " volume " )
layout . prop ( self , " volume " )
@property
def has_callbacks ( self ) :
return not self . is_random_sound
@classmethod
@classmethod
def _idprop_mapping ( cls ) :
def _idprop_mapping ( cls ) :
return { " emitter_object " : " object_name " }
return { " emitter_object " : " object_name " }
@property
def is_random_sound ( self ) :
if self . emitter_object is not None :
return self . emitter_object . plasma_modifiers . random_sound . enabled
return False
class PlasmaTimerCallbackMsgNode ( PlasmaMessageWithCallbacksNode , bpy . types . Node ) :
class PlasmaTimerCallbackMsgNode ( PlasmaMessageWithCallbacksNode , bpy . types . Node ) :
bl_category = " MSG "
bl_category = " MSG "