Package com.meapsoft.gui

Source Code of com.meapsoft.gui.SegmenterPanel

/*
* SegmenterPanel.java
*
* Created on October 28, 2007, 3:19 PM
*/

package com.meapsoft.gui;

import com.meapsoft.MEAPUtil;
import com.meapsoft.Segmenter;

/**
*
* @author  Mike
*/
public class SegmenterPanel extends BasePanel
{
   
    private SegmentBeatDetails mBeatDetailsPanel;       //the two detail panels
    private SegmentEventDetails mEventDetailsPanel;
   
    /** Creates new form SegmenterPanel */
    public SegmenterPanel(MeapsoftGUI mainScreen)
    {
      //pass this up to our main screen
      super(mainScreen);
       
        initComponents();
       
        //init the detail panels
        initDetailPanels();
       
        //set the default input file
        setDefaultInputFile();
    }
   

    private void initDetailPanels()
    {
        mBeatDetailsPanel = new SegmentBeatDetails();
        mBeatDetailsPanel.setSize(200, 100);
       
        //start off with event detail panel
        mEventDetailsPanel = new SegmentEventDetails();
        mEventDetailsPanel.setSize(300, 150);
        mDetailWrapper.add(mEventDetailsPanel);
    }
   
    private void setDefaultInputFile()
    {
    String[] inputName = new String[2];
    inputName[0] = dataDirectory + slash + "chris_mann.wav";
    inputName[1] = "chris_mann.wav";

        //set the input file names for us
        setInputFileName(inputName);
       
        //set the input file to be the short name
        mInputFileTxt.setText(inputName[1]);
    }
   
