/*****************************************************************************
 *  Compilation:  javac MiniHarp.java
 *  Execution:    java  MiniHarp
 *
 *  Plays two harp strings (A and C) when the user
 *  types the lowercase letters 'a' and 'c', in the 
 *  standard drawing window.
 *
 ****************************************************************************/

public class MiniHarp {
    public static void main(String[] args) {
        // create two harp strings, for concert A and C
        double A = 440.0;
        double C = A * Math.pow(2, 3.0/12.0);  
        HarpString stringA = new HarpString(A);
        HarpString stringC = new HarpString(C);

        while (true) {
            // check if the user has typed a key; if so, process it   
            if (StdDraw.hasNextKeyTyped()) {
                char key = StdDraw.nextKeyTyped();
                if      (key == 'a') { stringA.pluck(); }
                else if (key == 'c') { stringC.pluck(); }
            }

            // compute the combined sound of all notes
            double sample = stringA.sample() + stringC.sample();
  
            // play the sample on standard audio
            StdAudio.play(sample);
  
            // advance the simulation of each harp string by one step   
            stringA.tic();
            stringC.tic();
        }
    }
}
