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, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 + "