Skip to content

Commit

Permalink
added (back) sound for photon absorption, see #236
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Dec 17, 2019
1 parent aa4cf83 commit 4482362
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
24 changes: 18 additions & 6 deletions js/moleculesandlight/view/MoleculesAndLightScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ define( require => {

// sounds
const breakApartSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/break-apart.mp3' );
const infraredPhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-ir.mp3' );
const infraredPhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-ir.mp3' );
const microwavePhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-microwave.mp3' );
const moleculeEnergizedSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/glow-loop-higher.mp3' );
const microwavePhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-microwave.mp3' );
const photonAbsorbedSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/absorb-loop.mp3' );
const rotationClockwiseSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/rotate-clockwise.mp3' );
const rotationCounterclockwiseSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/rotate-counterclockwise.mp3' );
const ultravioletPhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-uv.mp3' );
const ultravioletPhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-uv.mp3' );
const vibrationSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/vibration.mp3' );
const microwavePhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-microwave.mp3' );
const infraredPhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-ir.mp3' );
const visiblePhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-visible.mp3' );
const ultravioletPhotonFromMoleculeSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-release-uv.mp3' );
const microwavePhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-microwave.mp3' );
const infraredPhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-ir.mp3' );
const visiblePhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-visible.mp3' );
const ultravioletPhotonInitialEmissionSoundInfo = require( 'sound!MOLECULES_AND_LIGHT/photon-emit-uv.mp3' );

// constants
// Model-view transform for intermediate coordinates.
Expand Down Expand Up @@ -232,6 +233,13 @@ define( require => {
// sound generation
//-----------------------------------------------------------------------------------------------------------------

// photon absorbed sound
const photonAbsorbedSound = new SoundClip( photonAbsorbedSoundInfo, { initialOutputLevel: 0.025 } );
soundManager.addSoundGenerator( photonAbsorbedSound );
const photonAbsorbedSoundPlayer = () => {
photonAbsorbedSound.play();
};

// TODO - @Ashton-Morris - please adjust level if needed, see https://github.com/phetsims/molecules-and-light/issues/233
// sound to play when molecule becomes "energized", which is depicted as glowing in the view
const moleculeEnergizedLoop = new SoundClip( moleculeEnergizedSoundInfo, {
Expand Down Expand Up @@ -312,6 +320,7 @@ define( require => {

// function that adds all of the listeners involved in creating sound
const addSoundPlayersToMolecule = molecule => {
molecule.photonAbsorbedEmitter.addListener( photonAbsorbedSoundPlayer );
molecule.highElectronicEnergyStateProperty.link( updateMoleculeEnergizedSound );
molecule.brokeApartEmitter.addListener( breakApartSoundPlayer );
molecule.rotatingProperty.link( updateRotationSound );
Expand All @@ -324,6 +333,9 @@ define( require => {

// remove listeners when the molecules go away
photonAbsorptionModel.activeMolecules.addItemRemovedListener( function( removedMolecule ) {
if ( removedMolecule.photonAbsorbedEmitter.hasListener( photonAbsorbedSoundPlayer ) ) {
removedMolecule.photonAbsorbedEmitter.removeListener( photonAbsorbedSoundPlayer );
}
if ( removedMolecule.highElectronicEnergyStateProperty.hasListener( updateMoleculeEnergizedSound ) ) {
removedMolecule.highElectronicEnergyStateProperty.unlink( updateMoleculeEnergizedSound );
}
Expand Down
4 changes: 4 additions & 0 deletions js/photon-absorption/model/Molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ define( require => {
// @public, set by PhotonAbsorptionModel
this.photonGroupTandem = null;

// @public (read-only) {Emitter} - emitter for when a photon is absorbed
this.photonAbsorbedEmitter = new Emitter( { parameters: [ { valueType: Photon } ] } );

// @public (read-only) {Emitter} - emitter for when a photon is emitted
this.photonEmittedEmitter = new Emitter( { parameters: [ { valueType: Photon } ] } );

Expand Down Expand Up @@ -431,6 +434,7 @@ define( require => {
absorbPhoton = true;
this.activePhotonAbsorptionStrategy = candidateAbsorptionStrategy;
this.activePhotonAbsorptionStrategy.queryAndAbsorbPhoton( photon );
this.photonAbsorbedEmitter.emit( photon );
}
else {

Expand Down
Binary file added sounds/absorb-loop.mp3
Binary file not shown.
8 changes: 8 additions & 0 deletions sounds/license.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"absorb-loop.mp3": {
"text": [
"Copyright 2018 University of Colorado Boulder"
],
"projectURL": "http://phet.colorado.edu",
"license": "contact [email protected]",
"notes": "created by Ashton Morris (PhET Interactive Simulations)"
},
"glow-loop-higher.mp3": {
"text": [
"Copyright 2018 University of Colorado Boulder"
Expand Down

0 comments on commit 4482362

Please sign in to comment.