// James Wade gtg361w (Brian) and Jonathan Guarte jduarte3 (Mark) // HW 7 import javax.swing.*; // Need this to reach Swing components import java.awt.*; // Need this to reach FlowLayout import java.awt.event.*; // Need this for listeners and events import jm.music.data.*; // you know what these do... import jm.JMC; import jm.util.*; import jm.music.tools.*; //turn in songNode!!!!!!!!!!!!!!!!!!!!11 public class MidiTool extends JFrame { // define variables that will be used JTextField input; // input for node JTextField inputRepeat; // input for repeat SongNode root = new SongNode(); // head of list SongNode node; // tail of list Phrase phr; // phrase goes into node //Phrase myPHR; // String text; // text that is used to make node Note myNote; // holds note SongNode weaveAt; // insert node here for weave int number; // number times for node to be repeated public MidiTool(){ super("MidiTool"); this.getContentPane().setLayout(new GridLayout (8,1)); // make text input and buttons input = new JTextField("Enter Notes Here"); JButton makeNode = new JButton("Make Node"); JButton playNode = new JButton("Play Node"); JButton clearSequence = new JButton("Clear Sequence"); // panel for repeat button and text field JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayout(1,2)); JButton repeatNode = new JButton("Repeat Node"); inputRepeat = new JTextField("int #"); JButton weaveNode = new JButton("Weave Node"); JButton playSequence = new JButton("Play Sequence"); JButton saveSequence = new JButton("Save Sequence"); // add text input and buttons to Frame (order added = order appear) add(input); add(makeNode); add(playNode); add(clearSequence); add(panel1); panel1.add(repeatNode); panel1.add(inputRepeat); add(weaveNode); add(playSequence); add(saveSequence); // make action for makeNode makeNode.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ //intitialize text = input.getText(); // text = input text phr = new Phrase(); node = new SongNode(); Note myNote = null; // loop through string of text and assign a note based on each letter for (int i = 0; i < text.length(); i++){ char c = text.charAt(i); if (c == 'c'){ myNote = new Note(JMC.C3,JMC.EN);} if (c == 'C'){ myNote = new Note(JMC.C3,JMC.QN);} if (c == 'd'){ myNote = new Note(JMC.D3,JMC.EN);} if (c == 'D'){ myNote = new Note(JMC.D3,JMC.QN);} if (c == 'e'){ myNote = new Note(JMC.E3,JMC.EN);} if (c == 'E'){ myNote = new Note(JMC.E3,JMC.QN);} if (c == 'f'){ myNote = new Note(JMC.F3,JMC.EN);} if (c == 'F'){ myNote = new Note(JMC.F3,JMC.QN);} if (c == 'g'){ myNote = new Note(JMC.G3,JMC.EN);} if (c == 'G'){ myNote = new Note(JMC.G3,JMC.QN);} if (c == 'a'){ myNote = new Note(JMC.A3,JMC.EN);} if (c == 'A'){ myNote = new Note(JMC.A3,JMC.QN);} if (c == 'b'){ myNote = new Note(JMC.B3,JMC.EN);} if (c == 'B'){ myNote = new Note(JMC.B3,JMC.QN);} phr.addNote(myNote);// add note from iTh letter to a phrase } node.setPhrase(phr); // put phrase in node root.last().setNext(node); // make node the lsat node in sequence } }); // make action for play node playNode.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Play.midi(node.getPhrase(), false); // play node with piano(method in SongNode } }); // make action for Play Sequence playSequence.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ root.midiPlay(JMC.PIANO);}// play sequence with piano(method in SongNode) }); // make action for Clear Sequence clearSequence.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ root.setNext(null);}// seperate head from tail }); // make action for Weave Node weaveNode.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ weaveAt = root.next(); // begin weave after first node in tail (head is empty) weaveAt.weaveInsert(node);} // call weave method (in SongNode) }); // make action for Repeat Node repeatNode.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ number = Integer.parseInt(inputRepeat.getText());// gets number out of text box node.repeatNext(node, (number - 1));} // repeat n-1 times at end of list (n - 1 b/c there is already 1 node at end of list from makeNode) }); // make action of Save Sequence saveSequence.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ root.midiWrite(JMC.PIANO);} // save using method in SongNode as played by a piano }); this.pack(); this.setVisible(true); } // main method that runs GUI public static void main(String[]args){ MidiTool m = new MidiTool(); } }