
let audioCtx = new AudioContext();
let osc1 = audioCtx.createOscillator();
let osc2 = audioCtx.createOscillator();
let osc3 = audioCtx.createOscillator();
let osc4 = audioCtx.createOscillator();
let osc5 = audioCtx.createOscillator();
let osc6 = audioCtx.createOscillator();
let osc7 = audioCtx.createOscillator();
let osc8 = audioCtx.createOscillator();
let osc9 = audioCtx.createOscillator();
let osc10 = audioCtx.createOscillator();
let osc11 = audioCtx.createOscillator();
let osc12 = audioCtx.createOscillator();
let osc13 = audioCtx.createOscillator();
let osc14 = audioCtx.createOscillator();
let osc15 = audioCtx.createOscillator();
let osc16 = audioCtx.createOscillator();

let osc1Gain = audioCtx.createGain();
let osc2Gain = audioCtx.createGain();
let osc3Gain = audioCtx.createGain();
let osc4Gain = audioCtx.createGain();
let osc5Gain = audioCtx.createGain();
let osc6Gain = audioCtx.createGain();
let osc7Gain = audioCtx.createGain();
let osc8Gain = audioCtx.createGain();
let osc9Gain = audioCtx.createGain();
let osc10Gain = audioCtx.createGain();
let osc11Gain = audioCtx.createGain();
let osc12Gain = audioCtx.createGain();
let osc13Gain = audioCtx.createGain();
let osc14Gain = audioCtx.createGain();
let osc15Gain = audioCtx.createGain();
let osc16Gain = audioCtx.createGain();


let OutputGain =audioCtx.createGain();


const a=document.getElementById('nota');
const s1=document.getElementById("slid1");
const s2=document.getElementById("slid2");
const s3=document.getElementById("slid3");
const s4=document.getElementById("slid4");
const s5=document.getElementById("slid5");
const s6=document.getElementById("slid6");
const s7=document.getElementById("slid7");
const s8=document.getElementById("slid8");
const s9=document.getElementById("slid9");
const s10=document.getElementById("slid10");
const s11=document.getElementById("slid11");
const s12=document.getElementById("slid12");
const s13=document.getElementById("slid13");
const s14=document.getElementById("slid14");
const s15=document.getElementById("slid15");
const s16=document.getElementById("slid16");
const OutputSlider=document.getElementById("slidOut");

const IN0=document.getElementById("f0In");
const IN1=document.getElementById("f1In");
const IN2=document.getElementById("f2In");
const IN3=document.getElementById("f3In");
const IN4=document.getElementById("f4In");
const IN5=document.getElementById("f5In");
const IN6=document.getElementById("f6In");
const IN7=document.getElementById("f7In");
const IN8=document.getElementById("f8In");
const IN9=document.getElementById("f9In");
const IN10=document.getElementById("f10In");
const IN11=document.getElementById("f11In");
const IN12=document.getElementById("f12In");
const IN13=document.getElementById("f13In");
const IN14=document.getElementById("f14In");
const IN15=document.getElementById("f15In");

const INOUT=document.getElementById("outIn");

const AIN=document.getElementById("AIn");
const DIN=document.getElementById("DIn");
const SIN=document.getElementById("SIn");
const RIN=document.getElementById("RIn");

// Vytvoření globálních proměnných a nastavení výchozí hodnoty kmitočtu (Event na change kmitočtu není proveden,je potřeba nadefinovat zde na hodnotu C0)
let Q = 0;
//
let f1 = 65.41;
osc1.frequency.value =  f1;
osc2.frequency.value =  2*f1;
osc3.frequency.value =  3*f1
osc4.frequency.value =  4*f1;
osc5.frequency.value =  5*f1;
osc6.frequency.value =  6*f1
osc7.frequency.value =  7*f1;
osc8.frequency.value =  8*f1;
osc9.frequency.value =  9*f1;
osc10.frequency.value = 10*f1;
osc11.frequency.value = 11*f1;
osc12.frequency.value = 12*f1
osc13.frequency.value = 13*f1;
osc14.frequency.value = 14*f1;
osc15.frequency.value = 15*f1
osc16.frequency.value = 16*f1;



const b=document.getElementById('Presety');
let pres=0;

function Preset(pres) {

if (pres ===0){

        osc1Gain.gain.value = 1;
        s1.value=1;
        osc2Gain.gain.value = 0;
        s2.value=0;
        osc3Gain.gain.value = 0;
        s3.value=0;
        osc4Gain.gain.value =0;
        s4.value=0;
        osc5Gain.gain.value =0;
        s5.value=0
        osc6Gain.gain.value =0;
        s6.value=0;
        osc7Gain.gain.value =0;
        s7.value=0;
        osc8Gain.gain.value = 0;
        s8.value=0;
        osc9Gain.gain.value =0;
        s9.value=0;
        osc10Gain.gain.value =0;
        s10.value=0;
        osc11Gain.gain.value =0;
        s11.value=0;
        osc12Gain.gain.value =0;
        s12.value=0;
        osc13Gain.gain.value =0;
        s13.value=0;
        osc14Gain.gain.value =0;
        s14.value=0;
        osc15Gain.gain.value =0;
        s15.value=0;
        osc16Gain.gain.value = 0;
        s16.value=0;




zmena();
zmenaHarm();

    }

   else if (pres ===1){


        osc1Gain.gain.value = 1;

        s1.value=1;
        osc2Gain.gain.value = 0;
        s2.value=0;

        osc3Gain.gain.value = 1/3;
        s3.value=1/3;
        osc4Gain.gain.value =0;
        s4.value=0;
        osc5Gain.gain.value = 1/5;
        s5.value=1/5;
        osc6Gain.gain.value =0;
        s6.value=0;
        osc7Gain.gain.value = 1/7;
        s7.value=1/7;
        osc8Gain.gain.value = 0;
        s8.value=0;
        osc9Gain.gain.value = 1/9;
        s9.value=1/9;
        osc10Gain.gain.value =0;
        s10.value=0;
        osc11Gain.gain.value = 1/11;
        s11.value=1/11;
        osc12Gain.gain.value =0;
        s12.value=0;
        osc13Gain.gain.value = 1/13;
        s13.value=1/13;
        osc14Gain.gain.value =0;
        s14.value=0;
        osc15Gain.gain.value = 1/15;
        s15.value=1/15;
        osc16Gain.gain.value = 0;
        s16.value=0;




    zmena();
    zmenaHarm();




    }

   else if(pres ===2){


        osc1Gain.gain.value = 1;

        s1.value=1;
        osc2Gain.gain.value = 1/2;
        s2.value=1/2;
        osc3Gain.gain.value = 1/3;
        s3.value=1/3;
        osc4Gain.gain.value =1/4;
        s4.value=1/4;
        osc5Gain.gain.value = 1/5;
        s5.value=1/5;
        osc6Gain.gain.value =1/6;
        s6.value=1/6;
        osc7Gain.gain.value = 1/7;
        s7.value=1/7;
        osc8Gain.gain.value = 1/8;
        s8.value=1/8;
        osc9Gain.gain.value = 1/9;
        s9.value=1/9;
        osc10Gain.gain.value =1/10;
        s10.value=1/10;
        osc11Gain.gain.value = 1/11;
        s11.value=1/11;
        osc12Gain.gain.value =1/12;
        s12.value=1/12;
        osc13Gain.gain.value = 1/13;
        s13.value=1/13;
        osc14Gain.gain.value =1/14;
        s14.value=1/14;
        osc15Gain.gain.value = 1/15;
        s15.value=1/15;
        osc16Gain.gain.value = 1/16;
        s16.value=1/16;





    zmena();
zmenaHarm();


}
}


