Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

SynthesizerPanel.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
00021  */
00022 
00023 package com.meapsoft.gui;
00024 
00025 import java.awt.*;
00026 import java.awt.event.*;
00027 import java.io.*;
00028 import java.util.*;
00029 import javax.swing.*; 
00030 import javax.swing.border.*; 
00031 
00032 import com.meapsoft.*;
00033 
00034 
00041 public class SynthesizerPanel extends MEAPsoftGUIPanel
00042 {
00043         //synthesizer
00044         String lastEDLFileName;
00045         JCheckBox enableBox;
00046         JLabel fileNameLabel;
00047         JTextField outputFileNameField;
00048         JButton listenButton;
00049         
00053     public SynthesizerPanel(MEAPsoftGUI msg)
00054         {
00055         super(msg);
00056         BuildSynthesizerGUI();
00057 
00058         title = "Synthesizer";
00059         helpURL += "#" + title;
00060     }
00061 
00062         private void BuildSynthesizerGUI()
00063         {
00064                 Color c = new Color((int)(Math.random() * 127 + 127),
00065                                         (int)(Math.random() * 127 + 127),
00066                                         (int)(Math.random() * 127 + 127));
00067         color = c;
00068 
00069                 setBackground(c);
00070                 BoxLayout synthbl = new BoxLayout(this, BoxLayout.Y_AXIS);
00071                 setLayout(synthbl);
00072                 
00073                 JPanel enableSynthPanel = new JPanel();
00074                 enableSynthPanel.setBackground(c);
00075                 
00076                 enableBox = new JCheckBox("ENABLE SYNTHESIZER");
00077                 enableBox.setBackground(c);
00078                 enableBox.setSelected(true);
00079                 enableSynthPanel.add(enableBox);
00080                 
00081                 enableSynthPanel.add(helpButton);
00082 
00083                 add(enableSynthPanel);
00084                 
00085                 JPanel fileIOPanel = new JPanel();
00086                 fileIOPanel.setBackground(c);
00087                 
00088                 JLabel sNL = new JLabel("input edl file: ");
00089                 fileIOPanel.add(sNL);
00090                 fileNameLabel = new JLabel(" " + dataBaseName + ".edl ");
00091                 fileNameLabel.setOpaque(true);
00092                 fileNameLabel.setBackground(c.darker());
00093                 fileIOPanel.add(fileNameLabel);
00094                 add(fileIOPanel);
00095                 
00096                 JPanel synthControlsPanel = new JPanel();
00097                 synthControlsPanel.setBackground(c);
00098                 TitledBorder title = BorderFactory.createTitledBorder(
00099                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
00100                         "Synthesizer Controls");
00101                 title.setTitleJustification(TitledBorder.CENTER);
00102                 synthControlsPanel.setBorder(title);
00103         synthControlsPanel.setAlignmentY(Component.CENTER_ALIGNMENT);
00104                 
00105         JPanel outputFileNamePanel = new JPanel();
00106         outputFileNamePanel.setBackground(c);
00107                 
00108                 JLabel outputFileNameBoxLabel = new JLabel("output sound file:");
00109                 outputFileNamePanel.add(outputFileNameBoxLabel);
00110         
00111                 outputFileNameField = new JTextField("chris_mann_MEAPed.wav");
00112                 outputFileNameField.setColumns(20);
00113                 //outputFileNameField.setEditable(false);
00114                 outputFileNameField.addActionListener(this);
00115                 outputFileNameField.setActionCommand("setOutputFile");
00116                 outputFileNamePanel.add(outputFileNameField);
00117                 
00118                 JButton outputBrowseButton = new JButton("browse");
00119                 outputBrowseButton.setBackground(c);
00120                 outputBrowseButton.addActionListener(this);
00121                 outputBrowseButton.setActionCommand("browseOutputFile");
00122                 outputFileNamePanel.add(outputBrowseButton);
00123 
00124                 listenButton = new JButton("listen");
00125                 listenButton.setBackground(c);
00126                 listenButton.addActionListener(this);
00127                 listenButton.setActionCommand("listen");
00128                 outputFileNamePanel.add(listenButton);
00129                 
00130                 synthControlsPanel.add(outputFileNamePanel);
00131                 
00132                 add(synthControlsPanel);
00133         }
00134 
00135         public void actionPerformed(ActionEvent arg0)
00136         {
00137                 String command = arg0.getActionCommand();
00138 
00139         if (command.equals("listen"))
00140                 {
00141                         if (outputSoundFileNameFull == null)
00142                         {
00143                                 GUIUtils.ShowDialog("You need to pick an output file!!!", GUIUtils.MESSAGE, meapsoftGUI.jframe);
00144                                 return;
00145                         }
00146             PlaySoundFile(outputSoundFileNameFull);
00147                 }
00148                 else if (command.equals("setOutputFile"))
00149         {
00150             String name = outputFileNameField.getText(); 
00151             // default directory
00152             String names[] = {dataDirectory + slash + name, name};
00153 
00154             // does outputFileNameField contain a full path?
00155             if((new File(name)).isAbsolute())
00156                 names[0] = name;
00157 
00158             String[] nameSplit = name.split("["+slash+"]");
00159             names[1] = nameSplit[nameSplit.length-1];
00160             
00161             SetOutputFileName(names);
00162         }
00163                 else if (command.equals("browseOutputFile"))
00164                 {
00165                         String names[] = GUIUtils.FileSelector(GUIUtils.SAVE, meapsoftGUI.dataDirectory, meapsoftGUI.jframe);
00166                         
00167                         if (names[0] == null)
00168                                 return;
00169                                 
00170                         SetOutputFileName(names);
00171                 }
00172     }
00173 
00174         public synchronized int run()
00175         {       
00176         if(!enableBox.isSelected())
00177             return 0;
00178 
00179         if (outputSoundFileNameFull == null)
00180         {
00181                         GUIUtils.ShowDialog("You need to pick an output file!!!", GUIUtils.MESSAGE, meapsoftGUI.jframe);
00182             return -1;
00183         }
00184     
00185                 Synthesizer synth = new Synthesizer(edlFile, outputSoundFileNameFull);
00186         synth.writeMEAPFile = meapsoftGUI.writeMEAPFile;
00187 
00188         JPanel progressPanel = new JPanel();
00189         progressPanel.add(new JLabel("Synthesizing: "));
00190         JProgressBar progressBar = new JProgressBar(synth.getProgress());
00191         progressBar.setStringPainted(true);
00192         progressPanel.add(progressBar);
00193         meapsoftGUI.setProgressPanel(progressPanel);
00194 
00195         try
00196         {
00197             synth.doSynthesizer();
00198         }
00199         catch(Exception e)
00200         {
00201                         GUIUtils.ShowDialog(e, "Error synthesizing audio file", GUIUtils.MESSAGE, meapsoftGUI.jframe);
00202             return -1;
00203         }
00204         
00205         return 0;
00206         }
00207 }

Generated on Tue Feb 6 19:02:27 2007 for MEAPsoft by doxygen1.2.18