/******************************************************************************/ // Project // // Roy Vanegas: rvanegas@hunter.cuny.edu /******************************************************************************/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.net.*; import javax.sound.midi.*; import java.util.*; /** * Notes and To do: * - Incorporate righty-lefty option, which is just a matter of flipping the * dot markers for the GUI, but reverse mapping the strings. * - Change the strings from drawlines to fillrects, when i have time. * - Remember that middle C on the guitar is an octave higher than middle c * on the piano. * - add port number (which port is best?) * - once connected, change the red status box to green. * - add latency monitor * - add listeners for everything * - reverse the fret numbers * - light grey: 192, 192, 192 * - nut: 240 238 212 * - check if jtextarea can be modified. * - although 16 is usually the amount of channels, query the machine for * the amount of channels, and display it in the interface. * - check on the serialization thing in java 1.5 * - differential calculations. MIDI is a protocol, not a computer-generated sound file It was designed to solve transmit instructions amongst musical devices. Because of its compact size in contrast to audio files, MIDI is ideal for a project of this nature. Traveling along a fast Internet connection, MIDI may be used to replicate one personŐs musical gesture on another personŐs computer. */ public class Project extends JFrame implements KeyListener { final static int X = 75; final static int Y = 70; final static int FRET_WIDTH = 5; final static int FRET_HEIGHT = 155; final static int FRETBOARD_WIDTH = 800; final static int VERTICAL_FRETBOARD_PADDING = 47; final static int START_ANGLE = 0; final static int ARC_ANGLE = 360; final static int DIAMETER = 27; final static int L_EDGE_PLUS_OFFSET = X - 25; final static int R_EDGE_PLUS_OFFSET = X + FRETBOARD_WIDTH + 10; final static int R_EDGE_OF_BOARD = X + FRETBOARD_WIDTH; final static int E6_LEVEL = 70; // 75; final static int A5_LEVEL = 103; // 108; final static int D4_LEVEL = 135; // 140; final static int G3_LEVEL = 166; // 171; final static int B2_LEVEL = 196; // 201; final static int E1_LEVEL = 225; // 230; final static int FRET_01 = X; final static int FRET_02 = X + 48; final static int FRET_03 = X + 96; final static int FRET_04 = X + 144; final static int FRET_05 = X + 198; final static int FRET_06 = X + 258; final static int FRET_07 = X + 318; final static int FRET_08 = X + 384; final static int FRET_09 = X + 450; final static int FRET_10 = X + 528; final static int FRET_11 = X + 612; final static int FRET_12 = X + 702; final static int STRING_SPAN = FRETBOARD_WIDTH + FRET_WIDTH; final static int FRET_12_WIDTH = R_EDGE_OF_BOARD - FRET_12; final static int FRET_11_WIDTH = FRET_12 - FRET_11; final static int FRET_10_WIDTH = FRET_11 - FRET_10; final static int FRET_09_WIDTH = FRET_10 - FRET_09; final static int FRET_08_WIDTH = FRET_09 - FRET_08; final static int FRET_07_WIDTH = FRET_08 - FRET_07; final static int FRET_06_WIDTH = FRET_07 - FRET_06; final static int FRET_05_WIDTH = FRET_06 - FRET_05; final static int FRET_04_WIDTH = FRET_05 - FRET_04; final static int FRET_03_WIDTH = FRET_04 - FRET_03; final static int FRET_02_WIDTH = FRET_03 - FRET_02; final static int FRET_01_WIDTH = FRET_02 - FRET_01; private String status = "not connected"; private InetAddress hostAndIP; private JPanel buttonPanel; private JButton connectToUser, disconnect, openSession, playMidi, openMidi; private JComboBox instrumentList; private Instrument[] ins; private Synthesizer synthesizer; private Soundbank soundbank; private JComboBox midiInfoBox, synthInfoBox, seqInfoBox; private JLabel devicesInstalled, synthsInstalled, seqsInstalled, availableInstruments; private Vector synthInfoObjects = new Vector(); private Vector sequenceInfoObjects = new Vector(); private ObjectOutputStream output; private ObjectInputStream input; private String message = ""; private ServerSocket server; private Socket connection; // Rename these variables int red = 255, green = 0, blue = 0; int one = 0, two = 0, three = 0, four = 0; public Project() { super( "Teacher-Server/Student-Client" ); Container container = getContentPane(); /* public Insets getInsets() { Insets currentInsets = super.getInsets(); Insets myInsets = new Insets(); myInsets.top = currentInsets.top + 2; myInsets.bottom = currentInsets.bottom + 2; myInsets.left = currentInsets.left + 2; myInsets.right = currentInsets.right + 2; return myInsets; } */ MidiDevice.Info[] midiInfo = MidiSystem.getMidiDeviceInfo(); midiInfoBox = new JComboBox( midiInfo ); MidiDevice device; for( int index = 0; index < midiInfo.length; index++ ) { try { device = MidiSystem.getMidiDevice( midiInfo[ index ] ); if( device instanceof Synthesizer ) synthInfoObjects.add( midiInfo[ index ] ); if( device instanceof Sequencer ) sequenceInfoObjects.add( midiInfo[ index ] ); } catch( MidiUnavailableException e ) {} } synthInfoBox = new JComboBox( synthInfoObjects ); seqInfoBox = new JComboBox( sequenceInfoObjects ); try { hostAndIP = InetAddress.getLocalHost(); buttonPanel = new JPanel(); buttonPanel.setLayout( new GridLayout( 4, 3, 60, 0 ) ); synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); soundbank = synthesizer.getDefaultSoundbank(); ins = soundbank.getInstruments(); } catch( MidiUnavailableException mue ) {} catch( UnknownHostException uhe ) {} openMidi = new JButton ( "Open MIDI File" ); synthsInstalled = new JLabel ( "Installed Synthesizers" ); seqsInstalled = new JLabel ( "Installed Sequencers" ); connectToUser = new JButton ( "Connect To Server" ); // Client only disconnect = new JButton ( "Disconnect" ); openSession = new JButton ( "Open Session" ); devicesInstalled = new JLabel ( "All Available Devices" ); instrumentList = new JComboBox( ins ); availableInstruments = new JLabel ( "Installed Instruments" ); buttonPanel.add( connectToUser ); buttonPanel.add( devicesInstalled ); buttonPanel.add( seqsInstalled ); buttonPanel.add( disconnect ); buttonPanel.add( midiInfoBox ); buttonPanel.add( seqInfoBox ); buttonPanel.add( openMidi ); buttonPanel.add( synthsInstalled ); buttonPanel.add( availableInstruments ); buttonPanel.add( openSession ); buttonPanel.add( synthInfoBox ); buttonPanel.add( instrumentList ); container.add( buttonPanel, BorderLayout.SOUTH ); addKeyListener( this ); setSize( X + FRETBOARD_WIDTH + X, 700 ); setVisible( true ); } /* -------------------------------------------------------------------------- | | Method: runServer() | \------------------------------------------------------------------------- */ private void runServer() { try { server = new ServerSocket( 5000, 100 ); while( true ) { waitForConnection(); getStreams(); processConnection(); closeConnection(); } } catch( EOFException eofe ) { System.out.println( "SERVER: Client terminated connection.\n\t" ); eofe.printStackTrace(); } catch( IOException ioe ) { System.out.println( "IOE Exception thrown by ........ \n\n\n\t" ); ioe.printStackTrace(); } } /* ----------------------------------------------------------------------- | | Method: waitForConnection() | \---------------------------------------------------------------------- */ private void waitForConnection() throws IOException { // Assign "waiting for connection" to the global field status. // repaint only the area that needs to be repainted, which in this case // is the string's area. // bind the server to the prot (handshake point) // once a successful connection is made, overwrite the status field // with "connection on ...", listing the host and ip. // again, repaint only what is needed, plus a little extra area in the // event that the new string is long. // assign the rgb combination for green, which is 0, 255, 0 // and repaint the little box to the left of the screen from red // to green. status = "waiting for connection..."; repaint( L_EDGE_PLUS_OFFSET, E1_LEVEL + 125, 40, 40 ); connection = server.accept(); status = "connection on " + connection.getInetAddress().getHostName(); repaint(L_EDGE_PLUS_OFFSET, E1_LEVEL + 125, 40, 40 ); red = 0; green = 255; blue = 0; repaint(L_EDGE_PLUS_OFFSET, E1_LEVEL + 125, 60, 60 ); } /* ----------------------------------------------------------------------- | | Method: getStreams() | | Now that we have a connection, let's connect the server's output to the | client's input, and vice versa. \---------------------------------------------------------------------- */ private void getStreams() throws IOException { output = new ObjectOutputStream( connection.getOutputStream() ); output.flush(); input = new ObjectInputStream( connection.getInputStream() ); System.out.println( "SERVER: Got I/O streams\n" ); } /* -------------------------------------------------------------------------- | | Method: waitForConnection() | \------------------------------------------------------------------------- */ private void processConnection() throws IOException { do { try { // Get and process input from THIS keyboard... InputStreamReader inputStream = new InputStreamReader( System.in ); BufferedReader textBuffer = new BufferedReader( inputStream ); message = "SERVER: ".concat( textBuffer.readLine() ); // then write the input out to the client, flush the pipe, wait for data FROM the client, then echo what's come in to THIS screen output.writeObject( message ); output.flush(); message = ( String ) input.readObject(); System.out.println( message ); } catch( ClassNotFoundException cnfe ){System.out.println( "\nSERVER: Unknown object type received.\n\t" );cnfe.printStackTrace();} } while( !message.equals( "quit" ) ) ; } /* ----------------------------------------------------------------------- | | Method: closeConnection() | \---------------------------------------------------------------------- */ private void closeConnection() throws IOException { output.close(); input.close(); connection.close(); } /* -------------------------------------------------------------------------- | | Method: paint( Graphics g ) | \------------------------------------------------------------------------- */ public void paint( Graphics g ) { Insets currentInsets = super.getInsets(); // int hiddenXCoord = currentInsets. // The following three variable are used to paint the strings. int space = 34; int yCoordinate = Y - 34; int stringNum; super.paint( g ); /* ----------------------------------------------------------------------- | | Draw background canvases for both necks. | \---------------------------------------------------------------------- */ g.setColor( Color.white ); g.fillRect( currentInsets.left + 1, currentInsets.top + 1, (X + FRETBOARD_WIDTH + X) - currentInsets.right - 3 , // old hardcoded value: 947; logic behind this: one pixel per side + 1 to be safe. hence, 2 pixels. currentInsets.bottom + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2) ); g.setColor( new Color( 234, 234, 234 ) ); g.fillRect( currentInsets.left + 1, currentInsets.top + 1 + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2), (X + FRETBOARD_WIDTH + X) - currentInsets.right - 3 , // old hardcoded value: 947; logic behind this: one pixel per side + 1 to be safe. hence, 2 pixels. currentInsets.bottom + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2) ); /* ----------------------------------------------------------------------- | | Draw background colors for both necks. | \---------------------------------------------------------------------- */ g.setColor( new Color( 234, 234, 174 ) ); g.fillRect( X, Y, FRETBOARD_WIDTH, FRET_HEIGHT ); g.setColor( new Color( 85, 85, 85 ) ); g.fillRect( X, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRETBOARD_WIDTH, FRET_HEIGHT ); /* ----------------------------------------------------------------------- | | Draw the nuts. | \---------------------------------------------------------------------- */ g.setColor( new Color( 240, 238, 212 ) ); g.fillRect( X + FRETBOARD_WIDTH, Y, FRET_WIDTH, FRET_HEIGHT ); g.setColor( Color.WHITE ); g.fillRect( X + FRETBOARD_WIDTH, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); /* ----------------------------------------------------------------------- | | Draw the twelve vertical frets of a two-octave guitar. | | Approximate fret distance calculations from nut: | 12th fret: 128mm from 1st fret | 11th fret: 120mm from 1st fret | 10th fret: 112mm from 1st fret | 9th fret: 104mm from 1st fret | 8th fret: 95mm from 1st fret | 7th fret: 85mm from 1st fret | 6th fret: 75mm from 1st fret | 5th fret: 64mm from 1st fret | 4th fret: 53mm from 1st fret | 3rd fret: 40mm from 1st fret | 2nd fret: 26mm from 1st fret | 1st fret: 12mm from 1st fret \---------------------------------------------------------------------- */ g.setColor( new Color( 192, 192, 192 ) ); g.fillRect( FRET_01, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_02, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_03, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_04, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_05, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_06, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_07, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_08, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_09, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_10, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_11, Y, FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_12, Y, FRET_WIDTH, FRET_HEIGHT ); g.setColor( Color.WHITE ); g.fillRect( FRET_01, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_02, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_03, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_04, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_05, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_06, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_07, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_08, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_09, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_10, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_11, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); g.fillRect( FRET_12, Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 ), FRET_WIDTH, FRET_HEIGHT ); /* ----------------------------------------------------------------------- | | Draw the white fretboard markers. | | ON THE SECOND TAKE, REMOVE THE HARDCODED VALUES HERE | \---------------------------------------------------------------------- */ g.setColor( new Color( 255, 255, 255 ) ); g.fillArc( 631, 138, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 480, 138, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 351, 138, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 234, 138, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 87, 100, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 87, 175, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); int Y2 = FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2); g.setColor( new Color( 255, 255, 255 ) ); g.fillArc( 631, 138 + Y2, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 480, 138 + Y2, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 351, 138 + Y2, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 234, 138 + Y2, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 87, 100 + Y2, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); g.fillArc( 87, 175 + Y2, DIAMETER, DIAMETER, START_ANGLE, ARC_ANGLE ); /* ----------------------------------------------------------------------- | | Draw the strings. | | Let's give the impression of gauge thickness by drawing each consecutive | string, upon each iteration of the loop, on the way down to the high E | string one pixel smaller. | | 1st iteration of the loop: | - yCoordinate is 70. | - space is decreased to 33 | - stringNum is 6 (the girth of the string and the string number) | | 2nd iteration of the loop: | - yCoordinate is 103. | - space is decreased to 32 | - stringNum is 5 (the girth of the string and the string number)... | | 3rd iteration of the loop: | - yCoordinate is 135. | - space is decreased to 31 | - stringNum is 4 | | 4th iteration of the loop: | - yCoordinate is 166. | - space is decreased to 30 | - stringNum is 3 | | 5th iteration of the loop: | - yCoordinate is 196. | - space is decreased to 29 | - stringNum is 2 | | 6th iteration of the loop: | - yCoordinate is 225. | - space is decreased to 28 | - stringNum is 1 | \---------------------------------------------------------------------- */ g.setColor( new Color( 170, 170, 170 ) ); for( stringNum = 6; stringNum >= 1; stringNum--, space-- ) g.fillRect( X, (yCoordinate += space), FRETBOARD_WIDTH + FRET_WIDTH, stringNum ); // reset these values so we can draw guitar two's strings, remembering // that the first occurrence of yCoordinate must be further down. space = 34; yCoordinate = (Y + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2 )) - 34; g.setColor( new Color( 192, 192, 192 ) ); for( stringNum = 6; stringNum >= 1; stringNum--, space-- ) g.fillRect( X, (yCoordinate += space), FRETBOARD_WIDTH + FRET_WIDTH, stringNum ); /* ----------------------------------------------------------------------- | | Draw in black ink the MIDI channel number to which is string is bound. | \---------------------------------------------------------------------- */ g.setColor( new Color( 0, 0, 0 ) ); g.drawString( "ch1", L_EDGE_PLUS_OFFSET, E6_LEVEL + 5 ); g.drawString( "ch2", L_EDGE_PLUS_OFFSET, A5_LEVEL + 5 ); g.drawString( "ch3", L_EDGE_PLUS_OFFSET, D4_LEVEL + 5 ); g.drawString( "ch4", L_EDGE_PLUS_OFFSET, G3_LEVEL + 5 ); g.drawString( "ch5", L_EDGE_PLUS_OFFSET, B2_LEVEL + 5 ); g.drawString( "ch6", L_EDGE_PLUS_OFFSET, E1_LEVEL + 5 ); g.drawString( "ch1", L_EDGE_PLUS_OFFSET, E6_LEVEL + 5 + Y2 ); g.drawString( "ch2", L_EDGE_PLUS_OFFSET, A5_LEVEL + 5 + Y2 ); g.drawString( "ch3", L_EDGE_PLUS_OFFSET, D4_LEVEL + 5 + Y2 ); g.drawString( "ch4", L_EDGE_PLUS_OFFSET, G3_LEVEL + 5 + Y2 ); g.drawString( "ch5", L_EDGE_PLUS_OFFSET, B2_LEVEL + 5 + Y2 ); g.drawString( "ch6", L_EDGE_PLUS_OFFSET, E1_LEVEL + 5 + Y2 ); /* ----------------------------------------------------------------------- | | Draw the string letters along the right side of the fretboard. | \---------------------------------------------------------------------- */ g.drawString( "E", R_EDGE_PLUS_OFFSET, E6_LEVEL + 5 ); g.drawString( "A", R_EDGE_PLUS_OFFSET, A5_LEVEL + 5 ); g.drawString( "D", R_EDGE_PLUS_OFFSET, D4_LEVEL + 5 ); g.drawString( "G", R_EDGE_PLUS_OFFSET, G3_LEVEL + 5 ); g.drawString( "B", R_EDGE_PLUS_OFFSET, B2_LEVEL + 5 ); g.drawString( "E", R_EDGE_PLUS_OFFSET, E1_LEVEL + 5 ); g.drawString( "E", R_EDGE_PLUS_OFFSET, E6_LEVEL + 5 + Y2 ); g.drawString( "A", R_EDGE_PLUS_OFFSET, A5_LEVEL + 5 + Y2 ); g.drawString( "D", R_EDGE_PLUS_OFFSET, D4_LEVEL + 5 + Y2 ); g.drawString( "G", R_EDGE_PLUS_OFFSET, G3_LEVEL + 5 + Y2 ); g.drawString( "B", R_EDGE_PLUS_OFFSET, B2_LEVEL + 5 + Y2 ); g.drawString( "E", R_EDGE_PLUS_OFFSET, E1_LEVEL + 5 + Y2 ); g.drawString( "Local host/IP: " + hostAndIP, L_EDGE_PLUS_OFFSET, E1_LEVEL + Y2 + 75 ); // used by server only g.drawString( "Status: " + status, L_EDGE_PLUS_OFFSET, E1_LEVEL + Y2 + 100 ); g.setColor( new Color( 0, 0, 0 ) ); g.drawString( "Student", L_EDGE_PLUS_OFFSET, 40 ); g.drawString( "Student", L_EDGE_PLUS_OFFSET + 1, 41 ); // until the bold thing is figured out g.drawString( "Teacher", L_EDGE_PLUS_OFFSET, 40 + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2) ); g.drawString( "Teacher", L_EDGE_PLUS_OFFSET + 1, 41 + FRET_HEIGHT + (VERTICAL_FRETBOARD_PADDING * 2) ); /* ----------------------------------------------------------------------- | | Draw the status indicator in red ink. | \---------------------------------------------------------------------- */ g.setColor( new Color( red, green, blue ) ); g.fillRect( L_EDGE_PLUS_OFFSET - 10, E1_LEVEL + 93 + Y2, 5, 5 ); /* For future use, the following set of fillrect methods will highlight each note on the fretboard. These should be triggered according to channel and MIDI note number. For example, MIDI note 60, which is middle c, could map to either the c note on the b-, g-, or d-string -- they're all the same. However, if we receive MIDI note 60 on channel 5, we are assured that it maps to the c note on string b. // Highlight all the c notes in ORANGE. g.setColor( Color.ORANGE ); g.fillRect( FRET_05, E1_LEVEL, FRET_05_WIDTH, 1 ); // MIDI note g.fillRect( FRET_12, B2_LEVEL, FRET_12_WIDTH, 2 ); // MIDI note 60 g.fillRect( FRET_08, G3_LEVEL, FRET_08_WIDTH, 3 ); // MIDI note g.fillRect( FRET_03, D4_LEVEL, FRET_03_WIDTH, 4 ); // MIDI note g.fillRect( FRET_10, A5_LEVEL, FRET_10_WIDTH, 5 ); // MIDI note g.fillRect( FRET_05, E6_LEVEL, FRET_05_WIDTH, 6 ); // MIDI note // Highlight all the c#/db notes in PINK. g.setColor( Color.PINK ); g.fillRect( FRET_04, E1_LEVEL, FRET_04_WIDTH, 1 ); // MIDI note g.fillRect( FRET_11, B2_LEVEL, FRET_11_WIDTH, 2 ); // MIDI note g.fillRect( FRET_07, G3_LEVEL, FRET_07_WIDTH, 3 ); // MIDI note g.fillRect( FRET_02, D4_LEVEL, FRET_02_WIDTH, 4 ); // MIDI note g.fillRect( FRET_09, A5_LEVEL, FRET_09_WIDTH, 5 ); // MIDI note g.fillRect( FRET_04, E6_LEVEL, FRET_04_WIDTH, 6 ); // MIDI note // Highlight all the d notes in CYAN. g.setColor( Color.CYAN ); g.fillRect( FRET_03, E1_LEVEL, FRET_03_WIDTH, 1 ); // MIDI note g.fillRect( FRET_10, B2_LEVEL, FRET_10_WIDTH, 2 ); // MIDI note g.fillRect( FRET_06, G3_LEVEL, FRET_06_WIDTH, 3 ); // MIDI note g.fillRect( FRET_01, D4_LEVEL, FRET_01_WIDTH, 4 ); // MIDI note g.fillRect( FRET_08, A5_LEVEL, FRET_08_WIDTH, 5 ); // MIDI note g.fillRect( FRET_03, E6_LEVEL, FRET_03_WIDTH, 6 ); // MIDI note // Highlight all the d#/eb notes in MAGENTA. g.setColor( Color.MAGENTA ); g.fillRect( FRET_02, E1_LEVEL, FRET_02_WIDTH, 1 ); // MIDI note g.fillRect( FRET_09, B2_LEVEL, FRET_09_WIDTH, 2 ); // MIDI note g.fillRect( FRET_05, G3_LEVEL, FRET_05_WIDTH, 3 ); // MIDI note g.fillRect( FRET_12, D4_LEVEL, FRET_12_WIDTH, 4 ); // MIDI note g.fillRect( FRET_07, A5_LEVEL, FRET_07_WIDTH, 5 ); // MIDI note g.fillRect( FRET_02, E6_LEVEL, FRET_02_WIDTH, 6 ); // MIDI note // Highlight all the e notes in YELLOW. g.setColor( Color.YELLOW ); g.fillRect( FRET_01, E1_LEVEL, FRET_01_WIDTH, 1 ); g.fillRect( FRET_08, B2_LEVEL, FRET_08_WIDTH, 2 ); g.fillRect( FRET_04, G3_LEVEL, FRET_04_WIDTH, 3 ); g.fillRect( FRET_11, D4_LEVEL, FRET_11_WIDTH, 4 ); g.fillRect( FRET_06, A5_LEVEL, FRET_06_WIDTH, 5 ); g.fillRect( FRET_01, E6_LEVEL, FRET_01_WIDTH, 6 ); // Highlight all the f notes in BLACK. g.setColor( Color.BLACK ); g.fillRect( FRET_12, E1_LEVEL, FRET_12_WIDTH, 1 ); g.fillRect( FRET_07, B2_LEVEL, FRET_07_WIDTH, 2 ); g.fillRect( FRET_03, G3_LEVEL, FRET_03_WIDTH, 3 ); g.fillRect( FRET_10, D4_LEVEL, FRET_10_WIDTH, 4 ); g.fillRect( FRET_05, A5_LEVEL, FRET_05_WIDTH, 5 ); g.fillRect( FRET_12, E6_LEVEL, FRET_12_WIDTH, 6 ); // Highlight all the f#/gb notes in WHITE. g.setColor( Color.WHITE ); g.fillRect( FRET_11, E1_LEVEL, FRET_11_WIDTH, 1 ); g.fillRect( FRET_06, B2_LEVEL, FRET_06_WIDTH, 2 ); g.fillRect( FRET_02, G3_LEVEL, FRET_02_WIDTH, 3 ); g.fillRect( FRET_09, D4_LEVEL, FRET_09_WIDTH, 4 ); g.fillRect( FRET_04, A5_LEVEL, FRET_04_WIDTH, 5 ); g.fillRect( FRET_11, E6_LEVEL, FRET_11_WIDTH, 6 ); // Highlight all the g notes in GRAY. g.setColor( Color.GRAY ); g.fillRect( FRET_10, E1_LEVEL, FRET_10_WIDTH, 1 ); g.fillRect( FRET_05, B2_LEVEL, FRET_05_WIDTH, 2 ); g.fillRect( FRET_01, G3_LEVEL, FRET_01_WIDTH, 3 ); g.fillRect( FRET_08, D4_LEVEL, FRET_08_WIDTH, 4 ); g.fillRect( FRET_03, A5_LEVEL, FRET_03_WIDTH, 5 ); g.fillRect( FRET_10, E6_LEVEL, FRET_10_WIDTH, 6 ); // Highlight all the g#/ab notes in BLUE g.setColor( Color.BLUE ); g.fillRect( FRET_09, E1_LEVEL, FRET_09_WIDTH, 1 ); g.fillRect( FRET_04, B2_LEVEL, FRET_04_WIDTH, 2 ); g.fillRect( FRET_12, G3_LEVEL, FRET_12_WIDTH, 3 ); g.fillRect( FRET_07, D4_LEVEL, FRET_07_WIDTH, 4 ); g.fillRect( FRET_02, A5_LEVEL, FRET_02_WIDTH, 5 ); g.fillRect( FRET_09, E6_LEVEL, FRET_09_WIDTH, 6 ); // Highlight all the a notes in DARK_GRAY. g.setColor( Color.DARK_GRAY ); g.fillRect( FRET_08, E1_LEVEL, FRET_08_WIDTH, 1 ); g.fillRect( FRET_03, B2_LEVEL, FRET_03_WIDTH, 2 ); g.fillRect( FRET_11, G3_LEVEL, FRET_11_WIDTH, 3 ); g.fillRect( FRET_06, D4_LEVEL, FRET_06_WIDTH, 4 ); g.fillRect( FRET_01, A5_LEVEL, FRET_01_WIDTH, 5 ); g.fillRect( FRET_08, E6_LEVEL, FRET_08_WIDTH, 6 ); // Highlight all the a#/bb notes in RED. g.setColor( Color.RED ); g.fillRect( FRET_07, E1_LEVEL, FRET_07_WIDTH, 1 ); g.fillRect( FRET_02, B2_LEVEL, FRET_02_WIDTH, 2 ); g.fillRect( FRET_10, G3_LEVEL, FRET_10_WIDTH, 3 ); g.fillRect( FRET_05, D4_LEVEL, FRET_05_WIDTH, 4 ); g.fillRect( FRET_12, A5_LEVEL, FRET_12_WIDTH, 5 ); g.fillRect( FRET_07, E6_LEVEL, FRET_07_WIDTH, 6 ); // Highlight all the b notes in GREEN. g.setColor( Color.GREEN ); g.fillRect( FRET_06, E1_LEVEL, FRET_06_WIDTH, 1 ); g.fillRect( FRET_01, B2_LEVEL, FRET_01_WIDTH, 2 ); g.fillRect( FRET_09, G3_LEVEL, FRET_09_WIDTH, 3 ); g.fillRect( FRET_04, D4_LEVEL, FRET_04_WIDTH, 4 ); g.fillRect( FRET_11, A5_LEVEL, FRET_11_WIDTH, 5 ); g.fillRect( FRET_06, E6_LEVEL, FRET_06_WIDTH, 6 ); */ } /* ----------------------------------------------------------------------------- | | Key events will map to areas on the fretboard that corespond to notes, | similar to Practica Musica or SoundSchool | \---------------------------------------------------------------------------- */ public void keyPressed( KeyEvent event ) { char note = event.getKeyChar(); switch( note ) { // q, Q, a, and A all trigger middle c, which is on the b case 'q': case 'Q': case 'a': case 'A': repaint( FRET_12, B2_LEVEL, FRET_12_WIDTH, 2 ); break; // w and W trigger C#/Db case 'w': case 'W': repaint( FRET_12, B2_LEVEL, FRET_11_WIDTH, 3 ); break; default: break; } } public void keyReleased( KeyEvent event ) { } public void keyTyped( KeyEvent event ) { } public static void main( String[] args ) { Project application = new Project(); application.runServer(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } }