// this shit broken, don't use

// Define the sine wave synth with non-ET tuning (just intonation)
// Define the sine wave synth with non-ET tuning and an envelope (Just Intonation)
(
SynthDef("sine_wave_non_et", {
    arg freq, amp, tuningRatio, outBus;

    // Set up tuning - ET scale (can use different tuning ratios)
 /*var tuning = [  33/32, 21/20, 11/10, 9/8, 7/6, 99/80, 77/60, 21/16,
        11/8, 7/5, 231/160, 3/2, 63/40, 77/48, 33/20, 7/4,
        9/5, 11/6, 77/40, 2/1]; // Example ratios for the 8-note scale
	*/
	var tuning = [
		113.20755,
		271.69811,
		384.90566,
		543.39623,
		656.60377,
		815.09434,
		928.30189,
		1086.79245,
		2/1
	]; // 53 edo

    // Calculate frequency based on tuning ratio
    var tunedFreq = freq * tuning * tuningRatio;

	    // Calculate frequency based on tuning ratio
    /*var scaleIndex = freq % tuning.size;  // Wrap the frequency to the scale size
    var tunedFreq = freq * tuning[scaleIndex];  // Apply the tuning ratio*/

    // Create an envelope (ADSR)
    var env = EnvGen.kr(Env.perc(0.01, 0.2), gate: 1); // Short attack and release times

    // Generate a sine wave oscillator with the tuned frequency and apply the envelope to the amplitude
    var sig = SinOsc.ar(tunedFreq, 0, amp * env); // Sine wave at tuned frequency with envelope

    // Send output to the specified bus
    Out.ar(outBus, sig);
}).add;
)



(
    // Use Pbind to bind parameters with patterns
    Pbind(
        \instrument, "sine_wave_non_et", // Synth name
	\freq, Pseq([60, 61, 62, 63].midicps), // Sequence of frequencies (A4, E5, A5)
        \amp, 0.3,  //Constant amplitude
	\tuningRatio, -2, // Tuning ratio for each frequency
        \outBus, 0 // Output bus
    ).play;
)

