public static void main(String[] args) { final JavaMixer sm = new JavaMixer(); final JFrame jf = new JFrame("Mixer Test"); final JPanel jp = new JPanel(); jf.add(jp); jp.add(sm.getTree()); jf.setSize(600, 500); jf.setVisible(true); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); sm.getTree() .addTreeSelectionListener( e -> { TreePath path = e.getPath(); if (path.getLastPathComponent() instanceof ControlNode) { ControlNode controlNode = (ControlNode) path.getLastPathComponent(); if (!(controlNode.getControl() instanceof CompoundControl)) { if (jp.getComponentCount() > 1) jp.remove(1); jp.add(controlNode.getComponent(), 1); jp.repaint(); } } }); jp.add(sm.getPrefferedMasterVolume()); jp.add(sm.getPrefferedMasterVolume()); jp.add(sm.getPrefferedInputVolume()); jp.repaint(); sm.setMicrophoneInput(); sm.setMuteForMicrophoneOutput(); }
JFrame openMonitorGUI(String title) { try { MonitorGUI gui = new MonitorGUI(this, title); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.addWindowListener(this); frame.getContentPane().add(gui); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle r = ge.getMaximumWindowBounds(); frame.setSize(400, 200); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); return frame; } catch (Exception e) { System.out.println("9\b" + getClass().getName() + "\n\t" + e); return null; } }
////////////// methods to create the interactive visualizer //////////////////////// private void createMainFrame() { mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); Container contentPane = mainFrame.getContentPane(); // contentPane.setLayout(new BorderLayout()); // creates the control panel controlPanel = new JPanel(null); controlPanel.setLayout(new FlowLayout()); makeSoundVis(); mainFrame.addComponentListener(new ResizeHandler()); // setting up the play sound button playBtn = new JButton("Play"); playBtn.setEnabled(true); playBtn.setToolTipText("Play the sound"); playBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stopBtn.setEnabled(true); pauseBtn.setEnabled(true); playBtn.setEnabled(false); playSelectionBtn.setEnabled(false); zoomInBtn.setEnabled(false); zoomOutBtn.setEnabled(false); isPlaying = true; myHelper.play(); } }); controlPanel.add(playBtn); // setting up the play selection button playSelectionBtn = new JButton("Play Selection"); playSelectionBtn.setEnabled(false); playSelectionBtn.setToolTipText("Play sound between start and stop index"); playSelectionBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { playSelClicked++; stopBtn.setEnabled(true); pauseBtn.setEnabled(true); playSelectionBtn.setEnabled(false); playBtn.setEnabled(false); zoomInBtn.setEnabled(false); zoomOutBtn.setEnabled(false); isPlaying = false; if (playSelClicked == 1) { myHelper.playInRange( wavePanel.getSelectionStartSample(), wavePanel.getSelectionEndSample()); } else { myHelper.play(); } } }); controlPanel.add(playSelectionBtn); // setting up the stop button stopBtn = new JButton("Stop"); stopBtn.setEnabled(false); stopBtn.setToolTipText("Stop playing the sound"); stopBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { myHelper.stop(); stopBtn.setEnabled(false); pauseBtn.setEnabled(false); playBtn.setEnabled(true); if (wavePanel.moreZoomInScope()) { zoomInBtn.setEnabled(true); playSelectionBtn.setEnabled(true); } if (wavePanel.moreZoomOutScope()) { zoomOutBtn.setEnabled(true); } playSelClicked = 0; isPlaying = false; } }); controlPanel.add(stopBtn); // setting up the stop button pauseBtn = new JButton("Pause"); pauseBtn.setEnabled(false); pauseBtn.setToolTipText("Pause the sound"); pauseBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { myHelper.pause(); if (isPlaying) { playBtn.setEnabled(true); } else { playSelectionBtn.setEnabled(true); } } }); controlPanel.add(pauseBtn); // setting up the zoom button zoomInBtn = new JButton("Zoom In"); zoomInBtn.setEnabled(false); zoomInBtn.setToolTipText("Click to see the samples within your selection"); zoomInBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { handleZoomIn(); } }); controlPanel.add(zoomInBtn); // setting up the zoom button zoomOutBtn = new JButton("Zoom Out"); zoomOutBtn.setEnabled(false); zoomOutBtn.setToolTipText("Click to zoom out"); zoomOutBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { handleZoomOut(); } }); controlPanel.add(zoomOutBtn); controlPanel.setBounds(0, controlLocY, frameWidth, controlHeight); contentPane.add(controlPanel); contentPane.add(wavePanel); contentPane.add(overViewPanel); wavePanel.setBounds(0, waveLocY, frameWidth, waveHeight); // controlPanel.removeAll(); // controlPanel.setBackground(Color.CYAN); mainFrame.setSize(frameWidth, frameHeight); overViewPanel.init(); wavePanel.init(); // // mainFrame.pack(); // mainFrame.setResizable(false); // mainFrame.validate(); mainFrame.setVisible(true); overViewPanel.setBounds(0, 0, frameWidth, overViewHeight); // mainFrame.validate(); }