From c795ff20e0445988d01597106c68574e1cd562ce Mon Sep 17 00:00:00 2001 From: cssummer17 Date: Thu, 29 Jun 2017 16:54:53 -0700 Subject: [PATCH] Converted FractalFrame into Dialog for better display in Windows. --- fractals/FractalFrame.form | 644 +++++++++++++++++++++++++++ fractals/FractalFrame.java | 866 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1510 insertions(+) create mode 100644 fractals/FractalFrame.form create mode 100644 fractals/FractalFrame.java diff --git a/fractals/FractalFrame.form b/fractals/FractalFrame.form new file mode 100644 index 000000000..c88778971 --- /dev/null +++ b/fractals/FractalFrame.form @@ -0,0 +1,644 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fractals/FractalFrame.java b/fractals/FractalFrame.java new file mode 100644 index 000000000..93479e7e1 --- /dev/null +++ b/fractals/FractalFrame.java @@ -0,0 +1,866 @@ +/** + * This Java Class is part of the Impro-Visor Application + * + * Copyright (C) 2005-2014 Robert Keller and Harvey Mudd College + * + * Impro-Visor is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Impro-Visor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * merchantability or fitness for a particular purpose. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Impro-Visor; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +package imp.fractal; + +import imp.guidetone.GuideToneLineDialog; +import imp.transform.TransformPanel; +import imp.ImproVisor; +import imp.com.CommandManager; +import imp.com.RectifyPitchesCommand; +import imp.fractal.Fractal; +import imp.data.MelodyPart; +import imp.gui.Notate; +import imp.gui.WindowMenuItem; +import imp.gui.WindowRegistry; +import imp.util.ErrorLog; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JFileChooser; +import static javax.swing.JFileChooser.SAVE_DIALOG; +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileNameExtensionFilter; + +/** + * A frame for fractally improvising over an existing melody part + * Accessible through notate + * @author Carli Lessard + */ +public class FractalFrame extends javax.swing.JDialog { + private final Notate notate; + private final CommandManager cm; + + private String EXTENSION = ".fractal"; + private JFileChooser chooser; + private String filename; + + private Fractal fractal; + + /** + * Creates new form FractalFrame + */ + public FractalFrame(Notate notate, CommandManager cm) { + this.notate = notate; + this.cm = cm; + + this.setTitle("Fractal Improvisation"); + + initComponents(); + + // set the file chooser and add the detection of overriding a file + chooser = new JFileChooser(){ + @Override + public void approveSelection(){ + File f = getSelectedFile(); + if(!f.getAbsolutePath().endsWith(EXTENSION)) + f = new File(f.getAbsolutePath()+EXTENSION); + if(f.exists() && getDialogType() == SAVE_DIALOG){ + int result = JOptionPane.showConfirmDialog(this, + "The file exists, overwrite?", + "Existing file", + JOptionPane.YES_NO_CANCEL_OPTION); + switch(result){ + case JOptionPane.YES_OPTION: + super.approveSelection(); + return; + case JOptionPane.NO_OPTION: + return; + case JOptionPane.CLOSED_OPTION: + return; + case JOptionPane.CANCEL_OPTION: + cancelSelection(); + return; + } + } + super.approveSelection(); + } + }; + + chooser.setCurrentDirectory(ImproVisor.getFractalDirectory()); + + FileNameExtensionFilter filter = new FileNameExtensionFilter("Fractal Files", + "fractal"); + chooser.setFileFilter(filter); + + filename = "My.fractal"; + + this.fractal = new Fractal(ImproVisor.getFractalFile()); + setTextBoxes(); + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + probabilitiesPanel = new javax.swing.JPanel(); + containerPanel = new javax.swing.JPanel(); + restProbPanel = new javax.swing.JPanel(); + wholeRestLabel = new javax.swing.JLabel(); + halfRestLabel = new javax.swing.JLabel(); + quarterRestLabel = new javax.swing.JLabel(); + eighthRestLabel = new javax.swing.JLabel(); + sixteenthRestLabel = new javax.swing.JLabel(); + defaultRestLabel = new javax.swing.JLabel(); + wholeRestText = new javax.swing.JTextField(); + halfRestText = new javax.swing.JTextField(); + quarterRestText = new javax.swing.JTextField(); + eighthRestText = new javax.swing.JTextField(); + sixteenthRestText = new javax.swing.JTextField(); + defaultRestText = new javax.swing.JTextField(); + numDivPanel = new javax.swing.JPanel(); + doubleLabel = new javax.swing.JLabel(); + tripleLabel = new javax.swing.JLabel(); + doubleText = new javax.swing.JTextField(); + tripleText = new javax.swing.JTextField(); + infoPanel = new javax.swing.JPanel(); + infoLabel1 = new javax.swing.JLabel(); + infoLabel2 = new javax.swing.JLabel(); + infoLabel3 = new javax.swing.JLabel(); + infoLabel4 = new javax.swing.JLabel(); + divProbPanel = new javax.swing.JPanel(); + wholeDivLabel = new javax.swing.JLabel(); + halfDivLabel = new javax.swing.JLabel(); + quarterDivLabel = new javax.swing.JLabel(); + eighthDivLabel = new javax.swing.JLabel(); + sixteenthDivLabel = new javax.swing.JLabel(); + defaultDivLabel = new javax.swing.JLabel(); + wholeDivText = new javax.swing.JTextField(); + halfDivText = new javax.swing.JTextField(); + quarterDivText = new javax.swing.JTextField(); + eighthDivText = new javax.swing.JTextField(); + sixteenthDivText = new javax.swing.JTextField(); + defaultDivText = new javax.swing.JTextField(); + dividingPanel = new javax.swing.JPanel(); + numDivisionsSpinner = new javax.swing.JSpinner(); + multDivideButton = new javax.swing.JButton(); + singleDivideButton = new javax.swing.JButton(); + menuBar = new javax.swing.JMenuBar(); + fileMenu = new javax.swing.JMenu(); + openFileMI = new javax.swing.JMenuItem(); + saveFileMI = new javax.swing.JMenuItem(); + windowMenu = new javax.swing.JMenu(); + closeWindowMI = new javax.swing.JMenuItem(); + cascadeMI = new javax.swing.JMenuItem(); + windowMenuSeparator = new javax.swing.JPopupMenu.Separator(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setAlwaysOnTop(true); + setMinimumSize(new java.awt.Dimension(600, 350)); + setSize(new java.awt.Dimension(650, 375)); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosed(java.awt.event.WindowEvent evt) { + formWindowClosed(evt); + } + }); + getContentPane().setLayout(new java.awt.GridBagLayout()); + + probabilitiesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Probabilities")); + probabilitiesPanel.setMinimumSize(new java.awt.Dimension(550, 250)); + probabilitiesPanel.setPreferredSize(new java.awt.Dimension(550, 250)); + probabilitiesPanel.setLayout(new java.awt.GridBagLayout()); + + containerPanel.setLayout(new java.awt.GridBagLayout()); + + restProbPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Rest")); + restProbPanel.setLayout(new java.awt.GridBagLayout()); + + wholeRestLabel.setText("Whole Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + restProbPanel.add(wholeRestLabel, gridBagConstraints); + + halfRestLabel.setText("Half Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + restProbPanel.add(halfRestLabel, gridBagConstraints); + + quarterRestLabel.setText("Quarter Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + restProbPanel.add(quarterRestLabel, gridBagConstraints); + + eighthRestLabel.setText("Eighth Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + restProbPanel.add(eighthRestLabel, gridBagConstraints); + + sixteenthRestLabel.setText("Sixteenth Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + restProbPanel.add(sixteenthRestLabel, gridBagConstraints); + + defaultRestLabel.setText("Default"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 5; + restProbPanel.add(defaultRestLabel, gridBagConstraints); + + wholeRestText.setMinimumSize(new java.awt.Dimension(50, 28)); + wholeRestText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + restProbPanel.add(wholeRestText, gridBagConstraints); + + halfRestText.setMinimumSize(new java.awt.Dimension(50, 28)); + halfRestText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + restProbPanel.add(halfRestText, gridBagConstraints); + + quarterRestText.setMinimumSize(new java.awt.Dimension(50, 28)); + quarterRestText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + restProbPanel.add(quarterRestText, gridBagConstraints); + + eighthRestText.setMinimumSize(new java.awt.Dimension(50, 28)); + eighthRestText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 3; + restProbPanel.add(eighthRestText, gridBagConstraints); + + sixteenthRestText.setMinimumSize(new java.awt.Dimension(50, 28)); + sixteenthRestText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 4; + restProbPanel.add(sixteenthRestText, gridBagConstraints); + + defaultRestText.setMinimumSize(new java.awt.Dimension(50, 28)); + defaultRestText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 5; + restProbPanel.add(defaultRestText, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + containerPanel.add(restProbPanel, gridBagConstraints); + + numDivPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Ways to Divide")); + numDivPanel.setMinimumSize(new java.awt.Dimension(155, 192)); + numDivPanel.setPreferredSize(new java.awt.Dimension(155, 192)); + numDivPanel.setLayout(new java.awt.GridBagLayout()); + + doubleLabel.setText("Duplet"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + numDivPanel.add(doubleLabel, gridBagConstraints); + + tripleLabel.setText("Triplet"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + numDivPanel.add(tripleLabel, gridBagConstraints); + + doubleText.setEditable(false); + doubleText.setMinimumSize(new java.awt.Dimension(50, 28)); + doubleText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + numDivPanel.add(doubleText, gridBagConstraints); + + tripleText.setMinimumSize(new java.awt.Dimension(50, 28)); + tripleText.setPreferredSize(new java.awt.Dimension(50, 28)); + tripleText.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tripleTextActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + numDivPanel.add(tripleText, gridBagConstraints); + + infoPanel.setLayout(new java.awt.GridBagLayout()); + + infoLabel1.setText("*Note these values"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridwidth = 2; + infoPanel.add(infoLabel1, gridBagConstraints); + + infoLabel2.setText("should sum to 1."); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; + infoPanel.add(infoLabel2, gridBagConstraints); + + infoLabel3.setText("The duplet value will"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; + infoPanel.add(infoLabel3, gridBagConstraints); + + infoLabel4.setText("automatically be set."); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; + infoPanel.add(infoLabel4, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + gridBagConstraints.gridwidth = 2; + numDivPanel.add(infoPanel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + containerPanel.add(numDivPanel, gridBagConstraints); + + divProbPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Division")); + divProbPanel.setLayout(new java.awt.GridBagLayout()); + + wholeDivLabel.setText("Whole Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + divProbPanel.add(wholeDivLabel, gridBagConstraints); + + halfDivLabel.setText("Half Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + divProbPanel.add(halfDivLabel, gridBagConstraints); + + quarterDivLabel.setText("Quarter Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + divProbPanel.add(quarterDivLabel, gridBagConstraints); + + eighthDivLabel.setText("Eighth Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + divProbPanel.add(eighthDivLabel, gridBagConstraints); + + sixteenthDivLabel.setText("Sixteenth Note"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + divProbPanel.add(sixteenthDivLabel, gridBagConstraints); + + defaultDivLabel.setText("Default"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 5; + divProbPanel.add(defaultDivLabel, gridBagConstraints); + + wholeDivText.setMinimumSize(new java.awt.Dimension(50, 28)); + wholeDivText.setPreferredSize(new java.awt.Dimension(50, 28)); + divProbPanel.add(wholeDivText, new java.awt.GridBagConstraints()); + + halfDivText.setMinimumSize(new java.awt.Dimension(50, 28)); + halfDivText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + divProbPanel.add(halfDivText, gridBagConstraints); + + quarterDivText.setMinimumSize(new java.awt.Dimension(50, 28)); + quarterDivText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + divProbPanel.add(quarterDivText, gridBagConstraints); + + eighthDivText.setMinimumSize(new java.awt.Dimension(50, 28)); + eighthDivText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 3; + divProbPanel.add(eighthDivText, gridBagConstraints); + + sixteenthDivText.setMinimumSize(new java.awt.Dimension(50, 28)); + sixteenthDivText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 4; + divProbPanel.add(sixteenthDivText, gridBagConstraints); + + defaultDivText.setMinimumSize(new java.awt.Dimension(50, 28)); + defaultDivText.setPreferredSize(new java.awt.Dimension(50, 28)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 5; + divProbPanel.add(defaultDivText, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + containerPanel.add(divProbPanel, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + probabilitiesPanel.add(containerPanel, gridBagConstraints); + + getContentPane().add(probabilitiesPanel, new java.awt.GridBagConstraints()); + + dividingPanel.setLayout(new java.awt.GridBagLayout()); + + numDivisionsSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 0, null, 1)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + dividingPanel.add(numDivisionsSpinner, gridBagConstraints); + + multDivideButton.setText("Divide Multiple Times"); + multDivideButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + multDivideButtonActionPerformed(evt); + } + }); + dividingPanel.add(multDivideButton, new java.awt.GridBagConstraints()); + + singleDivideButton.setText("Divide One Time"); + singleDivideButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + singleDivideButtonActionPerformed(evt); + } + }); + dividingPanel.add(singleDivideButton, new java.awt.GridBagConstraints()); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + getContentPane().add(dividingPanel, gridBagConstraints); + + fileMenu.setText("File"); + + openFileMI.setText("Open Fractal File"); + openFileMI.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + openFileMIActionPerformed(evt); + } + }); + fileMenu.add(openFileMI); + + saveFileMI.setText("Save Fractal File"); + saveFileMI.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveFileMIActionPerformed(evt); + } + }); + fileMenu.add(saveFileMI); + + menuBar.add(fileMenu); + + windowMenu.setText("Window"); + windowMenu.addMenuListener(new javax.swing.event.MenuListener() { + public void menuSelected(javax.swing.event.MenuEvent evt) { + windowMenuMenuSelected(evt); + } + public void menuDeselected(javax.swing.event.MenuEvent evt) { + } + public void menuCanceled(javax.swing.event.MenuEvent evt) { + } + }); + + closeWindowMI.setText("Close Window"); + closeWindowMI.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + closeWindowMIActionPerformed(evt); + } + }); + windowMenu.add(closeWindowMI); + + cascadeMI.setText("Cascade Windows"); + cascadeMI.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cascadeMIActionPerformed(evt); + } + }); + windowMenu.add(cascadeMI); + windowMenu.add(windowMenuSeparator); + + menuBar.add(windowMenu); + + setJMenuBar(menuBar); + + pack(); + }// //GEN-END:initComponents + + private void multDivideButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multDivideButtonActionPerformed + MelodyPart fractalSolo = fractalSolo(); + putSoloInNewChorus(fractalSolo); + playCurrentSelection(); + }//GEN-LAST:event_multDivideButtonActionPerformed + + private MelodyPart fractalSolo(){ + setProbabilities(); + setTextBoxes(); + int numTimes = (Integer)numDivisionsSpinner.getValue(); + MelodyPart fractalSolo = fractal.fractalImprovise(notate.getCurrentMelodyPart(), numTimes); + notate.cm.execute(new RectifyPitchesCommand(fractalSolo, + 0, + fractalSolo.getSize() - 1, + notate.getChordProg(), + false, + false, + true, + true, + true, + true)); + return fractalSolo; + } + + private void putSoloInNewChorus(MelodyPart fractalSolo){ + notate.addChorus(fractalSolo); + } + + private void putSoloInCurrentChorus(MelodyPart fractalSolo){ + notate.getCurrentMelodyPart().newPasteOver(fractalSolo, 0); + } + + private void playCurrentSelection(){ + notate.playCurrentSelection(true, + 0, + true, + "Playing fractal line"); + } + //for use in trading + public void dividePastePlay(){ + MelodyPart fractalSolo = fractalSolo(); + putSoloInCurrentChorus(fractalSolo); + playCurrentSelection(); + } + + private void singleDivideButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleDivideButtonActionPerformed + setProbabilities(); + setTextBoxes(); + MelodyPart fractalSolo = fractal.fractalImprovise(notate.getCurrentMelodyPart(), 1); + notate.cm.execute(new RectifyPitchesCommand(fractalSolo, + 0, + fractalSolo.getSize() - 1, + notate.getChordProg(), + false, + false, + true, + true, + true, + true)); + notate.addChorus(fractalSolo); + notate.playCurrentSelection(true, + 0, + true, + "Playing fractal line"); + }//GEN-LAST:event_singleDivideButtonActionPerformed + + private void openFileMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFileMIActionPerformed + open(); + setTextBoxes(); + }//GEN-LAST:event_openFileMIActionPerformed + + private void saveFileMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveFileMIActionPerformed + setProbabilities(); + saveCurrentFractal(); + }//GEN-LAST:event_saveFileMIActionPerformed + + private void closeWindowMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeWindowMIActionPerformed + closeWindow(); + }//GEN-LAST:event_closeWindowMIActionPerformed + + private void cascadeMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cascadeMIActionPerformed + WindowRegistry.cascadeWindows(this); + }//GEN-LAST:event_cascadeMIActionPerformed + + private void windowMenuMenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_windowMenuMenuSelected + windowMenu.removeAll(); + + windowMenu.add(closeWindowMI); + + windowMenu.add(cascadeMI); + + windowMenu.add(windowMenuSeparator); + + for (WindowMenuItem w : WindowRegistry.getWindows()) { + + windowMenu.add(w.getMI(this)); // these are static, and calling getMI updates the name on them too in case the window title changed + } + + windowMenu.repaint(); + }//GEN-LAST:event_windowMenuMenuSelected + + private void tripleTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tripleTextActionPerformed + double doubleProb = 1.0 - parseProb(tripleText.getText()); + doubleText.setText(String.valueOf(doubleProb)); + }//GEN-LAST:event_tripleTextActionPerformed + + private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed + + closeWindow(); + }//GEN-LAST:event_formWindowClosed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JMenuItem cascadeMI; + private javax.swing.JMenuItem closeWindowMI; + private javax.swing.JPanel containerPanel; + private javax.swing.JLabel defaultDivLabel; + private javax.swing.JTextField defaultDivText; + private javax.swing.JLabel defaultRestLabel; + private javax.swing.JTextField defaultRestText; + private javax.swing.JPanel divProbPanel; + private javax.swing.JPanel dividingPanel; + private javax.swing.JLabel doubleLabel; + private javax.swing.JTextField doubleText; + private javax.swing.JLabel eighthDivLabel; + private javax.swing.JTextField eighthDivText; + private javax.swing.JLabel eighthRestLabel; + private javax.swing.JTextField eighthRestText; + private javax.swing.JMenu fileMenu; + private javax.swing.JLabel halfDivLabel; + private javax.swing.JTextField halfDivText; + private javax.swing.JLabel halfRestLabel; + private javax.swing.JTextField halfRestText; + private javax.swing.JLabel infoLabel1; + private javax.swing.JLabel infoLabel2; + private javax.swing.JLabel infoLabel3; + private javax.swing.JLabel infoLabel4; + private javax.swing.JPanel infoPanel; + private javax.swing.JMenuBar menuBar; + private javax.swing.JButton multDivideButton; + private javax.swing.JPanel numDivPanel; + private javax.swing.JSpinner numDivisionsSpinner; + private javax.swing.JMenuItem openFileMI; + private javax.swing.JPanel probabilitiesPanel; + private javax.swing.JLabel quarterDivLabel; + private javax.swing.JTextField quarterDivText; + private javax.swing.JLabel quarterRestLabel; + private javax.swing.JTextField quarterRestText; + private javax.swing.JPanel restProbPanel; + private javax.swing.JMenuItem saveFileMI; + private javax.swing.JButton singleDivideButton; + private javax.swing.JLabel sixteenthDivLabel; + private javax.swing.JTextField sixteenthDivText; + private javax.swing.JLabel sixteenthRestLabel; + private javax.swing.JTextField sixteenthRestText; + private javax.swing.JLabel tripleLabel; + private javax.swing.JTextField tripleText; + private javax.swing.JLabel wholeDivLabel; + private javax.swing.JTextField wholeDivText; + private javax.swing.JLabel wholeRestLabel; + private javax.swing.JTextField wholeRestText; + private javax.swing.JMenu windowMenu; + private javax.swing.JPopupMenu.Separator windowMenuSeparator; + // End of variables declaration//GEN-END:variables + + /** + * Opens the open file dialog + */ + public void open(){ + if( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION ) + { + String newFilename = chooser.getSelectedFile().getName(); + String fractalStr = ""; + try { + fractalStr = new Scanner(chooser.getSelectedFile()).useDelimiter("\\Z").next(); + } catch (FileNotFoundException ex) { + Logger.getLogger(TransformPanel.class.getName()).log(Level.SEVERE, null, ex); + } + if(fractalStr.length() > 0) + { + fractal = new Fractal(fractalStr); + setTextBoxes(); + } + } + } + + /** + * Opens the file chooser to save a new/existing file + * @return + */ + public boolean saveCurrentFractal() + { + chooser.setSelectedFile(new File(filename)); + + if( chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION ) + { + if( chooser.getSelectedFile().getName().endsWith( + EXTENSION) ) + { + filename = chooser.getSelectedFile().getName(); + + saveFractalFile(chooser.getSelectedFile().getAbsolutePath()); + } + else + { + filename = chooser.getSelectedFile().getName() + EXTENSION; + + saveFractalFile(chooser.getSelectedFile().getAbsolutePath() + EXTENSION); + } + return true; + } + else + { + return false; + } + } + + /** + * Saves a file + * @param filepath + * @return + */ + private int saveFractalFile(String filepath) { + try + { + String content = fractal.toString(); + FileWriter out = new FileWriter(new File(filepath)); + out.write(content); + out.close(); + return 0; + } + catch( IOException e ) + { + ErrorLog.log(ErrorLog.WARNING, "Error saving to " + filename); + return -1; + } + } + + /** + * Loads the probabilities from a file + * @param file + * @return + */ + private String loadProbabilities(File file) + { + String probString = fileToString(file); + fractal.setProbabilities(probString); + return probString; + } + + /** + * Converts a file to a string that can be parsed + * @param file + * @return + */ + private static String fileToString(File file){ + String probStr = ""; + try { + probStr = new Scanner(file).useDelimiter("\\Z").next(); + } catch (FileNotFoundException ex) { + Logger.getLogger(GuideToneLineDialog.class.getName()).log(Level.SEVERE, null, ex); + } + return probStr; + } + + /** + * Gets the probabilities stored in Fractal and puts them into the + * text boxes + */ + private void setTextBoxes() + { + double tripletProb = fractal.getTripletProb(); + tripleText.setText(String.valueOf(tripletProb)); + + double twoProb = 1.0 - tripletProb; + doubleText.setText(String.valueOf(twoProb)); + + wholeDivText.setText(String.valueOf(fractal.getWholeDivProb())); + halfDivText.setText(String.valueOf(fractal.getHalfDivProb())); + quarterDivText.setText(String.valueOf(fractal.getQuarterDivProb())); + eighthDivText.setText(String.valueOf(fractal.getEighthDivProb())); + sixteenthDivText.setText(String.valueOf(fractal.getSixteenthDivProb())); + defaultDivText.setText(String.valueOf(fractal.getDefaultDivProb())); + + wholeRestText.setText(String.valueOf(fractal.getWholeRestProb())); + halfRestText.setText(String.valueOf(fractal.getHalfRestProb())); + quarterRestText.setText(String.valueOf(fractal.getQuarterRestProb())); + eighthRestText.setText(String.valueOf(fractal.getEighthRestProb())); + sixteenthRestText.setText(String.valueOf(fractal.getSixteenthRestProb())); + defaultRestText.setText(String.valueOf(fractal.getDefaultRestProb())); + } + + /** + * Gets the values from the text boxes and sets the probabilities in Fractal + */ + private void setProbabilities() + { + double triplet = parseProb(tripleText.getText()); + + doubleText.setText(String.valueOf(1.0 - triplet)); + + fractal.setTripletProb(triplet); + + fractal.setWholeDivProb(parseProb(wholeDivText.getText())); + fractal.setHalfDivProb(parseProb(halfDivText.getText())); + fractal.setQuarterDivProb(parseProb(quarterDivText.getText())); + fractal.setEighthDivProb(parseProb(eighthDivText.getText())); + fractal.setSixteenthDivProb(parseProb(sixteenthDivText.getText())); + fractal.setDefaultDivProb(parseProb(defaultDivText.getText())); + + fractal.setWholeRestProb(parseProb(wholeRestText.getText())); + fractal.setHalfRestProb(parseProb(halfRestText.getText())); + fractal.setQuarterRestProb(parseProb(quarterRestText.getText())); + fractal.setEighthRestProb(parseProb(eighthRestText.getText())); + fractal.setSixteenthRestProb(parseProb(sixteenthRestText.getText())); + fractal.setDefaultRestProb(parseProb(defaultRestText.getText())); + } + + /** + * Converts a string to a double. + * If it is empty, returns 0.0 + * @param text + * @return + */ + private double parseProb(String text) + { + if(text.isEmpty()){ + return 0.0; + } else { + return Double.parseDouble(text); + } + } + + /** + * Closes the Fractal Frame + */ + public void closeWindow() { + this.setVisible(false); + + WindowRegistry.unregisterWindow(this); + } + +}