Dynamically switching the "Play Sound" on and off
-
On 01/12/2015 at 07:26, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 17
Platform: Windows ;
Language(s) : C++ ; PYTHON ;---------
Hello;dynamically switching the "Play Sound" on and off doesn't seem to work for some reason.
In a script, it's easy enough: I just call
CallCommand(16391);
That works even if I press the button or execute the script or call it from the Customize Commands window while the animation is playing. The sound switches on and off properly.
But I want to do it programmatically: Switch the sound on at frame 30, switch it off at frame 130.
And once I execute this CallCommand from a Python tag, or from the Execute() routine of a C++ tag, it doesn't work. Just does nothing.
Also,
IsCommandChecked(16391)
always returns false - this, too, works fine in the context of a Python command script.
I don't quite see a reason why this command is switched off in the animation context. After all, it's just switching the virtual loudspeaker on or off. Is there any other way to do it? I do not want to play my own sounds through GePlaySnd, I just want to switch the loudspeaker icon during an animation.
-
On 02/12/2015 at 01:51, xxxxxxxx wrote:
Hello,
The Execute() function of a Tag is called in a thread context. It is not allowed to perform GUI operations in this context. CallCommand() is the exact same as clicking on the command icon in the GUI so it and other related functions are only allowed from the main thread, not from other threads.
Scripts in the Script Manager on the other hand are executed from the main thread so they can use CallCommand().
You could try to send core messages from your tag and catch these messages in a MessageData plugin. Such a MessageData plugin can then execute code from the main thread.
Best wishes,
Sebastian -
On 03/12/2015 at 00:41, xxxxxxxx wrote:
Thanks, the message seems to work now.
However, it raises another question that may be much more complicated: What's the timing on the execution now?
Some tag in a thread in the evaluation of the tree (which is set at, let's say, Animation 0) sends a message.
The main thread needs to receive the message and execute it. (I don't know if there is a queue for the message involved, or maybe even more messaging before the loudspeaker is shut down...)
The sound is probably played in a third thread and needs to react to the loudspeaker shutdown.But when is the sound played, and when is the loudspeaker shutoff actually executed?
If I send the message from that Animation 0 timing during a frame, will the sound for this frame be played or not? Has it already started being played (being a 1/25 sec sound snippet)? I can imagine that the sound breaks off in the middle of the frame. Can we at least say that the sound of the next frame is not starting to play if the message is sent during the current frame?
(Much of this depends on how the sound is played / sent to the sound card, and how a switchoff of the loudspeaker affects the playing...)
Thanks for having a look!
-
On 03/12/2015 at 02:22, xxxxxxxx wrote:
Hello,
the core message sent is stored in a queue and processed when the calculation of the complete frame has finished and before the next frame is calculated. Using CallCommand() will turn a switch that will be evaluated at the beginning of the next scene calculation (GePlaySnd::Stop() is called).
Best wishes,
Sebastian -
On 03/12/2015 at 13:03, xxxxxxxx wrote:
Thanks, that works perfectly fine!