From a816f1eccdff48a9a2f65835ccdc657c7432d460 Mon Sep 17 00:00:00 2001 From: William Rey Date: Tue, 31 Oct 2017 01:44:26 +0100 Subject: [PATCH] Added the VUMeter --- pom.xml | 30 +- .../com/oxande/wavecleaner/WaveCleaner.java | 16 +- .../wavecleaner/audio/AudioDocument.java | 13 +- .../wavecleaner/filters/AudioFilter.java | 7 +- .../filters/PreamplifierFilter.java | 18 + .../oxande/wavecleaner/filters/VUMeter.java | 31 + .../ui/AbstractControllerComponent.java | 814 +++++++++--------- .../wavecleaner/ui/AbstractMainScreen.java | 661 ++++++-------- .../wavecleaner/ui/AbstractRecordScreen.java | 265 ++++-- .../com/oxande/wavecleaner/ui/MainScreen.java | 9 +- .../oxande/wavecleaner/ui/RecordScreen.java | 105 ++- .../wavecleaner/ui/VUMeterComponent.java | 209 ++++- .../xmlswing/components/ComponentUI.java | 6 +- src/main/resources/MainScreen.xml | 2 +- src/main/resources/RecordScreen.xml | 9 +- 15 files changed, 1239 insertions(+), 956 deletions(-) create mode 100644 src/main/java/com/oxande/wavecleaner/filters/VUMeter.java diff --git a/pom.xml b/pom.xml index 53220e5..78bfb24 100644 --- a/pom.xml +++ b/pom.xml @@ -83,21 +83,21 @@ --> - - org.apache.logging.log4j - log4j-api - 2.9.1 - - - org.apache.logging.log4j - log4j-core - 2.9.1 - - - org.apache.logging.log4j - log4j-jcl - 2.9.1 - + + org.apache.logging.log4j + log4j-api + 2.9.1 + + + org.apache.logging.log4j + log4j-core + 2.9.1 + + + org.apache.logging.log4j + log4j-jcl + 2.9.1 + com.googlecode.soundlibs diff --git a/src/main/java/com/oxande/wavecleaner/WaveCleaner.java b/src/main/java/com/oxande/wavecleaner/WaveCleaner.java index d00c0f2..92051a7 100644 --- a/src/main/java/com/oxande/wavecleaner/WaveCleaner.java +++ b/src/main/java/com/oxande/wavecleaner/WaveCleaner.java @@ -1,16 +1,13 @@ package com.oxande.wavecleaner; import java.io.File; -import java.io.IOException; -import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import org.apache.logging.log4j.Logger; import com.oxande.wavecleaner.audio.AudioCache; -import com.oxande.wavecleaner.audio.AudioDocument; import com.oxande.wavecleaner.ui.MainScreen; import com.oxande.wavecleaner.util.ProcessingLegacy; import com.oxande.wavecleaner.util.logging.LogFactory; @@ -101,6 +98,19 @@ public AudioRecordingStream loadFileStream(File f){ return stream; } + /** + * Retrieve an audio recorder. + * + * @param f the file to save the sound. + * @param sampleRate the sample rate + * @return the {@link AudioRecorder}. + */ + public AudioRecorder getAudioRecorder(File f, float sampleRate){ + AudioInput in = this.minim.getLineIn(Minim.STEREO, (int)(sampleRate / 20), sampleRate); + AudioRecorder stream = minim.createRecorder(in, f.getAbsolutePath()); + return stream; + } + /** * Check for old temporary files created by other instances. If found, they are deleted. * Note the deletion works only if the file is not locked (then 2 instances can run diff --git a/src/main/java/com/oxande/wavecleaner/audio/AudioDocument.java b/src/main/java/com/oxande/wavecleaner/audio/AudioDocument.java index 36be617..00ff909 100644 --- a/src/main/java/com/oxande/wavecleaner/audio/AudioDocument.java +++ b/src/main/java/com/oxande/wavecleaner/audio/AudioDocument.java @@ -11,13 +11,12 @@ import com.oxande.wavecleaner.WaveCleaner; import com.oxande.wavecleaner.filters.AudioDocumentPlayer; import com.oxande.wavecleaner.filters.AudioPlayerListener; -import com.oxande.wavecleaner.filters.PreamplifierFilter; import com.oxande.wavecleaner.filters.DecrackleFilter; +import com.oxande.wavecleaner.filters.PreamplifierFilter; import com.oxande.wavecleaner.util.ListenerManager; import com.oxande.wavecleaner.util.logging.LogFactory; import ddf.minim.AudioOutput; -import ddf.minim.Minim; import ddf.minim.MultiChannelBuffer; import ddf.minim.spi.AudioRecordingStream; @@ -54,7 +53,7 @@ public class AudioDocument /*implements AudioListener*/ { int nbChannels = 2; private int totalSamples = 0; public DecrackleFilter decrackFilter = new DecrackleFilter(); - public PreamplifierFilter controlFilter = new PreamplifierFilter(null); + public PreamplifierFilter preamplifer = new PreamplifierFilter(null); private RMSSample[] samples = null; @@ -275,8 +274,8 @@ public synchronized void stop() { this.documentPlayer.pause(); // lineOut.removeListener(this); this.documentPlayer.unpatch(decrackFilter); - decrackFilter.unpatch(controlFilter); - controlFilter.unpatch(lineOut); + decrackFilter.unpatch(preamplifer); + preamplifer.unpatch(lineOut); LOG.info("PAUSED"); // for (AudioDocumentListener listener : listeners) { // listener.audioPaused(); @@ -303,8 +302,8 @@ public synchronized void play(int pos) { } // this.lineOut.addListener(this); - controlFilter.setPlayer(player); - player.patch(decrackFilter).patch(controlFilter).patch(lineOut); + preamplifer.setPlayer(player); + player.patch(decrackFilter).patch(preamplifer).patch(lineOut); // REAL VERSION player.patch(lineOut); player.rewind(); player.play(); diff --git a/src/main/java/com/oxande/wavecleaner/filters/AudioFilter.java b/src/main/java/com/oxande/wavecleaner/filters/AudioFilter.java index 6167cb8..68aec6d 100644 --- a/src/main/java/com/oxande/wavecleaner/filters/AudioFilter.java +++ b/src/main/java/com/oxande/wavecleaner/filters/AudioFilter.java @@ -111,7 +111,6 @@ public float setControl(String name, float value ){ LOG.error("Parameter '{}' unknown.", name); return 0.0f; } - LOG.debug("Parameter '{}' set to {}.", name, value); p.setValue(value); return p.getValue(); } @@ -217,8 +216,10 @@ void setValue( float v ){ LOG.warn("Parameter '{}' set to maximum {} instead of {}", name, max, v); v = max; } - LOG.debug("Parameter '{}' set to {}", name, v); - this.input.setLastValue(v); + if( v != this.input.getLastValue() ){ + LOG.debug("Parameter '{}' set to {}", name, v); + this.input.setLastValue(v); + } } public float getValue(){ diff --git a/src/main/java/com/oxande/wavecleaner/filters/PreamplifierFilter.java b/src/main/java/com/oxande/wavecleaner/filters/PreamplifierFilter.java index b522a9f..4c10128 100644 --- a/src/main/java/com/oxande/wavecleaner/filters/PreamplifierFilter.java +++ b/src/main/java/com/oxande/wavecleaner/filters/PreamplifierFilter.java @@ -2,6 +2,7 @@ import org.apache.logging.log4j.Logger; +import com.oxande.wavecleaner.ui.VUMeterComponent; import com.oxande.wavecleaner.util.ConvertUtils; import com.oxande.wavecleaner.util.logging.LogFactory; @@ -52,6 +53,7 @@ public class PreamplifierFilter extends AudioFilter { public static final int LEFT_RIGHT = 3; private AudioDocumentPlayer player; + private VUMeterComponent vumeter = null; public PreamplifierFilter( AudioDocumentPlayer player){ super(); @@ -72,6 +74,18 @@ public void setPlayer(AudioDocumentPlayer player){ LOG.debug("New player is now {}", player); this.player = player; } + + public void setVUMeter(VUMeterComponent vumeter){ + this.vumeter = vumeter; + this.vumeter.setSampleRate(this.sampleRate()); + } + + @Override + protected void sampleRateChanged(){ + if( this.vumeter != null ){ + this.vumeter.setSampleRate(this.sampleRate()); + } + } protected void process(MultiChannelBuffer buff) { if(player == null){ @@ -117,6 +131,10 @@ protected void process(MultiChannelBuffer buff) { sample[ch] = sample[ch] * mValue; buff.setSample(ch, i, sample[ch]); } + + if( vumeter != null ){ + vumeter.push(sample); + } } } diff --git a/src/main/java/com/oxande/wavecleaner/filters/VUMeter.java b/src/main/java/com/oxande/wavecleaner/filters/VUMeter.java new file mode 100644 index 0000000..4732b44 --- /dev/null +++ b/src/main/java/com/oxande/wavecleaner/filters/VUMeter.java @@ -0,0 +1,31 @@ +package com.oxande.wavecleaner.filters; + +import com.oxande.wavecleaner.ui.VUMeterComponent; + +import ddf.minim.UGen; + +public class VUMeter extends UGen { + + private UGen audio; + private VUMeterComponent vu = new VUMeterComponent(); + private float[] tickBuffer; + + public VUMeterComponent getComponent(){ + return this.vu; + } + + @Override + protected void addInput(UGen in) + { + this.audio = in; + this.tickBuffer = new float[in.channelCount()]; + } + + @Override + protected void uGenerate(float[] channels) { + audio.tick(tickBuffer); + + System.arraycopy(tickBuffer, 0, channels, 0, tickBuffer.length); + } + +} diff --git a/src/main/java/com/oxande/wavecleaner/ui/AbstractControllerComponent.java b/src/main/java/com/oxande/wavecleaner/ui/AbstractControllerComponent.java index afea651..fa50938 100644 --- a/src/main/java/com/oxande/wavecleaner/ui/AbstractControllerComponent.java +++ b/src/main/java/com/oxande/wavecleaner/ui/AbstractControllerComponent.java @@ -1,407 +1,407 @@ -package com.oxande.wavecleaner.ui; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.lang.Runnable; -import java.lang.UnsupportedOperationException; - -import javax.swing.ButtonGroup; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.JToggleButton; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -/** - * Class created automatically -- DO NOT UPDATE MANUALLY. - * This class has been created based on a XML file and must - * be extended by your own code. The following code only - * provide an easy way to obtain a basic GUI. - */ -public class AbstractControllerComponent extends JPanel { - private JPanel jpanel1 = new JPanel(); - protected JCheckBox crackle = new JCheckBox(); - protected JSlider crackle_factor = new JSlider(); - protected JSlider crackle_average = new JSlider(); - protected JSlider crackle_window = new JSlider(); - private JLabel jlabel1 = new JLabel(); - private JLabel jlabel2 = new JLabel(); - private JLabel jlabel3 = new JLabel(); - private JLabel jlabel4 = new JLabel(); - protected JSlider volume = new JSlider(); - private JLabel jlabel5 = new JLabel(); - private JPanel jpanel2 = new JPanel(); - private FlowLayout flowlayout1 = new FlowLayout(); - protected JToggleButton finalOutput = new JToggleButton(); - ButtonGroup audioOut = new ButtonGroup(); - protected JToggleButton originalOutput = new JToggleButton(); - protected JToggleButton diffOutput = new JToggleButton(); - protected JToggleButton leftRightOutput = new JToggleButton(); -public class ChangeListener1 implements javax.swing.event.ChangeListener { - - public void stateChanged(ChangeEvent e) - { - crackleFactorChanged(); - } -} - -public class ChangeListener2 implements javax.swing.event.ChangeListener { - - public void stateChanged(ChangeEvent e) - { - crackleAverageChanged(); - } -} - -private class SetCrackleWindowLabelClass implements Runnable { - private String input; - - public SetCrackleWindowLabelClass(String input) - { - this.input = input; - } - - public void run() - { - jlabel3.setText(String.valueOf(input)); - } -} - -public class ChangeListener3 implements javax.swing.event.ChangeListener { - - public void stateChanged(ChangeEvent e) - { - crackleWindowChanged(); - } -} - -private class SetCrackleFactorLabelClass implements Runnable { - private String input; - - public SetCrackleFactorLabelClass(String input) - { - this.input = input; - } - - public void run() - { - jlabel1.setText(String.valueOf(input)); - } -} - -private class SetCrackleAverageLabelClass implements Runnable { - private String input; - - public void run() - { - jlabel2.setText(String.valueOf(input)); - } - - public SetCrackleAverageLabelClass(String input) - { - this.input = input; - } -} - -public class ChangeListener4 implements javax.swing.event.ChangeListener { - - public void stateChanged(ChangeEvent e) - { - volumeChanged(); - } -} - - - /** - * Called by the menu item NORMAL. - */ - protected void onFinalOutput() - { - JOptionPane.showMessageDialog(finalOutput, "Not implemented.",finalOutput.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public String getCrackleFactorLabel() - { - return jlabel1.getText(); - } - - public void setCrackleAverageLabel(String in) - { - SwingUtilities.invokeLater(new SetCrackleAverageLabelClass(in)); - } - - protected void crackleAverageChanged() - { - throw new UnsupportedOperationException("Not implemented"); - } - - /** - * Called by the menu item DIFF. - */ - protected void onDiffOutput() - { - JOptionPane.showMessageDialog(diffOutput, "Not implemented.",diffOutput.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public void initComponents() - { - this.setLayout(new BorderLayout()); - GridBagLayout layout1 = new GridBagLayout(); - GridBagConstraints c1 = new GridBagConstraints(); - jpanel1.setLayout(layout1); - - crackle.setText("Decrackle"); - crackle.setFocusable(false); - c1.gridy = 0; - c1.gridx = 0; - c1.gridheight = 2; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(crackle, c1); - jpanel1.add(crackle); - - crackle_factor.setMinimumSize(new java.awt.Dimension(100,50)); - crackle_factor.setMaximum(100); - crackle_factor.setMinimum(1); - crackle_factor.setOrientation(JSlider.HORIZONTAL); - crackle_factor.setValue(2); - crackle_factor.addChangeListener(new ChangeListener1()); - c1.gridy = 0; - c1.gridx = 1; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(crackle_factor, c1); - jpanel1.add(crackle_factor); - - crackle_average.setMinimumSize(new java.awt.Dimension(100,50)); - crackle_average.setMaximum(100); - crackle_average.setMinimum(0); - crackle_average.setOrientation(JSlider.HORIZONTAL); - crackle_average.setValue(3); - crackle_average.addChangeListener(new ChangeListener2()); - c1.gridy = 0; - c1.gridx = 2; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(crackle_average, c1); - jpanel1.add(crackle_average); - - crackle_window.setMinimumSize(new java.awt.Dimension(100,50)); - crackle_window.setMaximum(20000); - crackle_window.setMinimum(1); - crackle_window.setOrientation(JSlider.HORIZONTAL); - crackle_window.setValue(2000); - crackle_window.addChangeListener(new ChangeListener3()); - c1.gridy = 0; - c1.gridx = 3; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(crackle_window, c1); - jpanel1.add(crackle_window); - - jlabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - c1.gridy = 1; - c1.gridx = 1; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jlabel1, c1); - jpanel1.add(jlabel1); - - jlabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - c1.gridy = 1; - c1.gridx = 2; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jlabel2, c1); - jpanel1.add(jlabel2); - - jlabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - c1.gridy = 1; - c1.gridx = 3; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jlabel3, c1); - jpanel1.add(jlabel3); - - jlabel4.setText("Volume"); - c1.gridy = 2; - c1.gridx = 0; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jlabel4, c1); - jpanel1.add(jlabel4); - - volume.setMinimumSize(new java.awt.Dimension(100,50)); - volume.setMaximum(24); - volume.setMinimum(-24); - volume.setOrientation(JSlider.HORIZONTAL); - volume.setValue(0); - volume.addChangeListener(new ChangeListener4()); - c1.gridy = 2; - c1.gridx = 1; - c1.gridheight = 1; - c1.gridwidth = 3; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 3; - layout1.setConstraints(volume, c1); - jpanel1.add(volume); - - jlabel5.setText("OUTPUT SELECTOR"); - c1.gridy = 3; - c1.gridx = 0; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jlabel5, c1); - jpanel1.add(jlabel5); - - flowlayout1.setHgap(0); - jpanel2.setLayout(flowlayout1); - audioOut.add(finalOutput); - finalOutput.setText("NORMAL"); - finalOutput.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onFinalOutput(); - } -} - -); - jpanel2.add(finalOutput); - audioOut.add(originalOutput); - originalOutput.setText("ORIGIN"); - originalOutput.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onOriginalOutput(); - } -} - -); - jpanel2.add(originalOutput); - audioOut.add(diffOutput); - diffOutput.setText("DIFF"); - diffOutput.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onDiffOutput(); - } -} - -); - jpanel2.add(diffOutput); - audioOut.add(leftRightOutput); - leftRightOutput.setText("L/R"); - leftRightOutput.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onLeftRightOutput(); - } -} - -); - jpanel2.add(leftRightOutput); - c1.gridy = 3; - c1.gridx = 1; - c1.gridheight = 1; - c1.gridwidth = 3; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 3; - layout1.setConstraints(jpanel2, c1); - jpanel1.add(jpanel2); - this.add(jpanel1, BorderLayout.CENTER); - this.setPreferredSize(new java.awt.Dimension(600,400)); - this.setName("com.oxande.wavecleaner.ui.AbstractControllerComponent"); - } - - public void setCrackleFactorLabel(String in) - { - SwingUtilities.invokeLater(new SetCrackleFactorLabelClass(in)); - } - - public void setCrackleWindowLabel(String in) - { - SwingUtilities.invokeLater(new SetCrackleWindowLabelClass(in)); - } - - protected void volumeChanged() - { - throw new UnsupportedOperationException("Not implemented"); - } - - /** - * Called by the menu item L/R. - */ - protected void onLeftRightOutput() - { - JOptionPane.showMessageDialog(leftRightOutput, "Not implemented.",leftRightOutput.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - /** - * Called by the menu item ORIGIN. - */ - protected void onOriginalOutput() - { - JOptionPane.showMessageDialog(originalOutput, "Not implemented.",originalOutput.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - protected void crackleFactorChanged() - { - throw new UnsupportedOperationException("Not implemented"); - } - - public String getCrackleWindowLabel() - { - return jlabel3.getText(); - } - - protected void crackleWindowChanged() - { - throw new UnsupportedOperationException("Not implemented"); - } - - public String getCrackleAverageLabel() - { - return jlabel2.getText(); - } -} - +package com.oxande.wavecleaner.ui; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.Runnable; +import java.lang.UnsupportedOperationException; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.JToggleButton; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +/** + * Class created automatically -- DO NOT UPDATE MANUALLY. + * This class has been created based on a XML file and must + * be extended by your own code. The following code only + * provide an easy way to obtain a basic GUI. + */ +public class AbstractControllerComponent extends JPanel { + private JPanel jpanel1 = new JPanel(); + protected JCheckBox crackle = new JCheckBox(); + protected JSlider crackle_factor = new JSlider(); + protected JSlider crackle_average = new JSlider(); + protected JSlider crackle_window = new JSlider(); + private JLabel jlabel1 = new JLabel(); + private JLabel jlabel2 = new JLabel(); + private JLabel jlabel3 = new JLabel(); + private JLabel jlabel4 = new JLabel(); + protected JSlider volume = new JSlider(); + private JLabel jlabel5 = new JLabel(); + private JPanel jpanel2 = new JPanel(); + private FlowLayout flowlayout1 = new FlowLayout(); + protected JToggleButton finalOutput = new JToggleButton(); + ButtonGroup audioOut = new ButtonGroup(); + protected JToggleButton originalOutput = new JToggleButton(); + protected JToggleButton diffOutput = new JToggleButton(); + protected JToggleButton leftRightOutput = new JToggleButton(); +public class ChangeListener1 implements javax.swing.event.ChangeListener { + + public void stateChanged(ChangeEvent e) + { + crackleFactorChanged(); + } +} + +public class ChangeListener2 implements javax.swing.event.ChangeListener { + + public void stateChanged(ChangeEvent e) + { + crackleAverageChanged(); + } +} + +private class SetCrackleWindowLabelClass implements Runnable { + private String input; + + public SetCrackleWindowLabelClass(String input) + { + this.input = input; + } + + public void run() + { + jlabel3.setText(String.valueOf(input)); + } +} + +public class ChangeListener3 implements javax.swing.event.ChangeListener { + + public void stateChanged(ChangeEvent e) + { + crackleWindowChanged(); + } +} + +private class SetCrackleFactorLabelClass implements Runnable { + private String input; + + public SetCrackleFactorLabelClass(String input) + { + this.input = input; + } + + public void run() + { + jlabel1.setText(String.valueOf(input)); + } +} + +private class SetCrackleAverageLabelClass implements Runnable { + private String input; + + public void run() + { + jlabel2.setText(String.valueOf(input)); + } + + public SetCrackleAverageLabelClass(String input) + { + this.input = input; + } +} + +public class ChangeListener4 implements javax.swing.event.ChangeListener { + + public void stateChanged(ChangeEvent e) + { + volumeChanged(); + } +} + + + /** + * Called by the menu item NORMAL. + */ + protected void onFinalOutput() + { + JOptionPane.showMessageDialog(finalOutput, "Not implemented.",finalOutput.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public String getCrackleFactorLabel() + { + return jlabel1.getText(); + } + + public void setCrackleAverageLabel(String in) + { + SwingUtilities.invokeLater(new SetCrackleAverageLabelClass(in)); + } + + protected void crackleAverageChanged() + { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Called by the menu item DIFF. + */ + protected void onDiffOutput() + { + JOptionPane.showMessageDialog(diffOutput, "Not implemented.",diffOutput.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public void initComponents() + { + this.setLayout(new BorderLayout()); + GridBagLayout layout1 = new GridBagLayout(); + GridBagConstraints c1 = new GridBagConstraints(); + jpanel1.setLayout(layout1); + + crackle.setText("Decrackle"); + crackle.setFocusable(false); + c1.gridy = 0; + c1.gridx = 0; + c1.gridheight = 2; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(crackle, c1); + jpanel1.add(crackle); + + crackle_factor.setMinimumSize(new java.awt.Dimension(100,50)); + crackle_factor.setMaximum(100); + crackle_factor.setMinimum(1); + crackle_factor.setOrientation(JSlider.HORIZONTAL); + crackle_factor.setValue(2); + crackle_factor.addChangeListener(new ChangeListener1()); + c1.gridy = 0; + c1.gridx = 1; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(crackle_factor, c1); + jpanel1.add(crackle_factor); + + crackle_average.setMinimumSize(new java.awt.Dimension(100,50)); + crackle_average.setMaximum(100); + crackle_average.setMinimum(0); + crackle_average.setOrientation(JSlider.HORIZONTAL); + crackle_average.setValue(3); + crackle_average.addChangeListener(new ChangeListener2()); + c1.gridy = 0; + c1.gridx = 2; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(crackle_average, c1); + jpanel1.add(crackle_average); + + crackle_window.setMinimumSize(new java.awt.Dimension(100,50)); + crackle_window.setMaximum(20000); + crackle_window.setMinimum(1); + crackle_window.setOrientation(JSlider.HORIZONTAL); + crackle_window.setValue(2000); + crackle_window.addChangeListener(new ChangeListener3()); + c1.gridy = 0; + c1.gridx = 3; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(crackle_window, c1); + jpanel1.add(crackle_window); + + jlabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + c1.gridy = 1; + c1.gridx = 1; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel1, c1); + jpanel1.add(jlabel1); + + jlabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + c1.gridy = 1; + c1.gridx = 2; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel2, c1); + jpanel1.add(jlabel2); + + jlabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + c1.gridy = 1; + c1.gridx = 3; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel3, c1); + jpanel1.add(jlabel3); + + jlabel4.setText("Volume"); + c1.gridy = 2; + c1.gridx = 0; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel4, c1); + jpanel1.add(jlabel4); + + volume.setMinimumSize(new java.awt.Dimension(100,50)); + volume.setMaximum(24); + volume.setMinimum(-24); + volume.setOrientation(JSlider.HORIZONTAL); + volume.setValue(0); + volume.addChangeListener(new ChangeListener4()); + c1.gridy = 2; + c1.gridx = 1; + c1.gridheight = 1; + c1.gridwidth = 3; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 3; + layout1.setConstraints(volume, c1); + jpanel1.add(volume); + + jlabel5.setText("OUTPUT SELECTOR"); + c1.gridy = 3; + c1.gridx = 0; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel5, c1); + jpanel1.add(jlabel5); + + flowlayout1.setHgap(0); + jpanel2.setLayout(flowlayout1); + audioOut.add(finalOutput); + finalOutput.setText("NORMAL"); + finalOutput.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onFinalOutput(); + } +} + +); + jpanel2.add(finalOutput); + audioOut.add(originalOutput); + originalOutput.setText("ORIGIN"); + originalOutput.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onOriginalOutput(); + } +} + +); + jpanel2.add(originalOutput); + audioOut.add(diffOutput); + diffOutput.setText("DIFF"); + diffOutput.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onDiffOutput(); + } +} + +); + jpanel2.add(diffOutput); + audioOut.add(leftRightOutput); + leftRightOutput.setText("L/R"); + leftRightOutput.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onLeftRightOutput(); + } +} + +); + jpanel2.add(leftRightOutput); + c1.gridy = 3; + c1.gridx = 1; + c1.gridheight = 1; + c1.gridwidth = 3; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 3; + layout1.setConstraints(jpanel2, c1); + jpanel1.add(jpanel2); + this.add(jpanel1, BorderLayout.CENTER); + this.setPreferredSize(new java.awt.Dimension(600,400)); + this.setName("com.oxande.wavecleaner.ui.AbstractControllerComponent"); + } + + public void setCrackleFactorLabel(String in) + { + SwingUtilities.invokeLater(new SetCrackleFactorLabelClass(in)); + } + + public void setCrackleWindowLabel(String in) + { + SwingUtilities.invokeLater(new SetCrackleWindowLabelClass(in)); + } + + protected void volumeChanged() + { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Called by the menu item L/R. + */ + protected void onLeftRightOutput() + { + JOptionPane.showMessageDialog(leftRightOutput, "Not implemented.",leftRightOutput.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + /** + * Called by the menu item ORIGIN. + */ + protected void onOriginalOutput() + { + JOptionPane.showMessageDialog(originalOutput, "Not implemented.",originalOutput.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + protected void crackleFactorChanged() + { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getCrackleWindowLabel() + { + return jlabel3.getText(); + } + + protected void crackleWindowChanged() + { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getCrackleAverageLabel() + { + return jlabel2.getText(); + } +} + diff --git a/src/main/java/com/oxande/wavecleaner/ui/AbstractMainScreen.java b/src/main/java/com/oxande/wavecleaner/ui/AbstractMainScreen.java index 00b6e6b..6320de5 100644 --- a/src/main/java/com/oxande/wavecleaner/ui/AbstractMainScreen.java +++ b/src/main/java/com/oxande/wavecleaner/ui/AbstractMainScreen.java @@ -1,381 +1,280 @@ -package com.oxande.wavecleaner.ui; - -import java.awt.BorderLayout; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.lang.Runnable; -import java.lang.UnsupportedOperationException; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.JToolBar; -import javax.swing.SwingUtilities; -import javax.swing.border.Border; - -/** - * Class created automatically -- DO NOT UPDATE MANUALLY. - * This class has been created based on a XML file and must - * be extended by your own code. The following code only - * provide an easy way to obtain a basic GUI. - */ -public class AbstractMainScreen extends JFrame { - private JPanel jpanel1 = new JPanel(); - private JMenuBar jmenubar1 = new JMenuBar(); - private JMenu jmenu1 = new JMenu(); - private JMenuItem jmenuitem1 = new JMenuItem(); - private JMenuItem jmenuitem2 = new JMenuItem(); - private JMenuItem jmenuitem3 = new JMenuItem(); - private JMenuItem jmenuitem4 = new JMenuItem(); - private JMenu jmenu2 = new JMenu(); - private JMenuItem jmenuitem5 = new JMenuItem(); - private JMenuItem jmenuitem6 = new JMenuItem(); - private JMenu jmenu3 = new JMenu(); - private JMenuItem jmenuitem7 = new JMenuItem(); - protected JLabel statusBar = new JLabel(); - protected JToolBar toolbar = new JToolBar(); - private JSplitPane jsplitpane1 = new JSplitPane(); - private JSplitPane jsplitpane2 = new JSplitPane(); - protected WaveComponent instant = new WaveComponent(); - protected AudioInfoComponent infos = new AudioInfoComponent(); - private JSplitPane jsplitpane3 = new JSplitPane(); - protected com.oxande.wavecleaner.ui.WaveFormComponent song = new com.oxande.wavecleaner.ui.WaveFormComponent(); - protected com.oxande.wavecleaner.ui.ControllerComponent controller = new com.oxande.wavecleaner.ui.ControllerComponent(); -public class WindowAdapter1 extends java.awt.event.WindowAdapter { - - public void windowClosing(WindowEvent e) - { - onExit(); - } -} - -private class SetStatusMessageClass implements Runnable { - private String input; - - public void run() - { - statusBar.setText(String.valueOf(input)); - } - - public SetStatusMessageClass(String input) - { - this.input = input; - } -} - - - /** - * Called by the menu item Help/About. - * Called by the menu item Help/About. - */ - protected void showAboutDlg() - { - JOptionPane.showMessageDialog(jmenuitem7, "Not implemented.",jmenuitem7.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public void setStatusMessage(String in) - { - SwingUtilities.invokeLater(new SetStatusMessageClass(in)); - } - - /** - * Called by the menu item Edit/Zoom In. - * Called by the menu item Edit/Zoom In. - */ - protected void onZoomIn() - { - JOptionPane.showMessageDialog(jmenuitem5, "Not implemented.",jmenuitem5.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - /** - * Called by the menu item File/Exit. - * Called by the menu item File/Exit. - */ - protected void onExit() - { - JOptionPane.showMessageDialog(jmenuitem4, "Not implemented.",jmenuitem4.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public String getStatusMessage() - { - return statusBar.getText(); - } - - /** - * Called by the menu item File/Record. - * Called by the menu item File/Record. - */ - protected void onRecordSound() - { - JOptionPane.showMessageDialog(jmenuitem2, "Not implemented.",jmenuitem2.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - /** - * Called by the menu item File/Play/Pause. - * Called by the menu item File/Play/Pause. - */ - protected void onPlayPause() - { - JOptionPane.showMessageDialog(jmenuitem3, "Not implemented.",jmenuitem3.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - /** - * Called by the menu item File/Load the music. - * Called by the menu item File/Load the music. - */ - protected void onLoadSound() - { - JOptionPane.showMessageDialog(jmenuitem1, "Not implemented.",jmenuitem1.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public static void main(String[] args) - { - AbstractMainScreen appl = new AbstractMainScreen(); - appl.initComponents(); - appl.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); - appl.setVisible(true); - } - - /** - * Called by the menu item Edit/Zoom Out. - * Called by the menu item Edit/Zoom Out. - */ - protected void onZoomOut() - { - JOptionPane.showMessageDialog(jmenuitem6, "Not implemented.",jmenuitem6.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public void initComponents() - { - jpanel1.setLayout(new BorderLayout()); - jmenu1.setText("File"); - jmenu1.setMnemonic(java.awt.event.KeyEvent.VK_F); - jmenu1.setDisplayedMnemonicIndex(0); - jmenuitem1.setText("Load the music"); - jmenuitem1.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onLoadSound(); - } -} - -); - jmenuitem1.setAction(new AbstractAction() { - { - putValue(Action.NAME, "Load the music"); - } - - public void actionPerformed(ActionEvent e) - { - onLoadSound(); - } -} - -); - jmenu1.add(jmenuitem1); - jmenuitem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke("ctrl R")); - jmenuitem2.setText("Record"); - jmenuitem2.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onRecordSound(); - } -} - -); - jmenuitem2.setAction(new AbstractAction() { - { - putValue(Action.NAME, "Record"); - putValue(Action.ACCELERATOR_KEY, jmenuitem2.getAccelerator()); - } - - public void actionPerformed(ActionEvent e) - { - onRecordSound(); - } -} - -); - jmenu1.add(jmenuitem2); - jmenuitem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke("SPACE")); - jmenuitem3.setText("Play/Pause"); - jmenuitem3.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onPlayPause(); - } -} - -); - jmenuitem3.setAction(new AbstractAction() { - { - putValue(Action.NAME, "Play/Pause"); - putValue(Action.ACCELERATOR_KEY, jmenuitem3.getAccelerator()); - } - - public void actionPerformed(ActionEvent e) - { - onPlayPause(); - } -} - -); - jmenu1.add(jmenuitem3); - jmenuitem4.setText("Exit"); - jmenuitem4.setMnemonic(java.awt.event.KeyEvent.VK_X); - jmenuitem4.setDisplayedMnemonicIndex(1); - jmenuitem4.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onExit(); - } -} - -); - jmenuitem4.setAction(new AbstractAction() { - { - putValue(Action.NAME, "Exit"); - putValue(Action.MNEMONIC_KEY, java.awt.event.KeyEvent.VK_X); - putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, new Integer(1)); - } - - public void actionPerformed(ActionEvent e) - { - onExit(); - } -} - -); - jmenu1.add(jmenuitem4); - jmenubar1.add(jmenu1); - jmenu2.setText("Edit"); - jmenu2.setMnemonic(java.awt.event.KeyEvent.VK_E); - jmenu2.setDisplayedMnemonicIndex(0); - jmenuitem5.setName("zoomIn"); - jmenuitem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke("ctrl L")); - jmenuitem5.setText("Zoom In"); - jmenuitem5.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onZoomIn(); - } -} - -); - jmenuitem5.setAction(new AbstractAction() { - { - putValue(Action.NAME, "Zoom In"); - putValue(Action.ACCELERATOR_KEY, jmenuitem5.getAccelerator()); - } - - public void actionPerformed(ActionEvent e) - { - onZoomIn(); - } -} - -); - jmenu2.add(jmenuitem5); - jmenuitem6.setName("zoomOut"); - jmenuitem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke("ctrl K")); - jmenuitem6.setText("Zoom Out"); - jmenuitem6.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - onZoomOut(); - } -} - -); - jmenuitem6.setAction(new AbstractAction() { - { - putValue(Action.NAME, "Zoom Out"); - putValue(Action.ACCELERATOR_KEY, jmenuitem6.getAccelerator()); - } - - public void actionPerformed(ActionEvent e) - { - onZoomOut(); - } -} - -); - jmenu2.add(jmenuitem6); - jmenubar1.add(jmenu2); - jmenu3.setText("Help"); - jmenu3.setMnemonic(java.awt.event.KeyEvent.VK_H); - jmenu3.setDisplayedMnemonicIndex(0); - jmenuitem7.setText("About"); - jmenuitem7.setMnemonic(java.awt.event.KeyEvent.VK_A); - jmenuitem7.setDisplayedMnemonicIndex(0); - jmenuitem7.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - showAboutDlg(); - } -} - -); - jmenuitem7.setAction(new AbstractAction() { - { - putValue(Action.NAME, "About"); - putValue(Action.MNEMONIC_KEY, java.awt.event.KeyEvent.VK_A); - putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, new Integer(0)); - } - - public void actionPerformed(ActionEvent e) - { - showAboutDlg(); - } -} - -); - jmenu3.add(jmenuitem7); - jmenubar1.add(jmenu3); - this.setJMenuBar(jmenubar1); - Border border1 = BorderFactory.createLoweredBevelBorder(); - statusBar.setBorder(border1); - statusBar.setText("Ready."); - statusBar.setFont(statusBar.getFont().deriveFont( Font.PLAIN )); - jpanel1.add(statusBar, BorderLayout.SOUTH); - toolbar.setOrientation(JToolBar.HORIZONTAL); - jpanel1.add(toolbar, "North"); - this.addWindowListener(new WindowAdapter1()); - jsplitpane2.setOrientation(JSplitPane.VERTICAL_SPLIT); - jsplitpane2.setDividerLocation(0.5); - jsplitpane2.setTopComponent(instant); - jsplitpane2.setBottomComponent(infos); - jsplitpane1.setTopComponent(jsplitpane2); - jsplitpane3.setMinimumSize(new java.awt.Dimension(100,200)); - jsplitpane3.setOrientation(JSplitPane.VERTICAL_SPLIT); - jsplitpane3.setTopComponent(song); - jsplitpane3.setBottomComponent(controller); - jsplitpane1.setBottomComponent(jsplitpane3); - jpanel1.add(jsplitpane1, BorderLayout.CENTER); - this.setContentPane(jpanel1); - this.setPreferredSize(new java.awt.Dimension(600,400)); - this.setName("com.oxande.wavecleaner.ui.AbstractMainScreen"); - this.setLocationByPlatform(true); - this.setTitle("Wave Cleaner"); - this.pack(); - } -} - +package com.oxande.wavecleaner.ui; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.lang.Runnable; +import java.lang.UnsupportedOperationException; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JToolBar; +import javax.swing.SwingUtilities; +import javax.swing.border.Border; + +/** + * Class created automatically -- DO NOT UPDATE MANUALLY. + * This class has been created based on a XML file and must + * be extended by your own code. The following code only + * provide an easy way to obtain a basic GUI. + */ +public class AbstractMainScreen extends JFrame { + private JPanel jpanel1 = new JPanel(); + private JMenuBar jmenubar1 = new JMenuBar(); + private JMenu jmenu1 = new JMenu(); + private JMenuItem jmenuitem1 = new JMenuItem(); + private JMenuItem jmenuitem2 = new JMenuItem(); + private JMenuItem jmenuitem3 = new JMenuItem(); + private JMenuItem jmenuitem4 = new JMenuItem(); + private JMenu jmenu2 = new JMenu(); + private JMenuItem jmenuitem5 = new JMenuItem(); + private JMenuItem jmenuitem6 = new JMenuItem(); + private JMenu jmenu3 = new JMenu(); + private JMenuItem jmenuitem7 = new JMenuItem(); + protected JLabel statusBar = new JLabel(); + protected JToolBar toolbar = new JToolBar(); + private JSplitPane jsplitpane1 = new JSplitPane(); + private JSplitPane jsplitpane2 = new JSplitPane(); + protected WaveComponent instant = new WaveComponent(); + protected VUMeterComponent vuMeter = new VUMeterComponent(); + private JSplitPane jsplitpane3 = new JSplitPane(); + protected com.oxande.wavecleaner.ui.WaveFormComponent song = new com.oxande.wavecleaner.ui.WaveFormComponent(); + protected com.oxande.wavecleaner.ui.ControllerComponent controller = new com.oxande.wavecleaner.ui.ControllerComponent(); +public class WindowAdapter1 extends java.awt.event.WindowAdapter { + + public void windowClosing(WindowEvent e) + { + onExit(); + } +} + +private class SetStatusMessageClass implements Runnable { + private String input; + + public void run() + { + statusBar.setText(String.valueOf(input)); + } + + public SetStatusMessageClass(String input) + { + this.input = input; + } +} + + + /** + * Called by the menu item Help/About. + */ + protected void showAboutDlg() + { + JOptionPane.showMessageDialog(jmenuitem7, "Not implemented.",jmenuitem7.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public void setStatusMessage(String in) + { + SwingUtilities.invokeLater(new SetStatusMessageClass(in)); + } + + /** + * Called by the menu item Edit/Zoom In. + */ + protected void onZoomIn() + { + JOptionPane.showMessageDialog(jmenuitem5, "Not implemented.",jmenuitem5.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + /** + * Called by the menu item File/Exit. + */ + protected void onExit() + { + JOptionPane.showMessageDialog(jmenuitem4, "Not implemented.",jmenuitem4.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public String getStatusMessage() + { + return statusBar.getText(); + } + + /** + * Called by the menu item File/Record. + */ + protected void onRecordSound() + { + JOptionPane.showMessageDialog(jmenuitem2, "Not implemented.",jmenuitem2.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + /** + * Called by the menu item File/Play/Pause. + */ + protected void onPlayPause() + { + JOptionPane.showMessageDialog(jmenuitem3, "Not implemented.",jmenuitem3.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + /** + * Called by the menu item File/Load the music. + */ + protected void onLoadSound() + { + JOptionPane.showMessageDialog(jmenuitem1, "Not implemented.",jmenuitem1.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public static void main(String[] args) + { + AbstractMainScreen appl = new AbstractMainScreen(); + appl.initComponents(); + appl.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); + appl.setVisible(true); + } + + /** + * Called by the menu item Edit/Zoom Out. + */ + protected void onZoomOut() + { + JOptionPane.showMessageDialog(jmenuitem6, "Not implemented.",jmenuitem6.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public void initComponents() + { + jpanel1.setLayout(new BorderLayout()); + jmenu1.setText("File"); + jmenu1.setMnemonic(java.awt.event.KeyEvent.VK_F); + jmenu1.setDisplayedMnemonicIndex(0); + jmenuitem1.setText("Load the music"); + jmenuitem1.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onLoadSound(); + } +} + +); + jmenu1.add(jmenuitem1); + jmenuitem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke("ctrl R")); + jmenuitem2.setText("Record"); + jmenuitem2.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onRecordSound(); + } +} + +); + jmenu1.add(jmenuitem2); + jmenuitem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke("SPACE")); + jmenuitem3.setText("Play/Pause"); + jmenuitem3.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onPlayPause(); + } +} + +); + jmenu1.add(jmenuitem3); + jmenuitem4.setText("Exit"); + jmenuitem4.setMnemonic(java.awt.event.KeyEvent.VK_X); + jmenuitem4.setDisplayedMnemonicIndex(1); + jmenuitem4.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onExit(); + } +} + +); + jmenu1.add(jmenuitem4); + jmenubar1.add(jmenu1); + jmenu2.setText("Edit"); + jmenu2.setMnemonic(java.awt.event.KeyEvent.VK_E); + jmenu2.setDisplayedMnemonicIndex(0); + jmenuitem5.setName("zoomIn"); + jmenuitem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke("ctrl L")); + jmenuitem5.setText("Zoom In"); + jmenuitem5.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onZoomIn(); + } +} + +); + jmenu2.add(jmenuitem5); + jmenuitem6.setName("zoomOut"); + jmenuitem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke("ctrl K")); + jmenuitem6.setText("Zoom Out"); + jmenuitem6.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + onZoomOut(); + } +} + +); + jmenu2.add(jmenuitem6); + jmenubar1.add(jmenu2); + jmenu3.setText("Help"); + jmenu3.setMnemonic(java.awt.event.KeyEvent.VK_H); + jmenu3.setDisplayedMnemonicIndex(0); + jmenuitem7.setText("About"); + jmenuitem7.setMnemonic(java.awt.event.KeyEvent.VK_A); + jmenuitem7.setDisplayedMnemonicIndex(0); + jmenuitem7.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + showAboutDlg(); + } +} + +); + jmenu3.add(jmenuitem7); + jmenubar1.add(jmenu3); + this.setJMenuBar(jmenubar1); + Border border1 = BorderFactory.createLoweredBevelBorder(); + statusBar.setBorder(border1); + statusBar.setText("Ready."); + statusBar.setFont(statusBar.getFont().deriveFont( Font.PLAIN )); + jpanel1.add(statusBar, BorderLayout.SOUTH); + toolbar.setOrientation(JToolBar.HORIZONTAL); + jpanel1.add(toolbar, "North"); + this.addWindowListener(new WindowAdapter1()); + jsplitpane2.setOrientation(JSplitPane.VERTICAL_SPLIT); + jsplitpane2.setDividerLocation(0.5); + jsplitpane2.setTopComponent(instant); + jsplitpane2.setBottomComponent(vuMeter); + jsplitpane1.setTopComponent(jsplitpane2); + jsplitpane3.setMinimumSize(new java.awt.Dimension(100,200)); + jsplitpane3.setOrientation(JSplitPane.VERTICAL_SPLIT); + jsplitpane3.setTopComponent(song); + jsplitpane3.setBottomComponent(controller); + jsplitpane1.setBottomComponent(jsplitpane3); + jpanel1.add(jsplitpane1, BorderLayout.CENTER); + this.setContentPane(jpanel1); + this.setPreferredSize(new java.awt.Dimension(600,400)); + this.setName("com.oxande.wavecleaner.ui.AbstractMainScreen"); + this.setLocationByPlatform(true); + this.setTitle("Wave Cleaner"); + this.pack(); + } +} + diff --git a/src/main/java/com/oxande/wavecleaner/ui/AbstractRecordScreen.java b/src/main/java/com/oxande/wavecleaner/ui/AbstractRecordScreen.java index 0f311c1..86ac20c 100644 --- a/src/main/java/com/oxande/wavecleaner/ui/AbstractRecordScreen.java +++ b/src/main/java/com/oxande/wavecleaner/ui/AbstractRecordScreen.java @@ -1,89 +1,176 @@ -package com.oxande.wavecleaner.ui; - -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - -/** - * Class created automatically -- DO NOT UPDATE MANUALLY. - * This class has been created based on a XML file and must - * be extended by your own code. The following code only - * provide an easy way to obtain a basic GUI. - */ -public class AbstractRecordScreen extends JDialog { - private JPanel jpanel1 = new JPanel(); - private JPanel jpanel2 = new JPanel(); - private JLabel jlabel1 = new JLabel(); - private JButton jbutton1 = new JButton(); - - /** - * Called by the menu item START RECORDING. - */ - protected void startRecord() - { - JOptionPane.showMessageDialog(jbutton1, "Not implemented.",jbutton1.getText(), JOptionPane.INFORMATION_MESSAGE); - } - - public static void main(String[] args) - { - AbstractRecordScreen appl = new AbstractRecordScreen(); - appl.initComponents(); - appl.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); - appl.setVisible(true); - } - - public void initComponents() - { - jpanel1.setLayout(new BorderLayout()); - GridBagLayout layout1 = new GridBagLayout(); - GridBagConstraints c1 = new GridBagConstraints(); - jpanel2.setLayout(layout1); - - jlabel1.setText("You must have the turnable running (the disc turns) and the stylus just above the disc. Then you can start recording."); - c1.gridy = 0; - c1.gridx = 0; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jlabel1, c1); - jpanel2.add(jlabel1); - - jbutton1.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) - { - startRecord(); - } -} - -); - jbutton1.setText("START RECORDING"); - c1.gridy = 1; - c1.gridx = 0; - c1.gridheight = 1; - c1.gridwidth = 1; - c1.anchor = GridBagConstraints.WEST; - c1.fill = GridBagConstraints.NONE; - c1.weightx = 1; - layout1.setConstraints(jbutton1, c1); - jpanel2.add(jbutton1); - jpanel1.add(jpanel2, BorderLayout.CENTER); - this.setContentPane(jpanel1); - this.pack(); - this.setPreferredSize(new java.awt.Dimension(400,200)); - this.setName("com.oxande.wavecleaner.ui.AbstractRecordScreen"); - this.setLocationByPlatform(true); - this.setTitle("Recording"); - } -} - +package com.oxande.wavecleaner.ui; + +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +/** + * Class created automatically -- DO NOT UPDATE MANUALLY. + * This class has been created based on a XML file and must + * be extended by your own code. The following code only + * provide an easy way to obtain a basic GUI. + */ +public class AbstractRecordScreen extends JDialog { + private JPanel jpanel1 = new JPanel(); + private JPanel jpanel2 = new JPanel(); + private JLabel jlabel1 = new JLabel(); + private JLabel jlabel2 = new JLabel(); + protected JComboBox inputLine = new JComboBox(); + private JButton jbutton1 = new JButton(); + private JButton jbutton2 = new JButton(); +public class SimpleMapEntry implements java.util.Map.Entry { + private String key; + private String value; + + public SimpleMapEntry(java.lang.String key, java.lang.String value) + { + this.key = key; + this.value = value; + } + + public String getKey() + { + return key; + } + + public String getValue() + { + return value; + } + + public String setValue(String value) + { + String old = this.value; + this.value = value.toString(); + return old; + } + + public String toString() + { + return this.value; + } +} + + + /** + * Called by the menu item START RECORDING. + */ + protected void startRecord() + { + JOptionPane.showMessageDialog(jbutton1, "Not implemented.",jbutton1.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + /** + * Called by the menu item END RECORDING. + */ + protected void endRecord() + { + JOptionPane.showMessageDialog(jbutton2, "Not implemented.",jbutton2.getText(), JOptionPane.INFORMATION_MESSAGE); + } + + public static void main(String[] args) + { + AbstractRecordScreen appl = new AbstractRecordScreen(); + appl.initComponents(); + appl.setDefaultCloseOperation(DISPOSE_ON_CLOSE); + appl.setVisible(true); + } + + public void initComponents() + { + jpanel1.setLayout(new BorderLayout()); + GridBagLayout layout1 = new GridBagLayout(); + GridBagConstraints c1 = new GridBagConstraints(); + jpanel2.setLayout(layout1); + + jlabel1.setText("You must have the turnable running (the disc turns) and \n" + + "\t\t\tthe stylus just above the disc. Then you can start recording."); + c1.gridy = 0; + c1.gridx = 0; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel1, c1); + jpanel2.add(jlabel1); + + jlabel2.setText("Select your input:"); + c1.gridy = 1; + c1.gridx = 0; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jlabel2, c1); + jpanel2.add(jlabel2); + + c1.gridy = 1; + c1.gridx = 1; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(inputLine, c1); + jpanel2.add(inputLine); + + jbutton1.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + startRecord(); + } +} + +); + jbutton1.setText("START RECORDING"); + c1.gridy = 2; + c1.gridx = 0; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jbutton1, c1); + jpanel2.add(jbutton1); + + jbutton2.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) + { + endRecord(); + } +} + +); + jbutton2.setText("END RECORDING"); + c1.gridy = 2; + c1.gridx = 1; + c1.gridheight = 1; + c1.gridwidth = 1; + c1.anchor = GridBagConstraints.WEST; + c1.fill = GridBagConstraints.NONE; + c1.weightx = 1; + layout1.setConstraints(jbutton2, c1); + jpanel2.add(jbutton2); + jpanel1.add(jpanel2, BorderLayout.CENTER); + this.setContentPane(jpanel1); + this.pack(); + this.setPreferredSize(new java.awt.Dimension(400,200)); + this.setName("com.oxande.wavecleaner.ui.AbstractRecordScreen"); + this.setLocationByPlatform(true); + this.setTitle("Recording"); + } +} + diff --git a/src/main/java/com/oxande/wavecleaner/ui/MainScreen.java b/src/main/java/com/oxande/wavecleaner/ui/MainScreen.java index 41c2be3..7a05eb1 100644 --- a/src/main/java/com/oxande/wavecleaner/ui/MainScreen.java +++ b/src/main/java/com/oxande/wavecleaner/ui/MainScreen.java @@ -60,14 +60,16 @@ public void setWaveForm( AudioDocument audio ){ this.instant.setAudioDocument(audio); this.audio.addChangedAudioListener(this); this.audio.addAudioPlayerListener(this); - this.infos.setAudioDocument(audio); + // this.infos.setAudioDocument(audio); // Initialize the controller component - this.controller.setFilters(audio.decrackFilter, audio.controlFilter); + this.audio.preamplifer.setVUMeter(this.vuMeter); + this.vuMeter.setVisible(true); + this.controller.setFilters(audio.decrackFilter, audio.preamplifer); } protected void onRecordSound(){ - RecordScreen dialog = new RecordScreen(); + RecordScreen dialog = new RecordScreen(this.app); dialog.initComponents(); } @@ -115,6 +117,7 @@ public void onPlayPause(){ int pos = song.getPlayHead(); if(this.audio.isPlaying()){ this.audio.stop(); + this.vuMeter.reset(); } else { this.audio.play(pos); diff --git a/src/main/java/com/oxande/wavecleaner/ui/RecordScreen.java b/src/main/java/com/oxande/wavecleaner/ui/RecordScreen.java index 7b9888e..732ad7f 100644 --- a/src/main/java/com/oxande/wavecleaner/ui/RecordScreen.java +++ b/src/main/java/com/oxande/wavecleaner/ui/RecordScreen.java @@ -1,19 +1,116 @@ package com.oxande.wavecleaner.ui; -import javax.swing.JFrame; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.Mixer; +import javax.sound.sampled.Port; +import javax.sound.sampled.TargetDataLine; + +import org.apache.logging.log4j.Logger; + +import com.oxande.wavecleaner.WaveCleaner; +import com.oxande.wavecleaner.util.logging.LogFactory; + +import ddf.minim.AudioRecorder; +import ddf.minim.Minim; public class RecordScreen extends AbstractRecordScreen { + private static Logger LOG = LogFactory.getLog(RecordScreen.class); + protected AudioRecorder recorder; + protected WaveCleaner app = null; + + RecordScreen( WaveCleaner application ){ + this.app = application; + } + /** - * Make this recording screen visible + * Make this recording screen visible. + * */ public void initComponents(){ super.initComponents(); - setVisible(true); setModal(true); + File f = new File("recording.wav"); + recorder = this.app.getAudioRecorder(f, 48000); + + + Mixer.Info[] mixers = AudioSystem.getMixerInfo(); + List availableLines = new ArrayList<>(); + for (Mixer.Info mixerInfo : mixers){ + System.out.println(mixerInfo); + Mixer m = AudioSystem.getMixer(mixerInfo); + + Line.Info[] lines = m.getSourceLineInfo(); + for (Line.Info li : lines){ + System.out.println("Found target line: " + li); + try { + m.open(); + if( li instanceof Port.Info ){ + Port.Info in = (Port.Info) li; + this.inputLine.addItem( new SimpleMapEntry("" + availableLines.size(), in.getName())); + availableLines.add(li); + } + } catch (LineUnavailableException e){ + System.out.println("Line unavailable."); + } + } + } + + for(Line.Info infoLine : availableLines ){ + LOG.info("Target line {}: {}", infoLine.getClass(), infoLine); + } + + + int sampleRate = 48000; + int bitDepth = 16; + int type = Minim.STEREO; + int bufferSize = 4096; + AudioFormat format = new AudioFormat(sampleRate, bitDepth, type, true, false); +// TargetDataLine line = getTargetDataLine(format, bufferSize * 4); +// if (line != null) +// { +// return new JSAudioInput(line, bufferSize); +// }; +// TargetDataLine line; + DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); // format is an AudioFormat object + if (!AudioSystem.isLineSupported(info)) { + // Handle the error. + } + // Obtain and open the line. + try { + Line.Info[] infoLines = AudioSystem.getSourceLineInfo(info); + for(Line.Info infoLine : infoLines ){ + LOG.info("Source line: {}", infoLine); + } + infoLines = AudioSystem.getTargetLineInfo(info); + for(Line.Info infoLine : infoLines ){ + LOG.info("Target line {}: {}", infoLine.getClass(), infoLine); + } + TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info); + line.open(format); + } catch (LineUnavailableException ex) { + // Handle the error. + //... + } + + + setVisible(true); } protected void startRecord(){ - + recorder.beginRecord(); + } + + protected void endRecord(){ + recorder.endRecord(); + recorder.save(); } } diff --git a/src/main/java/com/oxande/wavecleaner/ui/VUMeterComponent.java b/src/main/java/com/oxande/wavecleaner/ui/VUMeterComponent.java index b479749..b45c226 100644 --- a/src/main/java/com/oxande/wavecleaner/ui/VUMeterComponent.java +++ b/src/main/java/com/oxande/wavecleaner/ui/VUMeterComponent.java @@ -1,65 +1,196 @@ package com.oxande.wavecleaner.ui; +import java.awt.Color; import java.awt.Graphics; +import java.awt.Graphics2D; import javax.swing.JComponent; +import org.apache.logging.log4j.Logger; + +import com.oxande.wavecleaner.util.logging.LogFactory; + /** - * A component for displaying information about the RMS and peak levels - * + * A component for displaying information about the RMS and peak levels. The + * VUMeter stores its status which is not the way to do, but this should be + * sufficient. + * + * You have to set the sample rate and push each sample. The analysis is as + * fast as possible. Mainly used by the preamplifier with the output including + * the gain (which can explain some saturation). Only peaks level are displayed. + * By construction, the level is calculated for the last 20 milliseconds. When the + * level is higher than the peak, the peak is stored for 2 seconds. Thoses values could + * be changed (see code for reference). + * * @author wrey75 * */ @SuppressWarnings("serial") public class VUMeterComponent extends JComponent { + private static Logger LOG = LogFactory.getLog(VUMeterComponent.class); + + private static final int NB_CHANNELS = 2; // STEREO + + public static final int HORIZONAL = 1; + public static final int VERTICAL = 2; + public static final int AUTO = 3; + + public static final float LEVEL_6DB = 0.70794576f; // -6dB - int samples = 0; - float maxPeakLeft = 0; - float maxPeakRight = 0; - float peakLeft = 0; - float peakRight = 0; - float rmsRight = 0; - float rmsLeft = 0; - public synchronized void reset(){ - maxPeakLeft = 0; - maxPeakRight = 0; - peakLeft = 0; - peakRight = 0; - rmsRight = 0; - rmsLeft = 0; - samples = 0; + int border = 3; + boolean blocks; + int orientation = AUTO; + int bufferSize = 1024; + int buffCount = 0; + float sampleRate = 48000; + + private int mode = 0; + private int height; + private int width; + private Graphics2D g; + private ChannelData data[]; + + public VUMeterComponent(){ + super(); + this.setVisible(true); + this.setOpaque(true); + this.setBackground(Color.BLACK); + this.data = new ChannelData[2]; + for(int ch = 0; ch < NB_CHANNELS; ch++){ + this.data[ch] = new ChannelData(); + } } - public synchronized void push(float left, float right){ - samples++; + private static class ChannelData { + public static final float DELAY_PEAK = 2.0f; + public boolean over = false; + public float peak = 0; + public float rms = 0; + public float buffer = 0; + public int peakDelay = 0; + public int noPeak = 0; - if( left > peakLeft ){ - peakLeft = left; - if( peakLeft > maxPeakLeft ){ - maxPeakLeft = peakLeft; - } + public void reset() { + over = false; + peak = 0.0f; + rms = 0.0f; + buffer = 0.0f; + peakDelay = 0; + noPeak = 0; } - if( right > peakRight ){ - peakRight = right; - if( peakRight > maxPeakRight ){ - maxPeakRight = peakRight; + } + + public synchronized void reset() { + for(int ch = 0; ch < NB_CHANNELS; ch++){ + this.data[ch].reset(); + } + buffCount = 0; + } + + /** + * Set the sample rate. + * + * @param sampleRate + */ + public void setSampleRate(float sampleRate){ + this.bufferSize = (int)(sampleRate / 20.0); + this.sampleRate = sampleRate; + } + + public synchronized void push(float samples[]) { + boolean mustResetCounter = false; + buffCount++; + for(int ch = 0; ch < samples.length; ch++){ + ChannelData channel = this.data[ch]; + float level = Math.abs(samples[ch]); + if (level > channel.peak) { + channel.peak = level; + channel.noPeak = 0; + channel.peakDelay = (int)(channel.DELAY_PEAK * this.sampleRate); + if (channel.peak > 0.99f) { + channel.over = true; + } + } + channel.buffer = Math.max(channel.buffer, level); + if( buffCount >= bufferSize ){ + // LOG.debug("RMS = {} => {}", channel.rms, channel.peak); + channel.rms = channel.buffer; // (float) channel.buffer / (float)bufferSize; + channel.buffer = 0.0f; + mustResetCounter = true; + if( channel.peakDelay > 0 ){ + channel.peakDelay -= bufferSize; + } + else { + channel.noPeak++; + channel.peak -= (channel.noPeak * channel.noPeak * 0.2) / sampleRate; // 200.0 / sampleRate; + } } } + + if( mustResetCounter ) buffCount = 0; + } + + public static float dB2volt(float dBvalue) { + return (float) Math.pow(10.0, (0.05 * dBvalue)); + } - rmsRight += left; - rmsLeft += right; + public static float volt2db(float volt) { + return (float) (20.0 * Math.log10(volt)); + } + + private void drawRectangle( int channel, Color color, double start, double end ){ + int x0, x1, y0, y1; + int size; + + if( mode == HORIZONAL ){ + size = height / 2; + y0 = (channel * size) + border; + y1 = (channel + 1) * size - border; + x0 = (int)(start * width) + border; + x1 = (int)(end * width) + border; + if( Math.abs(x1 - x0) < 1 ) x1 = x0 + 7; + } + else { + size = width / 2; + x0 = (channel * size) + border; + x1 = (channel + 1) * size - border; + y1 = height - (int)(start * height); + y0 = height - (int)(end * height); + if( Math.abs(y1 - y0) < 1 ) y1 = y0 + 7; + } + g.setColor(color); + g.fillRect(x0, y0, x1 - x0, y1 - y0); + } + + private void drawLeft( Color color, double start, double end ){ + drawRectangle(0, color, start, end); } + private void drawRight( Color color, double start, double end ){ + drawRectangle(1, color, start, end); + } + @Override - public void paintComponent(Graphics g0){ -// Graphics2D g = (Graphics2D)g0; -// if( this.audio != null ){ -// this.line = 0; -// println(g, "Sample rate", "" + audio.getSampleRate()); -// int duration = (int)(audio.getNumberOfSamples() / audio.getSampleRate() / 60.0); -// println(g, "Duration:", duration + "min." ); -// } - + public void paintComponent(Graphics g0) { + g = (Graphics2D) g0; + + super.paintComponent(g0); + mode = (orientation == AUTO ? (width > height ? HORIZONAL : VERTICAL) : orientation); + width = getWidth() - 10; + height = getHeight() - 10; + + for(int ch = 0; ch < NB_CHANNELS; ch++ ){ + ChannelData channel = this.data[ch]; + if( channel.rms > 0 ){ + drawRectangle(ch, Color.YELLOW, -0.0, channel.rms); + drawRectangle(ch, Color.GREEN, -0.0, Math.min(channel.rms, LEVEL_6DB)); + } + if( channel.peak > 0.0 ){ + drawRectangle(ch, Color.ORANGE, channel.peak, channel.peak); + } + if( channel.over ) drawRectangle(ch, Color.RED, 1.0f, 1.0f); + } + } } diff --git a/src/main/java/com/oxande/xmlswing/components/ComponentUI.java b/src/main/java/com/oxande/xmlswing/components/ComponentUI.java index b16453a..c4d953d 100755 --- a/src/main/java/com/oxande/xmlswing/components/ComponentUI.java +++ b/src/main/java/com/oxande/xmlswing/components/ComponentUI.java @@ -5,7 +5,9 @@ import java.awt.event.MouseEvent; import java.util.EventObject; +import javax.swing.JComboBox; import javax.swing.JOptionPane; +import javax.swing.JRadioButton; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -130,13 +132,13 @@ else if( tagName.equals( GridBagLayoutUI.TABLE_TAG )){ else if( tagName.equals("iframe")){ component = new JInternalFrameUI(); } - else if( tagName.equals("select")){ + else if( tagName.equals("select") || tagName.equals(JComboBox.class.getSimpleName())){ component = new JComboBoxUI(); } else if( tagName.equalsIgnoreCase("JTable")){ component = new JTableUI(); } - else if( tagName.equals("radiobutton") || tagName.equals("radio")){ + else if( tagName.equals("radiobutton") || tagName.equals("radio") || tagName.equals(JRadioButton.class.getSimpleName())){ component = new JRadioButtonUI(); } else if( tagName.equals("checkbox")){ diff --git a/src/main/resources/MainScreen.xml b/src/main/resources/MainScreen.xml index 2d972d9..1f650c0 100644 --- a/src/main/resources/MainScreen.xml +++ b/src/main/resources/MainScreen.xml @@ -30,7 +30,7 @@ - + diff --git a/src/main/resources/RecordScreen.xml b/src/main/resources/RecordScreen.xml index 5d1c1dc..fa945d6 100644 --- a/src/main/resources/RecordScreen.xml +++ b/src/main/resources/RecordScreen.xml @@ -5,11 +5,16 @@ - + + + + + +
Select your input:
START RECORDINGEND RECORDING