
import music.*;

/*
 * A class containing some sample pieces of music
 *
 * Both: 
 *   Samples.sampleMusic1() 
 *   Samples.sampleMusic2()
 * return a Voice object
 *
 */
 
public class Samples {


    /* 
     * Creating a voice from an array of notes 
     */
    
    private static Voice fromArray (Note[] notes) {
	Voice result = Voice.empty();
	for (Note n : notes)
	    result = Voice.concatenated (result,Voice.oneNote (n));
	return result;
    }


    /*
     * Some abbreviations for notes creators
     */
    
    private static Note w (Pitch p) {
	return Note.whole(p);
    }
    private static Note h (Pitch p) {
	return Note.half(p);
    }
    private static Note q (Pitch p) {
	return Note.quarter(p);
    }
    private static Note e (Pitch p) {
	return Note.eighth(p);
    }
    private static Note s (Pitch p) {
	return Note.sixteenth(p);
    }



    /* 
     * First piece of music
     *
     * Should be easy to identify 
     */

    public static Voice sampleMusic1 () {
	
	Note r4 = Note.quarterRest ();
	Note r8 = Note.eighthRest ();
	
	Pitch c6 = Pitch.named("C",6);
	
	Pitch b5 = Pitch.named("Bb",5);
	Pitch a5 = Pitch.named("A",5);
	Pitch g5 = Pitch.named("G",5);
	Pitch f5s = Pitch.named("F#",5);
	Pitch f5 = Pitch.named("F",5);
	Pitch e5 = Pitch.named("Eb",5);
	Pitch d5 = Pitch.named("D",5);
	Pitch c5 = Pitch.named("C",5);
	
	Pitch b4 = Pitch.named("Bb",4);
	Pitch a4 = Pitch.named("A",4);
	Pitch g4 = Pitch.named("G",4);
	Pitch f4 = Pitch.named("F",4);
	Pitch e4 = Pitch.named("Eb",4);
	Pitch d4 = Pitch.named("D",4);
	Pitch c4 = Pitch.named("C",4);
	
	Pitch b3 = Pitch.named("Bb",3);
	Pitch a3 = Pitch.named("A",3);
	Pitch g3 = Pitch.named("G",3);
	Pitch f3s = Pitch.named("F#",3);
	Pitch f3 = Pitch.named("F",3);
	Pitch e3 = Pitch.named("Eb",3);
	Pitch d3 = Pitch.named("D",3);
	Pitch c3 = Pitch.named("C",3);
	Pitch a2 = Pitch.named("A",2);

	
	Note[] sample = {
	    e(e4), e(d4), 
	    q(d4), e(e4), e(d4), q(d4), e(e4), e(d4), 
	    q(d4), q(b5), r4,    e(b5), e(a5),
	    q(g5), e(g5), e(f5), q(e5), e(e5), e(d5),
	    q(c5), q(c5), r4,    e(d5), e(c5),
	    q(c5), e(d5), e(c5), q(c5), e(d5), e(c5),
	    q(c5), q(a5), r4,    e(a5), e(g5), 
	    q(f5s), e(f5s), e(e5), q(d5), e(d5), e(c5),
	    q(b4), q(b4), r4, e(b5), e(a5),
	    q(a5), q(c6), q(f5s), q(a5),
	    q(g5), q(d5), r4, e(b5), e(a5),
	    q(a5), q(c6), q(f5s), q(a5), 
	    q(g5), q(b5), e(a5), e(g5), e(f5), e(e5),
	    // w(d5)
	    q(d5), q(f3s), q(g3), q(a3),
	    q(b3), e(c4), e(b3), q(a3), q(g3),
	    q(d3), r4,    h(e3), 
	    q(d3), r4,  h(e3),
	    q(d3), r4, h(e3), 
	    q(d3), e(e3), r8, e(d3), r8, e(e3), r8,
	    e(d3), r8, r4, r4, r4
	};
	
	return fromArray (sample);

    }


    /*
     * Second piece of music
     * 
     * Probably harder to identify
     * Should really be played on an ocarina for full effect
     */

    public static Voice sampleMusic2 () {
	
	
	Note a42 = Note.half (Pitch.named("A",4));
	Note a44 = Note.quarter (Pitch.named("A",4));
	Note g44 = Note.quarter (Pitch.named("G",4));
	Note g42 = Note.half (Pitch.named("G",4));
	Note g41 = Note.whole (Pitch.named("G",4));
	Note f44 = Note.quarter (Pitch.named("F",4));
	Note f42 = Note.half (Pitch.named("F",4));
	Note e44 = Note.quarter (Pitch.named("E",4));
	Note e42 = Note.half (Pitch.named("E",4));
	Note d44 = Note.quarter (Pitch.named("D",4));
	Note d42 = Note.half (Pitch.named("D",4));
	Note c42 = Note.half (Pitch.named("C",4));
	Note r2 = Note.halfRest ();
	
	
	
	Note[] sample = {
	    a42, g44, f44, e42, d44, e44, f44, g41, r2,
	    a42, g44, f44, e42, d44, e44, f44, g41, r2,
	    g42, f44, e44, f42, f44, e44, d44, c42, r2,
	    a42, g44, f44, e42, d44, e44, f44, g41, r2
	};
	
	return fromArray (sample);
    }
    

}