    ////////////////////////////////////////////////////////////////////////
    // run() - does the segmenting here
    ////////////////////////////////////////////////////////////////////////
    public synchronized int run()
    {
      //if we don't have a file, just return
        if (inputSoundFileNameFull == null)
        {
            GUIUtils.ShowDialog("You need to pick an input file!!!", GUIUtils.MESSAGE, mMainScreen);
            return -1;
        }
     
      //are we detecting beats?
      boolean detectBeats = mBeatsRadioBtn.isSelected();
   
      //our detail values
      double segmentDensity = 0.25;    //between 1 and 0
      double segmentSensitivity = 1.5//between 0 and 3
      double tempoMult = 1.0;        //are we cutting the tempo in half?
      boolean firstFrameOnset = true;    //are we starting the first frame?
     
      //if we're detecting events, get slider values
      if(detectBeats)
      {
        //see if we're cutting the tempo in half
        if(mBeatDetailsPanel.isCutTempoInHalf())
        {
          tempoMult = 0.5;
        }
      }
      else
      {
        segmentDensity = mEventDetailsPanel.getDensity();
        segmentSensitivity = mEventDetailsPanel.getSensitivity();
      }
     
      //create the segment file name
    String segmentsFileName = dataDirectory + slash + outputSegmentsFileName;
   
    //create the segmenter
    Segmenter segmenter = new Segmenter(inputSoundFileNameFull,
                      segmentsFileName,
                      segmentSensitivity,
                      segmentDensity,
                      detectBeats,
                      firstFrameOnset);
   
    //set the tempo multiplier and the
      segmenter.setTempoMultiplier(tempoMult);
      segmenter.writeMEAPFile = MEAPUtil.writeMEAPFile;
   
      //update the progress bar
      mMainScreen.updateProgressBar("Segmenting...", segmenter.getProgress());
     
        try
        {
          //now actually process the audio file
            segmentFile = segmenter.processAudioFile(inputSoundFileNameFull);

            if(segmenter.writeMEAPFile)
                segmentFile.writeFile();

            segmentFile = segmenter.getSegFile();
        }
        catch (Exception e)
        {
            GUIUtils.ShowDialog(e, "Error running Segmenter", GUIUtils.MESSAGE, mMainScreen);

            return -1;
        }
     
       
        //should we show the visual preview?
        if(mMainScreen.shouldProcessVisualPreview())
        {
          //get the preview panel here
          VisualPreviewPanel previewPanel = mMainScreen.getPreviewPanel();
         
          //add a visual preview for the waveform and spectrum
          previewPanel.addVisualPreview("Segments", "Waveform", "Waveform", segmentFile);
          previewPanel.addVisualPreview("Segments", "Spectrum", "Spectrum", segmentFile);
          //mMainScreen.pack();
        }
       
      //if we got here, return with no error
      return 0;
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        segmentTypeBtnGrp = new javax.swing.ButtonGroup();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        mInputFileTxt = new javax.swing.JTextField();
        mBrowseBtn = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        mEventsRadioBtn = new javax.swing.JRadioButton();
        mBeatsRadioBtn = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        mDetailWrapper = new javax.swing.JPanel();

        jLabel4.setText("The segmenter will break up the audio files based on events or beats.");

        jLabel1.setText("Step 1: Choose a file");

        mInputFileTxt.setText("chris_mann.wav");

        mBrowseBtn.setText("Browse");
        mBrowseBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mBrowseBtnActionPerformed(evt);
            }
        });

        jLabel2.setText("Step 2: Choose segmentation type");

        segmentTypeBtnGrp.add(mEventsRadioBtn);
        mEventsRadioBtn.setSelected(true);
        mEventsRadioBtn.setText("Detect events");
        mEventsRadioBtn.setMargin(new java.awt.Insets(0, 0, 0, 0));
        mEventsRadioBtn.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                mEventsRadioBtnItemStateChanged(evt);
            }
        });

        segmentTypeBtnGrp.add(mBeatsRadioBtn);
        mBeatsRadioBtn.setText("Detect beats");
        mBeatsRadioBtn.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabel3.setText("Step 3: Set segmentation details");

        org.jdesktop.layout.GroupLayout mDetailWrapperLayout = new org.jdesktop.layout.GroupLayout(mDetailWrapper);
        mDetailWrapper.setLayout(mDetailWrapperLayout);
        mDetailWrapperLayout.setHorizontalGroup(
            mDetailWrapperLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 369, Short.MAX_VALUE)
        );
        mDetailWrapperLayout.setVerticalGroup(
            mDetailWrapperLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 185, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 280, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createSequentialGroup()
                .add(65, 65, 65)
                .add(mInputFileTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 195, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mBrowseBtn)
                .add(98, 98, 98))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 310, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createSequentialGroup()
                .add(89, 89, 89)
                .add(mEventsRadioBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mBeatsRadioBtn))
            .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(mDetailWrapper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 320, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(42, 42, 42))
            .add(layout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .add(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(mInputFileTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(mBrowseBtn))
                .add(22, 22, 22)
                .add(jLabel2)
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(mEventsRadioBtn)
                    .add(mBeatsRadioBtn))
                .add(31, 31, 31)
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mDetailWrapper, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void mEventsRadioBtnItemStateChanged(java.awt.event.ItemEvent evt)//GEN-FIRST:event_mEventsRadioBtnItemStateChanged
    {//GEN-HEADEREND:event_mEventsRadioBtnItemStateChanged
//did we select the event radio button. if so, swap out panels
        if(mEventsRadioBtn.isSelected())
        {
            mDetailWrapper.remove(mBeatDetailsPanel);
            mDetailWrapper.add(mEventDetailsPanel);
           
            //initialize the colors
            GUIUtils.initContainerColor(mEventDetailsPanel, this.getColor());
        }
        else
        {
            mDetailWrapper.remove(mEventDetailsPanel);
            mDetailWrapper.add(mBeatDetailsPanel);
           
            //initialze the colors
            GUIUtils.initContainerColor(mBeatDetailsPanel, this.getColor());
        }
       
        //invalidate the detail wrapper
        mDetailWrapper.validate();
        mDetailWrapper.invalidate();
        mDetailWrapper.repaint();
    }//GEN-LAST:event_mEventsRadioBtnItemStateChanged

    private void mBrowseBtnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_mBrowseBtnActionPerformed
    {//GEN-HEADEREND:event_mBrowseBtnActionPerformed
//show the file selector
        String[] names = GUIUtils.showFileSelector(GUIUtils.OPENSOUND, dataDirectory, mMainScreen);
       
        //if we didn't pick anything, just return here
        if(names[0] == null)
          return;
       
        //set the input file names for us
        setInputFileName(names);
       
        //set the input file to be the short name
        mInputFileTxt.setText(names[1]);
       
        mMainScreen.initFilesForPanels();
    }//GEN-LAST:event_mBrowseBtnActionPerformed
   
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JRadioButton mBeatsRadioBtn;
    private javax.swing.JButton mBrowseBtn;
    private javax.swing.JPanel mDetailWrapper;
    private javax.swing.JRadioButton mEventsRadioBtn;
    private javax.swing.JTextField mInputFileTxt;
    private javax.swing.ButtonGroup segmentTypeBtnGrp;
    // End of variables declaration//GEN-END:variables
   
}
TOP

Related Classes of com.meapsoft.gui.SegmenterPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.