// GuitarHero.java // Chris Wilcox // 4/13/2013 // cs160 // wilcox@cs.colostate.edu // ACKNOWLEDGEMENTS: // // This assignment was heavily copied from the geniuses at Princeton University. // Permission to use the assignment was granted via email by Dr. Robert Sedgewick // at Princeton, as follows: // // "Sure, thanks for your interest. Please acknowledge the source." // // Here is the assignment website we copied from: // // http://introcs.cs.princeton.edu/java/assignments // // This assignment was developed by Andrew Appel, Jeff Bernstein, Maia Ginsburg, // Ken Steiglitz, Ge Wang, and Kevin Wayne. Copyright © 2005 // // We gratefully acknowledge the material from Princeton used in this assignment! import java.util.Scanner; public class P8 { // Two guitar strings, for concert A and C GuitarString stringA; GuitarString stringC; public static void main(String[] args) { // Instantiate object P8 p8 = new P8(); // Create two guitar strings, for concert A and C p8.stringA = new GuitarString(440.0 * Math.pow(1.05956, 0.0)); p8.stringC = new GuitarString(440.0 * Math.pow(1.05956, 3.0)); // Play keyboard p8.playKeyboard(); // Play file if (args.length >= 1) p8.playFile(args[0]); } // Play from keyboard public void playKeyboard() { System.out.println("Press keys to play music, 'X' exits)."); // Processing loop while (true) { // Has user has typed a key? if (StdDraw.hasNextKeyTyped()) { // Which key has been typed char key = Character.toUpperCase(StdDraw.nextKeyTyped()); System.out.println("Key pressed: " + key); if (key == 'X') break; // Pluck string pluckGuitar(Character.toString(key)); } // Play guitar playGuitar(); } } // Play from file public void playFile(String filename) { } // Pluck guitar strings public void pluckGuitar(String note) { if (note.equals("A")) stringA.pluck(); else if (note.equals("C")) stringC.pluck(); } // Play guitar strings public void playGuitar() { double sample = 0.0; // Combine the samples sample = stringA.sample() + stringC.sample(); // Send sample to standard audio StdAudio.play(sample); // Advance the guitar simulation stringA.tic(); stringC.tic(); } }