package com.meapsoft.applets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import com.meapsoft.EDLFile;
import com.meapsoft.FeatFile;
import com.meapsoft.composers.NNComposer;
public class NearestNeighborApplet extends JApplet implements ActionListener
{
private static final long serialVersionUID = 1L;
JPanel GUIPanel = new JPanel();
JButton goButton;
JButton selectFileButton;
ButtonGroup segmenterTypeButtonGroup;
JRadioButton beatSegmenterButton;
JRadioButton eventSegmenterButton;
JLabel messageBox;
String soundFileName = null;
public void init()
{
segmenterTypeButtonGroup = new ButtonGroup();
beatSegmenterButton = new JRadioButton("segment by beat");
beatSegmenterButton.setSelected(true);
eventSegmenterButton = new JRadioButton("segment by event");
segmenterTypeButtonGroup.add(beatSegmenterButton);
segmenterTypeButtonGroup.add(eventSegmenterButton);
GUIPanel.add(beatSegmenterButton);
GUIPanel.add(eventSegmenterButton);
selectFileButton = new JButton("select file");
selectFileButton.addActionListener(this);
GUIPanel.add(selectFileButton);
goButton = new JButton("go!");
goButton.addActionListener(this);
GUIPanel.add(goButton);
messageBox = new JLabel("watch for messages here! they may be very long! watch for them!");
GUIPanel.add(messageBox);
setContentPane(GUIPanel);
}
private void go()
{
boolean beats = beatSegmenterButton.isSelected();
if (beats)
messageBox.setText("doing beat segmentation on " + soundFileName);
else
messageBox.setText("doing event segmentation on " + soundFileName);
FeatFile segments = MEAPAppletUtils.segment(soundFileName, beats);
System.out.println("got segs!: " + segments.filename);
System.out.println("chunks.size(): " + segments.chunks.size());
String[] featureStrings = {"AvgPitch", "AvgChunkPower", "AvgSpecCentroid"};
FeatFile features = MEAPAppletUtils.getFeatures(segments, featureStrings);
System.out.println("got features! " + features.filename);
NNComposer nNComposer = new NNComposer(features, new EDLFile(features.filename + ".edl"));
EDLFile edl = nNComposer.compose();
MEAPAppletUtils.compose(edl, edl.filename + ".wav");
System.out.println("done!");
messageBox.setText("done!");
}
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
if (e.getSource() == selectFileButton)
{
soundFileName = MEAPAppletUtils.getAudioFile();
}
else if (e.getSource() == goButton)
{
messageBox.setText("going!");
go();
}
}
}