Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to start/stop continuous sounds that are specific to a Screen? #101

Closed
pixelzoom opened this issue Jul 7, 2021 · 3 comments
Closed
Assignees

Comments

@pixelzoom
Copy link
Contributor

The Discrete screen has a checkbox/slider control for the sound associated with the Fourier series:

screenshot_1050

This is a continous sound. And I just discovered that switching screens does NOT stop this sound.

@jbphet Does soundManager provide any support for screen-specific sounds? Or do I need to handle this myself? If I need to handle it myself, what is the recommended pattern?

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Jul 7, 2021

In the above commit, I added a workaround that involves observing phet.joist.sim.screenProperty, and controlling the Fourier series sound based on whether the Discrete screen is selected. This needs to be done by the Screen, because ScreenView and Model do not know about (and should not know about) Screen. It also can't be wired up right away, because the model (and view) have not been constructed. So I had to override Screen.initializeModel, which is documented as @public (joist-internal) and should therefore not be accessed or overridden outside of joist.

I also don't think this is much of a solution because it would need to be duplicated in each sim that has this need. And that will be any sim that has a continous sound.

@jbphet is there a better way? Has this issue been considered in the design of UI sounds?

@pixelzoom pixelzoom changed the title How to start/stop screen-specific sounds? How to start/stop continuous sounds that are specific to a Screen? Jul 7, 2021
@jbphet
Copy link
Contributor

jbphet commented Jul 8, 2021

In the early days of this library I asked about how best to support this feature, and the consensus was that in cases where a sound needed to be muted when a screen change occurred, we should associate the sound generator with a scenery Node instead of a screen. That is supported through the associatedViewNode option to the soundManager.addSoundGenerator method. There is an example usage in tambo's TestingScreenView, and you can try it out by going to the "Testing" screen in the tambo demo, selecting the "Long Sound Test", kicking off the lightning, and switching screens. This example is not a loop, but I'm fairly certain that the loop case was tested and should work. Let me know if it doesn't.

@pixelzoom
Copy link
Contributor Author

Awesome, associatedViewNode works great. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants