00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package com.meapsoft.gui;
00024
00025 import java.awt.Color;
00026 import java.awt.Cursor;
00027 import java.awt.GridLayout;
00028 import java.awt.event.ActionEvent;
00029 import java.awt.event.ActionListener;
00030 import java.beans.PropertyChangeEvent;
00031 import java.beans.PropertyChangeListener;
00032 import java.io.File;
00033 import java.io.PrintWriter;
00034 import java.io.StringWriter;
00035 import java.util.Date;
00036
00037 import javax.swing.AbstractAction;
00038 import javax.swing.Action;
00039 import javax.swing.BorderFactory;
00040 import javax.swing.BoxLayout;
00041 import javax.swing.JButton;
00042 import javax.swing.JDialog;
00043 import javax.swing.JFileChooser;
00044 import javax.swing.JFrame;
00045 import javax.swing.JLabel;
00046 import javax.swing.JOptionPane;
00047 import javax.swing.JPanel;
00048 import javax.swing.JScrollPane;
00049 import javax.swing.JTabbedPane;
00050 import javax.swing.JTextArea;
00051 import javax.swing.KeyStroke;
00052 import javax.swing.border.EtchedBorder;
00053
00054 import com.meapsoft.ExceptionHandler;
00055 import com.meapsoft.MEAPUtil;
00056 import com.meapsoft.visualizer.Visualizer;
00057
00058
00065 public class MEAPsoftGUI extends MEAPUtil implements ActionListener, Runnable
00066 {
00067 protected JFrame jframe;
00068 private JPanel mainGuiPanel;
00069
00070
00071 public static String dataDirectory;
00072 public static String meapsoftDirectory;
00073
00074
00075 private JTabbedPane tabs;
00076 private JPanel[] stripes = new JPanel[5];
00077
00078
00079 public SegmenterPanel segmenterPanel;
00080 public FeatExtractorPanel featExtPanel;
00081 public ComposerPanel composerPanel;
00082 public SynthesizerPanel synthPanel;
00083 public PreferencesPanel prefsPanel;
00084
00085
00086
00087 private JButton startButton;
00088 private JPanel goPanel;
00089 private JLabel statusBar;
00090
00091
00092 private Thread runThread = null;
00093
00094 private JPanel progressPanel = null;
00095
00096
00097 private Color bgColor;
00098
00099
00100 public MEAPsoftGUI()
00101 {
00102 jframe = new JFrame("MEAPsoft-"+version);
00103
00104 String paths[] = MEAPUtil.getPaths();
00105 if (paths != null)
00106 {
00107 meapsoftDirectory = paths[0];
00108 dataDirectory = paths[1];
00109 }
00110 else
00111 System.exit(-1);
00112
00113
00114
00115 exceptionHandler = new GUIExceptionHandler(jframe, "");
00116
00117 jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00118 jframe.setResizable(false);
00119 BuildGUI();
00120 setDefaultInputFile();
00121 UpdateInfoTexts();
00122
00123 cycleComposers();
00124
00125 jframe.show();
00126 }
00127
00128 private void setDefaultInputFile()
00129 {
00130 String[] inputName = new String[2];
00131 inputName[0] = dataDirectory + slash + "chris_mann.wav";
00132 inputName[1] = "chris_mann.wav";
00133 segmenterPanel.SetInputFileName(inputName);
00134 }
00135
00136 private void BuildGUI()
00137 {
00139
00141
00142 mainGuiPanel = new JPanel();
00143 BoxLayout bl = new BoxLayout(mainGuiPanel, BoxLayout.Y_AXIS);
00144 mainGuiPanel.setLayout(bl);
00145 jframe.setContentPane(mainGuiPanel);
00146
00147
00148 Action goAction = new AbstractAction() {
00149 public void actionPerformed(ActionEvent e) {
00150 System.out.println("got a go...");
00151 GoButtonPressed();
00152 }
00153 };
00154
00155 KeyStroke keystroke =
00156 KeyStroke.getKeyStroke('g');
00157 mainGuiPanel.getInputMap().put(keystroke, "go");
00158 mainGuiPanel.getActionMap().put("go", goAction);
00159
00160 Color c = new Color((int)(Math.random() * 127 + 127),
00161 (int)(Math.random() * 127 + 127),
00162 (int)(Math.random() * 127 + 127));
00163 bgColor = c;
00164
00165 JPanel stripe = new JPanel();
00166 stripe.setBackground(c);
00167
00168 for (int i = 0; i < 5; i++)
00169 {
00170 JPanel p = new JPanel();
00171 p.add(new JLabel(" MEAP! "));
00172 stripes[i] = p;
00173 stripe.add(p);
00174 }
00175
00176 mainGuiPanel.add(stripe);
00177
00178 tabs = new JTabbedPane();
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 tabs.setBackground(c);
00196 mainGuiPanel.add(tabs);
00197
00198
00199
00201
00203
00204 segmenterPanel = new SegmenterPanel(this);
00205 featExtPanel = new FeatExtractorPanel(this);
00206 composerPanel = new ComposerPanel(this);
00207 synthPanel = new SynthesizerPanel(this);
00208 prefsPanel = new PreferencesPanel(this);
00209
00210
00211 tabs.addTab("segmenter", segmenterPanel);
00212 tabs.setBackgroundAt(0, segmenterPanel.color);
00213 stripes[0].setBackground(segmenterPanel.color);
00214
00215 tabs.addTab("feature extractors", featExtPanel);
00216 tabs.setBackgroundAt(1, featExtPanel.color);
00217 stripes[1].setBackground(featExtPanel.color);
00218
00219 tabs.addTab("composers", composerPanel);
00220 tabs.setBackgroundAt(2, composerPanel.color);
00221 stripes[2].setBackground(composerPanel.color);
00222
00223 tabs.addTab("synthesizer", synthPanel);
00224 tabs.setBackgroundAt(3, synthPanel.color);
00225 stripes[3].setBackground(synthPanel.color);
00226
00227 tabs.addTab("prefs/about", prefsPanel);
00228 tabs.setBackgroundAt(4, prefsPanel.color);
00229 stripes[4].setBackground(prefsPanel.color);
00230
00231
00232
00234
00236
00237
00238 goPanel = new JPanel();
00239 goPanel.setBackground(c);
00240 startButton = new JButton("go!");
00241 startButton.setBackground(c);
00242 startButton.addActionListener(this);
00243 startButton.setActionCommand("go");
00244 goPanel.add(startButton);
00245
00246 JButton displayVisualizerButton = new JButton("launch visualizer");
00247 displayVisualizerButton.addActionListener(this);
00248 displayVisualizerButton.setActionCommand("launchVisualizer");
00249 displayVisualizerButton.setBackground(c);
00250 goPanel.add(displayVisualizerButton);
00251
00252 mainGuiPanel.add(goPanel);
00253
00254 JPanel statusBarPanel = new JPanel(new GridLayout(1,1));
00255 statusBarPanel.setBackground(c.brighter());
00256 statusBarPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
00257 statusBar = new JLabel("...");
00258 statusBar.setBackground(c.brighter());
00259 statusBarPanel.add(statusBar);
00260
00261 mainGuiPanel.add(statusBarPanel);
00262
00263 jframe.validate();
00264 jframe.pack();
00265 jframe.repaint();
00266
00267 }
00268
00269 public synchronized void UpdateInfoTexts()
00270 {
00271
00272 segmenterPanel.outputSegFileLabel.setText(" "
00273 + segmenterPanel.outputSegmentsFileName + " ");
00274
00275 featExtPanel.inputSegmentsFileLabel.setText(" "
00276 + featExtPanel.inputSegmentsFileName + " ");
00277 featExtPanel.outputFeaturesFileLabel.setText(" "
00278 + featExtPanel.outputFeaturesFileName + " ");
00279
00280 composerPanel.inputFileNameLabel.setText(" "
00281 + composerPanel.inputFeaturesFileName + " ");
00282 composerPanel.outputFileNameLabel.setText(" "
00283 + composerPanel.outputEDLFileName + " ");
00284
00285 synthPanel.fileNameLabel.setText(" "
00286 + synthPanel.inputEDLFileName + " ");
00287 RefreshGUI();
00288
00289 segmenterPanel.initSegmentFile();
00290 featExtPanel.initFeatFile();
00291 featExtPanel.enableDisplayButton(false);
00292 composerPanel.initEDLFile();
00293 composerPanel.enableDisplayButton(false);
00294 }
00295
00296 public void cycleComposers()
00297 {
00298
00299 tabs.setSelectedIndex(2);
00300
00301 int numComposers = composerPanel.controlsPanels.size();
00302
00303 for (int i = 0; i < numComposers; i++)
00304 {
00305 composerPanel.controlsPanel.removeAll();
00306 composerPanel.controlsPanel.add((JPanel)composerPanel. controlsPanels.elementAt(i));
00307 RefreshGUI();
00308 }
00309
00310 composerPanel.controlsPanel.removeAll();
00311 composerPanel.controlsPanel.add((JPanel)composerPanel. controlsPanels.elementAt(0));
00312 RefreshGUI();
00313
00314 tabs.setSelectedIndex(0);
00315 }
00316
00317 public void RefreshGUI()
00318 {
00319 mainGuiPanel.invalidate();
00320 tabs.invalidate();
00321 segmenterPanel.invalidate();
00322 featExtPanel.invalidate();
00323 composerPanel.invalidate();
00324 synthPanel.invalidate();
00325 prefsPanel.invalidate();
00326 goPanel.invalidate();
00327
00328 jframe.invalidate();
00329
00330 jframe.validate();
00331 jframe.pack();
00332 jframe.repaint();
00333 }
00334
00335 public void actionPerformed(ActionEvent arg0)
00336 {
00337 String command = arg0.getActionCommand();
00338
00339 if (command.equals("go"))
00340 {
00341 GoButtonPressed();
00342 }
00343 if (command.equals("launchVisualizer"))
00344 {
00345 Visualizer visualizer = new Visualizer(composerPanel.featFile,
00346 composerPanel.edlFile);
00347 }
00348 }
00349
00350 public void GoButtonPressed()
00351 {
00352 runThread = new Thread(this, "MEAPsoftGUI.run");
00353 runThread.start();
00354 }
00355
00356 public synchronized void run()
00357 {
00358 jframe.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
00359
00360 writeMEAPFile = prefsPanel.saveFilesPrefBox.isSelected();
00361
00362 updateStatusBar("running Segmenter on "
00363 + segmenterPanel.inputSoundFileNameShort + "...");
00364 if (segmenterPanel.run() != 0)
00365 {
00366 runCleanup("Segmenter error.");
00367 return;
00368 }
00369
00370 updateStatusBar("running Feature Extractor on "
00371 + featExtPanel.inputSegmentsFileName + "...");
00372 if (featExtPanel.run() != 0)
00373 {
00374 runCleanup("Feature Extractor error.");
00375 return;
00376 }
00377
00378 updateStatusBar("running Composer on "
00379 + composerPanel.inputFeaturesFileName + "...");
00380 if (composerPanel.run() != 0)
00381 {
00382 runCleanup("Composer error.");
00383 return;
00384 }
00385
00386 updateStatusBar("running Synthesizer on "
00387 + synthPanel.inputEDLFileName + "...");
00388 if (synthPanel.run() != 0)
00389 {
00390 runCleanup("Synthesizer error.");
00391 return;
00392 }
00393
00394 runCleanup("Finished MEAPing.");
00395 }
00396
00397 private void runCleanup(String message)
00398 {
00399 jframe.getContentPane().setCursor(Cursor.getDefaultCursor());
00400
00401 if(progressPanel != null)
00402 goPanel.remove(progressPanel);
00403
00404 goPanel.add(startButton);
00405
00406 updateStatusBar(message);
00407
00408 RefreshGUI();
00409 }
00410
00411 private void updateStatusBar(String message)
00412 {
00413 String s = new Date()+": "+message;
00414 statusBar.setText(s);
00415 }
00416
00417 synchronized void setProgressPanel(JPanel panel)
00418 {
00419 if(progressPanel != null)
00420 goPanel.remove(progressPanel);
00421
00422 progressPanel = panel;
00423
00424 progressPanel.setBackground(bgColor);
00425
00426 goPanel.remove(startButton);
00427 goPanel.add(progressPanel);
00428 RefreshGUI();
00429 }
00430
00431 public static void main(String[] args)
00432 {
00433
00434
00435 javax.swing.SwingUtilities.invokeLater(new Runnable() {
00436 public void run()
00437 {
00438 new MEAPsoftGUI();
00439 }
00440 });
00441 }
00442 }
00443
00444
00451 class GUIExceptionHandler extends ExceptionHandler
00452 {
00453 private JFrame frame;
00454 private String msg;
00455
00456 public GUIExceptionHandler(JFrame f, String message)
00457 {
00458 frame = f;
00459 msg = message;
00460 }
00461
00465 public void handleException(Exception e)
00466 {
00467 GUIUtils.ShowDialog(e, msg, GUIUtils.MESSAGE, frame);
00468 }
00469 }