b.addEventListener('change', function handleChange(event) {

    pres = Number(event.target.value);
    console.log(pres)
    Preset(pres)

    zmena();
    zmenaHarm();


})



// Funkce pro určení kmitočtu fundamentu
function calculateFrequency(Q) {



    if (Q===25){

        return 65.41;

    }
    else if (Q===26){

        return 69.30;

    }
    else if (Q===27){

      return 73.42;

    }
    else if (Q===28){

        return 77.78;

    }
    else if (Q===29){

        return 82.41;

    }
    else if (Q===30){

        return 87.31;

    }
    else if (Q===31){

        return 92.5;

    }

    else if (Q===32){

        return 98;

    }
    else if (Q===33){

        return 103.83;

    }
    else if (Q===34){

        return 110;

    }
    else if (Q===35){

        return 116.54;

    }
    else if (Q===36){

        return 123.47;

    }

    else if (Q===37){

        return 130.81;

    }

    else if (Q===38){

        return 138.59;

    }

    else if (Q===39){

        return 146.83;

    }

    else if (Q===40){

        return 155.56;

    }
    else if (Q===41){

        return 164.81;

    }
    else if (Q===42){

        return 174.61;

    }
    else if (Q===43){

        return 185;

    }
    else if (Q===44){

        return 196;

    }
    else if (Q===45){

        return 207.65;

    }
    else if (Q===46){

        return 220;

    }
    else if (Q===47){

        return 233.08;

    }
    else if (Q===48){

        return 246.94;

    }
    else if (Q===49){

        return 261.63;

    }
    else if (Q===50){

        return 277.18;

    }
    else if (Q===51){

        return 293.66;

    }
    else if (Q===52){

        return 311.13;

    }
    else if (Q===53){

        return 329.63;

    }
    else if (Q===54){

        return 349.23;

    }
    else if (Q===55){

        return 369.99;

    }

    else if (Q===56){

        return 392;

    }
    else if (Q===57){

        return 415.3;

    }
    else if (Q===58){

        return 440;

    }
    else if (Q===59){

        return 466.16;

    }
    else if (Q===60){

        return 493.88;

    }

    else if (Q===61){

        return 523.25;

    }
    else if (Q===62){

        return 554.37;

    }
    else if (Q===63){

        return 587.33;

    }
    else if (Q===64){

        return 622.25;

    }
    else if (Q===65){

        return 659.26;

    }
    else if (Q===66){

        return 698.46;

    }

    else if (Q===67){

        return 739.99;

    }
    else if (Q===68){

        return 783.99;

    }
    else if (Q===69){

        return 830.61;

    }
    else if (Q===70){

        return 880;

    }
    else if (Q===71){

        return 932.33;

    }
    else if (Q===72){

        return 987.77;

    }

    else if (Q===73){

        return 1046.5;

    }
    else if (Q===74){

        return 1108.73;

    }
    else if (Q===75){

        return 1174.66;

    }
    else if (Q===76){

        return 1244.51;

    }
    else if (Q===77){

        return 1318.51;

    }

}


a.addEventListener('change', function handleChange(event) {

    Q = Number(event.target.value);
    f1 = calculateFrequency(Q);

    osc1.frequency.value =  f1;
    osc2.frequency.value =  2*f1;
    osc3.frequency.value =  3*f1
    osc4.frequency.value =  4*f1;
    osc5.frequency.value =  5*f1;
    osc6.frequency.value =  6*f1
    osc7.frequency.value =  7*f1;
    osc8.frequency.value =  8*f1;
    osc9.frequency.value =  9*f1;
    osc10.frequency.value = 10*f1;
    osc11.frequency.value = 11*f1;
    osc12.frequency.value = 12*f1
    osc13.frequency.value = 13*f1;
    osc14.frequency.value = 14*f1;
    osc15.frequency.value = 15*f1
    osc16.frequency.value = 16*f1;




    document.getElementById('1Harm').innerHTML=f1.toFixed(2);
    document.getElementById('2Harm').innerHTML=(2*f1).toFixed(2);
    document.getElementById('3Harm').innerHTML=(3*f1).toFixed(2);
    document.getElementById('4Harm').innerHTML=(4*f1).toFixed(2);
    document.getElementById('5Harm').innerHTML=(5*f1).toFixed(2);
    document.getElementById('6Harm').innerHTML=(6*f1).toFixed(2);
    document.getElementById('7Harm').innerHTML=(7*f1).toFixed(2);
    document.getElementById('8Harm').innerHTML=(8*f1).toFixed(2);
    document.getElementById('9Harm').innerHTML=(9*f1).toFixed(2);
    document.getElementById('10Harm').innerHTML=(10*f1).toFixed(2);
    document.getElementById('11Harm').innerHTML=(11*f1).toFixed(2);
    document.getElementById('12Harm').innerHTML=(12*f1).toFixed(2);
    document.getElementById('13Harm').innerHTML=(13*f1).toFixed(2);
    document.getElementById('14Harm').innerHTML=(14*f1).toFixed(2);
    document.getElementById('15Harm').innerHTML=(15*f1).toFixed(2);
    document.getElementById('16Harm').innerHTML=(16*f1).toFixed(2);


    zmena();
    zmenaHarm();

});






s1.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S1= Number(event.target.value);
    osc1Gain.gain.value =S1;
    IN0.value=S1;





zmena();
zmenaHarm();

identifikaceZkresleni()
});

IN0.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I0 = Number(event.target.value);
    s1.value=I0;
    S1=I0;
    osc1Gain.gain.value =S1;




    zmena();
    zmenaHarm();
    identifikaceZkresleni()
});

s2.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S2= Number(event.target.value);
    osc2Gain.gain.value=S2;
    IN1.value=S2;



    zmena();
    zmenaHarm();
    identifikaceZkresleni()

});

