package client.audio;

public class Instrument {
	public final Operator[] ops;
	public final int feedback1;
	public final int feedback2;
	public final int algo;
	
	public boolean fixed;
	public int percnum;
	
	public Instrument(int feedback1, int feedback2, int algo, Operator ... ops) {
		this.ops = ops;
		this.feedback1 = feedback1;
		this.feedback2 = feedback2;
		this.algo = algo;
	}
	
	public Instrument() {
		this(0, 0, 0);
	}
	
	public Instrument(Operator op1, Operator op2, boolean am, int detune, int offset, int feedback) {
		this(feedback, 0, am ? 1 : 0, op1, op2);
		op1.offset(offset).detune(detune);
		op2.offset(offset).detune(detune);
	}
	
	public Instrument(Operator op1A, Operator op2A, boolean amA, int detuneA, int offsetA, int feedbackA, 
			Operator op1B, Operator op2B, boolean amB, int detuneB, int offsetB, int feedbackB) {
		this(feedbackA, feedbackB, 0x08 | (amA ? 1 : 0) | (amB ? 2 : 0), op1A, op2A, op1B, op2B);
		op1A.offset(offsetA).detune(detuneA);
		op2A.offset(offsetA).detune(detuneA);
		op1B.offset(offsetB).detune(detuneB);
		op2B.offset(offsetB).detune(detuneB);
	}
	
	public Instrument(Operator op1, Operator op2, Operator op3, Operator op4, int algo, int detune, int offset, int feedback) {
		this(feedback, 0, 0x04 | (algo & 3), op1, op2, op3, op4);
		op1.offset(offset).detune(detune);
		op2.offset(offset).detune(detune);
		op3.offset(offset).detune(detune);
		op4.offset(offset).detune(detune);
	}
	
	public Instrument setFixed() {
		this.fixed = true;
		return this;
	}
	
	public Instrument setPercNum(int percnum) {
		this.percnum = percnum;
		return this;
	}
	
	public Instrument setFixed(int percnum) {
		this.fixed = true;
		this.percnum = percnum;
		return this;
	}
}
