001: /*
002: * $RCSfile: SimpleSoundsBehavior.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.2 $
041: * $Date: 2007/02/09 17:21:52 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.examples.sound;
046:
047: import javax.media.j3d.*;
048: import javax.vecmath.*;
049: import java.net.URL;
050: import java.util.Enumeration;
051:
052: // User defined audio behavior class
053: public class SimpleSoundsBehavior extends Behavior {
054: WakeupOnElapsedTime wt;
055: WakeupOnBehaviorPost wp;
056: BackgroundSound sound1 = new BackgroundSound();
057: PointSound sound2 = new PointSound();
058: PointSound sound3 = new PointSound();
059: static int WAKEUP_SOUND = 0;
060: int soundIndex = 0;
061: URL URLName1;
062: URL URLName2;
063: URL URLName3;
064: BoundingSphere bounds;
065:
066: // Override Behavior's initialize method to setup wakeup criteria
067: public void initialize() {
068: MediaContainer sample1 = new MediaContainer();
069: MediaContainer sample2 = new MediaContainer();
070: MediaContainer sample3 = new MediaContainer();
071: sample1.setCapability(MediaContainer.ALLOW_URL_WRITE);
072: sample1.setCapability(MediaContainer.ALLOW_URL_READ);
073: sample1.setURLObject(URLName1);
074: //sample1.setCacheEnable(false);
075: sound1.setLoop(0);
076: sound1.setContinuousEnable(false);
077: sound1.setReleaseEnable(false);
078: sound1.setSoundData(sample1);
079: sound1.setInitialGain(0.7f);
080: sample2.setCapability(MediaContainer.ALLOW_URL_WRITE);
081: sample2.setCapability(MediaContainer.ALLOW_URL_READ);
082: sample2.setURLObject(URLName2);
083: sound2.setLoop(Sound.INFINITE_LOOPS);
084: sound2.setContinuousEnable(false);
085: sound2.setReleaseEnable(false);
086: sound2.setSoundData(sample2);
087: sound2.setInitialGain(2.0f);
088: Point3f sound2Pos = new Point3f(-30.0f, 0.0f, 0.0f);
089: sound2.setPosition(sound2Pos);
090: sample3.setCapability(MediaContainer.ALLOW_URL_WRITE);
091: sample3.setCapability(MediaContainer.ALLOW_URL_READ);
092: sample3.setURLObject(URLName3);
093: sound3.setContinuousEnable(false);
094: sound3.setReleaseEnable(false);
095: sound3.setSoundData(sample3);
096: sound3.setInitialGain(4.0f);
097: Point3f sound3Pos = new Point3f(30.0f, 0.0f, 0.0f);
098: sound3.setPosition(sound3Pos);
099:
100: wt = new WakeupOnElapsedTime(2000);
101: WakeupOnElapsedTime wp = new WakeupOnElapsedTime(5000);
102: wakeupOn(wp);
103: }
104:
105: // Override Behavior's stimulus method to handle the event
106: public void processStimulus(Enumeration criteria) {
107:
108: switch (soundIndex) {
109: // Active
110: case 0:
111: // System.out.println("****Enable First Sound");
112: sound1.setEnable(true);
113: wakeupOn(wt);
114: break;
115: case 1:
116: // System.out.println("********Enable Second Sound");
117: sound2.setEnable(true);
118: wakeupOn(wt);
119: break;
120: case 2:
121: case 4:
122: case 6:
123: case 8:
124: case 10:
125: // System.out.println("************Enable Third Sound");
126: sound3.setEnable(true);
127: wakeupOn(wt);
128: break;
129: case 3:
130: case 5:
131: case 7:
132: case 9:
133: // System.out.println("************Disable Third Sound");
134: sound3.setEnable(false);
135: wakeupOn(wt);
136: break;
137:
138: case 11:
139: // System.out.println("********Disable Second Sound");
140: sound2.setEnable(false);
141: wakeupOn(wt);
142: break;
143: case 12:
144: // System.out.println("****Disable First Sound");
145: sound1.setEnable(false);
146: System.out.println("SimpleSounds: test complete");
147: wt = new WakeupOnElapsedTime(400000);
148: wakeupOn(wt);
149: break;
150:
151: default:
152: break;
153: }
154: soundIndex++;
155: }
156:
157: //
158: // Constructor for rotation behavior.
159: // Parameters: sound node
160: // sample file name
161: // sound node's bounds
162: //
163: public SimpleSoundsBehavior(BackgroundSound sound1,
164: PointSound sound2, PointSound sound3, URL urlName1,
165: URL urlName2, URL urlName3, BoundingSphere soundBounds) {
166: this .sound1 = sound1;
167: this .sound2 = sound2;
168: this .sound3 = sound3;
169: this .URLName1 = urlName1;
170: this .URLName2 = urlName2;
171: this .URLName3 = urlName3;
172: this .bounds = (BoundingSphere) soundBounds.clone();
173: }
174: }
|