IN1.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I1 = Number(event.target.value);
    s2.value=I1;
    S2=I1;
    osc2Gain.gain.value=S2;
    identifikaceZkresleni()




    zmena();
    zmenaHarm();
});






s3.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S3= Number(event.target.value);
    osc3Gain.gain.value=S3;
    IN2.value=S3;

    identifikaceZkresleni()

    zmena();
    zmenaHarm();
});



IN2.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I2 = Number(event.target.value);
    s3.value=I2;
    S3=I2;
    osc3Gain.gain.value=S3;
    identifikaceZkresleni()




    zmena();
    zmenaHarm();
});



s4.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S4= Number(event.target.value);
    osc4Gain.gain.value=S4;
    IN3.value=S4;



    zmena();
    zmenaHarm();
    identifikaceZkresleni()
});

IN3.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I3 = Number(event.target.value);
    s4.value=I3;
    S4=I3;
    osc4Gain.gain.value=S4;

    identifikaceZkresleni()

    zmena();
    zmenaHarm();
});





s5.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S5= Number(event.target.value);
    osc5Gain.gain.value=S5;
    IN4.value=S5;

    zmena();
    zmenaHarm();
    identifikaceZkresleni()

});

IN4.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I4 = Number(event.target.value);
    s5.value=I4;
    S5=I4;
    osc5Gain.gain.value=S5;
    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});





s6.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S6= Number(event.target.value);
    osc6Gain.gain.value=S6;
    IN5.value=S6;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});

IN5.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I5 = Number(event.target.value);
    s6.value=I5;
    S6=I5;
    osc6Gain.gain.value=S6;

    identifikaceZkresleni()

    zmena();
    zmenaHarm();
});




s7.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S7= Number(event.target.value);
    osc7Gain.gain.value=S7;
    IN6.value=S7;



    identifikaceZkresleni()
    zmena();
    zmenaHarm();

});

IN6.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I6 = Number(event.target.value);
    s7.value=I6;
    S7=I6;
    osc7Gain.gain.value=S7;
    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});








s8.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S8= Number(event.target.value);
    osc8Gain.gain.value=S8;
    IN7.value=S8;


    identifikaceZkresleni()

    zmena();
    zmenaHarm();

});

IN7.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I7 = Number(event.target.value);
    s8.value=I7;
    S8=I7;
    osc8Gain.gain.value=S8;

    identifikaceZkresleni()

    zmena();
    zmenaHarm();
});





s9.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S9= Number(event.target.value);
    osc9Gain.gain.value=S9;
    IN8.value=S9;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});


IN8.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I8 = Number(event.target.value);
    s9.value=I8;
    S9=I8;
    osc9Gain.gain.value=S9;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});


s10.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S10= Number(event.target.value);
    osc10Gain.gain.value=S10;
    IN9.value=S10;

    zmena();
    zmenaHarm();
    identifikaceZkresleni()
});


IN9.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I9 = Number(event.target.value);
    s10.value=I9;
    S10=I9;
    osc10Gain.gain.value=S10;
    identifikaceZkresleni()

    zmena();
    zmenaHarm();
});



s11.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S11= Number(event.target.value);
    osc11Gain.gain.value=S11;
    IN10.value=S11;

    zmena();
    zmenaHarm();
    identifikaceZkresleni()

});

IN10.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I10 = Number(event.target.value);
    s11.value=I10;
    S11=I10;
    osc11Gain.gain.value=S11;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});




s12.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S12= Number(event.target.value);
    osc12Gain.gain.value=S12;
    IN11.value=S12;

    identifikaceZkresleni()

    zmena();
    zmenaHarm();

});


IN11.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I11 = Number(event.target.value);
    s12.value=I11;
    S12=I11;
    osc12Gain.gain.value=S12;
    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});


s13.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S13= Number(event.target.value);
    osc13Gain.gain.value=S13;
    IN12.value=S13;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();

});

IN12.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I12 = Number(event.target.value);
    s13.value=I12;
    S13=I12;
    osc13Gain.gain.value=S13;
    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});


s14.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S14= Number(event.target.value);
    osc14Gain.gain.value=S14;
    IN13.value=S14;



    identifikaceZkresleni()

    zmena();
    zmenaHarm();

});

IN13.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I13 = Number(event.target.value);
    s14.value=I13;
    S14=I13;
    osc14Gain.gain.value=S14;
    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});


s15.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S15= Number(event.target.value);
    osc15Gain.gain.value=S15;
    IN14.value=S15;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();

});


IN14.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I14 = Number(event.target.value);
    s15.value=I14;
    S15=I14;
    osc15Gain.gain.value=S15;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});



s16.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    S16= Number(event.target.value);
    osc16Gain.gain.value=S16;
    IN15.value=S16;


    identifikaceZkresleni()

    zmena();
    zmenaHarm();
});

IN15.addEventListener('input', function handleChange(event) {

    console.log(event.target.value);
    I15 = Number(event.target.value);
    s16.value=I15;
    S16=I15;
    osc16Gain.gain.value=S16;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();
});


OutputSlider.addEventListener('input', function handleChange(event) {
    console.log(event.target.value);
    OutputSlider1 = Number(event.target.value);
    OutputGain.gain.value= OutputSlider1;

    INOUT.value=OutputSlider1;

    identifikaceZkresleni()
    zmena();
    zmenaHarm();


});

INOUT.addEventListener('input', function handleChange(event){

    Oout = Number(event.target.value);
    OutputSlider.value=Oout;
    OutputSlider1=Oout;
    OutputGain.gain.value= OutputSlider1;
    identifikaceZkresleni()

    zmena();
    zmenaHarm();


});

osc1Gain.gain.value =s1.value;
osc2Gain.gain.value =s2.value;
osc3Gain.gain.value =s3.value;
osc4Gain.gain.value =s4.value;
osc5Gain.gain.value =s5.value;
osc6Gain.gain.value =s6.value;
osc7Gain.gain.value =s7.value;
osc8Gain.gain.value =s8.value;
osc9Gain.gain.value =s9.value;
osc10Gain.gain.value =s10.value;
osc11Gain.gain.value =s11.value;
osc12Gain.gain.value =s12.value;
osc13Gain.gain.value =s13.value;
osc14Gain.gain.value =s14.value;
osc15Gain.gain.value =s15.value;
osc16Gain.gain.value =s16.value;

OutputGain.gain.value=OutputSlider.value;



osc1.connect(osc1Gain);
osc2.connect(osc2Gain);
osc3.connect(osc3Gain);
osc4.connect(osc4Gain);
osc5.connect(osc5Gain);
osc6.connect(osc6Gain);
osc7.connect(osc7Gain);
osc8.connect(osc8Gain);
osc9.connect(osc9Gain);
osc10.connect(osc10Gain);
osc11.connect(osc11Gain);
osc12.connect(osc12Gain);
osc13.connect(osc13Gain);
osc14.connect(osc14Gain);
osc15.connect(osc15Gain);
osc16.connect(osc16Gain);

