// Fragment 6 // User clicked on Close Window. stop timer and close MIDi devices. private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing masterTimer.cancel(); kProAllOff(); if(kProDevice != null) { kProDevice.close(); } synth.close(); }//GEN-LAST:event_formWindowClosing // User clicked on Read Patch File private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed patch p; // Read Patch file JFileChooser fileRead = new JFileChooser(); FileFilter ft = new FileNameExtensionFilter("Patch Patterns", "ptc"); fileRead.setFileFilter(ft); int userChoice = fileRead.showOpenDialog(this); if(userChoice == JFileChooser.APPROVE_OPTION) { try { BufferedReader reader = new BufferedReader(new FileReader(fileRead.getSelectedFile())); String line = ""; while((line = reader.readLine()) != null) { if(! line.isEmpty()) { p = new patch(); p.parseFromFile(line); patchList.add(p); } lastSavedPatchFile = fileRead.getSelectedFile().getPath(); } } catch (Exception ex) { jTextArea1.append("\nCouldn't open |" + fileRead.getSelectedFile() + "|.\n"); jTextArea1.append(ex.toString()); } File f = new File(patchList.get(0).arpPatternFile); // Read the arp patterns and pre-load the combo box. readArpPatFile(f); String s = ""; // Add patches to combo box for(patch patch1 : patchList) { s = patch1.name; jComboBox4.addItem(s); } jComboBox4.setSelectedIndex(0); // Pre-select patch 0 just to be on the safe side. } }//GEN-LAST:event_jMenuItem2ActionPerformed // User selected Save Patch objects to a file. private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed savePatchFile(lastSavedPatchFile); // Menu -> File -> Save Patch File }//GEN-LAST:event_jMenuItem3ActionPerformed // User selected SaveAs Patch file from the menu bar. private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed savePatchFile(""); // File -> Menu -> SaveAs Patch File }//GEN-LAST:event_jMenuItem4ActionPerformed // User clicked on Read Arp Patterns. private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed JFileChooser fileRead = new JFileChooser(); // File Menu Item ->Read Arp Patterns File FileFilter ft = new FileNameExtensionFilter("Arp Patterns", "arp"); fileRead.setFileFilter(ft); int userChoice = fileRead.showOpenDialog(this); if(userChoice == JFileChooser.APPROVE_OPTION) { readArpPatFile(fileRead.getSelectedFile()); } }//GEN-LAST:event_jMenuItem8ActionPerformed // User clicked on Save Arp File. private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed String s = ""; boolean done = false; JFileChooser fileSaveChoice = new JFileChooser(); // Save arp file FileFilter ft = new FileNameExtensionFilter("Arp Patterns", "arp"); fileSaveChoice.setFileFilter(ft); int userChoice = JFileChooser.CANCEL_OPTION; while (! done) { userChoice = fileSaveChoice.showSaveDialog(this); if(fileSaveChoice.getSelectedFile().exists()) { userChoice = JOptionPane.showConfirmDialog(this, "File already exists.\nOverwrite it?", "Patch File Save", JOptionPane.YES_NO_OPTION); if(userChoice == JFileChooser.APPROVE_OPTION) { done = true; } } else { done = true; } } if(userChoice == JFileChooser.APPROVE_OPTION) { try { BufferedWriter writer = new BufferedWriter(new FileWriter(fileSaveChoice.getSelectedFile())); for(ArrayList a : arpPatternsList) { s = ""; for(int i=0; i < a.size(); i++) { s += " " + a.get(i); } writer.write(s.trim() + "\n"); } writer.flush(); writer.close(); JOptionPane.showMessageDialog(this, "File Saved."); selectedArpFile = fileSaveChoice.getSelectedFile().getPath(); } catch(IOException ex) { System.err.println("Couldn't save file"); JOptionPane.showMessageDialog(this, "Couldn't Save File.\n" + ex); } } }//GEN-LAST:event_jMenuItem9ActionPerformed // User Clicked on K-Pro Channel private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed String s = (String)JOptionPane.showInputDialog(this, "K-Pro MIDI Channel:", "Channel", JOptionPane.PLAIN_MESSAGE, null, null, midiPorts.kProChannelNo); midiPorts.setKProChannel(Integer.parseInt(s)); }//GEN-LAST:event_jMenuItem6ActionPerformed // User Clicked on Keyboard Channel. private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed String s = (String)JOptionPane.showInputDialog(this, "Keyboard MIDI Channel:", "Channel", JOptionPane.PLAIN_MESSAGE, null, null, midiPorts.keyboardChannelNo); midiPorts.setKeyboardChannel(Integer.parseInt(s)); }//GEN-LAST:event_jMenuItem10ActionPerformed // User clicked on Default Synth Channel. private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed String s = (String)JOptionPane.showInputDialog(this, "Default Synth Starting MIDI Channel:", "Channel", JOptionPane.PLAIN_MESSAGE, null, null, midiPorts.defaultChannelNo); midiPorts.setDefaultSynthChannel(Integer.parseInt(s)); }//GEN-LAST:event_jMenuItem11ActionPerformed // My original plan was to allow the user to turn on the K-Pro after starting the app, and then using the Find K-Pro option // from the menu to see if the K-Pro driver was running yet. However, the System object doesn't seem to be refreshing // properly. According to the Java forums, refresh defaults to every 60 seconds, although it's possible to set it shorter. // But,after 5 minutes, System still hadn't refreshed and the K-Pro driver wasn't in the MIDI information list. So I deactivated // this option. private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed boolean quit = false; // Menu -> Edit -> Retry K-Pro Read int cntr = 1; jTextArea1.append("-------------------\n"); while(! quit) { initMidiDevices(); jTextArea1.append("------------------- Attempt No.: " + cntr + "\n"); cntr++; if(kProDevice != null) { quit = true; } else { int n = JOptionPane.showConfirmDialog(this, "K-Pro still not found.\nTry again?", "Find K-Pro", JOptionPane.YES_NO_OPTION); if(n == JFileChooser.CANCEL_OPTION) { quit = true; } } } }//GEN-LAST:event_jMenuItem12ActionPerformed // Display the About box. private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed JOptionPane.showMessageDialog(this, "Kaossilator MIDI Driver and Arpeggiator\nCopyright Curtis H. Hoffmann\n(c)2012", "About K-Gator", JOptionPane.PLAIN_MESSAGE); }//GEN-LAST:event_jMenuItem7ActionPerformed