wave.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. var global = typeof global !== 'undefined' ? global : window;
  2. global.edide = {};
  3. "use strict";edide.global = (function _global (edide) {
  4. return typeof global !== 'undefined' ? global : window;
  5. return this;
  6. }).call({}, edide);
  7. "use strict";edide.editorModule = (function _editorModule (edide) {
  8. var ref;
  9. return typeof file !== "undefined" && file !== null ? (ref = file.modules) != null ? ref.all : void 0 : void 0;
  10. return this;
  11. }).call({}, edide);
  12. "use strict";edide.logProd = (function _logProd (edide) {
  13. return (...args) => {
  14. var console, ref;
  15. ({console} = (ref = edide.editorModule) != null ? ref : window);
  16. return console.log(...args);
  17. };
  18. return this;
  19. }).call({}, edide);
  20. "use strict";edide.var = (function _var (edide) {
  21. var currentReact, debugging, dependees, dependsOn, depsRequired, inInitCall, infinityCheck, initSetter, newVar, parent, setLinks, setters, updateVar, values;
  22. values = new Map; // //edide.keep ?
  23. setters = new Map; // varName => setter:func
  24. dependees = new Map; // varName => deps:
  25. setLinks = new Map; // for reactiveGraph, show setters inside reactive/setter:s
  26. debugging = false; //edide.editorModule?
  27. depsRequired = new Map; // varName : dependsOn
  28. inInitCall = false; // TODO use dependsOn? instead
  29. dependsOn = new Set(); // remove
  30. initSetter = (name, setter) => {
  31. var debugName, err, parent, ref, val;
  32. debugName = (ref = setter.type) != null ? ref : name;
  33. if ((setters.get(name)) != null) {
  34. throw Error(`Reactive for '${debugName}' already exists`);
  35. }
  36. setters.set(name, setter);
  37. if (inInitCall) {
  38. throw Error(`can't create reactive setter (for '${debugName}') inside reactive context`);
  39. }
  40. inInitCall = name;
  41. dependsOn.clear(); // TODO clear => new Set
  42. try {
  43. val = setter(); // TODO: some day add revar and unvar as params; helps with multiple reactives to keep the separated
  44. } catch (error) {
  45. err = error;
  46. inInitCall = false;
  47. err.message = `Reactive initialization of '${debugName}' failed: ${err.message}`;
  48. throw err;
  49. }
  50. parent = null;
  51. dependsOn.forEach((depName) => {
  52. var deps;
  53. if ((deps = dependees.get(depName)) == null) {
  54. dependees.set(depName, deps = new Set);
  55. }
  56. return deps.add(name);
  57. });
  58. inInitCall = false;
  59. return val;
  60. };
  61. infinityCheck = new Set; //edide.keep
  62. parent = null;
  63. updateVar = function(name, val) {
  64. var ref, ref1, type;
  65. if (arguments.length === 1) {
  66. val = setters.get(name)();
  67. if (debugging && (type = setters.get(name).type)) {
  68. edide.logProd(`running ${(setters.get(name).type)}`);
  69. }
  70. }
  71. if (typeof name !== 'string') { // symbol ~ react function
  72. return;
  73. }
  74. if (values.get(name) === val) { // can't reset same value
  75. return;
  76. }
  77. if (infinityCheck.has(name)) {
  78. infinityCheck.forEach((k) => {
  79. return edide.logProd(k);
  80. });
  81. edide.logProd(name);
  82. if ((ref = edide.editorModule) != null) {
  83. if (typeof ref.reactiveGraph === "function") {
  84. ref.reactiveGraph();
  85. }
  86. }
  87. throw Error("Inifinite loop in \:var dependencies");
  88. }
  89. if (debugging) {
  90. edide.logProd(`updating ${name}`);
  91. }
  92. values.set(name, val);
  93. if (!inInitCall) {
  94. infinityCheck.add(name);
  95. if ((ref1 = dependees.get(name)) != null) {
  96. ref1.forEach((depName) => {
  97. return updateVar(depName);
  98. });
  99. }
  100. infinityCheck.delete(name);
  101. }
  102. return val;
  103. };
  104. currentReact = [];
  105. newVar = function(name, setter) {
  106. var context, contextSet, err;
  107. if (arguments.length === 1) {
  108. if (typeof name === 'string') {
  109. if (inInitCall) {
  110. dependsOn.add(name);
  111. }
  112. return values.get(name);
  113. } else {
  114. setter = name;
  115. name = Symbol();
  116. values.set(name, name); // for debugging (showing react/dom funcs in graph)
  117. }
  118. }
  119. if (currentReact.length) { // and debugging
  120. context = currentReact[currentReact.length - 1];
  121. if (!(contextSet = setLinks.get(context))) {
  122. setLinks.set(context, contextSet = new Set);
  123. }
  124. contextSet.add(name);
  125. }
  126. currentReact.push(name);
  127. if (typeof setter === 'function') {
  128. setter = initSetter(name, setter); // setter becomes value
  129. }
  130. if (typeof name === 'string') {
  131. try {
  132. updateVar(name, setter);
  133. } catch (error) {
  134. err = error;
  135. infinityCheck.clear();
  136. throw err;
  137. }
  138. }
  139. currentReact.pop();
  140. return setter;
  141. };
  142. Object.assign(newVar, {dependees, values, setters, setLinks});
  143. return newVar;
  144. return this;
  145. }).call({}, edide);
  146. "use strict";edide.strRandom = (function _strRandom (edide) {
  147. return (limit = 20) => {
  148. return (Math.random() + '').slice(2, +(limit + 1) + 1 || 9e9);
  149. };
  150. return this;
  151. }).call({}, edide);
  152. "use strict";edide.reactive = (function _reactive (edide) {
  153. return (initialVars = {}) => {
  154. var handler, id, key, react, revar, todoMap, unvar, val;
  155. id = edide.strRandom();
  156. handler = {
  157. get: (map, prop) => {
  158. var ref;
  159. if ((ref = edide.editorModule) != null ? ref.editor_inspector.inspectingNow : void 0) {
  160. console.log('IN inspector? Find out is it possible to end up here form inside setter');
  161. return edide.var.values.get(`${id}.${prop}`);
  162. }
  163. return edide.var(`${id}.${prop}`);
  164. },
  165. set: (map, prop, value) => {
  166. edide.var(`${id}.${prop}`, value);
  167. return true; // Proxy set must return true if set is successfull; In the future use Reflect.set, which returns true automatically?
  168. }
  169. };
  170. revar = new Proxy((todoMap = new Map), handler); // NOTE: map is not used yet
  171. unvar = new Proxy(todoMap, {
  172. get: (map, prop) => {
  173. return edide.var.values.get(`${id}.${prop}`);
  174. },
  175. set: (map, prop, value) => {
  176. return edide.var.values.set(`${id}.${prop}`, value);
  177. }
  178. });
  179. for (key in initialVars) {
  180. val = initialVars[key];
  181. revar[key] = val;
  182. }
  183. react = (nameOrFunc, func) => {
  184. if (func != null) {
  185. func.type = nameOrFunc;
  186. } else {
  187. func = nameOrFunc;
  188. func.type = 'react'; // for debugging
  189. }
  190. return edide.var(func);
  191. };
  192. return {
  193. react,
  194. revar,
  195. unvar,
  196. un: unvar,
  197. re: revar // , dom
  198. };
  199. };
  200. return this;
  201. }).call({}, edide);
  202. "use strict";edide.mmState = (function _mmState (edide) {Object.defineProperty(this, 'module_name', {value:'mmState'});
  203. this.defaults = {
  204. playing: false,
  205. recorderOn: false,
  206. sheet: '',
  207. diffText: '',
  208. note: null, // currently playing note
  209. bpm: 400, // -> beatDelay
  210. blur: 0,
  211. itch: 0,
  212. instrument: 'guitar-electric',
  213. scale: 'pentatonicMinor',
  214. highlight: null,
  215. keyboardInd: 0 // TODO --> keyboard
  216. };
  217. this.react = null;
  218. this.init = (startingProps = {}) => {
  219. if (this.react != null) {
  220. return this;
  221. }
  222. ({react: this.react, revar: this.revar, unvar: this.unvar} = edide.reactive(Object.assign({}, this.defaults, startingProps)));
  223. return this;
  224. };
  225. return this;
  226. }).call({}, edide);
  227. "use strict";edide.mmEffects = (function _mmEffects (edide) {Object.defineProperty(this, 'module_name', {value:'mmEffects'});
  228. ({revar: this.revar} = edide.mmState.init());
  229. this.maxLowpass = 10000;
  230. this.maxDistortion = 3;
  231. this.revar.lowpass = () => {
  232. var blur;
  233. ({blur} = this.revar);
  234. return this.maxLowpass - blur * (this.maxLowpass - 200);
  235. };
  236. this.revar.distortion = () => {
  237. var itch;
  238. ({itch} = this.revar);
  239. return this.maxDistortion * itch;
  240. };
  241. return this;
  242. }).call({}, edide);
  243. "use strict";edide.musicScales = (function _musicScales (edide) {Object.defineProperty(this, 'module_name', {value:'musicScales'});
  244. this.full = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
  245. this.scaleSteps = {
  246. pentatonicMinor: [
  247. 0,
  248. 3,
  249. 2,
  250. 2,
  251. 3 // hidden 2
  252. ],
  253. naturalMajor: [
  254. 0,
  255. 2,
  256. 2,
  257. 1,
  258. 2,
  259. 2,
  260. 2 // hidden to beginning: 1
  261. ],
  262. naturalMinor: [
  263. 0,
  264. 2,
  265. 1,
  266. 2,
  267. 2,
  268. 1,
  269. 2 // hidden to beginning: 2
  270. ]
  271. };
  272. this.triadSteps = {
  273. major: [
  274. 0,
  275. 4,
  276. 3 // positive valence
  277. ],
  278. minor: [0, 3, 4]
  279. };
  280. this.triadCombinations = {
  281. protagonism: 'M2M',
  282. outerSpace: 'M6M',
  283. fantastical: 'M8M',
  284. sadness: 'M4m',
  285. romantic: 'M5m', // and middle eastern
  286. wonder: 'm5M', // and trancendence
  287. mystery: 'm2M', // and dark comedy
  288. dramatic: 'm11M',
  289. antagonismDanger: 'm6m', // less character based
  290. antagonismEvil: 'm8m' // cahracter based
  291. };
  292. return this;
  293. }).call({}, edide);
  294. "use strict";edide.noteFreq = (function _noteFreq (edide) {Object.defineProperty(this, 'module_name', {value:'noteFreq'});
  295. var a4;
  296. this.notes = [['C0', 16.35, 2109.89], ['C#0', 17.32, 1991.47], ['D0', 18.35, 1879.69], ['D#0', 19.45, 1774.20], ['E0', 20.60, 1674.62], ['F0', 21.83, 1580.63], ['F#0', 23.12, 1491.91], ['G0', 24.50, 1408.18], ['G#0', 25.96, 1329.14], ['A0', 27.50, 1254.55], ['A#0', 29.14, 1184.13], ['B0', 30.87, 1117.67], ['C1', 32.70, 1054.94], ['C#1', 34.65, 995.73], ['D1', 36.71, 939.85], ['D#1', 38.89, 887.10], ['E1', 41.20, 837.31], ['F1', 43.65, 790.31], ['F#1', 46.25, 745.96], ['G1', 49.00, 704.09], ['G#1', 51.91, 664.57], ['A1', 55.00, 627.27], ['A#1', 58.27, 592.07], ['B1', 61.74, 558.84], ['C2', 65.41, 527.47], ['C#2', 69.30, 497.87], ['D2', 73.42, 469.92], ['D#2', 77.78, 443.55], ['E2', 82.41, 418.65], ['F2', 87.31, 395.16], ['F#2', 92.50, 372.98], ['G2', 98.00, 352.04], ['G#2', 103.83, 332.29], ['A2', 110.00, 313.64], ['A#2', 116.54, 296.03], ['B2', 123.47, 279.42], ['C3', 130.81, 263.74], ['C#3', 138.59, 248.93], ['D3', 146.83, 234.96], ['D#3', 155.56, 221.77], ['E3', 164.81, 209.33], ['F3', 174.61, 197.58], ['F#3', 185.00, 186.49], ['G3', 196.00, 176.02], ['G#3', 207.65, 166.14], ['A3', 220.00, 156.82], ['A#3', 233.08, 148.02], ['B3', 246.94, 139.71], ['C4', 261.63, 131.87], ['C#4', 277.18, 124.47], ['D4', 293.66, 117.48], ['D#4', 311.13, 110.89], ['E4', 329.63, 104.66], ['F4', 349.23, 98.79], ['F#4', 369.99, 93.24], ['G4', 392.00, 88.01], ['G#4', 415.30, 83.07], ['A4', 440.00, 78.41], ['A#4', 466.16, 74.01], ['B4', 493.88, 69.85], ['C5', 523.25, 65.93], ['C#5', 554.37, 62.23], ['D5', 587.33, 58.74], ['D#5', 622.25, 55.44], ['E5', 659.25, 52.33], ['F5', 698.46, 49.39], ['F#5', 739.99, 46.62], ['G5', 783.99, 44.01], ['G#5', 830.61, 41.54], ['A5', 880.00, 39.20], ['A#5', 932.33, 37.00], ['B5', 987.77, 34.93], ['C6', 1046.50, 32.97], ['C#6', 1108.73, 31.12], ['D6', 1174.66, 29.37], ['D#6', 1244.51, 27.72], ['E6', 1318.51, 26.17], ['F6', 1396.91, 24.70], ['F#6', 1479.98, 23.31], ['G6', 1567.98, 22.00], ['G#6', 1661.22, 20.77], ['A6', 1760.00, 19.60], ['A#6', 1864.66, 18.50], ['B6', 1975.53, 17.46], ['C7', 2093.00, 16.48], ['C#7', 2217.46, 15.56], ['D7', 2349.32, 14.69], ['D#7', 2489.02, 13.86], ['E7', 2637.02, 13.08], ['F7', 2793.83, 12.35], ['F#7', 2959.96, 11.66], ['G7', 3135.96, 11.00], ['G#7', 3322.44, 10.38], ['A7', 3520.00, 9.80], ['A#7', 3729.31, 9.25], ['B7', 3951.07, 8.73], ['C8', 4186.01, 8.24], ['C#8', 4434.92, 7.78], ['D8', 4698.63, 7.34], ['D#8', 4978.03, 6.93], ['E8', 5274.04, 6.54], ['F8', 5587.65, 6.17], ['F#8', 5919.91, 5.83], ['G8', 6271.93, 5.50], ['G#8', 6644.88, 5.19], ['A8', 7040.00, 4.90], ['A#8', 7458.62, 4.63], ['B8', 7902.13, 4.37]];
  297. this.findNote = (name) => {
  298. var ind;
  299. ind = this.notes.findIndex((arr) => {
  300. return arr[0] === name;
  301. });
  302. if (ind === -1) {
  303. return edide.logProd(`can't find: ${name}`);
  304. }
  305. return [ind, name, this.notes[ind][1]];
  306. };
  307. a4 = this.findNote('A4');
  308. this.diffToA4 = (name) => {
  309. var note;
  310. note = this.findNote(name);
  311. return note[0] - a4[0];
  312. };
  313. this.diff = (n1, n2) => {
  314. return this.findNote(n2)[0] - this.findNote(n1)[0];
  315. };
  316. return this;
  317. }).call({}, edide);
  318. "use strict";edide.mathOp = (function _mathOp (edide) {Object.defineProperty(this, 'module_name', {value:'mathOp'});
  319. this.sum = function(a, b) {
  320. return a + b;
  321. };
  322. this.multiply = function(a, b) {
  323. return a * b;
  324. };
  325. return this;
  326. }).call({}, edide);
  327. "use strict";edide.mmKeyboard = (function _mmKeyboard (edide) {Object.defineProperty(this, 'module_name', {value:'mmKeyboard'});
  328. var A, a, char, chari, i, j, len, len1, noncaps, qwertyChar, qwertyRows, revar, row, rowi, space, unvar;
  329. ({revar, unvar} = edide.mmState.init());
  330. revar.scaleSteps = () => {
  331. return edide.musicScales.scaleSteps[revar.scale];
  332. };
  333. this.special = {
  334. rest: '.',
  335. long: '=',
  336. comment: '#',
  337. var: ':',
  338. confStart: '{',
  339. confEnd: '}'
  340. };
  341. this.specialKeyCodes = new Set(Object.values(this.special).map((s) => {
  342. return s.charCodeAt(0);
  343. }));
  344. this.specialChars = new Set(Object.values(this.special));
  345. this.isPauseKey = (keyCode) => {
  346. return this.specialKeyCodes.has(keyCode);
  347. };
  348. this.isSpecialChar = (char) => {
  349. return this.specialChars.has(char);
  350. };
  351. this.isPauseChar = this.isSpecialChar; // not really...
  352. this.keyboards = ['qwerty', 'abc'];
  353. a = 'a'.charCodeAt(0);
  354. A = 'A'.charCodeAt(0);
  355. space = ' '.charCodeAt(0);
  356. this.isCaps = (key) => {
  357. return A <= key && key < a;
  358. };
  359. this.capsDiff = a - A;
  360. noncaps = (key) => {
  361. if (this.isCaps(key)) {
  362. return key + this.capsDiff;
  363. } else {
  364. return key;
  365. }
  366. };
  367. this.getNoteInd = (key) => {
  368. var maxInstrumentNoteInd, noteBaseInd, noteInd, notes, startNote, step;
  369. ({startNote, notes, step} = revar.instrumentConf);
  370. noteBaseInd = edide.noteFreq.findNote(startNote)[0];
  371. noteInd = this[this.keyboards[revar.keyboardInd]](noncaps(key), noteBaseInd);
  372. maxInstrumentNoteInd = noteBaseInd + notes * step;
  373. while (noteInd > maxInstrumentNoteInd) {
  374. noteInd -= 2 * 12;
  375. }
  376. return noteInd;
  377. };
  378. this.abc = (key, baseInd) => {
  379. var fromLowest, noteInd, stepsFromClosestOctave;
  380. fromLowest = key - a;
  381. stepsFromClosestOctave = fromLowest % revar.scaleSteps.length;
  382. noteInd = 0;
  383. noteInd += revar.scaleSteps.slice(0, +stepsFromClosestOctave + 1 || 9e9).reduce(edide.mathOp.sum);
  384. noteInd += 12 * Math.floor(fromLowest / revar.scaleSteps.length);
  385. return baseInd + noteInd;
  386. };
  387. qwertyRows = ['1234567890', 'qwertyuiop', 'asdfghjkl', 'zxcvbnm'];
  388. qwertyChar = {};
  389. for (rowi = i = 0, len = qwertyRows.length; i < len; rowi = ++i) {
  390. row = qwertyRows[rowi];
  391. for (chari = j = 0, len1 = row.length; j < len1; chari = ++j) {
  392. char = row[chari];
  393. qwertyChar[char.charCodeAt(0)] = [rowi, chari];
  394. }
  395. }
  396. this.qwerty = (key, baseInd) => {
  397. var charSteps, halfSteps, noteInd, octave, rowchar;
  398. if (!(rowchar = qwertyChar[key])) {
  399. return;
  400. }
  401. [row, char] = rowchar;
  402. octave = qwertyRows.length - 1 - row + Math.floor(char / unvar.scaleSteps.length);
  403. char = char % revar.scaleSteps.length;
  404. charSteps = revar.scaleSteps.slice(0, +char + 1 || 9e9).reduce((a, b) => {
  405. return a + b;
  406. });
  407. halfSteps = 12 * octave + charSteps;
  408. return noteInd = baseInd + halfSteps;
  409. };
  410. return this;
  411. }).call({}, edide);
  412. "use strict";edide.mmNote = (function _mmNote (edide) {Object.defineProperty(this, 'module_name', {value:'mmNote'});
  413. this.fromChar = (char) => {
  414. return this.fromKeyCode(char.charCodeAt(0));
  415. };
  416. this.fromKeyCode = (key) => {
  417. var noteInd, ref;
  418. if (typeof (noteInd = edide.mmKeyboard.getNoteInd(key)) === 'number') {
  419. return (ref = edide.noteFreq.notes[noteInd]) != null ? ref[0] : void 0;
  420. }
  421. };
  422. return this;
  423. }).call({}, edide);
  424. "use strict";edide.clone = (function _clone (edide) {
  425. return function(...objects) {
  426. if (Array.isArray(objects[0])) {
  427. return Object.assign([], ...objects);
  428. } else {
  429. return Object.assign({}, ...objects);
  430. }
  431. };
  432. return this;
  433. }).call({}, edide);
  434. "use strict";edide.strParsesToNumber = (function _strParsesToNumber (edide) {
  435. return (str) => {
  436. return !Number.isNaN(parseInt(str));
  437. };
  438. return this;
  439. }).call({}, edide);
  440. "use strict";edide.mmConfigs = (function _mmConfigs (edide) {Object.defineProperty(this, 'module_name', {value:'mmConfigs'});
  441. var defaultVars, mutatingProp, mutatingVars, vars;
  442. vars = {}; // varName: config object
  443. mutatingVars = {};
  444. this.hasVar = (varName) => {
  445. var ref;
  446. return !!((ref = vars[varName]) != null ? ref : mutatingVars[varName]);
  447. };
  448. this.activateVar = (name, value) => {
  449. var configs;
  450. if (value != null) {
  451. configs = edide.clone(mutatingVars[name]);
  452. if (edide.strParsesToNumber(value)) {
  453. value = parseFloat(value);
  454. }
  455. configs[mutatingProp(configs)] = value;
  456. return this.activate(configs);
  457. } else {
  458. return this.activate(vars[name]);
  459. }
  460. };
  461. mutatingProp = (configs) => {
  462. var name, val;
  463. for (name in configs) {
  464. val = configs[name];
  465. if (val === '*') {
  466. return name;
  467. }
  468. }
  469. return false;
  470. };
  471. this.activate = (conf) => {
  472. if (conf.name != null) {
  473. return; // throw warning?
  474. }
  475. return Object.assign(edide.mmState.revar, conf);
  476. };
  477. this.addVar = (varName, config) => { // , activate=true
  478. if (mutatingProp(config)) {
  479. return mutatingVars[varName] = config;
  480. } else {
  481. return vars[varName] = config;
  482. }
  483. };
  484. defaultVars = {
  485. bass: {
  486. "instrument": "bass-electric"
  487. },
  488. cello: {
  489. "instrument": "cello"
  490. },
  491. guitar: {
  492. "instrument": "guitar-acoustic"
  493. },
  494. eguitar: {
  495. "instrument": "guitar-electric"
  496. },
  497. piano: {
  498. "instrument": "piano"
  499. },
  500. synth: {
  501. "instrument": "synth-simple"
  502. },
  503. xylophone: {
  504. "instrument": "xylophone"
  505. },
  506. pentatonic: {
  507. "scale": "pentatonicMinor"
  508. },
  509. major: {
  510. "scale": "naturalMajor"
  511. },
  512. minor: {
  513. "scale": "naturalMinor"
  514. }
  515. };
  516. this.init = () => {
  517. var conf, name, results;
  518. vars = {};
  519. results = [];
  520. for (name in defaultVars) {
  521. conf = defaultVars[name];
  522. results.push(this.addVar(name, conf, false));
  523. }
  524. return results;
  525. };
  526. this.init();
  527. return this;
  528. }).call({}, edide);
  529. "use strict";edide.inEditor = (function _inEditor (edide) {
  530. return typeof window === 'object' &&
  531. typeof window.serverModule === 'object'
  532. return this;
  533. }).call({}, edide);
  534. "use strict";edide.edideNamespace = (function _edideNamespace (edide) {
  535. return 'edide'
  536. return this;
  537. }).call({}, edide);
  538. "use strict";edide.showError = (function _showError (edide) {
  539. var showError;
  540. showError = (err) => {
  541. if (edide.inEditor) {
  542. return edide.editorModule.editor_error.show(err);
  543. } else if (typeof edide.global.require === 'object' && (edide.global[edide.edideNamespace].prodErrorPrinter != null)) {
  544. return edide.global[edide.edideNamespace].prodErrorPrinter.showError(err);
  545. } else {
  546. return console.error(err);
  547. }
  548. };
  549. return (err) => {
  550. var error;
  551. if (err != null ? err.stack : void 0) {
  552. return showError(err); // create error to capture stack trace
  553. } else {
  554. try {
  555. throw Error(err);
  556. } catch (error1) {
  557. error = error1;
  558. return showError(error);
  559. }
  560. }
  561. };
  562. return this;
  563. }).call({}, edide);
  564. "use strict";edide.mmParserSpecial = (function _mmParserSpecial (edide) {Object.defineProperty(this, 'module_name', {value:'mmParserSpecial'});
  565. this.config = (trackStr, ts = {}) => {
  566. var endInd, err, name;
  567. endInd = trackStr.search('}') || trackStr.length;
  568. try {
  569. ts.conf = JSON.parse(trackStr.slice(0, +endInd + 1 || 9e9));
  570. if (ts.conf.name != null) {
  571. ({name} = ts.conf);
  572. delete ts.conf.name;
  573. edide.mmConfigs.addVar(name, ts.conf);
  574. } else {
  575. edide.mmConfigs.activate(ts.conf); // add variable if exists
  576. }
  577. } catch (error) {
  578. err = error;
  579. ts.skip = true; // could be used to show error highlighting in editor
  580. edide.showError(err); // remove this if error highlighting implemented
  581. }
  582. return endInd;
  583. };
  584. this.var = (track, trackState) => {
  585. var i, value, varLength, varName, varStr;
  586. ({i} = trackState);
  587. varLength = track.slice(i + 1).indexOf(edide.mmKeyboard.special.var);
  588. if (varLength === -1) {
  589. return false;
  590. }
  591. varStr = track.slice(i + 1, +(i + varLength) + 1 || 9e9);
  592. [varName, value] = varStr.split(' ');
  593. if (!edide.mmConfigs.hasVar(varName)) {
  594. return false;
  595. }
  596. edide.mmConfigs.activateVar(varName, value);
  597. trackState.i += varLength + 2;
  598. return true;
  599. };
  600. return this;
  601. }).call({}, edide);
  602. "use strict";edide.onUnload = (function _onUnload (edide) {
  603. var ref, ref1;
  604. return (ref = (ref1 = edide.editorModule) != null ? ref1.unload.add : void 0) != null ? ref : () => {};
  605. return this;
  606. }).call({}, edide);
  607. "use strict";edide.mmPipe = (function _mmPipe (edide) {Object.defineProperty(this, 'module_name', {value:'mmPipe'});
  608. var dist, lowpass, react, revar, reverber, unvar;
  609. ({revar, unvar, react} = edide.mmState.init());
  610. dist = lowpass = reverber = null;
  611. this.initPipe = () => {
  612. lowpass = new Tone.Filter(unvar.lowpass, 'lowpass', -12);
  613. dist = new Tone.Distortion(unvar.distortion);
  614. this.output = lowpass;
  615. lowpass.toMaster();
  616. dist.connect(lowpass);
  617. revar.pipeReady = true;
  618. return edide.onUnload(() => {
  619. if (dist != null) {
  620. if (typeof dist.dipose === "function") {
  621. dist.dipose();
  622. }
  623. }
  624. return lowpass != null ? typeof lowpass.dispose === "function" ? lowpass.dispose() : void 0 : void 0;
  625. });
  626. };
  627. this.initInstrument = (instrument) => {
  628. instrument.connect(dist);
  629. edide.onUnload(() => {
  630. return instrument != null ? instrument.disconnect() : void 0;
  631. });
  632. return instrument;
  633. };
  634. react('pipe distortion', () => {
  635. var ref;
  636. revar.distortion;
  637. revar.lowpass;
  638. if (dist != null) {
  639. dist.distortion = revar.distortion;
  640. }
  641. return lowpass != null ? (ref = lowpass.frequency) != null ? ref.linearRampTo(revar.lowpass, 0) : void 0 : void 0;
  642. });
  643. return this;
  644. }).call({}, edide);
  645. "use strict";edide.moduleGate = (function _moduleGate (edide) {Object.defineProperty(this, 'module_name', {value:'moduleGate'});
  646. if (!edide.inEditor) {
  647. return this;
  648. }
  649. this.all = typeof serverModule !== "undefined" && serverModule !== null ? serverModule.modules.all : void 0; // why not just use \:modules.all ?
  650. this.root; // module that is edited in root
  651. this.rootName;
  652. this.active; // module that is currently being edited (can be root or in window)
  653. this.activeName;
  654. this.executing;
  655. this.executingName;
  656. return this;
  657. }).call({}, edide);
  658. "use strict";edide.rejectIfRecompiled = (function _rejectIfRecompiled (edide) {
  659. if (!edide.inEditor) {
  660. return;
  661. }
  662. return (promise) => {
  663. var recompiled, rootModuleFunc, rootName;
  664. ({rootName} = edide.moduleGate);
  665. recompiled = false;
  666. edide.editorModule.editor_events.on('before_recompile', () => {
  667. return recompiled = true;
  668. });
  669. rootModuleFunc = edide.editorModule.modules.moduleFunc[rootName];
  670. return promise.then(function(arg) {
  671. if (recompiled || rootName !== edide.moduleGate.rootName) { // root module changed
  672. return Promise.reject(); // quiet rejection; no need to show error
  673. } else {
  674. return arg; // arg get wrapped in promise
  675. }
  676. });
  677. };
  678. return this;
  679. }).call({}, edide);
  680. "use strict";edide.promise = (function _promise (edide) {Object.defineProperty(this, 'module_name', {value:'promise'});
  681. this.new = function(cb) {
  682. if (edide.inEditor) {
  683. return edide.rejectIfRecompiled(new Promise(cb)); // don't fire cb if code has been re-executed in the meantime
  684. } else {
  685. return new Promise(cb); //, edide.editorModule?.editor_error.show
  686. }
  687. };
  688. this.all = function(cbArray) {
  689. if (edide.inEditor) { // check that after resolved, still editing same module
  690. return edide.rejectIfRecompiled(Promise.all(cbArray));
  691. } else {
  692. return Promise.all(cbArray);
  693. }
  694. };
  695. this.resolve = Promise.resolve.bind(Promise);
  696. this.reject = Promise.reject.bind(Promise);
  697. return this;
  698. }).call({}, edide);
  699. "use strict";edide.qs = (function _qs (edide) {
  700. return (selector) => {
  701. return document.querySelector(selector);
  702. };
  703. return this;
  704. }).call({}, edide);
  705. "use strict";edide.scriptContainer = (function _scriptContainer (edide) {
  706. var createContainer, ref;
  707. createContainer = () => {
  708. var s;
  709. s = document.createElement('div');
  710. s.id = 'scripts';
  711. return s;
  712. };
  713. return (ref = edide.qs('#scripts')) != null ? ref : document.body.appendChild(createContainer());
  714. return this;
  715. }).call({}, edide);
  716. "use strict";edide.requireScript = (function _requireScript (edide) {
  717. var base;
  718. if ((base = edide.global).requireScriptPromises == null) {
  719. base.requireScriptPromises = new Map;
  720. }
  721. return (scriptSrc) => {
  722. var promise;
  723. if (promise = requireScriptPromises.get(scriptSrc)) {
  724. return promise;
  725. } else {
  726. requireScriptPromises.set(scriptSrc, promise = edide.promise.new((resolve) => {
  727. var el;
  728. console.log('adding promised', scriptSrc);
  729. el = document.createElement('script');
  730. edide.scriptContainer.appendChild(el);
  731. el.onload = resolve; //load_ready
  732. el.type = 'application/javascript';
  733. return el.src = scriptSrc;
  734. }));
  735. return promise.catch((err) => {
  736. edide.showError(err);
  737. return requireScriptPromises.delete(scriptSrc);
  738. });
  739. }
  740. };
  741. return this;
  742. }).call({}, edide);
  743. "use strict";edide.set = (function _set (edide) {
  744. return (...args) => new Set(args)
  745. return this;
  746. }).call({}, edide);
  747. "use strict";edide.membrameSynth = (function _membrameSynth (edide) {Object.defineProperty(this, 'module_name', {value:'membrameSynth'});
  748. this.startNote = 'A0';
  749. this.init = () => {
  750. var bd, compressor, distortion, gain, reverb;
  751. distortion = new Tone.Distortion({
  752. distortion: 0.1,
  753. oversample: "4x" // none, 2x, 4x
  754. });
  755. reverb = new Tone.Freeverb(0.75, 1000);
  756. gain = new Tone.Gain(0.5);
  757. compressor = new Tone.Compressor({
  758. ratio: 12,
  759. threshold: -24,
  760. release: 0.05,
  761. attack: 0.003,
  762. knee: 1
  763. });
  764. bd = new Tone.MembraneSynth({
  765. pitchDecay: 0.05,
  766. octaves: 4,
  767. envelope: {
  768. attack: 0.01,
  769. decay: 0.74,
  770. sustain: 0.71,
  771. release: 0.05,
  772. attackCurve: "exponential"
  773. }
  774. });
  775. bd.chain(gain, distortion, reverb, compressor);
  776. return [bd, compressor];
  777. };
  778. return this;
  779. }).call({}, edide);
  780. "use strict";edide.toneSynth = (function _toneSynth (edide) {Object.defineProperty(this, 'module_name', {value:'toneSynth'});
  781. this.startNote = 'C3';
  782. this.init = () => {
  783. var ss;
  784. return ss = new Tone.PolySynth(12, Tone.Synth, {
  785. oscillator: {
  786. type: 'sine'
  787. },
  788. envelope: {
  789. attack: 0.005,
  790. decay: 0.1,
  791. sustain: 0.3,
  792. release: 1
  793. }
  794. });
  795. };
  796. return this;
  797. }).call({}, edide);
  798. "use strict";edide.instrumentConfigs = (function _instrumentConfigs (edide) {Object.defineProperty(this, 'module_name', {value:'instrumentConfigs'});
  799. var defaultUrl = 'https://nbrosowsky.github.io/tonejs-instruments/samples/'
  800. var { revar, unvar, react } = edide.mmState
  801. var defaultInstrument = 'electric-guitar'
  802. this.initInstrument = async (resolve) => {
  803. await edide.requireScript('https://cdnjs.cloudflare.com/ajax/libs/tone/13.8.9/Tone.js')
  804. edide.mmPipe.initPipe()
  805. }
  806. this.createNew = () => {
  807. var {name} = unvar.instrumentConf
  808. var instrument, endOfPipe
  809. var instrumentConf = this.instruments[name]
  810. if (instrumentConf.module_name) {
  811. var res = instrumentConf.init()
  812. if (Array.isArray(res)) {
  813. instrument = res[0]
  814. endOfPipe = res[1]
  815. } else {
  816. instrument = endOfPipe = res
  817. }
  818. } else {
  819. var noteFiles = buildNotes(instrumentConf)
  820. var inst = new Tone.Sampler(noteFiles, { //edide.instrumentConfigssAll[name]
  821. "release" : 1,
  822. "baseUrl" : instrumentConf.url || defaultUrl + name + '/'
  823. })
  824. inst.soundFontInstrument = true
  825. instrument = endOfPipe = inst //[inst, inst]
  826. }
  827. edide.mmPipe.initInstrument(endOfPipe)
  828. return instrument
  829. }
  830. this.isReady = () => {
  831. var { current } = this
  832. return current && (typeof current.loaded == 'undefined' || current.loaded === true)
  833. }
  834. function buildNotes({startNote, notes, step, skipNotes}) {
  835. var [startInd] = edide.noteFreq.findNote(startNote)
  836. var noteFiles = {}
  837. if (Array.isArray(notes)) {
  838. notes.forEach(note => {
  839. noteFiles[note] = note.replace('#','s') + '.[mp3|ogg]'
  840. })
  841. } else {
  842. for (let i=0; i < notes*step; i+=step) {
  843. let note = edide.noteFreq.notes[startInd + i][0];
  844. if (skipNotes && skipNotes.has(note))
  845. continue
  846. noteFiles[note] = note.replace('#','s') + '.[mp3|ogg]'
  847. }
  848. }
  849. return noteFiles
  850. }
  851. this.instruments = {
  852. 'bass-electric': {
  853. startNote: 'C#2',
  854. notes: 8, // 16
  855. step: 3
  856. },
  857. 'cello': {
  858. startNote: 'C2',
  859. notes: 11,
  860. step: 2,
  861. skipNotes: edide.set('F#2', 'C4')
  862. },
  863. 'drum-electric': edide.membrameSynth,
  864. 'guitar-acoustic': {
  865. startNote: 'D1',
  866. notes: 26, // 36
  867. step: 2,
  868. skipNotes: edide.set('E4', 'F#4', 'G#4', 'A#4', 'C5', 'D5', 'E5')
  869. }, // umm, would be simpler to just add all notes
  870. 'guitar-electric': {
  871. startNote: 'F#2',
  872. notes: 15, // 15
  873. step: 3,
  874. },
  875. 'piano': {
  876. startNote: 'A1',
  877. notes: 30, // 29
  878. step: 2,
  879. volume: -6, // TODO implement this
  880. baseUrl: "https://tonejs.github.io/examples/audio/salamander/"
  881. },
  882. 'synth-simple': edide.toneSynth,
  883. 'xylophone': {
  884. startNote: 'G3',
  885. notes: ['G3', 'C4', 'G4', 'C5', 'G5', 'C6', 'G6', 'C7']
  886. }
  887. }
  888. for (let inst in this.instruments) {
  889. this.instruments[inst].name = inst
  890. }
  891. this.instrumentList = Object.values(this.instruments)
  892. react('active instrument config', () => {
  893. revar.instrumentConf = this.instruments[revar.instrument] // this.instrumentList[revar.instrumentInd]
  894. })
  895. return this;
  896. }).call({}, edide);
  897. "use strict";edide.cloneSibling = (function _cloneSibling (edide) {
  898. return (srcObj) => {
  899. var o;
  900. o = Object.create(Object.getPrototypeOf(srcObj));
  901. Object.assign(o, srcObj);
  902. return o;
  903. };
  904. return this;
  905. }).call({}, edide);
  906. "use strict";edide.times = (function _times (edide) {
  907. return (timesNum, action) => {
  908. while (timesNum-- > 0) {
  909. action(timesNum + 1);
  910. }
  911. };
  912. return this;
  913. }).call({}, edide);
  914. "use strict";edide.setTimeout = (function _setTimeout (edide) {
  915. return function(arg1, arg2) {
  916. var fun, id, num;
  917. [fun, num] = typeof arg2 === 'function' ? [arg2, arg1] : [arg1, arg2];
  918. id = setTimeout(fun, num);
  919. edide.onUnload(() => {
  920. return clearTimeout(id);
  921. });
  922. return id;
  923. };
  924. return this;
  925. }).call({}, edide);
  926. "use strict";edide.sleep = (function _sleep (edide) {
  927. var sleep;
  928. sleep = (ms) => {
  929. var resolve, timeout;
  930. timeout = resolve = null;
  931. return edide.promise.new((res) => {
  932. resolve = res;
  933. return timeout = edide.setTimeout(ms, res);
  934. });
  935. };
  936. return sleep;
  937. return this;
  938. }).call({}, edide);
  939. "use strict";edide.mmInstrument = (function _mmInstrument (edide) {Object.defineProperty(this, 'module_name', {value:'mmInstrument'});
  940. var cloneOrCreateInstrument, getInstruments, instruments, play, react, revar, unvar, updateVolAndTune;
  941. instruments = {}; // name: [instrument instances...]
  942. ({unvar, revar, react} = edide.mmState);
  943. react('delay from bmp', () => {
  944. return revar.beatDelay = (1 / revar.bpm) * 60 * 1000;
  945. });
  946. react(() => {});
  947. updateVolAndTune = (inst) => {
  948. var detune, volume;
  949. ({volume, detune} = unvar);
  950. if ((detune != null) && (inst.detune != null)) {
  951. inst.set("detune", detune);
  952. }
  953. if ((volume != null) && (inst.volume != null)) {
  954. return inst.set("volume", volume);
  955. }
  956. };
  957. react(() => {
  958. var inst, insts, j, len, name;
  959. revar.volume;
  960. revar.detune;
  961. for (name in instruments) {
  962. insts = instruments[name];
  963. for (j = 0, len = insts.length; j < len; j++) {
  964. inst = insts[j];
  965. updateVolAndTune(inst);
  966. }
  967. }
  968. });
  969. react('create first instrument', () => {
  970. var name, ref;
  971. if (!(name = (ref = revar.instrumentConf) != null ? ref.name : void 0)) { // e.g. illegal instrument name
  972. return edide.showError(`Unknown instrument: ${unvar.instrument}`);
  973. }
  974. if (revar.pipeReady && !instruments[name]) {
  975. 'create initial instrument';
  976. return instruments[name] = [edide.instrumentConfigs.createNew()];
  977. }
  978. });
  979. cloneOrCreateInstrument = (name) => {
  980. var inst;
  981. inst = instruments[name][0].soundFontInstrument ? (inst = edide.cloneSibling(instruments[name][0]), inst.isPlaying = false, inst) : edide.instrumentConfigs.createNew();
  982. updateVolAndTune(inst);
  983. return inst;
  984. };
  985. getInstruments = (n) => {
  986. var all, free, name;
  987. ({name} = unvar.instrumentConf);
  988. all = instruments[name];
  989. free = all.filter((i) => {
  990. return !i.isPlaying;
  991. });
  992. edide.times(n - free.length, () => {
  993. var inst;
  994. free.push(inst = cloneOrCreateInstrument(name));
  995. return all.push(inst);
  996. });
  997. return free.slice(0, n);
  998. };
  999. this.playChord = (chord, noteLength = 1) => {};
  1000. this.playNote = (chord, noteLength = 1) => {
  1001. var ind, inst, insts, j, len, ref;
  1002. if (!Array.isArray(chord)) {
  1003. chord = [chord];
  1004. }
  1005. ref = insts = getInstruments(chord.length);
  1006. for (ind = j = 0, len = ref.length; j < len; ind = ++j) {
  1007. inst = ref[ind];
  1008. play(inst, chord[ind], noteLength);
  1009. }
  1010. };
  1011. play = async(instrument, note, length) => {
  1012. var err;
  1013. instrument.isPlaying = note; // true
  1014. try {
  1015. instrument.triggerAttackRelease(note, (length * unvar.beatDelay) / 1000);
  1016. } catch (error) {
  1017. err = error;
  1018. err.message = `Error in playing note ${note}, '${unvar.instrumentConf.name}' probably not loaded yet`;
  1019. edide.showError(err);
  1020. }
  1021. revar.note = note;
  1022. await edide.sleep(unvar.nextDelay);
  1023. return instrument.isPlaying = false;
  1024. };
  1025. return this;
  1026. }).call({}, edide);
  1027. "use strict";edide.mmParser = (function _mmParser (edide) {Object.defineProperty(this, 'module_name', {value:'mmParser'});
  1028. var getNoteLength, processTrack, react, revar, unvar;
  1029. ({revar, unvar, react} = edide.mmState);
  1030. getNoteLength = (row, noteInd) => {
  1031. var char, length;
  1032. length = 1;
  1033. while (char = row[++noteInd]) {
  1034. if (char === edide.mmKeyboard.special.long) {
  1035. length++;
  1036. } else {
  1037. break;
  1038. }
  1039. }
  1040. return length;
  1041. };
  1042. processTrack = (track, ccs, ts) => {
  1043. var chord, keyCode, note;
  1044. if (!track[ts.i]) {
  1045. return;
  1046. }
  1047. if (ts.skip) { // comment or erroneous chars
  1048. return;
  1049. }
  1050. switch (track[ts.i]) {
  1051. case '{':
  1052. return ts.i += edide.mmParserSpecial.config(track.slice(ts.i), ts); // parseConfigs
  1053. case '[':
  1054. ccs.chord = [];
  1055. ts.i++;
  1056. return processTrack(track, ccs, ts);
  1057. case ']':
  1058. ({chord} = ccs);
  1059. ccs.chord = null;
  1060. ts.i++;
  1061. if (chord.length) {
  1062. edide.mmInstrument.playNote(chord, getNoteLength(track, ts.i));
  1063. ccs.played = true;
  1064. } else {
  1065. processTrack(track, ccs, ts);
  1066. }
  1067. return;
  1068. case edide.mmKeyboard.special.var:
  1069. if (edide.mmParserSpecial.var(track, ts)) {
  1070. processTrack(track, ccs, ts); // recursive, since next char could be another var, e.g. \:bass::minor:
  1071. } else {
  1072. ts.skip = true; // parse error
  1073. }
  1074. return;
  1075. case edide.mmKeyboard.special.comment:
  1076. return ts.skip = true;
  1077. }
  1078. if (!(keyCode = track.charCodeAt(ts.i))) {
  1079. return;
  1080. }
  1081. ts.i++;
  1082. if (note = edide.mmNote.fromKeyCode(keyCode)) {
  1083. if (ccs.chord) {
  1084. ccs.chord.push(note);
  1085. processTrack(track, ccs, ts);
  1086. } else {
  1087. edide.mmInstrument.playNote(note, getNoteLength(track, ts.i));
  1088. ccs.played = true;
  1089. }
  1090. } else if (edide.mmKeyboard.isPauseKey(keyCode)) {
  1091. ccs.played = true; // "play silence"
  1092. } else {
  1093. processTrack(track, ccs, ts);
  1094. }
  1095. };
  1096. this.splitSections = (str) => {
  1097. var i, j, prevInd, ref, row, section, sections;
  1098. str = str.replace('&\n', ''); // TODO fix row tracking with &\n
  1099. sections = [];
  1100. section = null;
  1101. row = 0;
  1102. prevInd = 0;
  1103. for (i = j = 0, ref = str.length; (0 <= ref ? j <= ref : j >= ref); i = 0 <= ref ? ++j : --j) {
  1104. if (!(str[i] === '\n' || i === str.length)) {
  1105. continue;
  1106. }
  1107. if (str[i - 1] === '\n') {
  1108. if (section != null) {
  1109. sections.push(section);
  1110. }
  1111. section = null;
  1112. }
  1113. if (i > prevInd) {
  1114. if (section == null) {
  1115. section = {
  1116. row: row,
  1117. tracks: []
  1118. };
  1119. }
  1120. section.tracks.push(str.slice(prevInd, i));
  1121. }
  1122. row++;
  1123. prevInd = i + 1;
  1124. }
  1125. if (section != null) {
  1126. sections.push(section);
  1127. }
  1128. sections.row = 0;
  1129. return sections;
  1130. };
  1131. this.play = (song, sectionInd, trackStates) => {
  1132. var ccs, section;
  1133. if (!unvar.playing) {
  1134. return;
  1135. }
  1136. revar.highlight = null;
  1137. sectionInd = sectionInd || 0;
  1138. if (typeof song === 'string') {
  1139. song = this.splitSections(song);
  1140. }
  1141. section = song[sectionInd];
  1142. if (!section) { // song finished
  1143. return revar.playing = false;
  1144. }
  1145. if (!Array.isArray(trackStates)) {
  1146. trackStates = section.tracks.map(() => {
  1147. return {
  1148. i: 0 // initi track indices on first call to section
  1149. };
  1150. });
  1151. }
  1152. ccs = {}; // chord, played # TODO change back to chord: [C3, D3] and [].played = true
  1153. section.tracks.forEach((track, tInd) => {
  1154. var conf, i, iStart;
  1155. if (conf = trackStates[tInd].conf) {
  1156. return edide.mmConfigs.activate(conf);
  1157. } else {
  1158. trackStates[tInd].iStart = trackStates[tInd].i;
  1159. processTrack(track, ccs, trackStates[tInd]);
  1160. ({iStart, i} = trackStates[tInd]);
  1161. if (i > iStart) {
  1162. return revar.highlight = [song.row + section.row + tInd, iStart, i - 1];
  1163. }
  1164. }
  1165. });
  1166. if (ccs.played) {
  1167. edide.setTimeout(() => {
  1168. return this.play(song, sectionInd, trackStates);
  1169. }, unvar.beatDelay);
  1170. } else {
  1171. edide.setTimeout(() => {
  1172. return this.play(song, sectionInd + 1);
  1173. });
  1174. }
  1175. };
  1176. return this;
  1177. }).call({}, edide);
  1178. "use strict";edide.music = (function _music (edide) {Object.defineProperty(this, 'module_name', {value:'music'});
  1179. edide.global.music = this
  1180. edide.mmEffects
  1181. var { revar, unvar, react } = edide.mmState
  1182. var playQueue = []
  1183. this.play = (str) => {
  1184. if (!unvar.pipeReady) return playQueue.push(str)
  1185. revar.playing = true
  1186. edide.mmParser.play(str)
  1187. }
  1188. this.stop = () => revar.playing = false
  1189. edide.instrumentConfigs.initInstrument()
  1190. var initialSettings = {
  1191. "instrument": "synth-simple", //"piano"
  1192. }
  1193. react(() => {
  1194. if(!revar.pipeReady) return
  1195. edide.mmConfigs.activate(initialSettings)
  1196. this.play(playQueue.join("\n\n")) // JSON.stringify(initialSettings)
  1197. }) // TEMP init instrument
  1198. return this;
  1199. }).call({}, edide);
  1200. "use strict";edide.wave = (function _wave (edide) {
  1201. var parent = {
  1202. play: function(){
  1203. edide.music.play(this.sheet)
  1204. return this
  1205. },
  1206. stop: function(){
  1207. edide.music.stop(this.sheet)
  1208. return this
  1209. },
  1210. blur: function(val){
  1211. edide.mmConfigs.activate({'blur': val})
  1212. return this
  1213. },
  1214. itch: function(val){
  1215. edide.mmConfigs.activate({'itch': val})
  1216. return this
  1217. },
  1218. long: function(val){ // note delay in seconds
  1219. edide.mmConfigs.activate({'beatDelay': val*1000})
  1220. return this
  1221. },
  1222. pace: function(val) { // note delay in beats per minute
  1223. edide.mmConfigs.activate({'bpm': val})
  1224. return this
  1225. },
  1226. vary: function(val){
  1227. edide.mmConfigs.activate({'detune': val})
  1228. return this
  1229. },
  1230. loud: function(val){ // increase (>0) or decrease (<0) amplitude in decibels
  1231. edide.mmConfigs.activate({'volume': val})
  1232. return this
  1233. },
  1234. }
  1235. return edide.global.wave = (str) => {
  1236. var obj = Object.create(parent)
  1237. obj.sheet = str
  1238. return obj
  1239. }
  1240. return this;
  1241. }).call({}, edide);