osc1Gain.connect(OutputGain);
osc2Gain.connect(OutputGain);
osc3Gain.connect(OutputGain);
osc4Gain.connect(OutputGain);
osc5Gain.connect(OutputGain);
osc6Gain.connect(OutputGain);
osc7Gain.connect(OutputGain);
osc8Gain.connect(OutputGain);
osc9Gain.connect(OutputGain);
osc10Gain.connect(OutputGain);
osc11Gain.connect(OutputGain);
osc12Gain.connect(OutputGain);
osc13Gain.connect(OutputGain);
osc14Gain.connect(OutputGain);
osc15Gain.connect(OutputGain);
osc16Gain.connect(OutputGain);

document.getElementById('1Harm').innerHTML=f1.toFixed(2);
document.getElementById('2Harm').innerHTML=(2*f1).toFixed(2);
document.getElementById('3Harm').innerHTML=(3*f1).toFixed(2);
document.getElementById('4Harm').innerHTML=(4*f1).toFixed(2);
document.getElementById('5Harm').innerHTML=(5*f1).toFixed(2);
document.getElementById('6Harm').innerHTML=(6*f1).toFixed(2);
document.getElementById('7Harm').innerHTML=(7*f1).toFixed(2);
document.getElementById('8Harm').innerHTML=(8*f1).toFixed(2);
document.getElementById('9Harm').innerHTML=(9*f1).toFixed(2);
document.getElementById('10Harm').innerHTML=(10*f1).toFixed(2);
document.getElementById('11Harm').innerHTML=(11*f1).toFixed(2);
document.getElementById('12Harm').innerHTML=(12*f1).toFixed(2);
document.getElementById('13Harm').innerHTML=(13*f1).toFixed(2);
document.getElementById('14Harm').innerHTML=(14*f1).toFixed(2);
document.getElementById('15Harm').innerHTML=(15*f1).toFixed(2);
document.getElementById('16Harm').innerHTML=(16*f1).toFixed(2);



    let konec = 2 * Math.PI * f1;
    var vektort = [];
    var vektors = [];


if(f1<100) {
    for (let i = 0; i <= konec; i = i + 0.05) {
         t = i;
         s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }
}

