temploophack = -1; //filtertestkilian = 0; //apa9 = 0; var midiFrequency = { get: function(noteNumber) { var tuningFrequency = 440; var tuningNote = 69; var freqSplit = 12; return Math.exp((noteNumber - tuningNote) * Math.log(2) / freqSplit) * tuningFrequency }, getOld: function(noteNumber) { var freq = [8.176, 8.662, 9.177, 9.723, 10.301, 10.913, 11.562, 12.25, 12.978, 13.75, 14.568, 15.434, 16.352, 17.324, 18.354, 19.445, 20.602, 21.827, 23.125, 24.5, 25.957, 27.5, 29.135, 30.868, 32.703, 34.648, 36.708, 38.891, 41.203, 43.654, 46.249, 48.999, 51.913, 55, 58.27, 61.735, 65.406, 69.296, 73.416, 77.782, 82.407, 87.307, 92.499, 97.999, 103.826, 110, 116.541, 123.471, 130.813, 138.591, 146.832, 155.563, 164.814, 174.614, 184.997, 195.998, 207.652, 220, 233.082, 246.942, 261.626, 277.183, 293.665, 311.127, 329.628, 349.228, 369.994, 391.995, 415.305, 440, 466.164, 493.883, 523.251, 554.365, 587.33, 622.254, 659.255, 698.456, 739.989, 783.991, 830.609, 880, 932.328, 987.767, 1046.502, 1108.731, 1174.659, 1244.508, 1318.51, 1396.913, 1479.978, 1567.982, 1661.219, 1760, 1864.655, 1975.533, 2093.005, 2217.461, 2349.318, 2489.016, 2637.02, 2793.826, 2959.955, 3135.963, 3322.438, 3520, 3729.31, 3951.066, 4186.009, 4434.922, 4698.636, 4978.032, 5274.041, 5587.652, 5919.911, 6271.927, 6644.875, 7040, 7458.62, 7902.133, 8372.018, 8869.844, 9397.273, 9956.063, 10548.08, 11175.3, 11839.82, 12543.85]; return freq[noteNumber] } }; var waveforms = { square303: { real: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], imag: [0, -.46267, -0, .514476, 0, -.222225, -0, .198434, 0, -.131464, -0, .122448, 0, -.093145, -0, .088485, 0, -.072092, -0, .069258, 0, -.058792, -0, .056891, 0, -.049633, 0, .048269, 0, -.042941, -0, .041916, 0, -.037839, 0, .03704, 0, -.03382, -0, .03318, 0, -.030572, 0, .030049, 0, -.027894, -0, .027457, 0, -.025647, 0, .025277, -0, -.023735, -0, .023418, 0, -.022088, 0, .021813, 0, -.020655, -0, .020414, 0, -.019396, -0, .019184, -0, -.018282, -0, .018094, 0, -.01729, -0, .017121, 0, -.016399, -0, .016247, 0, -.015595, -0, .015458, -0, -.014867, -0, .014742, 0, -.014204, -0, .01409, 0, -.013597, 0, .013492, 0, -.01304, -0, .012944, -0, -.012527, -0, .012438, -0, -.012053, -0, .01197, 0, -.011613, 0, .011536, 0, -.011204, -0, .011133, -0, -.010823, -0, .010757, 0, -.010467, -0, .010405, 0, -.010134, 0, .010076, 0, -.009821, -0, .009767, 0, -.009527, -0, .009476, -0, -.009251, -0, .009202, 0, -.008989, 0, .008943, 0, -.008742, -0, .008699, 0, -.008509, -0, .008468, 0, -.008287, -0, .008248, 0, -.008077, 0, .00804, 0, -.007877, -0, .007842, 0, -.007687, 0, .007653, -0, -.007506, -0, .007474, 0, -.007333, -0, .007302, 0, -.007168, 0, .007138, 0, -.00701, -0, .006982, 0, -.006859, -0, .006832, -0, -.006714, -0, .006688, 0, -.006575, -0, .006551, 0, -.006442, 0, .006419, -0, -.006314, -0, .006292, 0, -.006192, -0, .00617, -0, -.006073, 0, .006053, 0, -.00596, -0, .00594, 0, -.00585, -0, .005831, -0, -.005745, -0, .005726, 0, -.005643, -0, .005625, 0, -.005545, 0, .005527, -0, -.00545, -0, .005433, 0, -.005358, -0, .005342, 0, -.005269, 0, .005253, 0, -.005183, -0, .005168, 0, -.0051, -0, .005086, -0, -.00502, -0, .005006, 0, -.004942, -0, .004928, 0, -.004866, 0, .004853, 0, -.004793, -0, .00478, 0, -.004722, -0, .004709, -0, -.004653, 0, .004641, 0, -.004586, -0, .004574, 0, -.004521, -0, .004509, -0, -.004458, -0, .004446, 0, -.004396, -0, .004385, 0, -.004336, 0, .004325, 0, -.004278, -0, .004267, 0, -.004221, -0, .004211, 0, -.004166, -0, .004156, 0, -.004112, -0, .004102, 0, -.00406, -0, .00405, -0, -.004008, -0, .003999, 0, -.003959, -0, .00395, 0, -.00391, -0, .003901, 0, -.003863, -0, .003854, -0, -.003816, 0, .003808, -0, -.003771, -0, .003763, 0, -.003727, -0, .003719, 0, -.003684, -0, .003676, 0, -.003642, -0, .003634, 0, -.0036, 0, .003593, -0, -.00356, 0, .003553, 0, -.003521, -0, .003514, 0, -.003482, -0, .003475, 0, -.003445, -0, .003438, 0, -.003408, 0, .003401, -0, -.003372, 0, .003365, 0, -.003336, -0, .00333, 0, -.003302, -0, .003295, 0, -.003268, -0, .003262, 0, -.003235, -0, .003229, -0, -.003202, 0, .003196, -0, -.00317, -0, .003164, 0, -.003139, -0, .003133, 0, -.003108, -0, .003103, 0, -.003078, -0, .003073, -0, -.003049, 0, .003043, -0, -.00302, -0, .003015, 0, -.002991, -0, .002986, 0, -.002964, -0, .002959, 0, -.002936, -0, .002931, 0, -.002909, 0, .002905, -0, -.002883, 0, .002878, 0, -.002857, -0, .002852, 0, -.002832, -0, .002827, 0, -.002807, -0, .002802, 0, -.002782, -0, .002778, -0, -.002758, 0, .002754, -0, -.002734, -0, .00273, 0, -.002711, -0, .002707, 0, -.002688, -0, .002684, 0, -.002666, -0, .002662, 0, -.002644, 0, .00264, -0, -.002622, -0, .002618, 0, -.0026, -0, .002597, 0, -.002579, -0, .002576, 0, -.002559, -0, .002555, 0, -.002538, 0, .002534, -0, -.002518, 0, .002514, 0, -.002498, -0, .002495, 0, -.002479, -0, .002475, 0, -.00246, -0, .002456, 0, -.002441, -0, .002437, -0, -.002422, 0, .002419, 0, -.002404, -0, .002401, 0, -.002386, -0, .002383, 0, -.002368, -0, .002365, 0, -.002351, -0, .002348, -0, -.002333, 0, .00233, -0, -.002317, -0, .002313, 0, -.0023, -0, .002297, 0, -.002283, -0, .00228, 0, -.002267, -0, .002264, 0, -.002251, 0, .002248, -0, -.002235, -0, .002232, 0, -.00222, -0, .002217, 0, -.002204, -0, .002201, 0, -.002189, -0, .002186, 0, -.002174, -0, .002171, -0, -.002159, 0, .002157, 0, -.002145, -0, .002142, 0, -.00213, -0, .002128, 0, -.002116, -0, .002114, 0, -.002102, -0, .0021, 0, -.002089, 0, .002086, 0, -.002075, -0, .002072, 0, -.002061, -0, .002059, 0, -.002048, -0, .002046, 0, -.002035, -0, .002033, 0, -.002022, 0, .00202, -0, -.002009, -0, .002007, 0, -.001997, -0, .001995, 0, -.001984, -0, .001982, 0, -.001972, -0, .00197, 0, -.00196, -0, .001958, 0, -.001948, -0, .001946, 0, -.001936, -0, .001934, 0, -.001924, -0, .001922, -0, -.001913, -0, .001911, -0, -.001901, -0, .001899, -0, -.00189, -0, .001888, 0, -.001879, -0, .001877, 0, -.001868, -0, .001866, 0, -.001857, 0, .001855, 0, -.001846, 0, .001844, 0, -.001836, 0, .001834, 0, -.001825, -0, .001823, 0, -.001815, -0, .001813, 0, -.001804, -0, .001803, -0, -.001794, -0, .001792, -0, -.001784, -0, .001782, -0, -.001774, -0, .001772, 0, -.001764, -0, .001763, 0, -.001755, 0, .001753, 0, -.001745, 0, .001743, 0, -.001736, 0, .001734, 0, -.001726, 0, .001724, 0, -.001717, -0, .001715, 0, -.001708, -0, .001706, -0, -.001698, -0, .001697, -0, -.001689, -0, .001688, -0, -.001681, -0, .001679, 0, -.001672, -0, .00167, 0, -.001663, -0, .001661, 0, -.001654, 0, .001653, 0, -.001646, 0, .001644, 0, -.001637, 0, .001636, 0, -.001629, -0, .001627, 0, -.001621, -0, .001619, 0, -.001612, -0, .001611, -0, -.001604, -0, .001603, -0, -.001596, -0, .001595, -0, -.001588, -0, .001587, 0, -.00158, -0, .001579, 0, -.001573, -0, .001571, 0, -.001565, 0, .001563, 0, -.001557, 0, .001556, 0, -.00155, 0, .001548, 0, -.001542, -0, .001541, 0, -.001535, -0, .001533, -0, -.001527, -0, .001526, -0, -.00152, -0, .001519, -0, -.001513, -0, .001512, 0, -.001506, -0, .001504, 0, -.001499, -0, .001497, 0, -.001492, 0, .00149, 0, -.001485, 0, .001483, 0, -.001478, 0, .001476, 0, -.001471, -0, .00147, 0, -.001464, -0, .001463, 0, -.001457, -0, .001456, -0, -.001451, -0, .00145, -0, -.001444, -0, .001443, -0, -.001438, -0, .001436, 0, -.001431, -0, .00143, 0, -.001425, -0, .001424, 0, -.001418, 0, .001417, 0, -.001412, 0, .001411, 0, -.001406, 0, .001405, 0, -.0014, -0, .001399, 0, -.001394, -0, .001392, 0, -.001388, -0, .001386, -0, -.001381, -0, .00138, -0, -.001376, -0, .001374, -0, -.00137, -0, .001369, 0, -.001364, -0, .001363, 0, -.001358, -0, .001357, 0, -.001352, 0, .001351, 0, -.001346, 0, .001345, 0, -.001341, -0, .00134, 0, -.001335, -0, .001334, 0, -.00133, -0, .001329, 0, -.001324, -0, .001323, -0, -.001319, -0, .001318, -0, -.001313, -0, .001312, 0, -.001308, -0, .001307, 0, -.001302, -0, .001301, 0, -.001297, 0, .001296, 0, -.001292, 0, .001291, 0, -.001287, 0, .001286, 0, -.001281, -0, .00128, 0, -.001276, -0, .001275, 0, -.001271, -0, .00127, -0, -.001266, -0, .001265, -0, -.001261, -0, .00126, -0, -.001256, -0, .001255, 0, -.001251, -0, .00125, 0, -.001246, -0, .001245, 0, -.001241, 0, .001241, 0, -.001237, 0, .001236, 0, -.001232, -0, .001231, 0, -.001227, -0, .001226, 0, -.001222, -0, .001221, 0, -.001218, -0, .001217, -0, -.001213, -0, .001212, -0, -.001208, -0, .001208, 0, -.001204, -0, .001203, 0, -.001199, -0, .001198, 0, -.001195, -0, .001194, 0, -.00119, 0, .00119, 0, -.001186, 0, .001185, 0, -.001182, -0, .001181, 0, -.001177, -0, .001176, 0, -.001173, -0, .001172, -0, -.001168, -0, .001168, -0, -.001164, -0, .001163, -0, -.00116, -0, .001159, 0, -.001156, -0, .001155, 0, -.001152, -0, .001151, 0, -.001147, 0, .001147, 0, -.001143, 0, .001143, 0, -.001139, -0, .001138, 0, -.001135, -0, .001134, 0, -.001131, -0, .00113, 0, -.001127, -0, .001126, -0, -.001123, -0, .001122, -0, -.001119, -0, .001118, 0, -.001115, -0, .001115, 0, -.001111, -0, .001111, 0, -.001108, -0, .001107, 0, -.001104, 0, .001103, 0, -.0011, 0, .001099, 0, -.001096, -0, .001095, 0, -.001092, -0, .001092, 0, -.001089, -0, .001088, 0, -.001085, -0, .001084, -0, -.001081, -0, .001081, -0, -.001078, -0, .001077, 0, -.001074, -0, .001073, 0, -.00107, -0, .00107, 0, -.001067, -0, .001066, 0, -.001063, 0, .001062, 0, -.00106, 0, .001059, 0, -.001056, -0, .001055, 0, -.001053, -0, .001052, 0, -.001049, -0, .001048, 0, -.001046, -0, .001045, -0, -.001042, -0, .001042, 0, -.001039, -0, .001038, 0, -.001035, -0, .001035, 0, -.001032, -0, .001031, 0, -.001029, 0, .001028, 0, -.001025, 0, .001025, 0, -.001022, -0, .001022, 0, -.001019, -0, .001018, 0, -.001016, -0, .001015, 0, -.001012, -0, .001012, -0, -.001009, -0, .001009, -0, -.001006, -0, .001005, 0, -.001003, -0, .001002, 0, -.001, -0, 999e-6, 0, -997e-6, -0, 996e-6, 0, -993e-6, 0, 993e-6, 0, -99e-5, 0, 99e-5, 0, -987e-6, -0, 987e-6, 0, -984e-6, -0, 984e-6, 0, -981e-6, -0, 981e-6, 0, -978e-6, -0, 978e-6, 0, -975e-6, 0, 975e-6, 0, -972e-6, -0, 972e-6, 0, -969e-6, 0, 969e-6, 0, -966e-6, -0, 966e-6, 0, -963e-6, 0, 963e-6, 0, -96e-5, -0, 96e-5, -0, -958e-6, -0, 957e-6, 0, -955e-6, -0, 954e-6, -0, -952e-6, -0, 951e-6, 0, -949e-6, -0, 949e-6, -0, -946e-6, -0, 946e-6, 0, -943e-6, 0, 943e-6, 0, -941e-6, -0, 94e-5, 0, -938e-6, 0, 937e-6, 0, -935e-6, -0, 935e-6, 0, -932e-6, 0, 932e-6, 0, -93e-5, -0, 929e-6, -0, -927e-6, -0, 926e-6, 0, -924e-6, -0, 924e-6, -0, -922e-6, -0, 921e-6, 0, -919e-6, -0, 918e-6, -0, -916e-6, -0, 916e-6, 0, -914e-6, 0, 913e-6, 0, -911e-6, -0, 911e-6, 0, -908e-6, 0, 908e-6, 0, -906e-6, -0, 905e-6, 0, -903e-6, 0, 903e-6, 0, -901e-6, -0, 9e-4, -0, -898e-6, -0, 898e-6, 0, -896e-6, -0, 895e-6, -0, -893e-6, -0, 893e-6, 0, -891e-6, 0, 89e-5, -0, -888e-6, -0, 888e-6, 0, -886e-6, 0, 885e-6, 0, -883e-6, -0, 883e-6, 0, -881e-6, 0, 88e-5, 0, -878e-6, -0, 878e-6, -0, -876e-6, 0, 875e-6, 0, -873e-6, -0, 873e-6, -0, -871e-6, -0, 871e-6, 0, -869e-6, -0, 868e-6, -0, -866e-6, -0, 866e-6, 0, -864e-6, 0, 864e-6, -0, -862e-6, -0, 861e-6, 0, -859e-6, 0, 859e-6, 0, -857e-6, -0, 857e-6, 0, -855e-6, 0, 854e-6, 0, -852e-6, -0, 852e-6, -0, -85e-5, -0, 85e-5, 0, -848e-6, -0, 847e-6, -0, -846e-6, -0, 845e-6, 0, -843e-6, -0, 843e-6, -0, -841e-6, -0, 841e-6, 0, -839e-6, 0, 839e-6, 0, -837e-6, -0, 836e-6, 0, -835e-6, 0, 834e-6, 0, -832e-6, -0, 832e-6, 0, -83e-5, 0, 83e-5, 0, -828e-6, -0, 828e-6, -0, -826e-6, -0, 826e-6, 0, -824e-6, -0, 823e-6, -0, -822e-6, -0, 821e-6, 0, -82e-5, -0, 819e-6, -0, -817e-6, -0, 817e-6, 0, -815e-6, 0, 815e-6, 0, -813e-6, -0, 813e-6, 0, -811e-6, 0, 811e-6, 0, -809e-6, -0, 809e-6, 0, -807e-6, 0, 807e-6, 0, -805e-6, -0, 805e-6, -0, -803e-6, -0, 803e-6, 0, -801e-6, -0, 801e-6, -0, -799e-6, -0, 799e-6, 0, -797e-6, -0, 797e-6, -0, -795e-6, -0, 795e-6, 0, -793e-6, 0, 793e-6, 0, -791e-6, -0, 791e-6, 0, -789e-6, 0, 789e-6, 0, -787e-6, -0, 787e-6, 0, -785e-6, 0, 785e-6, 0, -783e-6, -0, 783e-6, -0, -781e-6, -0, 781e-6, 0, -779e-6, -0, 779e-6, -0, -777e-6, -0, 777e-6, 0, -776e-6, -0, 775e-6, -0, -774e-6, -0, 773e-6, 0, -772e-6, 0, 771e-6, 0, -77e-5, -0, 77e-5, 0, -768e-6, 0, 768e-6, 0, -766e-6, -0, 766e-6, -0, -764e-6, 0, 764e-6, 0, -763e-6, -0, 762e-6, -0, -761e-6, -0, 76e-5, 0, -759e-6, -0, 759e-6, -0, -757e-6, -0, 757e-6, 0, -755e-6, 0, 755e-6, 0, -754e-6, -0, 753e-6, 0, -752e-6, 0, 751e-6, 0, -75e-5, -0, 75e-5, 0, -748e-6, 0, 748e-6, 0, -746e-6, -0, 746e-6, -0, -745e-6, -0, 744e-6, 0, -743e-6, -0, 743e-6, -0, -741e-6, -0, 741e-6, 0, -74e-5, -0, 739e-6, -0, -738e-6, -0, 738e-6, 0, -736e-6, 0, 736e-6, 0, -734e-6, -0, 734e-6, 0, -733e-6, 0, 732e-6, 0, -731e-6, -0, 731e-6, 0, -729e-6, 0, 729e-6, 0, -728e-6, -0, 727e-6, -0, -726e-6, -0, 726e-6, 0, -724e-6, -0, 724e-6, -0, -723e-6, -0, 722e-6, 0, -721e-6, -0, 721e-6, -0, -719e-6, -0, 719e-6, 0, -718e-6, 0, 718e-6, 0, -716e-6, -0, 716e-6, 0, -715e-6, 0, 714e-6, 0, -713e-6, -0, 713e-6, 0, -711e-6, 0, 711e-6, 0, -71e-5, -0, 71e-5, -0, -708e-6, -0, 708e-6, 0, -707e-6, -0, 706e-6, -0, -705e-6, -0, 705e-6, 0, -704e-6, -0, 703e-6, -0, -702e-6, -0, 702e-6, 0, -7e-4, 0, 7e-4, 0, -699e-6, -0, 699e-6, 0, -697e-6, 0, 697e-6, 0, -696e-6, -0, 696e-6, 0, -694e-6, 0, 694e-6, 0, -693e-6, -0, 693e-6, -0, -691e-6, -0, 691e-6, 0, -69e-5, -0, 69e-5, -0, -688e-6, -0, 688e-6, 0, -687e-6, -0, 687e-6, -0, -685e-6, -0, 685e-6, 0, -684e-6, 0, 684e-6, 0, -682e-6, -0, 682e-6, 0, -681e-6, 0, 681e-6, 0, -68e-5, -0, 679e-6, 0, -678e-6, -0, 678e-6, 0, -677e-6, -0, 676e-6, -0, -675e-6, -0, 675e-6, 0, -674e-6, -0, 674e-6, -0, -672e-6, -0, 672e-6, 0, -671e-6, -0, 671e-6, 0, -67e-5, -0, 669e-6, 0, -668e-6, 0, 668e-6, 0, -667e-6, -0, 666e-6, 0, -665e-6, 0, 665e-6, 0, -664e-6, -0, 664e-6, 0, -663e-6, -0, 662e-6, 0, -661e-6, -0, 661e-6, -0, -66e-5, -0, 66e-5, 0, -658e-6, -0, 658e-6, -0, -657e-6, -0, 657e-6, 0, -656e-6, 0, 656e-6, 0, -654e-6, -0, 654e-6, 0, -653e-6, 0, 653e-6, 0, -652e-6, -0, 651e-6, 0, -65e-5, 0, 65e-5, 0, -649e-6, -0, 649e-6, -0, -648e-6, -0, 648e-6, 0, -646e-6, -0, 646e-6, -0, -645e-6, -0, 645e-6, 0, -644e-6, -0, 644e-6, -0, -643e-6, -0, 642e-6, 0, -641e-6, 0, 641e-6, 0, -64e-5, -0, 64e-5, 0, -639e-6, 0, 638e-6, 0, -637e-6, -0, 637e-6, 0, -636e-6, 0, 636e-6, 0, -635e-6, -0, 635e-6, -0, -634e-6, -0, 633e-6, 0, -632e-6, -0, 632e-6, -0, -631e-6, -0, 631e-6, 0, -63e-5, -0, 63e-5, -0, -629e-6, -0, 628e-6, 0, -627e-6, 0, 627e-6, 0, -626e-6, -0, 626e-6, 0, -625e-6, 0, 625e-6, 0, -624e-6, -0, 623e-6, 0, -622e-6, -0, 622e-6] } }; var scales = [{ name: "Locrian", scale: [0, 1, 3, 5, 6, 8, 10] }, { name: "Aeolian", scale: [0, 2, 3, 5, 7, 8, 10] }, { name: "Mixolydian", scale: [0, 2, 4, 5, 7, 9, 10] }, { name: "Lydian", scale: [0, 2, 4, 6, 7, 9, 11] }, { name: "Phrygian", scale: [0, 1, 3, 5, 7, 8, 10] }, { name: "Dorian", scale: [0, 2, 3, 5, 7, 9, 10] }, { name: "Hungarian minor", scale: [0, 2, 3, 6, 7, 8, 11] }, { name: "Neapolitan minor", scale: [0, 1, 3, 5, 7, 8, 11] }, { name: "Neapolitan", scale: [0, 1, 3, 5, 7, 9, 11] }, { name: "Enigmatic", scale: [0, 1, 4, 6, 8, 10, 11] }, { name: "Arabic", scale: [0, 1, 4, 5, 7, 8, 11] }, { name: "Blues", scale: [0, 3, 5, 6, 7, 10] }, { name: "Dominant bebop", scale: [0, 2, 4, 5, 7, 9, 10, 11] }, { name: "Major bebop", scale: [0, 2, 4, 5, 7, 8, 9, 11] }, { name: "Minor pentatonic", scale: [0, 3, 5, 7, 10] }, { name: "Major pentatonic", scale: [0, 2, 4, 7, 9] }, { name: "Diminished", scale: [0, 2, 3, 5, 6, 8, 9, 11] }, { name: "Whole tone", scale: [0, 2, 4, 6, 8, 10] }, { name: "Melodic minor", scale: [0, 2, 3, 5, 7, 9, 11] }, { name: "Harmonic minor", scale: [0, 2, 3, 5, 7, 8, 11] }, { name: "Major", scale: [0, 2, 4, 5, 7, 9, 11] }]; var song = { title: "", author: "Unknown", website: "", patterns: {}, instruments: {}, instrumentCounts: {}, instrumentNames: {}, fxUnits: {}, currentPattern: {}, waitingPattern: {}, currentBank: {}, patternList: {}, automation: {}, initDemo: {}, init: function() { this.demoSong() // this.new(); }, demoSong: function() { // var $_GET = {}; // if (document.location.toString().indexOf('?') !== -1) { // var query = document.location // .toString() // // get the query string // .replace(/^.*?\?/, '') // // and remove any existing hash string (thanks, @vrijdenker) // .replace(/#.*$/, '') // .split('&'); // for (var i = 0, l = query.length; i < l; i++) { // var aux = query[i].split('='); // $_GET[decodeURIComponent(aux[0])] = decodeURIComponent(aux[1]); // } // } // var loadthis; //get the 'index' query parameter //loadthis = "songs/defaultsong.kil.php"; // loadthis = "songs/defaultsong.kil.php"; function getUrlVars() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { vars[key] = value; }); return vars; } function getUrlParam(parameter, defaultvalue) { // var urlparameter = defaultvalue; var urlparameter = "none"; if (window.location.href.indexOf(parameter) > -1) { urlparameter = getUrlVars()[parameter]; } return urlparameter; } // var defaultsong = 'songs/defaultsong.kil.php'; // var defaultsong = ' // var loadthis = ''; // loadthis = getUrlParam("s", "none"); //alert(s); // loadthis = 'songs/o.kil'; // //if (loadthis == "none"){ loadthis = ''; // } // loadthis = "songs/defaultsong.kil.php"; //loadthis == defaultsong ? "" : $('#listamedlatar').hide(); /** if ($_GET['s'] === 'undefined') { loadthis = "songs/defaultsong.kil"; } else { } */ /** if ($_GET['s'] == "") { loadthis = "songs/defaultsong.kil"; } else { loadthis = $_GET['s']; } */ // if ($_GET['s'] == 2) { // loadthis = "songs/demosong2.kil"; // } else if ($_GET['s'] == 1) { // loadthis = "songs/demosong1.kil"; // } else if ($_GET['s'] ==3) { // loadthis = "songs/demosong3.kil"; // } else { // loadthis = "songs/defaultsong.kil.php"; // } // } //loadthis = "songs/maskin_2_1585406947950.kil"; //loadthis = "songs/maskin_2_1586355694056.kil"; //loadthis = "songs/maskin_2_1586532542724.kil"; loadthis = "songs/maskin_2_1586553521940.kil"; $.get(loadthis, function(data) { song.load(data); }) }, clear: function() { song.title = ""; song.author = ""; //console.log("New button pressed"); app.stopSequence(); // $(".js-transport").removeClass("btn-transport-active"); mixer.clear(false); // true???? $("#main-instrument-area").html(""); ui.changeScreen("instruments"); //editor - ... ;) startscreen after clear... this.patterns = {}; this.instruments = {}; this.instrumentCounts = {}; this.instrumentNames = {}; this.fxUnits = {}; this.currentPattern = {}; this.waitingPattern = {}; this.currentBank = {}; this.patternList = {}; this.automation = {}; editor.instrumentID = null; }, new: function() { song.clear(); setTimeout(function() { // new song newsong loadsong load demo demmosong ... meh .. new.. app.newInstrumentInstance("rave_synth"); app.newInstrumentInstance("rave_synth"); // app.newInstrumentInstance("rave_synth"); // app.newInstrumentInstance("sampler2"); app.newInstrumentInstance("sampler2"); app.newInstrumentInstance("sampler2"); // app.newInstrumentInstance("sinth1"); // app.newInstrumentInstance("sampler1"); // app.newInstrumentInstance("sampler4"); // app.newInstrumentInstance("sampler3"); song.refreshAfterLoad() }, 50) }, load: function(data) { this.clear(); // $(".apa8").html("♚ ♛").addClass("btn-transport-active"); // if song mode... sequencer setTimeout(function() { //song.instruments = songData.apainstruments; console.log(data); var allData = JSON.parse(data); var songData = allData.song; app.setTempo(songData.global.tempo); app.setshuffle(songData.global.shuffle); console.log(songData.global.songMode); app.songMode = songData.global.songMode; if (app.songMode == true) { $(".apa8").html("SONG").addClass("btn-transport-active"); // if song mode... sequencer } // song.instruments = songData.apainstruments; song.title = allData.info.songTitle; song.author = allData.info.songAuthor; for (var key in songData.instruments) { if (songData.instruments.hasOwnProperty(key)) { app.newInstrumentInstance(songData.instruments[key].maskinName, songData.instruments[key].instrumentID, false); for (var i = 0; i < songData.instruments[key].controls.length; i++) { song.instruments[key].controls[i].value = songData.instruments[key].controls[i] } // selectedsamplekit ... KILIAN ... // if lärde mig juh if set !"#€=!"=€ if (songData.instruments[key].selectedKit > -1){ song.instruments[key].selectedKit = songData.instruments[key].selectedKit; // sampler2.prototype.changeKit( songData.instruments[key].selectedKit ); //sampler2.prototype.updatekit(); //selectedKit( songData.instruments[key].selectedKit ); //sampler2.prototype.selectedKit( songData.instruments[key].selectedKit ); song.instruments[key].loadSamples(); } song.instruments[key].initControlValues(); ui.newInstrumentUI(key) } } // for (var key in songData.apainstruments) { // if (songData.apainstruments.hasOwnProperty(key)) { // app.newInstrumentInstance(songData.apainstruments[key].maskinName, songData.apainstruments[key].instrumentID, false); // for (var i = 0; i < songData.apainstruments[key].controls.length; i++) { // song.instruments[key].controls[i].value = songData.apainstruments[key].controls[i] // } // song.instruments[key].initControlValues(); // ui.newInstrumentUI(key) // } // } for (var property in songData) { if (songData.hasOwnProperty(property)) { if (property !== "instruments" && property !== "fxUnits") { song[property] = songData[property] } } } // BIG CHUNK RIGHT IN .. hehe for (var key in songData.fxUnits) { if (songData.fxUnits.hasOwnProperty(key)) { var params = key.split("_"), channel = params[0], slot = params[1], fxid = params[2]; mixer.addFX(channel, slot, fxid, false); for (var i = 0; i < songData.fxUnits[key].controls.length; i++) { if (song.fxUnits[key].controls[i]) { song.fxUnits[key].controls[i].value = songData.fxUnits[key].controls[i] } } song.fxUnits[key].initControlValues(); var fxType = song.fxUnits[key].fxNames[fxid]; // var fxType = song.getfxtype(fxid); // kilians... behövs ej. //fxType = 6; //console.log("OOOOOOOOOOOO "+ fxType); // if (fxType != parseInt(fxType)) { // reverb-tweak // //if (parseInt(this.type) > 10 || parseInt(this.type) == "") { // reverb-tweak // fxType = 6; // } ui.newFX(fxType, channel, slot, key, false) } } for (var channel in songData.mixer) { for (var i in songData.mixer[channel]) { var newChannel = parseInt(channel) + 1; mixer.controls[newChannel][i].value = songData.mixer[channel][i] } } song.patternList = songData.patternList; ui.changeScreen("instruments"); // startscreen hmm song.refreshAfterLoad(); }, 50) }, /* getfxtype: function(fxid) { console.warn("heeeelo " + fxid); var type = null; switch (fxid) { case 0: console.warn("heeeelo2 " + fxid); // addDistortion(); type = "distortion"; break; case 1: // addPhaser(); type = "phaser"; break; case 2: type = "chorus"; // addChorus(); break; case 3: // addFilter(); type = "filter"; break; case 4: // addAutoWah(); type = "wahwah"; break; case 5: // addDelay(); type = "delay"; break; case 6: // addReverb(); type = "reverb"; break; case 7: // addCompressor(); type = "compressor"; break; case 8: // addMoogfilter(); type = "moog"; break; case 9: // addBitcrusher(); type = "bitcrusher"; break; case 10: // addPanner(); type = "panner"; break default: //Reverb // addReverb(fxid); // BEHÖVS INTE HÄR FAKTISKT type = 'reverb'; break; } return type; },*/ save: function() { if (song.title == "") { song.title = ui.getDefaultSaveTitle() } var newSong = { // YO THIS IS SAVE! instruments: {}, // SAMPLE-LIST? instrumentCounts: song.instrumentCounts, patterns: song.patterns, // pattern-length? currentPattern: song.currentPattern, currentBank: song.currentBank, fxUnits: {}, mixer: [], global: { tempo: app.tempo, shuffle: app.shuffle, songMode: app.songMode } }; // BIG CHUNK OF TOTAL RECALL ;) // newSong.apainstruments = song.instruments; // HMMM REWORK!?"€!#%" for (var key in song.instruments) { newSong.instruments[key] = { maskinName: song.instruments[key].maskinName, instrumentID: key, selectedKit: song.instruments[key].selectedKit, /** instrument.sampleKits[instrument.selectedKit] */ /* drumSAMPLEDATAK: [], */ controls: [] }; for (var i = 0; i < song.instruments[key].controls.length; i++) { newSong.instruments[key].controls.push(song.instruments[key].controls[i].value) } } for (var channel in mixer.controls) { newSong.mixer.push([]); for (var i = 0; i < mixer.controls[channel].length; i++) { newSong.mixer[channel - 1].push(mixer.controls[channel][i].value) } } for (var fx in song.fxUnits) { newSong.fxUnits[fx] = { controls: [] }; for (var i = 0; i < song.fxUnits[fx].controls.length; i++) { newSong.fxUnits[fx].controls.push(song.fxUnits[fx].controls[i].value) } } newSong.patternList = song.patternList; var completeSong = { info: { appTitle: app.title, appAuthor: app.author, appWebsite: app.website, appVersion: app.version, songTitle: song.title, songAuthor: song.author, songDate: new Date }, song: newSong }; newSong = JSON.stringify(completeSong); return newSong // save on server }, refreshAfterLoad: function() { ui.refreshInstruments(); mixer.initControlValues(); sequencer.init(false); options.refresh() } }; var instruments = {}; var app = { title: "alkizz | popmaskin 3", version: "1.0", author: "alkizz Media", website: "http://www.alkizz.com", fileExtension: "kil", appVersion: true, chromeApp: false, loaded: false, instrumentBasePath: "instrument_data/", fxBasePath: "fx/", instrumentExtension: ".instrument.js", instrumentNames: ["rave_synth", "dr1", "sinth"], fxNames: ["distortion", "phaser", "chorus", "filter", "wahwah", "delay", "reverb", "compressor", "moog", "bitcrusher", "panner"], screenNames: ["editor", "sequencer", "mixer", "options", "about"], screenDefaultVars: {}, mainInstrumentDivID: "main-instrument-area", tempo: 130, shuffle: 6, ppq: 96, stepSpeed: null, tickSpeed: null, context: null, masterGainNode: null, patternLength: 16, maxPatterns: 32, // bufferSize: .1, bufferSize: 1, //256? sequencePlaying: false, randomNotes: [38, 39, 43, 45, 46], lastInstrument: null, tuna: null, currentScreen: "instruments", currentBar: 0, deltaTime: 0, songMode: false, /** false ... true */ upgradeUrl: "https://www.alkizz.com/", scheduleAheadTime: .4, //.18*2*2*2 lookAhead: 25, currentStep: 0, nextStepTime: 0, lastStepTime: 0, stepQueue: [], nextStep: function() { var secondsPerBeat = 60 / app.tempo; //ddddddddddd app.currentStep % 2 == 1 ? shuffle = 1 - Math.round(app.shuffle) / 200 : shuffle = 1 + Math.round(app.shuffle) / 200; app.nextStepTime += .25 * secondsPerBeat * shuffle; // if (app.currentStep % 4 == 0) { // for (var key in song.instruments) { // if (filtertestkilian == 0) { // filtertestkilian++; // apa9 = Math.round(Math.random() * 100); // // z ///** lyssnar ändå på gränssnitt ? */ // song.instruments[key].setControlValue(2, apa9); // console.log(apa9); // // ui.setKnobRotation("instrument", key, automation[i].id, automation[i].val, true) ui.setKnobRotation("instrument", key, automation[i].id, automation[i].val, true) // // ui.setKnobRotation("instrument", key, automation[i].id, automation[i].val, true) ui.setKnobRotation("instrument", key, automation[i].id, automation[i].val, true) // ui.setKnobRotation("instrument", key, 2, apa9, false); // console.log(key); //ui.setKnobRotation("instrument", key, 2, apa9, false); //ui.setKnobRotation("instrument", "rave_synth_1582727490441", 2, apa9, false); //console.log(apa9); // } // } // } app.currentStep++; if (app.currentStep == app.patternLength) { app.currentStep = 0; app.currentBar += 1; if (app.songMode && sequencer.loopEnd - sequencer.loopStart > 0) { if (app.currentBar > sequencer.loopEnd) { //console.log("Looping"); app.currentBar = sequencer.loopStart } } } if (app.songMode) { for (var key in song.instruments) { if (song.instruments.hasOwnProperty(key)) { //console.log("Current Step: " + app.currentStep); if (typeof song.patternList[key][app.currentBar] !== "undefined" && app.currentStep === 0) { ui.patternSelect(key, song.patternList[key][app.currentBar], true) } else {} if (typeof song.automation[key][app.deltaTime] !== "undefined") { var automation = song.automation[key][app.deltaTime]; //console.log("AUTOMATION: ", automation); for (var i = 0; i < automation.length; i++) { if (automation[i].id < 9) { song.instruments[key].setControlValue(automation[i].id, automation[i].val); ui.setKnobRotation("instrument", key, automation[i].id, automation[i].val, true) } else if (automation[i].id == 99) { var enabled = automation[i].val; if (enabled < 1) { ui.muteInstrument(key) } } } } } } app.deltaTime += 2 } app.lastStepTime = app.context.currentTime }, scheduler: function() { while (app.nextStepTime < app.context.currentTime + app.scheduleAheadTime) { app.scheduleStep(app.currentStep, app.nextStepTime); app.nextStep() } }, scheduleStep: function(stepNumber, startTime) { temploophack++; for (var key in song.instruments) { var step = app.currentStep; if (song.instruments.hasOwnProperty(key)) { var instrumentID = key; var patternNumber = song.currentPattern[instrumentID]; var waitingPatternNumber = song.waitingPattern[instrumentID]; // step = app.currentStep % (2*(song.currentPattern[instrumentID] + 1)); // KILIAN! if (step === 0 && waitingPatternNumber != null) { if (patternNumber !== waitingPatternNumber) { song.currentPattern[instrumentID] = waitingPatternNumber; patternNumber = waitingPatternNumber; ui.patternSelect(instrumentID, waitingPatternNumber, true); song.waitingPattern[instrumentID] = null } } var stepData = []; if (song.patterns[instrumentID][patternNumber]) { //step = app.currentStep % (song.patterns[instrumentID][patternNumber].pattern.length + 1); //kilian //console.log("HOOOOOOI"); //console.log( song.patterns); //step = app.currentStep % 3 //kilian // if (song.instruments[instrumentID].maskinName == "rave_synth") { // looplength = song.patterns[instrumentID][patternNumber].looplength; //1 * $("#temploop").val(); // //song.patterns.sampler4_1582046774428[0].pattern[1][0].veloc; //songsong.patterns.sampler4_1582046774428[0].pattern[1][0].veloc.patterns[instrumentID][patternNumber][0].value; //1 * $("#temploop").val(); // cast to number öhhh kilian hmm // //if record == true... record ... styrsr av hand i luft... annars spela upp :D // //lägg in filter ändring automation... // // song.instruments[key].setControlValue(automation[i].id, automation[i].val); // // ui.setKnobRotation("instrument", key, automation[i].id, automation[i].val, true) // //looplength2 = 3 + looplength; // looplength2 = 9; // temploophack++; // if (temploophack % 2 == 0) // step = temploophack % $("#temploop").val(); //kilian // if (temploophack % 2 == 1) { // var ptnLength = song.patterns[instrumentID][patternNumber].barLength * looplength; // step = temploophack % looplength; // } else { // var ptnLength = song.patterns[instrumentID][patternNumber].barLength * looplength2; // step = temploophack % looplength2; // } // } else { if (song.patterns[instrumentID][patternNumber].loopsteps) { console.log(song.patterns[instrumentID][patternNumber].loopsteps); // console.log(song.patterns[instrumentID][patternNumber]); loopsteps = song.patterns[instrumentID][patternNumber].loopsteps; //because 1 means to repeat first... ? nooe... hmm -1 .. eh step = temploophack % loopsteps; console.log(step); } else { var ptnLength = song.patterns[instrumentID][patternNumber].barLength * 16; step = app.currentStep % ptnLength; } //step = app.currentStep % (song.patterns[instrumentID][patternNumber].pattern.length + 1); //kilian // } if (ptnLength > 16 && !app.songMode) { if ((app.currentBar + 1) % 2 === 0 && app.currentBar > 0) { step = step + 16; //console.log("Step: " + step) } } // stepData = song.patterns[instrumentID][patternNumber].pattern[step] stepData = song.patterns[instrumentID][patternNumber].pattern[step] } if (app.songMode && typeof song.patternList[instrumentID][app.currentBar] == "undefined") { if (app.currentBar > 0) { if (!sequencer.checkPreviousBarOverlap(instrumentID, app.currentBar)) { stepData = [{ val: null }] } else { patternNumber = song.patternList[instrumentID][app.currentBar - 1]; step = step + 16; stepData = song.patterns[instrumentID][patternNumber].pattern[step] } } else { stepData = [{ val: null }] } } if (stepData.length < 1) { stepData = [{ val: null }] } if (mixer.startRecordNextStep) { mixer.rec.record(); mixer.startRecordNextStep = false } for (var i = 0; i < stepData.length; i++) { song.instruments[instrumentID].playStep(stepData[i], startTime) } } } ui.step(stepNumber) }, init: function() { var userAgent = navigator.userAgent.toLowerCase(); if (userAgent.indexOf(" electron/") > -1) { app.appVersion = true } this.context = new(window.AudioContext || window.webkitAudioContext); this.tempoWorker = new Worker("tempo_worker.js"); app.tempoWorker.onmessage = function(e) { // filtertestkilian = 0; app.scheduler() }; this.setTempo(this.tempo); this.setshuffle(this.shuffle); this.tuna = new Tuna(this.context); this.screenDefaultVars = { editor: { patternLength: 16 } }; this.handlebarsHelpers(); this.loadData() }, handlebarsHelpers: function() { Handlebars.registerHelper("simpleLoop", function(n, block) { var accum = ""; for (var i = 0; i < n; ++i) accum += block.fn(i); return accum }); Handlebars.registerHelper("simpleLoopInverse", function(n, block) { var accum = ""; var n = n - 1; for (var i = n; i >= 0; --i) accum += block.fn(i); return accum }); Handlebars.registerHelper("plusOne", function(value, opts) { return parseInt(value) + 1 }); Handlebars.registerHelper("is_equal", function(a, b, opts) { if (a === b) { return opts.fn(this) } else { return opts.inverse(this) } }) }, loadData: function() { setTimeout(function() { $(".main-container").show(); $(".loading-container").show(); app.loadScreens(); song.init(); ui.updateTempo(); ui.updateshuffle(); ui.ready() }, 500); $(".activate").on("mousedown", function() { $(".loading-container").fadeOut("slow"); app.context.resume().then(() => { // ACTIVATE AUDIO-CONTEXT ////console.log('Playback resumed successfully'); // document.querySelector('body').removeEventListener; }); //$('#play').mousedown(); }); }, loadScreens: function() { for (var i = 0; i < app.screenNames.length; i++) { var name = app.screenNames[i]; var screenTemplate = templates[name]; var template = screenTemplate(); var screenHtml = template; if (app.screenDefaultVars[name]) { app.screenDefaultVars[name]; screenHtml = screenTemplate(app.screenDefaultVars[name]) } if (name != "options") { $('.js-screen[data-screen-name="' + name + '"]').html(screenHtml) } else { options.init(true) } if (name == "editor") { editor.init(); } } ui.refreshInstruments() }, newInstrumentInstance: function(instrumentName, id, addUI) { id = typeof id !== "undefined" ? id : false; addUI = typeof addUI !== "undefined" ? addUI : true; var instrumentRef = window[instrumentName]; var tempInstrument = new instrumentRef; //console.log("######" + instrumentName); if (!id) { var instrumentID = tempInstrument.maskinName + "_" + Date.now() } else { var instrumentID = id } tempInstrument.instrumentID = instrumentID; song.instruments[instrumentID] = tempInstrument; var maskinName = song.instruments[instrumentID].maskinName; song.instruments[instrumentID].instrumentID = instrumentID; if (song.instrumentCounts[maskinName]) { song.instrumentCounts[maskinName]++ } else { song.instrumentCounts[maskinName] = 1 } if (song.instrumentNames.hasOwnProperty(maskinName)) { song.instrumentNames[maskinName][song.instrumentCounts[maskinName]] = instrumentID } else { song.instrumentNames[maskinName] = {}; song.instrumentNames[maskinName][song.instrumentCounts[maskinName]] = instrumentID } var instrumentCount = song.instrumentCounts[maskinName]; var instrumentCountDisplay = ""; if (instrumentCount > 1) { instrumentCountDisplay = "(" + instrumentCount + ")" } song.instruments[instrumentID].instrumentName = song.instruments[instrumentID].instrumentName + " " + instrumentCountDisplay; song.patterns[instrumentID] = []; song.patternList[instrumentID] = {}; song.automation[instrumentID] = []; song.currentPattern[instrumentID] = 0; song.currentBank[instrumentID] = 0; var totalInstruments = 0; for (var key in song.instruments) { if (song.instruments.hasOwnProperty(key)) { totalInstruments++ } } song.instruments[instrumentID].mixerChannel = totalInstruments; song.instruments[instrumentID].context = this.context; song.instruments[instrumentID].init(); if (addUI) { ui.newInstrumentUI(instrumentID) } if (!editor.instrumentID) { editor.instrumentID = instrumentID } return instrumentID }, createPattern: function(instrumentID, patternID, length) { length = typeof length !== "undefined" ? length : app.patternLength; var barLength = length / 16; song.patterns[instrumentID][patternID] = { barLength: barLength, pattern: new Array(length) }; for (var i = 0; i < length; i++) { song.patterns[instrumentID][patternID].pattern[i] = [] } }, setKnobPos: function(vPos) { function limitVal(newVal) { if (newVal < 0) { newVal = 0 } else if (newVal > 127) { newVal = 127 } return newVal } var instrumentID = ui.lastInstrumentID; var pointer = { y: vPos }; if (!ui.mouseDown) { ui.dragStart = pointer.y; ui.mouseDown = true } ui.dragNew = pointer.y; var moveAmount = ui.dragNew - ui.dragStart; if (moveAmount < 0) { moveAmount = Math.abs(moveAmount) } else if (moveAmount > 0) { moveAmount = -Math.abs(moveAmount) } var currentKnobID = ui.lastControlID, controlType = ui.lastControlType, uiType = "knob", currentVal; if (controlType == "instrument") { uiType = song.instruments[instrumentID].controls[currentKnobID].type; currentVal = song.instruments[instrumentID].controls[currentKnobID].value; if (song.instruments[instrumentID].controls[currentKnobID].faster) { moveAmount = moveAmount * 2 } var newVal = limitVal(currentVal + moveAmount); song.instruments[instrumentID].setControlValue(currentKnobID, newVal); //console.log(song.instruments[instrumentID].setControlValue(currentKnobID, newVal)); } else if (controlType == "mixer") { var mixerChannel = ui.lastMixerChannel; uiType = mixer.controls[mixerChannel][currentKnobID].type; if (uiType == "slider") { var knobHeight = 10; var outer = $('.js-control-knob[data-mixer-channel="' + ui.lastMixerChannel + '"][data-control-id="' + currentKnobID + '"][data-control-type="mixer"]').find(".slider-outer"); var scrollTop = $(window).scrollTop(), sliderHeight = outer.height(), sliderTop = outer.offset().top - scrollTop, sliderBottom = sliderTop + sliderHeight, mousePos = sliderBottom - ui.mousePos.y, valPercent = mousePos / sliderHeight * 100 - knobHeight / 2; if (valPercent > 100) valPercent = 100; var newVal = Math.round(Math.max(0, 127 / 100 * valPercent)) } else { currentVal = mixer.controls[mixerChannel][currentKnobID].value; var newVal = limitVal(currentVal + moveAmount) } mixer.setControlValue(mixerChannel, currentKnobID, newVal) } else { instrumentID = ui.lastfxid; //console.log("FX CONTROL"); //console.log(controlType); currentVal = song.fxUnits[ui.lastfxid].controls[currentKnobID].value; var newVal = limitVal(currentVal + moveAmount); song.fxUnits[ui.lastfxid].setControlValue(currentKnobID, newVal) } if (uiType == "knob") { ui.setKnobRotation(controlType, instrumentID, currentKnobID, newVal) } else if (uiType == "slider") { //console.log("Setting a slider knob"); ui.setSliderPos(controlType, instrumentID, currentKnobID, newVal) } //console.log(currentKnobID + " Val: " + newVal); ui.dragStart = ui.dragNew; return }, setTempo: function(tempo) { //console.log("setting tempo"); this.tempo = tempo; this.stepSpeed = 6e4 / (tempo * 4); this.tickSpeed = 6e4 / (tempo * this.ppq); app.tempoWorker.postMessage({ speed: this.stepSpeed, message: "tempo" }); ui.updateTempo() }, setshuffle: function(shuffle) { this.shuffle = shuffle; //console.log("setting shuffle"); ui.updateshuffle() }, clearPattern: function(instrumentID, patternID) { if (!song.patterns[instrumentID][patternID].pattern) { return } var patternLength = song.patterns[instrumentID][patternID].pattern.length; for (var i = 0; i < patternLength; i++) { song.patterns[instrumentID][patternID].pattern[i] = [] } }, randomiseNotes: function(instrumentID, patternID) { if (!song.patterns[instrumentID][patternID]) { app.createPattern(instrumentID, patternID) } var patternLength = song.patterns[instrumentID][patternID].barLength * 16; this.clearPattern(instrumentID, patternID); availableNotes = scales[options.randScale].scale; var splitNumber = options.randSplitNum; var chunks = []; var patternChunkLength = patternLength / splitNumber; var randomNotes = []; if (song.instruments[instrumentID].drummaskin) { var drumNotes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; availableNotes = []; for (var i = 0; i < 5; i++) { var randomNumber = Math.floor(Math.random() * drumNotes.length); availableNotes.push(drumNotes[randomNumber]) } } for (var chunk = 0; chunk < splitNumber; chunk++) { chunks[chunk] = []; for (var i = 0; i < patternChunkLength; i++) { var randomNumber = Math.floor(Math.random() * (availableNotes.length + options.randEmpty)); var randomNote = availableNotes[randomNumber] + 36; if (randomNote) { var octaveRand = Math.floor(Math.random() * 20); var octaveUpSetting, octaveDownSetting = 0; if (octaveRand >= 1 && octaveRand < 4) { octaveUpSetting = 1; octaveDownSetting = 0 } else if (octaveRand == 5) { octaveDownSetting = 1; octaveUpSetting = 0 } var slideRand = Math.floor(Math.random() * 10); var slideSetting = 0; if (slideRand < 3) { slideSetting = 1 } var accentRand = Math.floor(Math.random() * 15); var accentSetting = 0; if (accentRand < 3) { accentSetting = 1 } chunks[chunk][i] = { note: randomNote, slide: slideSetting, accent: accentSetting, octaveUp: octaveUpSetting, octaveDown: octaveDownSetting } } else { chunks[chunk][i] = null } } var selectedChunk = chunk; if (chunk > 0) { if (Math.floor(Math.random() * 2) == 1) { selectedChunk = chunk - 1 } } randomNotes = randomNotes.concat(chunks[selectedChunk]) } for (i = 0; i < patternLength; i++) { if (randomNotes[i]) { var rStep = { type: 0, start: i, val: randomNotes[i].note, duration: 1, offset: 0 }; if (song.instruments[instrumentID].maskinName == "rave_synth") { rStep.slide = randomNotes[i].slide; rStep.accent = randomNotes[i].accent; rStep.octUp = randomNotes[i].octaveUp; rStep.octDown = randomNotes[i].octaveDown } if (song.instruments[instrumentID].drummaskin) { rStep.veloc = 115 } song.patterns[instrumentID][patternID].pattern[i].push(rStep) } else { song.patterns[instrumentID][patternID].pattern[i] = [{ val: null }] } } }, playSequence: function() { temploophack = -1; //filtertestkilian = 0; //apa9 = 0; //console.log("Play"); if (sequencer.loopEnd - sequencer.loopStart > 0) { app.currentBar = sequencer.loopStart } else { app.currentBar = app.currentBar } if (this.sequencePlaying) { return } if (mixer.recordWav) { mixer.rec.record() } if (this.songMode) { for (var instrumentID in song.instruments) { if (typeof song.patternList[instrumentID][app.currentBar] !== "undefined") { ui.patternSelect(instrumentID, song.patternList[instrumentID][app.currentBar], true) } } } app.currentStep = 0; app.nextStepTime = app.context.currentTime + app.scheduleAheadTime; app.stepQueue = []; this.sequencePlaying = true; song.waitingPatternNumber = null; var workerParams = { speed: app.stepSpeed, message: "start" }; app.tempoWorker.postMessage(workerParams) }, stopSequence: function() { //console.log("Stop"); this.sequencePlaying = false; app.lastStepTime = 0; app.currentStep = 0; app.currentBar = 0; app.deltaTime = 0; app.tempoWorker.postMessage({ message: "stop" }); for (var key in song.instruments) { if (song.instruments.hasOwnProperty(key)) { var instrumentID = key; song.instruments[instrumentID].stopAll(); song.waitingPattern[instrumentID] = null; ui.removePatternWaiting() } } if (mixer.wavRecord) { mixer.rec.stop(); mixer.rec.exportWAV(); ui.toggleWavRecord() } }, readFile: function(element) { var errors = { song: "This does not appear to be an alkizz | popmaskin 3 file.", // rb: "This does not appear to be a Rebirth 2 file.", // abl: "This does not appear to be a ABL2 or ABL3 pattern file." }; element = element[0]; var fileType = $(element).data("type"); if (fileType == "song") { var allowedExtension = app.fileExtension } // else if (fileType == "rb") { // var allowedExtension = "rbs" // } else if (fileType == "abl") { // var allowedExtension = "pat" // } var files = element.files; if (!files.length) { //console.log("No file selected"); return } var file = files[0]; var extension = file.name.split("."); extension = extension[extension.length - 1].toLowerCase(); // if (extension != allowedExtension) { // var alertMessage = "File Type Error: " + errors[fileType]; // notification.show({ // message: alertMessage, // type: "alert" // }); // return // } var reader = new FileReader; reader.onloadend = function(e) { if (e.target.readyState == FileReader.DONE) { var data = e.target.result; if (fileType == "song") { song.load(data) } else if (fileType == "mkz") { song.load(data) } } }; if (fileType == "song" || fileType == "mkz") { reader.readAsBinaryString(file) } // } else if (fileType == "apa") { // reader.readAsArrayBuffer(file) // } } }; var storage = { getItem: function(key, callback) { if (app.chromeApp) { chrome.storage.local.get(key, function(data) { //console.log("Get storage key: " + key); if (chrome.runtime.lastError) { //console.log("Error getting value from storage: " + key); //console.log(data) } callback(key, data[key]) }) } else { var value = localStorage.getItem(key); callback(key, value) } }, setItem: function(key, value) { if (app.chromeApp) { var params = {}; params[key] = value; var item = {}; item[key] = value; chrome.storage.local.set(item) } else { localStorage.setItem(key, value) } }, removeItem: function(key) { if (app.chromeApp) { chrome.storage.local.remove(key) } else { localStorage.removeItem(key) } } }; var mixer = { channelCount: 5, fxSlotCount: 5, channels: {}, masterVolume: .85, channelInputVolume: .9, channelOutputVolume: .9, inputMute: [0, 0, 0, 0, 0], inputSolo: false, controls: [], wavRecord: false, startRecordNextStep: false, init: function(firstTime) { this.masterGainNode = app.context.createGain(); this.masterGainNode.gain.value = this.masterVolume; for (var i = 1; i <= this.channelCount; i++) { this.channels[i] = { input: app.context.createGain(), output: app.context.createGain(), analyser: app.context.createAnalyser(), fxSlots: {} }; this.channels[i].input.gain.value = this.channelInputVolume; this.channels[i].output.gain.value = this.channelOutputVolume; this.channels[i].analyser.fftSize = 32; this.channels[i].analyser.smoothingTimeConstant = .4; this.channels[i].analyser.minDecibels = -100; this.channels[i].analyser.maxDecibels = -10; for (var i2 = 1; i2 <= this.fxSlotCount; i2++) { this.channels[i].fxSlots[i2] = app.context.createGain() } this.controls[i] = [{ label: "Volume", type: "slider", value: 114 }, { label: "Pan", type: "knob", value: 64 }, { label: "Mute", type: "toggle", value: 0 }, { label: "Solo", type: "toggle", value: 0 }] } this.connectNodes(); if (firstTime) { this.setupChannelMeters() } }, clear: function() { this.masterGainNode = null; this.channels = {}; this.controls = []; this.inputMute = [0, 0, 0, 0, 0]; /** hmmm more dynamic? */ this.inputSolo = false; this.init(false) }, connectNodes: function() { for (var i = 1; i <= mixer.channelCount; i++) { this.channels[i].input.connect(this.channels[i].fxSlots[1]); for (var i2 = 1; i2 < mixer.fxSlotCount; i2++) { this.channels[i].fxSlots[i2].connect(this.channels[i].fxSlots[i2 + 1]) } this.channels[i].fxSlots[this.fxSlotCount].connect(this.channels[i].output); this.channels[i].output.connect(this.channels[i].analyser); this.channels[i].analyser.connect(this.masterGainNode) } this.masterGainNode.connect(app.context.destination); // try { // om redan satt varde // if( mixer.rec ){} // } catch (e) { // if (!mixer.rec) { var recConfig = { workerPath: "recorderWorker.js", callback: mixer.wavExportCallback, numChannels: 2, bufferLen: 8192 }; mixer.rec = new Recorder(mixer.masterGainNode, recConfig); // } // } }, disconnectNodes: function() { this.masterGainNode.disconnect(); for (var i = 1; i <= mixer.channelCount; i++) { this.channels[i].analyser.disconnect(); this.channels[i].output.disconnect(); this.channels[i].fxSlots[this.fxSlotCount].disconnect(); for (var i2 = 1; i2 < mixer.fxSlotCount; i2++) { this.channels[i].fxSlots[i2].disconnect() } this.channels[i].input.disconnect() } }, addFX: function(channel, slot, fxid, addUI) { var self = this; var loadingStatus = false; channel = parseInt(channel); slot = parseInt(slot); reverbpath = fxid; if (parseInt(fxid) == 0) { fxid = parseInt(fxid) } else { fxid = fxid; } // fxid = parseInt(fxid) //parseInt(fxid); // hmmm kilian... PAJAR DISTORTION EFTERSOM 0 <-----(!) om inte parseInt var uniqueID = channel + "_" + slot + "_" + fxid; var fxUnit = new window["fxUnit"]; fxUnit.type = fxid; fxUnit.uniqueID = uniqueID; fxUnit.channel = channel; fxUnit.slot = slot; song.fxUnits[uniqueID] = fxUnit; function addDistortion() { console.log("adding distortion to ch: " + channel + " , slot: " + slot); mixer.channels[channel].fxSlots[slot] = new app.tuna.Overdrive({ outputGain: .5, drive: .9, curveAmount: .75, algorithmIndex: 0, bypass: 0 }) } function addChorus() { //console.log("adding chorus to ch: " + channel + " , slot: " + slot); mixer.channels[channel].fxSlots[slot] = new app.tuna.Chorus({ rate: 1.5, feedback: .8, delay: .0045, bypass: 0 }) } function addPhaser() { mixer.channels[channel].fxSlots[slot] = new app.tuna.Phaser({ rate: 1.2, depth: .6, feedback: .8, stereoPhase: 180, baseModulationFrequency: 1500, bypass: 0 }) } function addFilter() { mixer.channels[channel].fxSlots[slot] = new app.tuna.Filter({ frequency: 440, Q: 1, gain: 0, filterType: "lowpass", bypass: 0 }) } function addAutoWah() { mixer.channels[channel].fxSlots[slot] = new app.tuna.WahWah({ automode: true, baseFrequency: .2, excursionOctaves: 3, sweep: 0.5, resonance: 0.75, sensitivity: .4, bypass: 0 }) } function addCompressor() { mixer.channels[channel].fxSlots[slot] = new app.tuna.Compressor({ threshold: .5, makeupGain: 1, attack: 1, release: 0, ratio: 4, knee: 5, automakeup: true, bypass: 0 }) } function addDelay() { var stepTime = app.stepSpeed; var delayAmount = 3; var delayTime = stepTime * delayAmount; mixer.channels[channel].fxSlots[slot] = new app.tuna.Delay({ feedback: .35, delayTime: delayTime, wetLevel: .4, dryLevel: 1, cutoff: 3500, bypass: 0 }) // kör en uppdatering av delay via knob-twist ... ehh öjhhh // KÖR KNOBTWIST.. } // function addReverb() { // loadingStatus = true; // // var impulseFilePath = "assets/impulse/church.wav"; //drainage-tunnel ! :D // function loadImpulse() { // var getSound = new XMLHttpRequest; // getSound.open("GET", impulseFilePath, true); // getSound.responseType = "arraybuffer"; // getSound.onload = function () { // //console.log("reverb loaded"); // loadingStatus = false; // ui.setFXLoadingStatus(uniqueID, loadingStatus) // }; // getSound.send() // } // loadImpulse(); // mixer.channels[channel].fxSlots[slot] = new app.tuna.Convolver({ // highCut: 22050, // lowCut: 20, // dryLevel: 1, // wetLevel: 1, // level: 1, // impulse: impulseFilePath, // bypass: 0 // }) // } function addReverb(thisconvolver = "assets/impulse/church.wav") { //thisconvolver = "assets/impulse/church.wav" loadingStatus = true; var impulseFilePath = thisconvolver; //;'ucantjustsample/ir' + thisconvolver + '.wav '; // var impulseFilePath = thisconvolver; //drainage-tunnel ! :D //var impulseFilePath = "assets/impulse/church.wav"; function loadImpulse() { var getSound = new XMLHttpRequest; getSound.open("GET", impulseFilePath, true); getSound.responseType = "arraybuffer"; getSound.onload = function() { console.log(impulseFilePath + "reverb loaded"); loadingStatus = false; ui.setFXLoadingStatus(uniqueID, loadingStatus) }; getSound.send() } loadImpulse(); mixer.channels[channel].fxSlots[slot] = new app.tuna.Convolver({ highCut: 22050, lowCut: 20, dryLevel: 1, wetLevel: 1, level: 1, impulse: impulseFilePath, bypass: 0 }) } function addBitcrusher() { //console.log("adding bitcrusher to ch: " + channel + " , slot: " + slot); mixer.channels[channel].fxSlots[slot] = new app.tuna.Bitcrusher({ bits: 12, bufferSize: 256, bypass: 0 }) } function addMoogfilter() { mixer.channels[channel].fxSlots[slot] = new app.tuna.MoogFilter({ outputGain: .5, cutoff: 0.5, resonance: 3, bypass: 0 }) } function addPanner() { mixer.channels[channel].fxSlots[slot] = new app.tuna.Panner({ outputGain: .5, pan: 0, bypass: 0 }) } var type = null; switch (parseInt(fxid)) { //kilian!!! hmm? case 0: addDistortion(); type = "distortion"; break; case 1: addPhaser(); type = "phaser"; break; case 2: type = "chorus"; addChorus(); break; case 3: addFilter(); type = "filter"; break; case 4: addAutoWah(); type = "wahwah"; break; case 5: addDelay(); type = "delay"; break; case 6: addReverb(); type = "reverb"; break; case 7: addCompressor(); type = "compressor"; break; case 8: addMoogfilter(); type = "moog"; break; case 9: addBitcrusher(); type = "bitcrusher"; break; case 10: addPanner(); type = "panner"; break default: //Reverb //fxid = 11; addReverb(reverbpath); type = 'reverb'; break; } this.disconnectNodes(); this.connectNodes(); song.fxUnits[uniqueID].init(); if (addUI) { ui.newFX(type, channel, slot, uniqueID, loadingStatus); console.log("uniqueID" + uniqueID); } }, deleteFX: function(channel, slot, fxid) { //mixer.deleteFX console.log("removing audio" + channel + " - " + slot); //song.fxUnits[fxid] = {}; //kilian ... unset object remove object... delete song.fxUnits[fxid]; //[channel].fxSlots[slot] mixer.channels[channel].fxSlots[slot] = app.context.createGain(); mixer.disconnectNodes(); mixer.connectNodes(); }, muteInputToggle: function(channel) { //console.log("MUTE TOGGGGGGGLLLLLLEEEE"); //console.log(channel); var time = app.context.currentTime + .05; if (!mixer.inputMute[channel]) { mixer.channels[channel].input.gain.value = 0; mixer.inputMute[channel] = 1 } else { mixer.channels[channel].input.gain.value = this.channelInputVolume, time; mixer.inputMute[channel] = 0 } }, soloInputToggle: function(channel) { var time = app.context.currentTime + .05; if (!mixer.solo) { for (var i in mixer.channels) { //console.log(i); if (i == channel) { //console.log("Not muting channel: " + i); mixer.inputMute[i] = 0; mixer.channels[i].input.gain.linearRampToValueAtTime(mixer.channelInputVolume, time) } else { mixer.inputMute[i] = 1; mixer.channels[i].input.gain.linearRampToValueAtTime(0, time) } } mixer.solo = channel } else { if (mixer.solo == channel) { for (var i in mixer.channels) { mixer.inputMute[i] = 0; mixer.channels[i].input.gain.linearRampToValueAtTime(mixer.channelInputVolume, time) } mixer.solo = false } else { mixer.solo = false; mixer.soloInputToggle(channel) } } }, setControlValue: function(channel, controlID, value) { this.controls[channel][controlID].value = value; switch (controlID) { case 0: value = value / 127; this.channels[channel].output.gain.value = value; break; case 1: break } }, initControlValues: function() { //this.sampler2.prototype.changeKit(0); for (var ch = 1; ch <= this.channelCount; ch++) { for (var i = 0; i < this.controls[ch].length; i++) { this.setControlValue(ch, i, this.controls[ch][i].value) } var visualVal = this.controls[ch][0].value / 127 * 100; $('.js-control-knob[data-control-type="mixer"][data-mixer-channel="' + ch + '"][data-control-id="0"]').find(".slider-inner").css({ height: visualVal + "%" }); var knobHeight = 10; knobHeight = knobHeight / 2; $('.js-control-knob[data-control-type="mixer"][data-mixer-channel="' + ch + '"][data-control-id="0"]').find(".slider-knob").css({ bottom: visualVal - knobHeight + "%" }) } }, setupChannelMeters: function() { return; //console.log("Setup channel meters"); function getAverageVolume(array) { var values = 0; var nonZeroCount = 0; for (var i = 0; i < array.length; i++) { values += array[i]; if (array[i] > 0) { nonZeroCount++ } } var average = values / array.length; return average } function clearMeters() { for (var i = 1; i <= song.instruments.length; i++) { var canvasContext = $('.js-channel-meter[data-channel-id="' + i + '"]')[0].getContext("2d"); canvasContext.clearRect(0, 0, mixerUI.channelMeterWidth, mixerUI.channelMeterHeight) } } function drawLoop() { for (var i = 1; i <= 3; i++) { var freqArray = new Uint8Array(mixer.channels[i].analyser.frequencyBinCount); mixer.channels[i].analyser.getByteFrequencyData(freqArray); var volume = getAverageVolume(freqArray); volume = volume / 128 * 100; var meterWidth = 10; var meterHeight = 100; var threshold = 90; volume = 100 - volume; var inner = $('.js-channel-meter[data-channel-id="' + i + '"]').find(".js-channel-meter-inner"); inner.css({ height: volume + "%" }) } window.requestAnimationFrame(function() { drawLoop() }) } drawLoop() }, wavExportCallback: function(wavData) { //console.log("wav export"); var name = "popmaskin_" + Date.now() + ".wav"; if (!app.chromeApp) { var url = (window.URL || window.webkitURL).createObjectURL(wavData); var link = window.document.createElement("a"); link.href = url; link.download = name; link.click() } else { var extension = "wav"; chrome.fileSystem.chooseEntry({ type: "saveFile", suggestedName: name, accepts: [{ description: "Wav files (*." + extension + ")", extensions: [extension] }] }, function(writableFileEntry) { function errorHandler() { //console.log("File Export Error") } writableFileEntry.createWriter(function(writer) { var truncated = false; var blob = new Blob([wavData], { type: "audio/wav" }); notification.show({ type: "loading", message: "Exporting wav file..." }); writer.onerror = errorHandler; writer.onwriteend = function(e) { if (!truncated) { truncated = true; this.truncate(blob.size); return } //console.log("wav file export complete"); setTimeout(function() { notification.dismiss() }, 800) }; writer.write(blob) }, errorHandler) }) } mixer.rec.clear() } }; var editor = { instrumentID: null, patternID: 0, notes: ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b", "c"], barCount: 4, barLength: 1, cellWidth: 0, cellHeight: 0, keyboardWidth: 0, pianoRollHeight: 0, menuBarHeight: 0, pianoRoll: null, colHighlight: null, noteSprites: [], keySprites: [], keyboardLines: null, menuBar: null, selectedNote: {}, velocityDisplayNote: null, init: function() { this.drawKeyboard(); this.eventListeners() }, eventListeners: function() { $(document).on("mousedown touchmove", ".pr-button", function() { if ("vibrate" in navigator) { // vibration API supported navigator.vibrate([ 20, 10 ]); } /** // enable vibration support navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { // vibration API supported } */ var type = $(this).data("type"); var step = $(this).data("col-id"); var pattern = song.patterns[editor.instrumentID][editor.patternID].pattern; if (pattern[step][0]) { var currentSetting = pattern[step][0][type]; if (currentSetting) { pattern[step][0][type] = 0 } else { pattern[step][0][type] = 1; if (type == "octUp") pattern[step][0]["octDown"] = 0; if (type == "octDown") pattern[step][0]["octUp"] = 0 } } editor.drawNotes() }).on("mousedown", ".js-pr-pattern-select", function() { var id = $(this).data("pattern-id"); var currentBank = song.currentBank[editor.instrumentID]; var newPatternID = currentBank * 8 + id; editor.patternID = newPatternID; song.currentPattern[editor.instrumentID] = newPatternID; editor.refresh() }).on("mousedown", ".js-pr-bank-select", function() { var newBank = $(this).data("bank-id"); var currentBank = song.currentBank[editor.instrumentID]; var currentPattern = song.currentPattern[editor.instrumentID]; var displayPatternID = editor.patternID - currentBank * 8; var newPattern = displayPatternID + newBank * 8; song.currentBank[editor.instrumentID] = newBank; song.currentPattern[editor.instrumentID] = newPattern; editor.patternID = newPattern; editor.refresh() }).on("mousedown", ".js-pr-randomise", function() { editor.buttonFlash($(this)); app.randomiseNotes(editor.instrumentID, editor.patternID); editor.refresh() }).on("mousedown", ".js-pr-clear", function() { editor.buttonFlash($(this)); if (!song.patterns[editor.instrumentID][editor.patternID]) return; app.clearPattern(editor.instrumentID, editor.patternID); editor.refresh() }).on("mousedown", ".instrument-selector-button", function() { $(".instrument-selector-button").removeClass("pr-button-active2"); $(this).addClass('pr-button-active2'); editor.buttonFlash($(this)); var id = $(this).data("instrument-key"); editor.instrumentID = id; editor.refresh() }).on("mousedown", ".js-piano-roll-key", function() { var id = $(this).data("id"); id += 3 * 12; editor.velocityDisplayNote = id; editor.drawVelocity() }).on("mousedown", ".js-ptn-length", function() { var barLength = $(this).data("pattern-length"); editor.patternLength = 16 * barLength; editor.setPatternLength(barLength); $(".js-ptn-length").removeClass("length-button-active"); $('.js-ptn-length[data-pattern-length="' + barLength + '"').addClass("length-button-active") }).on("mousedown", ".js-clipboard", function() { var type = $(this).data("type"); if (type == "copy") { if (song.patterns[editor.instrumentID][editor.patternID]) { clipboard.contents = JSON.parse(JSON.stringify(song.patterns[editor.instrumentID][editor.patternID])) } else { //console.log("Tried to copy non-existing pattern") } } else if (type == "paste") { if (clipboard.contents !== null) { song.patterns[editor.instrumentID][editor.patternID] = JSON.parse(JSON.stringify(clipboard.contents)); editor.refresh() } } editor.buttonFlash($(this)) }).on("mousedown", ".js-ptn-shift", function() { editor.buttonFlash($(this)); var direction = $(this).data("direction"); var currentPattern = song.patterns[editor.instrumentID][editor.patternID]; if (!currentPattern) return; var patternLength = currentPattern.barLength * 16; function shiftY(amount) { var newVal; var maxVal = 48; var minVal = 36; for (var i = 0; i < patternLength; i++) { var step = currentPattern.pattern[i]; for (var i2 = 0; i2 < step.length; i2++) { if (step[i2].val) { newVal = step[i2].val + amount; if (newVal > maxVal) { newVal = minVal } else if (newVal < minVal) { newVal = maxVal } step[i2].val = newVal } } } } function shiftX(amount) { var patternCopy = { barLength: currentPattern.barLength, pattern: [] }; for (var i = 0; i < patternLength; i++) { var step = currentPattern.pattern[i]; var newPos = i + amount; if (amount > 0) { if (newPos < patternLength) { patternCopy.pattern[newPos] = step } else { patternCopy.pattern[0] = step } } else { if (newPos < 0) { patternCopy.pattern[patternLength - 1] = step } else { patternCopy.pattern[newPos] = step } } } song.patterns[editor.instrumentID][editor.patternID] = patternCopy } if (direction == "left") { shiftX(-1) } else if (direction == "right") { shiftX(1) } else if (direction == "up") { shiftY(1) } else if (direction == "down") { shiftY(-1) } editor.refresh() }).on("mousedown", "#pr-grid td", function(e) { //touchmove mousemove if (e.buttons < 1) return; //console.log(e); var cell = $(this); var note = cell.data("row-id"); var step = cell.data("col-id"); var rightButton = false; //if note is set then un... // $(this).parent().hasClass(".note-active", function(){ // rightButton = true; // }); // if (e.which > 1) { // } editor.addNote(step, note, rightButton) }).on("touchmove mousemove mousedown", "#pr-velocity td", function(e) { if (e.buttons < 1) return; var step = $(this).data("col-id"); var totalHeight = $(this).height(); var offsetTop = $(this).offset().top; touch = undefined; if (e.originalEvent.touches) { touch = e.originalEvent.touches[0]; ////console.log(touch.pageY); // ui.mousePos = { // x: Math.round(touch.pageX), // y: Math.round(touch.pageY), // }; mouseOffset = Math.round(touch.pageY); } else { // ui.mousePos = { // x: e.pageX, // y: e.pageY, // }; mouseOffset = e.clientY; } // var mouseOffset = e.pageY; var difference = mouseOffset - offsetTop; var newHeight = totalHeight - difference; if (newHeight > totalHeight) newHeight = totalHeight; var percentage = Math.floor(newHeight / totalHeight * 100); var midiVal = Math.floor(127 / 100 * percentage); if (midiVal < 0) { midiVal = 0 } editor.setVelocity(step, midiVal) }) }, buttonFlash: function(button) { button.addClass("length-button-active"); setTimeout(function() { button.removeClass("length-button-active") }, 60) }, recompileTemplate: function() { //console.log("Recompling Template"); var screenTemplate = Handlebars.compile(templates["editor"]); var screenHtml = screenTemplate({ patternLength: editor.barLength * 16 }); //console.log(editor.barLength); $('.js-screen[data-screen-name="editor"]').html(screenHtml) }, setPatternLength: function(barLength) { if (!song.patterns[editor.instrumentID][editor.patternID]) { app.createPattern(editor.instrumentID, editor.patternID) } var pattern = song.patterns[editor.instrumentID][editor.patternID]; var newLength = 16 * barLength; var newPattern = new Array(newLength); pattern.barLength = barLength; if (pattern.pattern.length < newLength) { for (var i = 0; i < pattern.pattern.length; i++) { newPattern[i] = pattern.pattern[i] } for (var i = pattern.pattern.length; i < newLength; i++) { newPattern[i] = [] } pattern.pattern = newPattern } this.barLength = barLength; this.setGridLength(newLength); editor.refresh(); if (barLength > 1) { for (var i in song.patternList[editor.instrumentID]) { if (song.patternList[editor.instrumentID][i] == editor.patternID) { //console.log("Found this pattern in the patternList: " + i); var nextBar = parseInt(i) + 1; if (song.patternList[editor.instrumentID].hasOwnProperty(nextBar)) { delete song.patternList[editor.instrumentID][nextBar] } } } } }, setGridLength: function(newSize) { var gridSize = $("#pr-grid tr:nth-child(2) td").length; if (newSize > gridSize) {} $("#pr-grid").html(function() { var html = ""; for (var row = 12; row >= 0; row--) { html = html + ""; for (var col = 0; col < newSize; col++) { html = html + '' } html = html + "" } return html }); $("#pr-buttons").html(function() { var htmlSample = $("#pr-buttons tr td").html(); var html = ""; for (var i = 0; i < newSize; i++) { var col = $("", { html: htmlSample }); col.find("div").each(function() { $(this).attr("data-col-id", i) }, i); html = html + "" + col.html() + "" } html = html + ""; return html }); $("#pr-velocity tr").html(function() { var html; for (var i = 0; i < newSize; i++) { html = html + '
' } return html }); $(".pr-lights tr").html(function() { var html; for (var i = 0; i < newSize; i++) { html = html + '
' + (i + 1) + "
" } return html }); var colCount = 0; $("#pr-grid td").each(function() { if (colCount > 0 && colCount % 4 === 0) { $(this).css({ "border-left": "1px solid #000000" }) } colCount++ }); this.drawNotes() }, drawKeyboard: function() { var notes = this.notes; var instrument = song.instruments[editor.instrumentID]; if (instrument && instrument.drummaskin) { var drumLabels = instrument.sampleKits[instrument.selectedKit].labels; $(".js-piano-roll-key").each(function() { var count = $(this).data("id"), background = "#505050", color = "#efefef"; $(this).css({ background: background, color: color }).html(" "); if (drumLabels[count]) { $(this).html(drumLabels[count].toUpperCase()).addClass("drum-label") } }) } else { $(".js-piano-roll-key").each(function() { var count = $(this).data("id"), background = "#fff", color = "#333"; if (notes[count].length > 1) { background = "#121314"; color = "#efefef" } $(this).css({ background: background, color: color }).html(notes[count].toUpperCase()) }) } }, updateInstrumentSelector: function() { $("#pr-instrument-selector").html(""); var icount = 0; for (var key in song.instruments) { var selected = "pr-button-active2"; if (song.instruments.hasOwnProperty(key)) { var name = song.instruments[key].instrumentName; if (editor.instrumentID == key) { //console.log(""); selected = "pr-button-active2" } else { selected = ""; } $("#pr-instrument-selector").append(''); } } }, refresh: function() { this.velocityDisplayNote = null; if (!this.instrumentID) { for (var key in song.instruments) { if (song.instruments.hasOwnProperty(key)) { editor.instrumentID = key; break } } } if (song.instruments[this.instrumentID].maskinName == "rave_synth" || song.instruments[this.instrumentID].maskinName == "sinth1") { $("#pr-buttons").show(); $("#pr-velocity").hide() } else { $("#pr-buttons").hide(); $("#pr-velocity").show() } this.patternID = song.currentPattern[this.instrumentID]; if (song.patterns[this.instrumentID][this.patternID]) { this.barLength = song.patterns[this.instrumentID][this.patternID].barLength } else { this.barLength = 1 } this.patternLength = this.barLength * 16; this.updateInstrumentSelector(); this.drawKeyboard(); this.setGridLength(this.patternLength); this.drawVelocity(); $(".js-ptn-length").removeClass("length-button-active"); if (song.patterns[this.instrumentID][this.patternID]) { $('.js-ptn-length[data-pattern-length="' + editor.barLength + '"]').addClass("length-button-active") } else { $('.js-ptn-length[data-pattern-length="1"]').addClass("length-button-active") } }, cellClick: function(input) {}, setVelocity: function(step, midiVal) { var container = $('#pr-velocity td[data-col-id="' + step + '"]'); var col = step; if (!song.patterns[this.instrumentID][editor.patternID]) return; var step = song.patterns[this.instrumentID][editor.patternID].pattern[col]; if (step.length < 1) return; var velocitySet = false; for (var key in step) { velocitySet = false; if (step[key].val != editor.velocityDisplayNote) { continue } step[key].veloc = midiVal; var percentage = midiVal / 127 * 100; $('.js-velocity-level[data-col-id="' + col + '"]').height(percentage + "%"); break } }, addNote: function(stepNumber, noteNumber, rightButton) { var currentPattern = editor.patternID; if (!song.patterns[this.instrumentID][editor.patternID]) { app.createPattern(this.instrumentID, editor.patternID) } var step = song.patterns[this.instrumentID][editor.patternID].pattern[stepNumber]; var monophonic = false; if (song.instruments[this.instrumentID].monophonic) { monophonic = true } noteNumber += 12 * 3; var noteData = { type: 0, start: stepNumber, val: noteNumber, duration: 1, offset: 0 }; if (song.instruments[this.instrumentID].maskinName == "rave_synth") { noteData.slide = 0; noteData.accent = 0; noteData.octUp = 0; noteData.octDown = 0 } else if (song.instruments[this.instrumentID].maskinName == "sinth1") { noteData.slide = 0; noteData.accent = 0; noteData.octUp = 0; noteData.octDown = 0 } else { noteData.veloc = 110 } if (monophonic && step.length > 0) { if (step[0].val == noteNumber) { if (1) { rightButton = true; // WORKAROUND PAD! step.splice(0, 1); this.selectNote(noteNumber, false, false) // } else { // this.selectNote(noteNumber, stepNumber, step[0]) // }' } } else { if (!rightButton) { step[0].val = noteNumber; this.selectNote(noteNumber, stepNumber, step[0]) } } } else { for (var i = 0; i < step.length; i++) { if (step[i].val == noteNumber) { // if (rightButton) { if (1) { rightButton = true; // WORKAROUND PAD! step.splice(i, 1); this.selectNote(noteNumber, false, false); break } else { this.selectNote(noteNumber, stepNumber, step[0]); return } } } if (!rightButton) { step.push(noteData); this.selectNote(noteNumber, stepNumber, step[0]) } } this.drawNotes() }, clearNotes: function() { $(".note-active").each(function() { $(this).removeClass("note-active").html("") }); $(".pr-button-active").removeClass("pr-button-active") }, drawNotes: function() { this.clearNotes(); var currentPattern = editor.patternID; var patternData = []; var patternLength = 16; if (song.patterns[this.instrumentID][currentPattern]) { var pattern = song.patterns[this.instrumentID][currentPattern]; patternData = pattern.pattern; patternLength = 16 * pattern.barLength } var note, noteName; for (var i = 0; i < patternLength; i++) { for (var key in patternData[i]) { note = patternData[i][key].val; if (!note) continue; var newNote = note - 12 * 3; noteName = this.notes[newNote]; var cell = $("#pr-grid").find('[data-row-id="' + newNote + '"][data-col-id="' + i + '"]'); if (song.instruments[this.instrumentID].maskinName == "rave_synth" || song.instruments[this.instrumentID].maskinName == "sinth1") { var textString = ""; if (patternData[i][key].accent) { textString += "A"; $("#pr-buttons").find('[data-col-id="' + i + '"][data-type="accent"]').addClass("pr-button-active") } if (patternData[i][key].slide) { textString += "S"; $("#pr-buttons").find('[data-col-id="' + i + '"][data-type="slide"]').addClass("pr-button-active") } if (patternData[i][key].octUp) { textString += "▲"; $("#pr-buttons").find('[data-col-id="' + i + '"][data-type="octUp"]').addClass("pr-button-active") } if (patternData[i][key].octDown) { textString += "▼"; $("#pr-buttons").find('[data-col-id="' + i + '"][data-type="octDown"]').addClass("pr-button-active") } } cell.addClass("note-active"); cell.html(textString) } } var posBar = 100 / patternLength; $(".pr-pos-highlight").css({ width: posBar + "%" }); editor.highlightPattern(); editor.highlightBank() }, highlightPattern: function() { var displayPatternID = editor.patternID - song.currentBank[editor.instrumentID] * 8; $('.js-pr-pattern-select[data-pattern-id="' + displayPatternID + '"]').addClass("pr-button-active") }, highlightBank: function() { $('.js-pr-bank-select[data-bank-id="' + song.currentBank[editor.instrumentID] + '"]').addClass("pr-button-active") }, drawVelocity: function() { $("#pr-velocity td").html(""); $(".js-velocity-title").html(""); if (song.instruments[editor.instrumentID].drummaskin && editor.velocityDisplayNote) { var instrument = song.instruments[editor.instrumentID]; var drumLabels = instrument.sampleKits[instrument.selectedKit].labels; var drumID = editor.velocityDisplayNote - 12 * 3; if (drumLabels[drumID]) { $(".js-velocity-title").html("Velocity:
" + drumLabels[drumID].toUpperCase()) } } var currentPattern = editor.patternID; var patternData = []; var patternLength = 16; if (song.patterns[this.instrumentID][currentPattern]) { var pattern = song.patterns[this.instrumentID][currentPattern]; patternData = pattern.pattern; patternLength = pattern.barLength * 16 } var note, newNote, velocity, velocityHtml; for (var i = 0; i < patternLength; i++) { for (var key in patternData[i]) { note = patternData[i][key].val; if (!note) continue; if (note != editor.velocityDisplayNote) continue; newNote = note - 12 * 3; velocity = patternData[i][key].veloc; velocityHtml = '
'; $('#pr-velocity td[data-col-id="' + i + '"]').html(velocityHtml); editor.setVelocity(i, velocity) } } }, deleteNote: function() { if (this.selectedNote.noteNumber) { var step = song.patterns[this.instrumentID][song.currentPattern[this.instrumentID]].pattern[this.selectedNote.stepNumber]; for (var i = 0; i < step.length; i++) { if (step[i].val == this.selectedNote.noteNumber) { step.splice(i, 1); this.selectedNote = {}; this.drawNotes() } } } }, selectNote: function(noteNumber, stepNumber, noteData) { var optionsContainer = $("#pr-note-options"); //console.log(stepNumber); if (stepNumber === false) { //console.log("Clearing Selected Note"); this.selectedNote = {}; optionsContainer.html(""); this.velocityDisplayNote = noteNumber; this.drawVelocity(); return } //console.log("Select Note"); this.selectedNote = { noteNumber: noteNumber, stepNumber: stepNumber, noteData: noteData }; optionsContainer.html("Note: " + noteNumber + "
Step: " + stepNumber + "
"); this.velocityDisplayNote = noteNumber; this.drawVelocity() }, stepHighlight: function(step) { var ptnLength = song.patterns[this.instrumentID][this.patternID]["pattern"].length; if (app.currentBar > 0 && (app.currentBar + 1) % 2 === 0 && ptnLength > 16) { step += 16 } $(".pr-pos-light-on").removeClass("pr-pos-light-on"); if (step > document.getElementById("pr-lights").rows[0].cells.length - 1) { step -= 16 } $(".pr-pos-light").removeClass("pr-pos-light-on"); $('.pr-pos-light[data-col-id="' + step + '"]').addClass("pr-pos-light-on") } }; var sequencer = { cellWidth: 4, maxBars: 256, clickCount: 0, instrumentCount: 0, selected: {}, loopStart: 0, loopEnd: 15, // 15 ,,, 16-1 ... 32-1 init: function(firstTime) { if (typeof firstTime == "undefined") { firstTime = true } //console.log("Sequencer Init"); if (firstTime) { this.eventListeners(); this.animate() } this.addInstruments(); this.selected = {}; for (var instrumentID in song.instruments) { this.selected[instrumentID] = [0, 0] } this.updatePatternSelector() }, updatePatternSelector: function() { $(".js-seq-bank-select").removeClass("btn-pattern-on"); $(".js-seq-pattern-select").removeClass("btn-pattern-on"); for (var instrumentID in this.selected) { // //console.log("Updating ptn selector: " + instrumentID); $('.js-seq-bank-select[data-bank-id="' + sequencer.selected[instrumentID][0] + '"][data-instrument-id="' + instrumentID + '"]').addClass("btn-pattern-on"); $('.js-seq-pattern-select[data-pattern-id="' + sequencer.selected[instrumentID][1] + '"][data-instrument-id="' + instrumentID + '"]').addClass("btn-pattern-on") // $('.js-seq-bank-select[data-bank-id="' + sequencer.selected[instrumentID][0] + '"]').addClass("btn-pattern-on"); // $('.js-seq-pattern-select[data-pattern-id="' + sequencer.selected[instrumentID][1] + '"]').addClass("btn-pattern-on") } }, eventListeners: function() { $(document).on("touchmove touchstart mousemove mousedown", ".js-seq-table", function(e) { if (e.buttons < 1) return; var rightButton = false; if (e.buttons > 1) rightButton = true; //console.log(">>>", rightButton); var instrumentID = $(e.target).closest("tr").data("instrument-id"); if ($(e.target).is("td")) { var td = $(e.target) } else { var td = $(e.target).closest("td") } var bar = td.parent().children().index(td); var bankLabels = ["A", "B", "C", "D"]; var pattern = sequencer.selected[instrumentID][0] * 8 + sequencer.selected[instrumentID][1]; var label = bankLabels[sequencer.selected[instrumentID][0]] + sequencer.selected[instrumentID][1]; var params = { instrumentID: instrumentID, patternID: pattern, bar: bar, label: label, cell: e.target, rightButton: rightButton, e: e }; sequencer.addPattern(params); var overlap = false; if (sequencer.checkPreviousBarOverlap(instrumentID, bar)) { overlap = true; bar = bar - 1 } if ((!$(e.target).is("td") || overlap) && !rightButton) { //console.log("Left click on seq block;"); if (app.songMode && app.sequencePlaying) return; if (e.type != "mousedown") return; sequencer.clickCount++; // if (sequencer.clickCount >= 2) { // OPENS EDITOR FROM SEQUENCE // editor.instrumentID = instrumentID; // var editPattern = song.patternList[instrumentID][bar]; // var bank = Math.floor(editPattern / 8); // editPattern = editPattern - 8 * bank; // song.currentPattern[instrumentID] = song.patternList[instrumentID][bar]; // song.currentBank[instrumentID] = bank; // editor.patternID = editPattern; // editor.refresh(); // ui.changeScreen("editor") // } else { sequencer.setCurrentPattern(instrumentID, bar) // } setTimeout(function() { sequencer.clickCount = 0 }, 200) } }).on("mousedown", ".js-seq-pattern-select", function() { var instrumentID = $(this).data("instrument-id"); var patternID = $(this).data("pattern-id"); sequencer.selected[instrumentID][1] = patternID; sequencer.updatePatternSelector() }).on("mousedown", ".js-seq-bank-select", function() { var instrumentID = $(this).data("instrument-id"); var bankID = $(this).data("bank-id"); sequencer.selected[instrumentID][0] = bankID; sequencer.updatePatternSelector() }).on("mousedown", ".js-seq-numbers td", function() { if (!app.songMode) { var test = $('.js-transport[data-name="mode"]'); test.mousedown() } var bar = $(this)[0].cellIndex; var wasPlaying = false; if (app.sequencePlaying) { app.stopSequence(); wasPlaying = true } app.currentBar = bar; sequencer.loopStart = bar; sequencer.loopEnd = bar; sequencer.barHighlight(); if (wasPlaying) { app.playSequence() } }).on("mousemove touchmove", ".js-seq-numbers td", function() { if (!app.songMode) return; if (ui.mouseDown) { var bar = $(this)[0].cellIndex; if (bar !== app.currentBar) { sequencer.loopStart = app.currentBar; sequencer.loopEnd = bar } } sequencer.highlightLoop() }) }, refresh: function() { $(".js-seq-table").find("tr td").html(""); var bankLabels = ["A", "B", "C", "D"]; var pattern, bank, displayPattern, label, barLength; var i = 0; for (var instrumentID in song.patternList) { for (var bar in song.patternList[instrumentID]) { if (bar >= app.maxSongBars) break; if (typeof song.patternList[instrumentID][bar] !== "undefined") { pattern = song.patternList[instrumentID][bar]; bank = Math.floor(pattern / 8); displayPattern = pattern - 8 * bank + 1; label = bankLabels[bank] + displayPattern; barLength = 1; // barLength = 0.5; if (typeof song.patterns[instrumentID][pattern] !== "undefined") { barLength = song.patterns[instrumentID][pattern].barLength } blockWidth = barLength * sequencer.cellWidth; console.warn(i, bar); document.getElementById("seq-table").rows[i].cells[bar].innerHTML = '
' + label + "
" } } i++ } if (app.sequencePlaying && app.songMode) { this.barHighlight() } var instrumentCount = 0; for (var i in song.instruments) { instrumentCount++ } this.instrumentCount = instrumentCount; this.updatePatternSelector() }, addInstruments: function() { this.recompileTemplate() }, cellClick: function() {}, recompileTemplate: function() { //console.log("Recompling Template"); var instrumentData = []; for (var key in song.instruments) { instrumentData.push({ instrumentName: song.instruments[key].instrumentName, instrumentID: key }) } var templateData = { cellWidth: sequencer.cellWidth, songBars: sequencer.maxBars, instruments: instrumentData, tableWidth: sequencer.maxBars * 4, banks: ["A", "B", "C", "D"] }; var screenTemplate = templates["sequencer"]; var screenHtml = screenTemplate(templateData); $('.js-screen[data-screen-name="sequencer"]').html(screenHtml); for (var key in song.instruments) { var colCount = 0; var altCol = false; var css = { background: "rgba(0,0,0,0)" }; $('.js-seq-table tr[data-instrument-id="' + key + '"] td').each(function() { if (colCount % 4 === 0) { if (!altCol) { altCol = true; css["background"] = "rgba(0,0,0,0.1)"; css["background"] = "rgba(0,0,0,0.1)" } else { altCol = false; css["background"] = "rgba(0,0,0,0)" } } if ((colCount + 1) % 4 === 0) { css["border-right"] = "2px solid rgba(255,255,255,1)" } else { css["border-right"] = "1px solid rgba(123,123,123,1)" } $(".js-seq-numbers td:eq(" + colCount + ")").css({ "border-right": css["border-right"] }); $(this).css(css); $(this).attr("data-background", css["background"]); colCount++ }) } }, checkPreviousBarOverlap: function(instrumentID, bar) { if (song.patternList[instrumentID].hasOwnProperty(bar - 1)) { if (typeof song.patterns[instrumentID][song.patternList[instrumentID][bar - 1]] != "undefined") { if (song.patterns[instrumentID][song.patternList[instrumentID][bar - 1]].barLength > 1) { return true } } } return false }, checkNextBarOverlap: function(instrumentID, bar) { //console.log("Checking if bar: " + bar + " of " + instrumentID + " overlaps with the next one."); var currentPattern = sequencer.selected[instrumentID][1]; if (typeof song.patterns[instrumentID][currentPattern] != "undefined") { if (song.patterns[instrumentID][currentPattern].barLength > 1) { if (song.patternList[instrumentID].hasOwnProperty(bar + 1)) { //console.log("Preventing overlap"); return true } } } return false }, addPattern: function(params) { //console.log("ADD", params.e); if (!song.patternList[params.instrumentID].hasOwnProperty(params.bar) && !params.rightButton) { if (sequencer.checkPreviousBarOverlap(params.instrumentID, params.bar)) { return } if (sequencer.checkNextBarOverlap(params.instrumentID, params.bar)) { return } song.patternList[params.instrumentID][params.bar] = params.patternID } else { if (params.rightButton) { var toDelete = params.bar; if (!song.patternList[params.instrumentID].hasOwnProperty[toDelete]) { if (sequencer.checkPreviousBarOverlap(params.instrumentID, params.bar)) { toDelete = params.bar - 1 } } delete song.patternList[params.instrumentID][toDelete] } else { this.setCurrentPattern(params.instrumentID, params.bar) } } this.refresh() }, setCurrentPattern: function(instrumentID, bar) { var pattern = song.patternList[instrumentID][bar]; var bank = Math.floor(pattern / 8); this.selected[instrumentID] = [bank, pattern]; this.updatePatternSelector() }, clearHighlight: function() { var tds = document.getElementById("seq-table").getElementsByTagName("td"); for (var i = 0; i < tds.length; i++) { tds[i].style.background = tds[i].getAttribute("data-background") } var tds = document.getElementById("seq-numbers").getElementsByTagName("td"); for (var i = 0; i < tds.length; i++) { tds[i].style.background = "" } sequencer.highlightLoop(); var posMarkers = document.getElementsByClassName("seq-pos-marker"); for (var i = 0; i < posMarkers.length; i++) { posMarkers[i].style.display = "none" } }, barHighlight: function() { var bar = app.currentBar; var instrumentCount = this.instrumentCount; this.clearHighlight(); for (var i = 0; i < instrumentCount; i++) { document.getElementById("seq-table").rows[i].cells[bar].style.background = "rgba(255,255,255,0.2)" } var pos = document.getElementById("seq-numbers").rows[0].cells[bar]; pos.style.background = "rgba(0,0,0,0.3)"; var cellWidth = $(".js-seq-numbers"); cellWidth = cellWidth[0].clientWidth / this.maxBars; //console.log(cellWidth); var markerPos = cellWidth * bar; if (!app.sequencePlaying) { $("#seq-pos-marker-2").css({ transform: "translateX(" + markerPos + "px)" }) } }, highlightLoop: function() { $(".seq-loop-highlight").removeClass("seq-loop-highlight"); if (sequencer.loopEnd - sequencer.loopStart < 1) { return } for (var i = sequencer.loopStart; i <= sequencer.loopEnd; i++) { $(".js-seq-numbers td:eq(" + i + ")").addClass("seq-loop-highlight") } }, animate: function() { var self = this; requestAnimationFrame(function() { if (app.currentScreen == "sequencer" && app.songMode && app.sequencePlaying) { var step = app.currentStep; var secondsPerBeat = 60 / app.tempo; var secondsPerStep = secondsPerBeat / 4; var stepPlayed = app.context.currentTime - app.lastStepTime; var percentage = Math.min(stepPlayed / secondsPerStep * 100, 100); percentage = Math.max(percentage, 0); var cellWidth = $(".js-seq-numbers"); cellWidth = cellWidth[0].clientWidth / self.maxBars; var stepWidth = cellWidth / 16; var markerPos = app.currentBar * cellWidth; markerPos += app.currentStep * stepWidth; markerPos += stepWidth / 100 * percentage; document.getElementById("seq-pos-marker-2").style.transform = "translateX(" + markerPos + "px)" } self.animate() }) } }; var options = { randScale: 11, randSplitNum: 4, randEmpty: 4, init: function(firstTime) { //console.log("OPTIONS INIT"); if (firstTime) { this.compileTemplate(); this.eventListeners() } }, setOption: function(key, value) { if (value) { options[key] = parseInt(value); options.compileTemplate() } }, refresh: function() { var randOptions = ["randScale", "randSplitNum", "randEmpty"]; for (var i = 0; i < randOptions.length; i++) { storage.getItem(randOptions[i], this.setOption) } }, compileTemplate: function() { //console.log("Compling Template"); var templateData = { midiDevices: midi.devices, scales: scales, splitNumOptions: [1, 2, 3, 4, 6, 8], emptyNoteOptions: [0, 2, 4, 8], currentOptions: { scale: options.randScale, splitNum: options.randSplitNum, empty: options.randEmpty } }; var screenTemplate = templates["options"]; var screenHtml = screenTemplate(templateData); $('.js-screen[data-screen-name="options"]').html(screenHtml) }, eventListeners: function() { $(document).on("mousedown", ".js-midi-clear-mappings", function() { notification.show({ message: "Are you sure you want to clear all MIDI control mappings?", type: "confirm", callback: midi.clearMappings }) }).on("change", ".js-random-option", function() { var randParam = $(this).data("name"); var val = $(this).val(); options[randParam] = parseInt(val); storage.setItem(randParam, val) }) } }; function fxUnit() { this.type = null; this.uniqueID = null; this.channel = null; this.slot = null; this.fxNames = ["distortion", "phaser", "chorus", "filter", "wahwah", "delay", "reverb", "compressor", "moog", "bitcrusher", "panner"]; // this.defaults = [ [{ /** DISTORTION:OVERDRIVE */ label: "Bypass", type: "button", value: 0 }, { label: "Curve", type: "knob", value: 64 } ], /** PHASER */ [{ label: "Bypass", type: "button", value: 0 }, { label: "Rate", type: "knob", value: 64 }, { label: "Depth", type: "knob", value: 64 }, { label: "Fdbk", type: "knob", value: 64 }, { label: "dryLevel", type: "knob", value: 64 }, { label: "wetLevel", type: "knob", value: 64 }], /** CHORUS */ [{ label: "Bypass", type: "button", value: 0 }, { label: "Rate", type: "knob", value: 16 }, { label: "Fdbk", type: "knob", value: 32 }, { label: "Delay", type: "knob", value: 4 } ], /** FILTER */ [{ label: "Bypass", type: "button", value: 0 }, { label: "Freq", type: "knob", value: 64 }, { label: "Reso", type: "knob", value: 64 }, { label: "Type", type: "knob", value: 0 } ], /** WAH WAHWAH */ [{ label: "Bypass", type: "button", value: 0 }, { label: "Freq", type: "knob", value: 64 }, { label: "Sweep", type: "knob", value: 64 }, { label: "Sens.", type: "knob", value: 64 } ], /** DELAY */ [{ label: "Bypass", type: "pbutton", value: 0 }, { label: "Fdbk", type: "knob", value: 64 }, { label: "Cutoff", type: "knob", value: 64 }, { label: "Steps", type: "knob", value: 64 }, { label: "dryLevel", type: "knob", value: 64 }, { label: "wetLevel", type: "knob", value: 64 }], /** REVERB CONVOLVER */ [{ label: "Bypass", type: "pbutton", value: 0 }, { label: "wetLevel", type: "knob", value: 120 }, { label: "High", type: "knob", value: 120 }, { label: "Low", type: "knob", value: 1 }, { label: "dryLevel", type: "knob", value: 64 }], /** COMPRESSOR */ [{ label: "Bypass", type: "pbutton", value: 0 }, { label: "wetLevel", type: "knob", value: 48 }, { label: "High", type: "knob", value: 32 }, { label: "Low", type: "knob", value: 6 }, { label: "dry", type: "dryLevel", value: 6 }], /** MOOG */ [{ label: "Bypass", type: "pbutton", value: 0 }, { label: "wetLevel", type: "knob", value: 48 }, { label: "High", type: "knob", value: 32 }, { label: "Low", type: "knob", value: 6 }, { label: "dryLevel", type: "knob", value: 64 }, { label: "wetLevel", type: "knob", value: 64 }], /** BITCRUSHER */ [{ label: "Bypass", type: "pbutton", value: 0 }, { label: "wetLevel", type: "knob", value: 48 }, { label: "High", type: "knob", value: 32 }, { label: "Low", type: "knob", value: 6 }, { label: "dryLevel", type: "knob", value: 64 }], /** PANNER */ [{ label: "Bypass", type: "pbutton", value: 0 }, { label: "wetLevel", type: "knob", value: 48 }, { label: "High", type: "knob", value: 32 }, { label: "Low", type: "knob", value: 6 }, { label: "dryLevel", type: "knob", value: 64 }, { label: "wetLevel", type: "knob", value: 64 }] ]; this.controls = [] } fxUnit.prototype.init = function() { console.warn("aga" + this.type); if (this.type != parseInt(this.type)) { // reverb-tweak //if (parseInt(this.type) > 10 || parseInt(this.type) == "") { // reverb-tweak this.type = 6; } console.warn("aga2" + this.type); //Set the default control values var defaults = this.defaults[this.type]; this.controls = defaults; for (var i = 0; i < defaults.length; i++) { this.setControlValue(i, defaults[i].value); } // this.defaults = []; //kilian hmm kan varit bort-kommenderad..ZZZZ this.initControlValues(); //console.log("Created a new effect unit in channel " + this.channel + ", slot: " + this.slot); //console.log("Type: " + this.type + " (" + this.fxNames[this.type] + ")"); //console.log("Unique ID: " + this.uniqueID) }; fxUnit.prototype.initControlValues = function() { for (var i = 0; i < this.controls.length; i++) { this.setControlValue(i, this.controls[i].value); //console.log("Init control: " + i + " Val: " + this.controls[i].value) } }; fxUnit.prototype.setControlValue = function(controlID, value) { //console.log("FX: " + this.uniqueID + ": " + controlID + " : ", value); this.controls[controlID].value = value; var paramName = null; value = parseInt(value); var newValue; if (this.type === 0) { /** OVERDRIVE DISTORTION */ //console.log("##", 0); switch (controlID) { case 1: newValue = value / 127; paramName = "curveAmount"; break } } else if (this.type == 1) { /** PHASER */ //console.log("##", 1); switch (controlID) { case 1: newValue = value / 127 * 8 + .01; paramName = "rate"; break; case 2: newValue = value / 127; paramName = "depth"; break; case 3: newValue = value / 127 * .9; paramName = "feedback"; break } } else if (this.type == 2) { /** CHORUS */ //console.log("##", 2); switch (controlID) { case 1: newValue = value / 127 * 8 + .01; paramName = "rate"; break; case 2: newValue = value / 127 * .9; paramName = "feedback"; break; case 3: newValue = value / 127; paramName = "delay"; break } } else if (this.type == 3) { /** FILTER */ //console.log("##", 3); switch (controlID) { case 1: newValue = Math.round(value / 127 * 500 + 30); // 16030 + 129 paramName = "frequency"; break; case 2: newValue = value / 127 * 26; paramName = "Q"; break; case 3: var types = ["lowpass", "highpass", "bandpass", "lowshelf", "highshelf", "peaking", "notch", "allpass"]; newValue = Math.round(value / 127 * 7); newValue = types[newValue]; paramName = "filterType"; break } } else if (this.type == 4) { /** WAHWAH */ //console.log("##", 4); switch (controlID) { case 1: newValue = value / 127; paramName = "frequency"; break; case 2: newValue = value / 127; paramName = "sweep"; break; case 3: newValue = value / 127; paramName = "sensitivity"; break; case 4: newValue = Math.round(value / 127 * 6); paramName = "excursionOctaves"; break } } else if (this.type == 5) { /** DELAY */ //console.log("##", 5); switch (controlID) { case 1: newValue = value / 127 * .8; paramName = "feedback"; break; case 2: newValue = Math.round(value / 127 * 20030 + 150); paramName = "cutoff"; break; case 3: var timesteps = [ // 1/512, // 1/256, 1 / 128, 1 / 64, 1 / 48, // 1/f32, // 1/24, // 1/16, 1 / 8, 1 / 6, 1 / 4, 1 / 3, 1 / 2, 1, 2, 2, 2, 3, 4, 4, 4, 4, 4, 4, 6, 8 // 3, 4, 4, // 6,6,6, // 8,10,12, // 14,16,24 ]; /** */ newValue = Math.round(value / 127 * (timesteps.length - 1)); newValue = timesteps[newValue]; newValue = app.stepSpeed * newValue; paramName = "delayTime"; break; case 4: newValue = value / 127; paramName = "dryLevel"; break; case 5: newValue = value / 127; paramName = "wetLevel"; break } } else if (this.type == 6) { //console.log("##", 6); switch (controlID) { case 1: newValue = value / 127 * 1; paramName = "wetLevel"; break; case 2: newValue = value / 127 * 5000 + 20; paramName = "highCut"; break; case 3: newValue = value / 127 * 5000 + 20; paramName = "lowCut"; break; case 4: newValue = value / 127; paramName = "dryLevel"; break } } else if (this.type == 7) { switch (controlID) { case 1: newValue = value / 127 * 1; paramName = "wetLevel"; break; case 2: newValue = value / 127 * 5000 + 20; paramName = "highCut"; break; case 3: newValue = value / 127 * 5000 + 20; paramName = "lowCut"; break; case 4: newValue = value / 127; paramName = "dryLevel"; break } } else if (this.type == 8) { switch (controlID) { case 1: newValue = value / 127 * 1; paramName = "wetLevel"; break; case 2: newValue = value / 127 * 5000 + 20; paramName = "highCut"; break; case 3: newValue = value / 127 * 5000 + 20; paramName = "lowCut"; break; case 4: newValue = value / 127; paramName = "dryLevel"; break; case 5: newValue = value / 127; paramName = "wetLevel"; break } } else if (this.type == 9) { switch (controlID) { case 1: newValue = value / 127 * 1; paramName = "wetLevel"; break; case 2: newValue = value / 127 * 5000 + 20; paramName = "highCut"; break; case 3: newValue = value / 127 * 5000 + 20; paramName = "lowCut"; break; case 4: newValue = value / 127; paramName = "dryLevel"; break; case 5: newValue = value / 127; paramName = "wetLevel"; break } } else if (this.type == 10) { switch (controlID) { case 1: newValue = value / 127 * 1; paramName = "wetLevel"; break; case 2: newValue = value / 127 * 5000 + 20; paramName = "highCut"; break; case 3: newValue = value / 127 * 5000 + 20; paramName = "lowCut"; break; case 4: newValue = value / 127; paramName = "dryLevel"; break; case 5: newValue = value / 127; paramName = "wetLevel"; break } } if (controlID === 0) { paramName = "bypass"; newValue = value } if (paramName !== null) { //console.log("FX Val: " + newValue); mixer.channels[this.channel].fxSlots[this.slot][paramName] = newValue } }; var clipboard = { contents: null }; var midi = { midiAcess: null, inputDeviceID: null, outputDeviceID: null, output: null, active: false, tempInstrument: null, connected: false, devices: {}, deviceMapping: {}, learn: false, learnSelected: { type: null, instrument: null, instrumentCount: null, controlID: null, controlType: null }, init: function() { //console.log("Starting MIDI...."); function onMIDISuccess(midiAccess) { //console.log("<===---MIDI INPUTS---===>"); //console.log(midiAccess.inputs); midi.connected = true; midi.midiAccess = midiAccess; var inputDeviceCount = midiAccess.inputs.size; var outputDeviceCount = midiAccess.outputs.size; var inputs = midiAccess.inputs.values(); for (var input = inputs.next(); input && !input.done; input = inputs.next()) { var deviceName = input.value.name; //console.log("MIDI Device: "); //console.log(input); if (input.value.type.toLowerCase() == "input") { midi.devices[input.value.id] = { id: input.value.id, name: deviceName, state: input.value.state, connection: input.value.connection, enabled: 1 }; midi.deviceMapping[input.value.id] = {} } } var inputs = midiAccess.inputs.values(); for (var input = inputs.next(); input && !input.done; input = inputs.next()) { input.value.onmidimessage = midi.midiMessage } storage.getItem("midiDeviceMapping", midi.setDeviceMapping); options.refresh() } function onMIDIFailure(e) { midi.connected = false; //console.log("No access to MIDI devices or your browser doesn't support WebMIDI API. Please use WebMIDIAPIShim " + e) } // if (navigator.requestMIDIAccess) { // navigator.requestMIDIAccess({ // sysex: false // }).then(onMIDISuccess, onMIDIFailure) // } else { // //console.log("No MIDI support in your browser.") // } }, setDeviceMapping: function(key, mappingJson) { //console.log("SET DEVICE MAPPING CALLBACK"); if (mappingJson) { //console.log("Mapping exists", mappingJson); midi.deviceMapping = JSON.parse(mappingJson) } else { //console.log("No device mapping") } }, midiMessage: function(message) { var deviceID = message.target.id; var data = message.data; var controlType = data[0]; var controlID = data[1]; var controlVal = data[2]; //console.log(controlID); if (controlType != 176) {} if (midi.learn) { //console.log(); if (midi.learnSelected.instrument !== null) { if (midi.deviceMapping.hasOwnProperty(deviceID)) { midi.deviceMapping[deviceID][controlID] = { type: midi.learnSelected.type, instrument: midi.learnSelected.instrument, count: midi.learnSelected.instrumentCount, controlID: midi.learnSelected.controlID, controlType: midi.learnSelected.controlType }; storage.setItem("midiDeviceMapping", JSON.stringify(midi.deviceMapping)) } } } var devMap = midi.deviceMapping; if (devMap[deviceID]) { if (devMap[deviceID][controlID]) { var devMidi = devMap[deviceID][controlID]; if (devMidi.type == "instrument") { var instrumentID = song.instrumentNames[devMidi.instrument][devMidi.count]; var controlType = devMidi.controlType; if (controlType == "knob") { ui.setKnobRotation("instrument", instrumentID, devMidi.controlID, controlVal, false); song.instruments[instrumentID].setControlValue(devMidi.controlID, controlVal) } else if (controlType == "drumMute") { ui.drumMuteToggle(instrumentID, devMidi.controlID) } } else { ui.lastMixerChannel = devMidi.count; ui.setSliderPos("mixer", 0, devMidi.controlID, controlVal, false); mixer.setControlValue(devMidi.count, devMidi.controlID, controlVal) } } } }, clearMappings: function() { midi.deviceMapping = {}; for (var deviceID in midi.devices) { midi.deviceMapping[midi.devices[deviceID].id] = {} } storage.getItem("midiDeviceMapping", midi.clearMappingsCallback); //console.log("Midi mappings cleared"); setTimeout(function() { notification.show({ message: "Middi mappings have been cleared", type: "alert" }) }, 100) }, clearMappingsCallback: function(key, deviceMappings) { if (deviceMappings) { storage.removeItem(key); //console.log("Device mappings removed from storage") } } }; var ui = { lastInstrumentID: null, lastControlID: null, lastControlType: null, lastMixerChannel: null, lastfxid: null, mousePos: {}, fxSelected: false, init: function() { //console.log("UI Init"); this.eventListeners(); if (app.appVersion) { // $(".social-share-container").hide() } else { // ui.webRestrict() } }, ready: function() { setTimeout(function() { sequencer.init(); options.init(); }, 100); }, // fullscreenok: function(){ // // notification.show({ // // message: "Entering fullscreen for an improved experience to enjoy?", // // type: "alert" // // } // // var confirmfull = confirm("Enter fullscreen for an improved experience to enjoy this?"); // // if (confirmfull) { // // goFullScreen(); // // app.context.resume().then(() => { // // //console.log('Playback resumed successfully'); // // }); // // } // } // , webRestrict: function() { // $('.js-file-button[data-name="load"]').css({ // opacity: .4 // }).mousedown(function () { // var type = $(this).data("type"); // ui.upgradeMessage(type) // }); // //console.log("REMOVE"); // $('.js-file-button[data-type="song]"').remove(); // setTimeout(function () { // $(".js-buy-app").fadeIn("slow").mousedown(function () { // window.open(app.upgradeUrl) // }) // }, 1e3) }, upgradeMessage: function(type) { // var message = "This feature is only available in the app version. Check it out?"; // if (type == "rb") { // message = "Rebirth Import - Only available in the app version. Check it out?" // } else if (type == "abl") { // message = "AudioRealism Bass Line Import - Only in the app version. Check it out?" // } // var confirmUpgrade = confirm(message); // if (confirmUpgrade) { // window.open(app.upgradeUrl) // } }, eventListeners: function() { $(".js-transport").on("mousedown", function() { var button = $(this).data("name"); if (button == "play") { app.playSequence(); // $(this).addClass("btn-transport-active") $('#play').hide(); $('#stop').show(); } else if (button == "stop") { app.stopSequence(); $('#play').show(); $('#stop').hide(); //$('.js-transport[data-name="play"]').removeClass("btn-transport-active"); // $(this).addClass("btn-transport-active"); // setTimeout(function() { // $('.js-transport[data-name="stop"]').removeClass("btn-transport-active") // }, 100); sequencer.clearHighlight() } else if (button == "mode") { if (app.songMode) { if (app.sequencePlaying) { app.stopSequence(); app.songMode = false; app.playSequence(); if (app.currentScreen == "sequencer") { sequencer.clearHighlight() } } app.songMode = false; $(this).html("SONG").removeClass("btn-transport-active"); $(".js-song-mode-msg").css({ opacity: 1 }) } else { if (app.sequencePlaying) { app.stopSequence(); app.songMode = true; app.playSequence(); if (app.currentScreen == "sequencer") { sequencer.barHighlight() } } app.songMode = true; $(this).html("SONG").addClass("btn-transport-active"); $(".js-song-mode-msg").css({ opacity: 0 }) } } }); $(".js-file-button").on(" mousedown", function(e) { // STOP AUDIO!!!! load.. save .. new.. $("#stop").mousedown(); var name = $(this).data("name"); if (name == "load") { e.preventDefault() } else if (name == "save") { if (!app.chromeApp) { $("#save-filename").val(ui.getDefaultSaveTitle()); $(".overlay-box").hide(); $("#save-box").show(); $("#dark-overlay").fadeIn("fast", function() { $("#save-filename").select().focus(); $("#btn-save").mousedown(); //trigger click on data "save".. go with default title.. Oliver-trashing-the-art-mode-bit-protection ;D }) } else { var extension = app.fileExtension; var suggestedFileName = "popmaskin_Untitled"; chrome.fileSystem.chooseEntry({ type: "saveFile", suggestedName: suggestedFileName, accepts: [{ description: "ALKIZZ | RAVE BASS files (*." + extension + ")", extensions: [extension] }] }, function(writableFileEntry) { function errorHandler() { //console.log("File Error") } writableFileEntry.createWriter(function(writer) { var saveData = song.save(); var truncated = false; var blob = new Blob([saveData], { type: "text/plain" }); writer.onerror = errorHandler; writer.onwriteend = function(e) { //console.log("write complete"); if (!truncated) { truncated = true; this.truncate(blob.size); return } }; writer.write(blob) }, errorHandler) }) } } else if (name == "new") { notification.show({ message: "Are you sure you want to clear this track and start a new one?", type: "confirm", callback: song.new }) } // else if (name == "import") { // //console.log("Rebirth Import Clicked") // } }); $("body").keyup(function(e) { if ($("#dark-overlay").is(":visible")) return; if (e.keyCode == 32) { // space keyboard if (app.sequencePlaying) { // app.stopSequence(); // $('.js-transport[data-name="play"]').removeClass("btn-transport-active"); // sequencer.clearHighlight() $('#stop').mousedown(); //.trigger( "mousedown" )click(); //.trigger("click"); // trigger clicks button } else { //app.playSequence(); //$('.js-transport[data-name="play"]').addClass("btn-transport-active") $('#play').mousedown(); //.trigger( "mousedown" )//trigger("click"); // trigger clicks button $('#play').hide(); $('#stop').show(); } } }); $("body").keydown(function(e) { if ($("#dark-overlay").is(":visible")) return; if (e.keyCode <= 57 && e.keyCode >= 48) { var drumID = e.keyCode - 49; var instrumentID = ""; if (drumID < 0) drumID = 9; for (var key in song.instruments) { if (song.instruments[key].drummaskin) { instrumentID = key; song.instruments[key].padPush({ padpush: true, type: 0, start: 0, duration: 1, offset: 0, instant: true, veloc: 110, decay: 0.9, val: drumID }) } } var pad = $('.js-control-pad[data-instrument-id="' + instrumentID + '"][data-control-id="' + drumID + '"]'); pad.addClass("pad-pushed"); setTimeout(function() { pad.removeClass("pad-pushed") }, 100) } }); $(".js-tempo").change(function() { //console.log($(this).val()); app.setTempo($(this).val()) }); $(".js-shuffle").change(function() { //console.log($(this).val()); app.setshuffle($(this).val()) }); $(".js-fx-select").click(function() { var fxid = $(this).data("id"); var fxChannel = $("#fx-selector-channel").val(); var fxSlot = $("#fx-selector-slot").val(); mixer.addFX(fxChannel, fxSlot, fxid, true) }); $("#dark-overlay").click(function(e) { var clickedElem = e.target.id; if (clickedElem == "dark-overlay") { $(this).hide() } }); $(".js-file-reader").change(function() { var elem = $(this); //console.log("CHANGE"); app.readFile(elem); $(this).val("").blur() }); $(document).on(' mousedown', function() { ui.mouseDown = true }).on('touchend mouseup', function() { ui.mouseDown = false; ui.lastInstrumentID = null; ui.lastControlID = null; ui.dragStart = null; ui.lastSliderID = null; ui.lastMixerChannel = null }).on('touchmove mousemove', function(e) { touch = undefined; if (e.originalEvent.touches) { touch = e.originalEvent.touches[0]; ////console.log(touch.pageY); ui.mousePos = { x: Math.round(touch.pageX), y: Math.round(touch.pageY), }; vPos = Math.round(touch.pageY); } else { ui.mousePos = { x: e.pageX, y: e.pageY, }; vPos = e.clientY; } if (ui.lastControlID == null) return; //Set knob pos //console.log(vPos + "aaaaaa"); app.setKnobPos(vPos) }).on("mousedown ", ".js-tab-change", function() { var tab = $(this).data("tab"); $(".js-tab-change").removeClass("btn-transport-active"); $(this).addClass('btn-transport-active'); if (tab == "editor") { var instrumentID = $(this).data("instrument-id"); if (instrumentID) editor.instrumentID = instrumentID; editor.refresh() } else if (tab == "sequencer") { sequencer.refresh() } ui.changeScreen($(this).data("tab")) }).on("mousedown ", ".js-randomise-pattern", function() { var instrumentID = $(this).data("instrument-id"); var patternID = song.currentPattern[instrumentID]; app.randomiseNotes(instrumentID, patternID) }).on("mousedown ", ".js-pattern-select", function() { var patternID = $(this).data("pattern-id"); // $(".js-pattern-select").each(function() { // IF APPLY TO ALL, KILIAN var instrumentID = $(this).data("instrument-id"); patternID = patternID + song.currentBank[instrumentID] * 8; //console.log(patternID); ui.patternSelect($(this).data("instrument-id"), patternID, false) // $(this).toggleClass("example"); // }); }).on("mousedown ", ".js-bank-select", function() { var instrumentID = $(this).data("instrument-id"); var bankID = $(this).data("bank-id"); ui.bankSelect(instrumentID, bankID) }).on("mousedown ", ".js-mute-instrument", function() { var instrumentID = $(this).data("instrument-id"); ui.muteInstrument(instrumentID) }).on("mousedown ", ".js-solo-instrument", function() { var instrumentID = $(this).data("instrument-id"); var mixerChannel = song.instruments[instrumentID].mixerChannel; mixer.soloInputToggle(mixerChannel); for (var key in song.instruments) { if (key !== instrumentID) { song.instruments[key].solo = false } } if (!song.instruments[instrumentID].solo) { $(".js-solo-instrument").removeClass("solo-highlight"); song.instruments[instrumentID].solo = true; if (mixerinputSolo && song.instruments[instrumentID].solo) { for (var key in song.instruments) { if (key !== instrumentID) { $('.js-mute-instrument[data-instrument-id="' + key + '"]').addClass("mute-highlight") } } $('.js-mute-instrument[data-instrument-id="' + instrumentID + '"]').removeClass("mute-highlight"); $(this).addClass("solo-highlight") } } else { $(".js-solo-instrument").removeClass("solo-highlight"); $(".js-mute-instrument").removeClass("mute-highlight"); song.instruments[instrumentID].solo = false } }).on("mousedown ", ".js-toggle-switch", function() { var instrumentID = $(this).data("instrument-id"); var controlID = $(this).data("control-id"); var oldValue = song.instruments[instrumentID].controls[controlID].value; if (oldValue > 0) { var newValue = 0 } else { var newValue = 1 } ui.setToggleSwitch(instrumentID, controlID, newValue); song.instruments[instrumentID].setControlValue(controlID, newValue); //console.log(song.instruments[instrumentID].controls[controlID].value) }).on("mousedown touchstart", ".js-control-knob", function(e) { var controlType = $(this).data("control-type"); ui.lastControlType = controlType; var instrumentID = null, fxid = null, controlID = $(this).data("control-id"); if (controlType == "fx") { ui.lastfxid = $(this).data("fxid") } else if (controlType == "mixer") { ui.lastMixerChannel = $(this).data("mixer-channel") } else if (controlType == "instrument") { ui.lastInstrumentID = $(this).data("instrument-id") } //console.log(">>", ui.lastfxid); ui.mouseDown = true; ui.lastControlID = controlID; if (e.originalEvent.touches) { touch = e.originalEvent.touches[0]; ////console.log(touch.pageY); // ui.mousePos = { // x: Math.round(touch.pageX), // y: Math.round(touch.pageY), // }; ui.dragStart = Math.round(touch.clientY); } else { // ui.mousePos = { // x: e.pageX, // y: e.pageY, // }; ui.dragStart = e.clientY; } }).on("mousedown", ".js-control-pad", function(e) { var type = $(this).data("type"); var instrumentID = $(this).data("instrument-id"); var controlID = $(this).data("control-id"); if (type == "drum-trigger") { song.instruments[instrumentID].padPush({ padpush: true, type: 0, start: 0, val: controlID, duration: 1, offset: 0, instant: true, veloc: 110, decay: 0.9 }); var pad = $(this).addClass("pad-pushed") } else if (type == "drum-mute") { ui.drumMuteToggle(instrumentID, controlID) } }).on("mousedown", ".js-control-button", function() { var controlID = $(this).data("control-id"); if ($(this).data("fxid")) { var fxid = $(this).data("fxid"); var currentState = song.fxUnits[fxid].controls[controlID].value; var newValue; if (controlID === 0) { if (currentState === 0) { newValue = 1 } else { newValue = 0 } } song.fxUnits[fxid].setControlValue(controlID, newValue); ui.setButtonState("fx", fxid, controlID, newValue) } else { var instrumentID = ui.getInstrumentID($(this)); //console.log("test"); song.instruments[instrumentID].button(controlID) } }).on("mouseup touchend", ".js-control-pad", function(e) { $(this).removeClass("pad-pushed") }).on("mouseout touchend touchcancel", ".js-control-pad", function(e) { /** hmm¸† */ $(this).removeClass("pad-pushed") }).on("mousedown ", ".js-add-fx", function(e) { /**hmm */ ui.fxSelected = false; $(".overlay-box").hide(); $("#fx-selector").show(); $("#dark-overlay").show(); var fxChannel = $(this).data("mixer-channel"); var fxSlot = $(this).data("mixer-slot"); $("#fx-selector-channel").val(fxChannel); $("#fx-selector-slot").val(fxSlot) }).on("mousedown ", ".js-delete-fx", function(e) { var fxid = $(this).data("fxid"); var fxChannel = $(this).data("mixer-channel"); var fxSlot = $(this).data("mixer-slot"); //var fxid = $(this).data("fxid"); //kilian mixer.deleteFX(fxChannel, fxSlot, fxid); ui.deleteFX(fxChannel, fxSlot, fxid); }).on("mousedown ", ".js-dialogue-button", function(e) { var songData = song.save(); //console.log("Save data: ", songData); $("#dark-overlay").hide(); if ($(this).data("name") == "cancel") return; if ($(this).data("type") == "song" && $(this).data("name") == "save") { var fileName = $("#save-filename").val(); if (fileName.length < 1) { fileName = ui.getDefaultSaveTitle() } var varsong = "varsong"; var data = {}; data[varsong] = encodeURIComponent(songData); varsong2 = varsong2 = encodeURIComponent(songData);; $.ajax({ type: 'POST', url: 'songs/upload.php', /** just heads up WONT WORK WITH ../ but works below when called trough js; */ data: { "data2": fileName + '.kil', "data": songData }, complete: function(r) { // alert(r.responseText); console.log(r.responseText); } }); $("", { download: fileName + "." + app.fileExtension, href: "data:text/json;charset=utf8," + encodeURIComponent(songData) }).appendTo("body").click(function() { $(this).remove() })[0].click() } }).on("mousedown ", ".js-midi-learn-toggle", function() { if (midi.learn) { midi.learn = false; $(".midi-learn-overlay-active").removeClass("midi-learn-overlay-active"); $(".js-midi-learn-overlay").hide(); $(this).removeClass("btn-transport-active"); midi.learnSelected.type = null; midi.learnSelected.instrument = null; midi.learnSelected.instrumentCount = null; midi.learnSelected.controlID = null } else { midi.learn = true; $(".js-midi-learn-overlay").fadeIn(200); $(this).addClass("btn-transport-active") } }).on("mousedown ", ".js-midi-learn-overlay", function() { $(".midi-learn-overlay-active").removeClass("midi-learn-overlay-active"); var instrumentID = $(this).data("instrument-id"); var controlID = $(this).data("control-id"); var controlType = "knob"; $(this).addClass("midi-learn-overlay-active"); var type = $(this).data("control-type"); if (type == "instrument") { var maskinName = song.instruments[instrumentID].maskinName; var instrumentCount = $(this).data("instrument-count"); if ($(this).data("type") == "drum-mute") { controlType = "drumMute" } } else { var maskinName = "mixer"; var instrumentCount = $(this).data("mixer-channel"); controlType = "slider" } midi.learnSelected.type = type; midi.learnSelected.instrument = maskinName; midi.learnSelected.instrumentCount = instrumentCount; midi.learnSelected.controlID = controlID; midi.learnSelected.controlType = controlType }).on("mousedown ", ".js-toggle-wav", function() { ui.toggleWavRecord() }) }, toggleWavRecord: function() { //console.log("Toggle wav record"); if (!mixer.wavRecord) { $(".js-toggle-wav").addClass("btn-transport-active"); mixer.startRecordNextStep = true; mixer.wavRecord = true } else { if (app.sequencePlaying) { //console.log("Stop recording"); mixer.rec.stop(); mixer.rec.exportWAV() } $(".js-toggle-wav").removeClass("btn-transport-active"); mixer.wavRecord = false } }, drumMuteToggle: function(instrumentID, drumID) { song.instruments[instrumentID].toggleMute(drumID); var muteList = song.instruments[instrumentID].mute; //console.log(muteList); for (var i = 0; i < muteList.length; i++) { var element = $("#" + instrumentID + "_" + "mute" + "_" + i); if (muteList[i] > 0) { element.addClass("drum-mute-active") } else if (muteList[i] == 0) { element.removeClass("drum-mute-active") } } }, muteInstrument: function(instrumentID) { var mixerChannel = song.instruments[instrumentID].mixerChannel; mixer.muteInputToggle(mixerChannel); song.instruments[instrumentID].solo = false; var element = $('.js-mute-instrument[data-instrument-id="' + instrumentID + '"]'); if (mixer.inputMute[mixerChannel]) { element.addClass("mute-highlight") } else { element.removeClass("mute-highlight") } $(".js-solo-instrument").removeClass("solo-highlight"); mixer.solo = false }, step: function(step) { //console.log("-----Playing step: " + step); if (app.currentScreen == "editor") { editor.stepHighlight(step) } if (app.currentScreen == "sequencer" && app.songMode) { if (step % 16 === 0) { sequencer.barHighlight() } } }, bar: function(bar) { //console.log("BAR: " + bar) }, changeScreen: function(name) { app.currentScreen = name; if (name == "instruments") { ui.refreshInstruments() } $(".js-screen").hide(); $('.js-screen[data-screen-name="' + name + '"]').show(); $(".js-tab-change").removeClass("btn-transport-active"); $("." + name + "tab").addClass('btn-transport-active'); }, patternSelect: function(instrumentID, patternID, forceOn) { $('.js-pattern-select[data-instrument-id="' + instrumentID + '"]').removeClass("btn-pattern-waiting"); var displayPatternID = patternID - song.currentBank[instrumentID] * 8; //console.log("pattern:" + patternID); //console.log("bank:" + song.currentBank[instrumentID]); //console.log("display: " + displayPatternID); var btn = $('.js-pattern-select[data-instrument-id="' + instrumentID + '"][data-pattern-id="' + displayPatternID + '"]'); if (app.sequencePlaying && !forceOn) { $(btn).addClass("btn-pattern-waiting"); song.waitingPattern[instrumentID] = patternID } else { $('.js-pattern-select[data-instrument-id="' + instrumentID + '"]').removeClass("btn-pattern-on"); $(btn).addClass("btn-pattern-on"); song.currentPattern[instrumentID] = patternID; if (app.currentScreen == "editor") { editor.refresh() } } }, bankSelect: function(instrumentID, bankID) { $('.js-bank-select[data-instrument-id="' + instrumentID + '"]').removeClass("btn-pattern-on"); var btn = $('.js-bank-select[data-instrument-id="' + instrumentID + '"][data-bank-id="' + bankID + '"]'); $(btn).addClass("btn-pattern-on"); song.currentBank[instrumentID] = bankID; this.patternSelect(instrumentID, song.currentPattern[instrumentID], true); if (app.currentScreen == "editor") { editor.refresh() } }, getInstrumentID: function(element) { return element.closest(".instrument-wrapper").attr("id") }, refreshInstruments: function() { $(".js-pattern-select").removeClass("btn-pattern-on btn-pattern-waiting"); for (var key in song.instruments) { if (song.instruments.hasOwnProperty(key)) { var id = song.instruments[key].instrumentID; var patternID = song.currentPattern[id]; var bankID = song.currentBank[id]; this.patternSelect(id, patternID, true); this.bankSelect(id, bankID) } } }, newInstrumentUI: function(instrumentID) { var maskinName = song.instruments[instrumentID].maskinName; var instrumentName = song.instruments[instrumentID].instrumentName; var controls = []; if (song.instruments[instrumentID].controls) { controls = song.instruments[instrumentID].controls } var viewData = []; if (song.instruments[instrumentID].viewData) { viewData = song.instruments[instrumentID].viewData } //console.log("----\x3e" + instrumentID); //console.log(viewData); var mixerChannel = song.instruments[instrumentID].mixerChannel; //console.log(mixerChannel); var emptyTemplate = templates.instruments[maskinName].view; var cssLoaded = 0; if (song.instrumentCounts.hasOwnProperty(maskinName)) { if (song.instrumentCounts[maskinName] > 1) { cssLoaded = 1 } } var instrumentTemplateData = { instrumentName: song.instruments[instrumentID].instrumentName, instrumentID: instrumentID, prefix: maskinName + "-container", maskinName: maskinName, basePath: app.instrumentBasePath + maskinName, /* drumSAMPLEDATAK: drumSAMPLEDATAK, */ controls: controls, cssLoaded: cssLoaded, instrumentCount: song.instrumentCounts[maskinName], viewData: viewData }; var instrumentTemplate = emptyTemplate; var instrumentHtml = instrumentTemplate(instrumentTemplateData); var wrapperTemplateData = { instrumentID: instrumentID, instrumentHtml: instrumentHtml, instrumentName: instrumentName, maskinName: maskinName, mixerChannel: mixerChannel, banks: ["A", "B", "C", "D"] }; //console.log("-----\x3e"); //console.log(wrapperTemplateData); var wrapperTemplate = templates.instrument_wrapper; var completeInstrumentView = wrapperTemplate(wrapperTemplateData); $("#" + app.mainInstrumentDivID).append(completeInstrumentView); for (var i = 0; i < song.instruments[instrumentID].controls.length; i++) { var control = song.instruments[instrumentID].controls[i]; if (control.type == "knob") { ui.setKnobRotation("instrument", instrumentID, i, control.value, true) } else if (control.type == "toggle") { ui.setToggleSwitch(instrumentID, i, control.value) } } }, newFX: function(type, channel, slot, fxid, loadingStatus) { console.warn("###", type, channel, slot, fxid, loadingStatus); var addButton = $('.js-add-fx[data-mixer-channel="' + channel + '"][data-mixer-slot="' + slot + '"]'); var container = addButton.parent(); addButton.hide(); var controls = song.fxUnits[fxid].controls; var name = type; //type.substr(0, 1).toUpperCase() + type.substr(1); var wrapperTemplateData = { mixerChannel: channel, mixerSlot: slot, fxName: name, controls: controls, fxid: fxid, cssClass: "fx-unit-" + type, loadingStatus: loadingStatus }; var wrapperTemplate = templates.fx_unit; var completeFxView = wrapperTemplate(wrapperTemplateData); container.append(completeFxView); this.setFXLoadingStatus(fxid, loadingStatus); for (var i = 0; i < song.fxUnits[fxid].controls.length; i++) { var control = song.fxUnits[fxid].controls[i]; //console.log("Setting visual on: " + fxid + " val: " + control.value); //console.log(control); if (control.type == "knob") { ui.setKnobRotation("fx", fxid, i, control.value, true) } else if (control.type == "button") { ui.setButtonState("fx", fxid, i, control.value) } else if (control.type == "toggle") {} } $("#dark-overlay").hide() }, setFXLoadingStatus: function(uniqueID, status) { if (status) { $('.js-fx-loading[data-fxid="' + uniqueID + '"]').show(); } else { $('.js-fx-loading[data-fxid="' + uniqueID + '"]').fadeOut("fast"); } }, deleteFX: function(channel, slot, fxid) { console.log("removing " + channel + " - " + slot); // $('.js-fx-wrapper[data-mixer-channel="' + channel + '"][data-fxid="' + slot + '"][data-mixer-slot="' + slot + '"]').remove(); // $('.js-add-fx[data-mixer-channel="' + channel + '"][data-fxid="' + slot + '"][data-mixer-slot="' + slot + '"]').show() // $('.js-fx-wrapper[data-mixer-channel="' + channel + '"][data-mixer-slot="' + slot + '"]').remove(); $('.js-add-fx[data-mixer-channel="' + channel + '"][data-mixer-slot="' + slot + '"]').show() }, removePatternWaiting: function() { $(".js-pattern-select").removeClass("btn-pattern-waiting") }, setKnobRotation: function(type, instrumentID, controlID, value, animate) { var valPercent = Math.round(value / 127 * 100); var rotAngle = 270 / 100 * valPercent - 135; var css = { transition: "transform 0s", transform: "rotate(" + rotAngle + "deg)" }; if (type !== "fx") { var element = document.getElementById("control_knob_" + instrumentID + "_" + controlID + "_" + type) } else { var elementId = "control_fx_" + instrumentID + "_" + controlID; var element = document.getElementById(elementId) } if (element) { if (animate) { setTimeout(function() { css = { transition: "transform 0s", transform: "rotate(" + rotAngle + "deg)" }; Object.assign(element.style, css) }, 1) } else { Object.assign(element.style, css) } } }, setButtonState: function(type, instrumentID, controlID, value) { if (type == "fx") { var fxid = instrumentID; if (controlID === 0) { var button = $('.js-control-button.js-fx-bypass[data-fxid="' + fxid + '"]'); if (value === 0) { button.addClass("btn-pattern-on").html("") } else { button.removeClass("btn-pattern-on").html("") } } } }, setSliderPos: function(type, instrumentID, controlID, value, animate) { if (type == "mixer") { var inner = $('.js-control-knob[data-mixer-channel="' + ui.lastMixerChannel + '"][data-control-id="' + controlID + '"][data-control-type="' + type + '"]').find(".slider-inner"); var knob = $('.js-control-knob[data-mixer-channel="' + ui.lastMixerChannel + '"][data-control-id="' + controlID + '"][data-control-type="' + type + '"]').find(".slider-knob") } else { var inner = $('.js-control-knob[data-instrument-id="' + instrumentID + '"][data-control-id="' + controlID + '"][data-control-type="' + type + '"]').find(".slider-inner"); var knob = $('.js-control-knob[data-instrument-id="' + instrumentID + '"][data-control-id="' + controlID + '"][data-control-type="' + type + '"]').find(".slider-knob") } animate = typeof animate !== "undefined" ? animate : false; var knobHeight = 10; var valPercent = value / 127 * 100 + knobHeight; if (valPercent < knobHeight) { valPercent = knobHeight } else if (valPercent > 100) { valPercent = 100 } inner.css({ height: valPercent + "%" }); knob.css({ bottom: valPercent - knobHeight + "%" }) }, setToggleSwitch: function(instrumentID, controlID, value) { var toggleSwitchOuter = $('.js-toggle-switch[data-instrument-id="' + instrumentID + '"][data-control-id="' + controlID + '"]'); var toggleSwitch = toggleSwitchOuter.children(".switch-inner"); var type = toggleSwitchOuter.data("type"); if (type == "vertical") { if (value < 1) { toggleSwitch.addClass("top"); toggleSwitch.removeClass("bottom") } else { toggleSwitch.addClass("bottom"); toggleSwitch.removeClass("top") } } else { if (value < 1) { toggleSwitch.addClass("left"); toggleSwitch.removeClass("right") } else { toggleSwitch.addClass("right"); toggleSwitch.removeClass("left") } } }, updateTempo: function() { $(".js-tempo").val(app.tempo) $(".lcdtempo").html('' + app.tempo + ' BPM'); }, updateshuffle: function() { $(".js-shuffle").val(app.shuffle) $(".lcdshuffle").html('SWI ' + app.shuffle + '%'); }, getDefaultSaveTitle: function() { var fileName = "maskin_2_" + (new Date).getTime(); return fileName } }; var notification = { defaultMessage: "Message...", callback: false, init: function() { this.eventListeners(); this.dismiss() }, eventListeners: function() { $("#notification-confirm").click(function() { //console.log("Notification confirm"); if (notification.callback) { notification.callback() } notification.dismiss() }); $("#notification-dismiss").click(function() { notification.dismiss() }) }, show: function(params) { this.reset(); var callback = params.callback || false; this.callback = callback; $(".overlay-box").hide(); $("#dark-overlay").fadeIn(100, function() {}); $("#notification-text").html(params.message); $("#notification-container").show(); if (params.type == "confirm") { $("#notification-confirm").show(); $("#notification-dismiss").show(); $("#notification-dismiss").html("Cancel") } else if (params.type == "alert") { $("#notification-confirm").hide(); $("#notification-dismiss").html("OK"); $("#notification-dismiss").show() } else if (params.type == "loading") { $("#notification-confirm").hide(); $("#notification-dismiss").hide() } }, dismiss: function() { //console.log("Notification dismiss"); $("#dark-overlay").hide(); $("#notification-container").hide() }, reset: function() { this.message = this.defaultMessage; this.callback = false } }; app.init(); ui.init(); midi.init(); mixer.init(true); notification.init();