001: /*
002: * @(#)DemoJMFJ3DLAR.java 1.0, 1 May 2000
003: *
004: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
005: *
006: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
007: * royalty free, license to use, modify and redistribute this
008: * software in source and binary code form,
009: * provided that i) this copyright notice and license appear on all copies of
010: * the software; and ii) Licensee does not utilize the software in a manner
011: * which is disparaging to Silvere Martin-Michiellot.
012: *
013: * This software is provided "AS IS," without a warranty of any kind. ALL
014: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
015: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
016: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
017: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
018: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
020: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
021: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
022: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
023: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
024: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
025: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
026: *
027: * This software is not designed or intended for use in on-line control of
028: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
029: * the design, construction, operation or maintenance of any nuclear
030: * facility. Licensee represents and warrants that it will not use or
031: * redistribute the Software for such purposes.
032: *
033: * @Author: Silvere Martin-Michiellot
034: *
035: */
036:
037: package com.db.media.in;
038:
039: import javax.media.*;
040: import javax.media.format.*;
041: import javax.media.control.*;
042: import java.awt.*;
043: import java.awt.event.*;
044: import java.io.File;
045: import javax.swing.*;
046: import javax.media.j3d.*;
047: import com.sun.j3d.utils.universe.SimpleUniverse;
048:
049: /*
050: * This is the demo program to render live audio given a microphone
051: */
052:
053: public class DemoJMFJ3DLAR extends JFrame implements ActionListener {
054:
055: private JMenuItem printItem;
056: private JMenuItem saveItem;
057: private JMenuItem quitItem;
058:
059: private Canvas3D canvas3D;
060:
061: private SimpleUniverse simpleUniverse;
062:
063: private class AppPanel extends JPanel {
064:
065: public BranchGroup createSceneGraph(String args[]) {
066: // Create the root of the branch graph
067:
068: BranchGroup objRoot;
069:
070: objRoot = new BranchGroup();
071: //this is the place you have to put your code to
072: //DISPLAY SOMETHING in the Canvas3D
073:
074: return objRoot;
075:
076: }
077:
078: // Create the Canvas3D (both on-screen and off-screen)
079: private void createCanvas3D(String[] args) {
080:
081: J3DLiveAudioRenderer j3DLiveAudioRenderer;
082:
083: // Create Canvas3D
084: GraphicsConfiguration config = SimpleUniverse
085: .getPreferredConfiguration();
086:
087: canvas3D = new Canvas3D(config);
088: canvas3D.setSize(600, 450);
089:
090: // Create a simple scene and attach it to the virtual universe
091: BranchGroup scene = createSceneGraph(args);
092: simpleUniverse = new SimpleUniverse(canvas3D);
093: // This will move the ViewPlatform back a bit so the
094: // objects in the scene can be viewed.
095: simpleUniverse.getViewingPlatform()
096: .setNominalViewingTransform();
097: simpleUniverse.addBranchGraph(scene);
098:
099: BranchGroup objects = new BranchGroup();
100:
101: //create a new Sound to play live audio in
102: PointSound sound = new PointSound();
103: objects.addChild(sound);
104:
105: simpleUniverse.addBranchGraph(objects);
106:
107: setLayout(new BorderLayout());
108:
109: //you must have a microphone
110: j3DLiveAudioRenderer = new J3DLiveAudioRenderer(sound);
111: System.out.println("audio processor start");
112:
113: }
114:
115: private AppPanel(String args[]) {
116: setLayout(new BorderLayout());
117:
118: // Create Canvas3D and scene graph
119: createCanvas3D(args);
120: add("Center", canvas3D);
121: }
122:
123: }
124:
125: public void actionPerformed(ActionEvent event) {
126:
127: Object target = event.getSource();
128:
129: if (target == quitItem) {
130: simpleUniverse.removeAllLocales();
131: System.exit(0);
132: }
133:
134: }
135:
136: private JMenuBar createMenuBar() {
137:
138: JMenuBar menuBar = new JMenuBar();
139: JMenu fileMenu = new JMenu("File");
140: quitItem = new JMenuItem("Quit");
141: quitItem.addActionListener(this );
142: fileMenu.add(quitItem);
143: menuBar.add(fileMenu);
144:
145: return menuBar;
146:
147: }
148:
149: private DemoJMFJ3DLAR(String args[]) {
150:
151: this .setTitle("Canvas3D Live Audio Test");
152:
153: // Create and initialize menu bar
154: JPopupMenu.setDefaultLightWeightPopupEnabled(false);
155: this .setJMenuBar(createMenuBar());
156:
157: // Handle the close event
158: this .addWindowListener(new WindowAdapter() {
159: public void windowClosing(WindowEvent winEvent) {
160: System.exit(0);
161: }
162: });
163:
164: // Add main panel to top-level frame and make it visible
165: this .getContentPane().add(new AppPanel(args));
166: this .pack();
167: this .setVisible(true);
168:
169: }
170:
171: public static void main(String[] args) {
172:
173: new DemoJMFJ3DLAR(args);
174:
175: }
176:
177: public static void printUsage() {
178:
179: System.out.println("java DemoJMFJ3DLAR");
180:
181: }
182:
183: }
|