else if(f1>100&&f1<250){

    for (let i = 0; i <= konec; i = i +2) {

        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}

else if(f1>250&&f1<500){

    for (let i = 0; i <= konec; i = i +5) {

        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}

else if(f1>500&&f1<1000){

    for (let i = 0; i <= konec; i = i +10) {

        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}
else if(f1>1000){

    for (let i = 0; i <= konec; i = i +15) {

        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}

    var xValues = vektort;
    var yValues = vektors;

   var graf = new Chart("myCanvas", {
        type: "line",
        title:"Aditivní syntéza ",
        borderWidth: 0.01,
        lineWidth:0.001,


        data: {
            yAxisID: "S(t)",
            labels: xValues,
            datasets: [{

                borderColor: "rgba(122,192,103,0.38)",
                data: yValues,
                lineWidth:1,
                label: "Aditivní syntéza",

            }],

        },


    });




function zmena() {

    let konec = 2 * Math.PI * f1;
    var vektort = [];
    var vektors = [];

if(f1<100) {
    for (let i = 0; i <= konec; i = i + 0.05) {
        var t = i;
        var s =(s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }
}
else if(f1>100&&f1<250){

    for (let i = 0; i <= konec; i = i +2) {
        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}
else if(f1>250&&f1<500){

    for (let i = 0; i <= konec; i = i +5) {
        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}
else if(f1>500&&f1<1000){

    for (let i = 0; i <= konec; i = i +10) {
        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}

else if(f1>1000){

    for (let i = 0; i <= konec; i = i +15) {
        var t = i;
        var s = (s1.value * Math.sin(t / f1) + s2.value * Math.sin(t * 2 / f1) + s3.value * Math.sin(t * 3 / f1) + s4.value * Math.sin(t * 4 / f1) + s5.value * Math.sin(t * 5 / f1)
            + s6.value * Math.sin(t * 6 / f1) + s7.value * Math.sin(t * 7 / f1) + s8.value * Math.sin(t * 8 / f1) + s9.value * Math.sin(t * 9 / f1) + s10.value * Math.sin(t * 10 / f1) + s11.value * Math.sin(t * 11 / f1)
            + s12.value * Math.sin(t * 12 / f1) + s13.value * Math.sin(t * 13 / f1) + s14.value * Math.sin(t * 14 / f1) + s15.value * Math.sin(t * 15 / f1) + s16.value * Math.sin(t * 16 / f1));

        vektort.push(t);
        vektors.push(s);
    }


}

    graf.data.labels=vektort;
graf.data.datasets[0].data =vektors;

    graf.update();

}




    let konec2 = 2 * Math.PI * f1;
    var vektort2 =[];
    var vektors1 =[];
    var vektors2 =[];
    var vektors3=[];
    var vektors4 =[];
    var vektors5 =[];
    var vektors6=[];
    var vektors7 =[];
    var vektors8 =[];
    var vektors9=[];
    var vektors10=[];
    var vektors11 =[];
    var vektors12=[];
    var vektors13=[];
    var vektors14=[];
    var vektors15=[];
    var vektors16=[];

if (f1<100) {

    for (let i = 0; i <= konec2; i = i + 0.5) {
        var t2 = i;
        var sl1 = s1.value * Math.sin(t2 / f1);
        var sl2 = s2.value * Math.sin(t2 * 2 / f1);
        var sl3 = s3.value * Math.sin(t2 * 3 / f1);
        var sl4 = s4.value * Math.sin(t2 * 4 / f1);
        var sl5 = s5.value * Math.sin(t2 * 5 / f1);
        var sl6 = s6.value * Math.sin(t2 * 6 / f1);
        var sl7 = s7.value * Math.sin(t2 * 7 / f1);
        var sl8 = s8.value * Math.sin(t2 * 8 / f1);
        var sl9 = s9.value * Math.sin(t2 * 9 / f1);
        var sl10 =s10.value * Math.sin(t2 * 10 / f1);
        var sl11 = s11.value * Math.sin(t2 * 11 / f1);
        var sl12 = s12.value * Math.sin(t2 * 12 / f1);
        var sl13 = s13.value * Math.sin(t2 * 13 / f1);
        var sl14 = s14.value * Math.sin(t2 * 14 / f1);
        var sl15 = s15.value * Math.sin(t2 * 15 / f1);
        var sl16 = s16.value * Math.sin(t2 * 16 / f1);


        vektort2.push(t2);
        vektors1.push(sl1);
        vektors2.push(sl2);
        vektors3.push(sl3);
        vektors4.push(sl4);
        vektors5.push(sl5);
        vektors6.push(sl6);
        vektors7.push(sl7);
        vektors8.push(sl8);
        vektors9.push(sl9);
        vektors10.push(sl10);
        vektors11.push(sl11);
        vektors12.push(sl12);
        vektors13.push(sl13);
        vektors14.push(sl14);
        vektors15.push(sl15);
        vektors16.push(sl16);
    }

}

else if (f1>100&& f1<250){

    for (let i = 0; i <= konec2; i = i +2) {
        var t2 = i;
        var sl1 = s1.value * Math.sin(t2 / f1);
        var sl2 = s2.value * Math.sin(t2 * 2 / f1);
        var sl3 = s3.value * Math.sin(t2 * 3 / f1);
        var sl4 = s4.value * Math.sin(t2 * 4 / f1);
        var sl5 = s5.value * Math.sin(t2 * 5 / f1);
        var sl6 = s6.value * Math.sin(t2 * 6 / f1);
        var sl7 = s7.value * Math.sin(t2 * 7 / f1);
        var sl8 = s8.value * Math.sin(t2 * 8 / f1);
        var sl9 = s9.value * Math.sin(t2 * 9 / f1);
        var sl10 = s10.value * Math.sin(t2 * 10 / f1);
        var sl11 = s11.value * Math.sin(t2 * 11 / f1);
        var sl12 = s12.value * Math.sin(t2 * 12 / f1);
        var sl13 = s13.value * Math.sin(t2 * 13 / f1);
        var sl14 = s14.value * Math.sin(t2 * 14 / f1);
        var sl15 = s15.value * Math.sin(t2 * 15 / f1);
        var sl16 = s16.value * Math.sin(t2 * 16 / f1);


        vektort2.push(t2);
        vektors1.push(sl1);
        vektors2.push(sl2);
        vektors3.push(sl3);
        vektors4.push(sl4);
        vektors5.push(sl5);
        vektors6.push(sl6);
        vektors7.push(sl7);
        vektors8.push(sl8);
        vektors9.push(sl9);
        vektors10.push(sl10);
        vektors11.push(sl11);
        vektors12.push(sl12);
        vektors13.push(sl13);
        vektors14.push(sl14);
        vektors15.push(sl15);
        vektors16.push(sl16);
    }


}

else if (f1>250&&f1<500)

{   for (let i = 0; i <= konec2; i = i +5) {
    var t2 = i;
    var sl1 = s1.value * Math.sin(t2 / f1);
    var sl2 = s2.value * Math.sin(t2 * 2 / f1);
    var sl3 = s3.value * Math.sin(t2 * 3 / f1);
    var sl4 = s4.value * Math.sin(t2 * 4 / f1);
    var sl5 = s5.value * Math.sin(t2 * 5 / f1);
    var sl6 = s6.value * Math.sin(t2 * 6 / f1);
    var sl7 = s7.value * Math.sin(t2 * 7 / f1);
    var sl8 = s8.value * Math.sin(t2 * 8 / f1);
    var sl9 = s9.value * Math.sin(t2 * 9 / f1);
    var sl10 = s10.value * Math.sin(t2 * 10 / f1);
    var sl11 = s11.value * Math.sin(t2 * 11 / f1);
    var sl12 = s12.value * Math.sin(t2 * 12 / f1);
    var sl13 = s13.value * Math.sin(t2 * 13 / f1);
    var sl14 = s14.value * Math.sin(t2 * 14 / f1);
    var sl15 = s15.value * Math.sin(t2 * 15 / f1);
    var sl16 = s16.value * Math.sin(t2 * 16 / f1);


    vektort2.push(t2);
    vektors1.push(sl1);
    vektors2.push(sl2);
    vektors3.push(sl3);
    vektors4.push(sl4);
    vektors5.push(sl5);
    vektors6.push(sl6);
    vektors7.push(sl7);
    vektors8.push(sl8);
    vektors9.push(sl9);
    vektors10.push(sl10);
    vektors11.push(sl11);
    vektors12.push(sl12);
    vektors13.push(sl13);
    vektors14.push(sl14);
    vektors15.push(sl15);
    vektors16.push(sl16);
}}

else if (f1>500&&f1<1000)

{   for (let i = 0; i <= konec2; i = i +10) {
    var t2 = i;
    var sl1 = s1.value * Math.sin(t2 / f1);
    var sl2 = s2.value * Math.sin(t2 * 2 / f1);
    var sl3 = s3.value * Math.sin(t2 * 3 / f1);
    var sl4 = s4.value * Math.sin(t2 * 4 / f1);
    var sl5 = s5.value * Math.sin(t2 * 5 / f1);
    var sl6 = s6.value * Math.sin(t2 * 6 / f1);
    var sl7 = s7.value * Math.sin(t2 * 7 / f1);
    var sl8 = s8.value * Math.sin(t2 * 8 / f1);
    var sl9 = s9.value * Math.sin(t2 * 9 / f1);
    var sl10 = s10.value * Math.sin(t2 * 10 / f1);
    var sl11 = s11.value * Math.sin(t2 * 11 / f1);
    var sl12 = s12.value * Math.sin(t2 * 12 / f1);
    var sl13 = s13.value * Math.sin(t2 * 13 / f1);
    var sl14 = s14.value * Math.sin(t2 * 14 / f1);
    var sl15 = s15.value * Math.sin(t2 * 15 / f1);
    var sl16 = s16.value * Math.sin(t2 * 16 / f1);


    vektort2.push(t2);
    vektors1.push(sl1);
    vektors2.push(sl2);
    vektors3.push(sl3);
    vektors4.push(sl4);
    vektors5.push(sl5);
    vektors6.push(sl6);
    vektors7.push(sl7);
    vektors8.push(sl8);
    vektors9.push(sl9);
    vektors10.push(sl10);
    vektors11.push(sl11);
    vektors12.push(sl12);
    vektors13.push(sl13);
    vektors14.push(sl14);
    vektors15.push(sl15);
    vektors16.push(sl16);
}}
else if (f1>1000)

{   for (let i = 0; i <= konec2; i = i +15) {
    var t2 = i;
    var sl1 = s1.value * Math.sin(t2 / f1);
    var sl2 = s2.value * Math.sin(t2 * 2 / f1);
    var sl3 = s3.value * Math.sin(t2 * 3 / f1);
    var sl4 = s4.value * Math.sin(t2 * 4 / f1);
    var sl5 = s5.value * Math.sin(t2 * 5 / f1);
    var sl6 = s6.value * Math.sin(t2 * 6 / f1);
    var sl7 = s7.value * Math.sin(t2 * 7 / f1);
    var sl8 = s8.value * Math.sin(t2 * 8 / f1);
    var sl9 = s9.value * Math.sin(t2 * 9 / f1);
    var sl10 = s10.value * Math.sin(t2 * 10 / f1);
    var sl11 = s11.value * Math.sin(t2 * 11 / f1);
    var sl12 = s12.value * Math.sin(t2 * 12 / f1);
    var sl13 = s13.value * Math.sin(t2 * 13 / f1);
    var sl14 = s14.value * Math.sin(t2 * 14 / f1);
    var sl15 = s15.value * Math.sin(t2 * 15 / f1);
    var sl16 = s16.value * Math.sin(t2 * 16 / f1);


    vektort2.push(t2);
    vektors1.push(sl1);
    vektors2.push(sl2);
    vektors3.push(sl3);
    vektors4.push(sl4);
    vektors5.push(sl5);
    vektors6.push(sl6);
    vektors7.push(sl7);
    vektors8.push(sl8);
    vektors9.push(sl9);
    vektors10.push(sl10);
    vektors11.push(sl11);
    vektors12.push(sl12);
    vektors13.push(sl13);
    vektors14.push(sl14);
    vektors15.push(sl15);
    vektors16.push(sl16);
}}


    var grafSlozky = new Chart("Slozky", {
        type: "line",
        lineWidth:0.001,


        data: {
            labels: vektort2,
            datasets: [{

                borderColor: "rgba(170,140,208,0.38)",
                data: vektors1,
                lineWidth:1,
                label: "1.Harm. "



            },
                {

                    borderColor: "rgba(206,167,162,0.38)",
                    data: vektors2,
                    lineWidth:1,
                    label: "2.Harm. "

                },
                {

                    borderColor: "rgba(213,45,24,0.38)",
                    data: vektors3,
                    lineWidth:1,
                    label: "3.Harm. "

                },
                {

                    borderColor: "rgba(51,106,176,0.38)",
                    data: vektors4,
                    lineWidth:1,
                    label: "4.Harm. "


                },
                {

                    borderColor: "rgba(146,224,107,0.38)",
                    data: vektors5,
                    lineWidth:1,
                    label: "5.Harm. "

                },
                {

                    borderColor: "rgba(206,167,162,0.38)",
                    data: vektors6,
                    lineWidth:1,
                    label: "6.Harm. "

                },
                {

                    borderColor: "rgba(33,27,6,0.38)",
                    data: vektors7,
                    lineWidth:1,
                    label: "7.Harm. "


                },
                {

                    borderColor: "rgba(154,97,222,0.38)",
                    data: vektors8,
                    lineWidth:1,
                    label: "8.Harm. "

                },
                {

                    borderColor: "rgba(206,167,162,0.38)",
                    data: vektors9,
                    lineWidth:1,
                    label: "9.Harm. "

                },
                {

                    borderColor: "rgba(121,69,34,0.38)",
                    data: vektors10,
                    lineWidth:1,
                    label: "10.Harm. "

                },
                {

                    borderColor: "rgba(206,167,162,0.38)",
                    data: vektors11,
                    lineWidth:1,
                    label: "11.Harm. "

                },
                {

                    borderColor: "rgba(239,36,10,0.38)",
                    data: vektors12,
                    lineWidth:1,
                    label: "12.Harm. "

                },
                {

                    borderColor: "rgba(38,87,4,0.38)",
                    data: vektors13,
                    lineWidth:1,
                    label: "13.Harm. "

                },
                {

                    borderColor: "rgba(231,28,227,0.38)",
                    data: vektors14,
                    lineWidth:1,
                    label: "14.Harm. "

                },
                {

                    borderColor: "rgba(255,131,109,0.94)",
                    data: vektors15,
                    lineWidth: 1,
                    label: "15.Harm. "
                },
                {

                    borderColor: "rgba(243,223,221,0.38)",
                    data: vektors16,
                    lineWidth:1,
                    label: "16.Harm. "


                }],



        },


    });




function zmenaHarm(){

    var vektort2=[];
    var vektors1=[];
    var vektors2=[];
    var vektors3=[];
    var vektors4=[];
    var vektors5=[];
    var vektors6=[];
    var vektors7=[];
    var vektors8=[];
    var vektors9=[];
    var vektors10=[];
    var vektors11=[];
    var vektors12=[];
    var vektors13=[];
    var vektors14=[];
    var vektors15=[];
    var vektors16=[];


    let konec2 = 2 * Math.PI * f1;


    if (f1<100) {

        for (let i = 0; i <= konec2; i = i + 0.5) {
            var t2 = i;
            var sl1 = s1.value * Math.sin(t2 / f1);
            var sl2 = s2.value * Math.sin(t2 * 2 / f1);
            var sl3 = s3.value * Math.sin(t2 * 3 / f1);
            var sl4 = s4.value * Math.sin(t2 * 4 / f1);
            var sl5 = s5.value * Math.sin(t2 * 5 / f1);
            var sl6 = s6.value * Math.sin(t2 * 6 / f1);
            var sl7 = s7.value * Math.sin(t2 * 7 / f1);
            var sl8 = s8.value * Math.sin(t2 * 8 / f1);
            var sl9 = s9.value * Math.sin(t2 * 9 / f1);
            var sl10 = s10.value * Math.sin(t2 * 10 / f1);
            var sl11 = s11.value * Math.sin(t2 * 11 / f1);
            var sl12 = s12.value * Math.sin(t2 * 12 / f1);
            var sl13 = s13.value * Math.sin(t2 * 13 / f1);
            var sl14 = s14.value * Math.sin(t2 * 14 / f1);
            var sl15 = s15.value * Math.sin(t2 * 15 / f1);
            var sl16 = s16.value * Math.sin(t2 * 16 / f1);


            vektort2.push(t2);
            vektors1.push(sl1);
            vektors2.push(sl2);
            vektors3.push(sl3);
            vektors4.push(sl4);
            vektors5.push(sl5);
            vektors6.push(sl6);
            vektors7.push(sl7);
            vektors8.push(sl8);
            vektors9.push(sl9);
            vektors10.push(sl10);
            vektors11.push(sl11);
            vektors12.push(sl12);
            vektors13.push(sl13);
            vektors14.push(sl14);
            vektors15.push(sl15);
            vektors16.push(sl16);
        }

    }

    else if (f1>100&& f1<250){

        for (let i = 0; i <= konec2; i = i +2) {
            var t2 = i;
            var sl1 = s1.value * Math.sin(t2 / f1);
            var sl2 = s2.value * Math.sin(t2 * 2 / f1);
            var sl3 = s3.value * Math.sin(t2 * 3 / f1);
            var sl4 = s4.value * Math.sin(t2 * 4 / f1);
            var sl5 = s5.value * Math.sin(t2 * 5 / f1);
            var sl6 = s6.value * Math.sin(t2 * 6 / f1);
            var sl7 = s7.value * Math.sin(t2 * 7 / f1);
            var sl8 = s8.value * Math.sin(t2 * 8 / f1);
            var sl9 = s9.value * Math.sin(t2 * 9 / f1);
            var sl10 = s10.value * Math.sin(t2 * 10 / f1);
            var sl11 = s11.value * Math.sin(t2 * 11 / f1);
            var sl12 = s12.value * Math.sin(t2 * 12 / f1);
            var sl13 = s13.value * Math.sin(t2 * 13 / f1);
            var sl14 = s14.value * Math.sin(t2 * 14 / f1);
            var sl15 = s15.value * Math.sin(t2 * 15 / f1);
            var sl16 = s16.value * Math.sin(t2 * 16 / f1);


            vektort2.push(t2);
            vektors1.push(sl1);
            vektors2.push(sl2);
            vektors3.push(sl3);
            vektors4.push(sl4);
            vektors5.push(sl5);
            vektors6.push(sl6);
            vektors7.push(sl7);
            vektors8.push(sl8);
            vektors9.push(sl9);
            vektors10.push(sl10);
            vektors11.push(sl11);
            vektors12.push(sl12);
            vektors13.push(sl13);
            vektors14.push(sl14);
            vektors15.push(sl15);
            vektors16.push(sl16);
        }


    }

    else if (f1>250&&f1<500)

    {   for (let i = 0; i <= konec2; i = i +5) {
        var t2 = i;
        var sl1 = s1.value * Math.sin(t2 / f1);
        var sl2 = s2.value * Math.sin(t2 * 2 / f1);
        var sl3 = s3.value * Math.sin(t2 * 3 / f1);
        var sl4 = s4.value * Math.sin(t2 * 4 / f1);
        var sl5 = s5.value * Math.sin(t2 * 5 / f1);
        var sl6 = s6.value * Math.sin(t2 * 6 / f1);
        var sl7 = s7.value * Math.sin(t2 * 7 / f1);
        var sl8 = s8.value * Math.sin(t2 * 8 / f1);
        var sl9 = s9.value * Math.sin(t2 * 9 / f1);
        var sl10 = s10.value * Math.sin(t2 * 10 / f1);
        var sl11 = s11.value * Math.sin(t2 * 11 / f1);
        var sl12 = s12.value * Math.sin(t2 * 12 / f1);
        var sl13 = s13.value * Math.sin(t2 * 13 / f1);
        var sl14 = s14.value * Math.sin(t2 * 14 / f1);
        var sl15 = s15.value * Math.sin(t2 * 15 / f1);
        var sl16 = s16.value * Math.sin(t2 * 16 / f1);


        vektort2.push(t2);
        vektors1.push(sl1);
        vektors2.push(sl2);
        vektors3.push(sl3);
        vektors4.push(sl4);
        vektors5.push(sl5);
        vektors6.push(sl6);
        vektors7.push(sl7);
        vektors8.push(sl8);
        vektors9.push(sl9);
        vektors10.push(sl10);
        vektors11.push(sl11);
        vektors12.push(sl12);
        vektors13.push(sl13);
        vektors14.push(sl14);
        vektors15.push(sl15);
        vektors16.push(sl16);
    }}

    else if (f1>500&&f1<1000)

    {   for (let i = 0; i <= konec2; i = i +10) {
        var t2 = i;
        var sl1 = s1.value * Math.sin(t2 / f1);
        var sl2 = s2.value * Math.sin(t2 * 2 / f1);
        var sl3 = s3.value * Math.sin(t2 * 3 / f1);
        var sl4 = s4.value * Math.sin(t2 * 4 / f1);
        var sl5 = s5.value * Math.sin(t2 * 5 / f1);
        var sl6 = s6.value * Math.sin(t2 * 6 / f1);
        var sl7 = s7.value * Math.sin(t2 * 7 / f1);
        var sl8 = s8.value * Math.sin(t2 * 8 / f1);
        var sl9 = s9.value * Math.sin(t2 * 9 / f1);
        var sl10 = s10.value * Math.sin(t2 * 10 / f1);
        var sl11 = s11.value * Math.sin(t2 * 11 / f1);
        var sl12 = s12.value * Math.sin(t2 * 12 / f1);
        var sl13 = s13.value * Math.sin(t2 * 13 / f1);
        var sl14 = s14.value * Math.sin(t2 * 14 / f1);
        var sl15 = s15.value * Math.sin(t2 * 15 / f1);
        var sl16 = s16.value * Math.sin(t2 * 16 / f1);


        vektort2.push(t2);
        vektors1.push(sl1);
        vektors2.push(sl2);
        vektors3.push(sl3);
        vektors4.push(sl4);
        vektors5.push(sl5);
        vektors6.push(sl6);
        vektors7.push(sl7);
        vektors8.push(sl8);
        vektors9.push(sl9);
        vektors10.push(sl10);
        vektors11.push(sl11);
        vektors12.push(sl12);
        vektors13.push(sl13);
        vektors14.push(sl14);
        vektors15.push(sl15);
        vektors16.push(sl16);
    }}
    else if (f1>1000)

    {   for (let i = 0; i <= konec2; i = i +15) {
        var t2 = i;
        var sl1 = s1.value * Math.sin(t2 / f1);
        var sl2 = s2.value * Math.sin(t2 * 2 / f1);
        var sl3 = s3.value * Math.sin(t2 * 3 / f1);
        var sl4 = s4.value * Math.sin(t2 * 4 / f1);
        var sl5 = s5.value * Math.sin(t2 * 5 / f1);
        var sl6 = s6.value * Math.sin(t2 * 6 / f1);
        var sl7 = s7.value * Math.sin(t2 * 7 / f1);
        var sl8 = s8.value * Math.sin(t2 * 8 / f1);
        var sl9 = s9.value * Math.sin(t2 * 9 / f1);
        var sl10 = s10.value * Math.sin(t2 * 10 / f1);
        var sl11 = s11.value * Math.sin(t2 * 11 / f1);
        var sl12 = s12.value * Math.sin(t2 * 12 / f1);
        var sl13 = s13.value * Math.sin(t2 * 13 / f1);
        var sl14 = s14.value * Math.sin(t2 * 14 / f1);
        var sl15 = s15.value * Math.sin(t2 * 15 / f1);
        var sl16 = s16.value * Math.sin(t2 * 16 / f1);


        vektort2.push(t2);
        vektors1.push(sl1);
        vektors2.push(sl2);
        vektors3.push(sl3);
        vektors4.push(sl4);
        vektors5.push(sl5);
        vektors6.push(sl6);
        vektors7.push(sl7);
        vektors8.push(sl8);
        vektors9.push(sl9);
        vektors10.push(sl10);
        vektors11.push(sl11);
        vektors12.push(sl12);
        vektors13.push(sl13);
        vektors14.push(sl14);
        vektors15.push(sl15);
        vektors16.push(sl16);
    }}


    grafSlozky.data.labels=vektort2;
    grafSlozky.data.datasets[0].data =vektors1;
    grafSlozky.data.datasets[1].data =vektors2;
    grafSlozky.data.datasets[2].data =vektors3;
    grafSlozky.data.datasets[3].data =vektors4;
    grafSlozky.data.datasets[4].data =vektors5;
    grafSlozky.data.datasets[5].data=vektors6;
    grafSlozky.data.datasets[6].data =vektors7;
    grafSlozky.data.datasets[7].data =vektors8;
    grafSlozky.data.datasets[8].data =vektors9;
    grafSlozky.data.datasets[9].data =vektors10;
    grafSlozky.data.datasets[10].data =vektors11;
    grafSlozky.data.datasets[11].data=vektors12;
    grafSlozky.data.datasets[12].data=vektors13;
    grafSlozky.data.datasets[13].data =vektors14;
    grafSlozky.data.datasets[14].data =vektors15;
    grafSlozky.data.datasets[15].data =vektors16;


    grafSlozky.update();

}




const att=document.getElementById("Atack1");
const dec=document.getElementById("Decay1");
const sus=document.getElementById("Sustain1");
const rel=document.getElementById("Release1");





let stav=false;

function start(){

     osc1 = audioCtx.createOscillator();
     osc2 = audioCtx.createOscillator();
     osc3 = audioCtx.createOscillator();
     osc4 = audioCtx.createOscillator();
     osc5 = audioCtx.createOscillator();
     osc6 = audioCtx.createOscillator();
     osc7 = audioCtx.createOscillator();
      osc8 = audioCtx.createOscillator();
      osc9 = audioCtx.createOscillator();
     osc10 = audioCtx.createOscillator();
     osc11 = audioCtx.createOscillator();
    osc12 = audioCtx.createOscillator();
    osc13 = audioCtx.createOscillator();
    osc14 = audioCtx.createOscillator();
     osc15 = audioCtx.createOscillator();
    osc16 = audioCtx.createOscillator();





    osc1.connect(osc1Gain);
    osc2.connect(osc2Gain);
    osc3.connect(osc3Gain);
    osc4.connect(osc4Gain);
    osc5.connect(osc5Gain);
    osc6.connect(osc6Gain);
    osc7.connect(osc7Gain);
    osc8.connect(osc8Gain);
    osc9.connect(osc9Gain);
    osc10.connect(osc10Gain);
    osc11.connect(osc11Gain);
    osc12.connect(osc12Gain);
    osc13.connect(osc13Gain);
    osc14.connect(osc14Gain);
    osc15.connect(osc15Gain);
    osc16.connect(osc16Gain);

calculateFrequency();


    osc1.frequency.value =  f1;
    osc2.frequency.value =  2*f1;
    osc3.frequency.value =  3*f1
    osc4.frequency.value =  4*f1;
    osc5.frequency.value =  5*f1;
    osc6.frequency.value =  6*f1
    osc7.frequency.value =  7*f1;
    osc8.frequency.value =  8*f1;
    osc9.frequency.value =  9*f1;
    osc10.frequency.value = 10*f1;
    osc11.frequency.value = 11*f1;
    osc12.frequency.value = 12*f1
    osc13.frequency.value = 13*f1;
    osc14.frequency.value = 14*f1;
    osc15.frequency.value = 15*f1
    osc16.frequency.value = 16*f1;






    osc1Gain.connect(OutputGain);
    osc2Gain.connect(OutputGain);
    osc3Gain.connect(OutputGain);
    osc4Gain.connect(OutputGain);
    osc5Gain.connect(OutputGain);
    osc6Gain.connect(OutputGain);
    osc7Gain.connect(OutputGain);
    osc8Gain.connect(OutputGain);
    osc9Gain.connect(OutputGain);
    osc10Gain.connect(OutputGain);
    osc11Gain.connect(OutputGain);
    osc12Gain.connect(OutputGain);
    osc13Gain.connect(OutputGain);
    osc14Gain.connect(OutputGain);
    osc15Gain.connect(OutputGain);
    osc16Gain.connect(OutputGain);



    OutputGain.connect(audioCtx.destination)


    osc1.start();
    osc2.start();
    osc3.start();
    osc4.start();
    osc5.start();
    osc6.start();
    osc7.start();
    osc8.start();
    osc9.start();
    osc10.start();
    osc11.start();
    osc12.start();
    osc13.start();
    osc14.start();
    osc15.start();
    osc16.start();

  //  osc1.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc2.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc3.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc4.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc5.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc6.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc7.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc8.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc9.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc10.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc11.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc12.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc13.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc14.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc15.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);
    //osc16.stop(audioCtx.currentTime + attackVal+decayVal+releaseVal+1);

    stav=true;
}




function stop(){

    osc1.stop();
    osc2.stop();
    osc3.stop();
    osc4.stop();
    osc5.stop();
    osc6.stop();
    osc7.stop();
    osc8.stop();
    osc9.stop();
    osc10.stop();
    osc11.stop();
    osc12.stop();
    osc13.stop();
    osc14.stop();
    osc15.stop();
    osc16.stop();

stav=false

}



function stisk() {
    const tlacitko = document.getElementById('tlac1');
    if (tlacitko.textContent === 'Přehrát') {
        start();
        tlacitko.textContent = 'Zastavit';
        tlacitko.style.backgroundColor="red";
    } else {
        stop();
        tlacitko.textContent = 'Přehrát';
        tlacitko.style.backgroundColor="green";

    }
}

const tlacitko = document.getElementById('tlac1');
tlacitko.addEventListener('click', stisk);








function identifikaceZkresleni(){


   let  Totalgain =OutputGain.gain.value*(osc1Gain.gain.value+osc2Gain.gain.value +
       osc3Gain.gain.value+osc4Gain.gain.value+osc5Gain.gain.value+osc6Gain.gain.value+osc7Gain.gain.value
       +osc8Gain.gain.value+osc9Gain.gain.value+osc10Gain.gain.value+osc11Gain.gain.value+osc12Gain.gain.value+osc13Gain.gain.value+osc14Gain.gain.value+osc15Gain.gain.value+osc16Gain.gain.value);

   console.log(Totalgain);


    const varovani = document.getElementById("zkresleni");

    if (Totalgain>1) {
        varovani.textContent = "Výsledné zesílení signálu není v rozsahu -1:1, pro eliminaci zkreslení snižte úroveň Master Volume";

    } else {
        varovani.textContent = "Rozsah celkového zesílení je v pořádku, Signál není zkreslený";
    }


}

identifikaceZkresleni()