nodeskini 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +31 -0
  2. package/client/archive/bundle.js +11528 -0
  3. package/client/archive/golem.html +60 -0
  4. package/client/archive/golemClient.js +595 -0
  5. package/client/archive/golembundle.js +11634 -0
  6. package/client/archive/sequencer.html +43 -0
  7. package/client/archive/sequenceurClient.js +815 -0
  8. package/client/archive/stylegolem.css +158 -0
  9. package/client/archive/stylesequenceur.css +204 -0
  10. package/client/clientListe/Sortable-master/.circleci/config.yml +33 -0
  11. package/client/clientListe/Sortable-master/.editorconfig +15 -0
  12. package/client/clientListe/Sortable-master/.github/ISSUE_TEMPLATE/bug-report.md +73 -0
  13. package/client/clientListe/Sortable-master/.github/ISSUE_TEMPLATE/custom-template.md +48 -0
  14. package/client/clientListe/Sortable-master/.github/ISSUE_TEMPLATE/feature-request.md +41 -0
  15. package/client/clientListe/Sortable-master/.jshintrc +25 -0
  16. package/client/clientListe/Sortable-master/.testcaferc.json +7 -0
  17. package/client/clientListe/Sortable-master/CONTRIBUTING.md +26 -0
  18. package/client/clientListe/Sortable-master/LICENSE +21 -0
  19. package/client/clientListe/Sortable-master/README.md +813 -0
  20. package/client/clientListe/Sortable-master/Sortable.js +3709 -0
  21. package/client/clientListe/Sortable-master/Sortable.min.js +2 -0
  22. package/client/clientListe/Sortable-master/Sortable.min.old.js +2 -0
  23. package/client/clientListe/Sortable-master/Sortable.min.old.old.js +2 -0
  24. package/client/clientListe/Sortable-master/babel.config.js +27 -0
  25. package/client/clientListe/Sortable-master/bower.json +30 -0
  26. package/client/clientListe/Sortable-master/entry/entry-complete.js +8 -0
  27. package/client/clientListe/Sortable-master/entry/entry-core.js +19 -0
  28. package/client/clientListe/Sortable-master/entry/entry-defaults.js +19 -0
  29. package/client/clientListe/Sortable-master/index.html +460 -0
  30. package/client/clientListe/Sortable-master/modular/sortable.complete.esm.js +3701 -0
  31. package/client/clientListe/Sortable-master/modular/sortable.core.esm.js +3698 -0
  32. package/client/clientListe/Sortable-master/modular/sortable.esm.js +3699 -0
  33. package/client/clientListe/Sortable-master/package-lock.json +5704 -0
  34. package/client/clientListe/Sortable-master/package.json +56 -0
  35. package/client/clientListe/Sortable-master/plugins/AutoScroll/AutoScroll.js +270 -0
  36. package/client/clientListe/Sortable-master/plugins/AutoScroll/README.md +80 -0
  37. package/client/clientListe/Sortable-master/plugins/AutoScroll/index.js +1 -0
  38. package/client/clientListe/Sortable-master/plugins/MultiDrag/MultiDrag.js +617 -0
  39. package/client/clientListe/Sortable-master/plugins/MultiDrag/README.md +96 -0
  40. package/client/clientListe/Sortable-master/plugins/MultiDrag/index.js +1 -0
  41. package/client/clientListe/Sortable-master/plugins/OnSpill/OnSpill.js +79 -0
  42. package/client/clientListe/Sortable-master/plugins/OnSpill/README.md +60 -0
  43. package/client/clientListe/Sortable-master/plugins/OnSpill/index.js +1 -0
  44. package/client/clientListe/Sortable-master/plugins/README.md +178 -0
  45. package/client/clientListe/Sortable-master/plugins/Swap/README.md +55 -0
  46. package/client/clientListe/Sortable-master/plugins/Swap/Swap.js +90 -0
  47. package/client/clientListe/Sortable-master/plugins/Swap/index.js +1 -0
  48. package/client/clientListe/Sortable-master/scripts/banner.js +8 -0
  49. package/client/clientListe/Sortable-master/scripts/build.js +17 -0
  50. package/client/clientListe/Sortable-master/scripts/esm-build.js +28 -0
  51. package/client/clientListe/Sortable-master/scripts/minify.js +11 -0
  52. package/client/clientListe/Sortable-master/scripts/test-compat.js +30 -0
  53. package/client/clientListe/Sortable-master/scripts/test.js +21 -0
  54. package/client/clientListe/Sortable-master/scripts/umd-build.js +15 -0
  55. package/client/clientListe/Sortable-master/src/Animation.js +175 -0
  56. package/client/clientListe/Sortable-master/src/BrowserInfo.js +12 -0
  57. package/client/clientListe/Sortable-master/src/EventDispatcher.js +57 -0
  58. package/client/clientListe/Sortable-master/src/PluginManager.js +87 -0
  59. package/client/clientListe/Sortable-master/src/Sortable.js +1971 -0
  60. package/client/clientListe/Sortable-master/src/utils.js +556 -0
  61. package/client/clientListe/Sortable-master/st/app.js +224 -0
  62. package/client/clientListe/Sortable-master/st/iframe/frame.html +32 -0
  63. package/client/clientListe/Sortable-master/st/iframe/index.html +49 -0
  64. package/client/clientListe/Sortable-master/st/logo.png +0 -0
  65. package/client/clientListe/Sortable-master/st/og-image.png +0 -0
  66. package/client/clientListe/Sortable-master/st/prettify/prettify.css +1 -0
  67. package/client/clientListe/Sortable-master/st/prettify/prettify.js +46 -0
  68. package/client/clientListe/Sortable-master/st/prettify/run_prettify.js +64 -0
  69. package/client/clientListe/Sortable-master/st/saucelabs.svg +1 -0
  70. package/client/clientListe/Sortable-master/st/theme.css +254 -0
  71. package/client/clientListe/Sortable-master/tests/Sortable.compat.test.js +39 -0
  72. package/client/clientListe/Sortable-master/tests/Sortable.test.js +386 -0
  73. package/client/clientListe/Sortable-master/tests/dual-list.html +34 -0
  74. package/client/clientListe/Sortable-master/tests/empty-list.html +30 -0
  75. package/client/clientListe/Sortable-master/tests/filter.html +27 -0
  76. package/client/clientListe/Sortable-master/tests/handles.html +27 -0
  77. package/client/clientListe/Sortable-master/tests/nested.html +67 -0
  78. package/client/clientListe/Sortable-master/tests/single-list.html +25 -0
  79. package/client/clientListe/Sortable-master/tests/style.css +18 -0
  80. package/client/clientListe/clientListe.html +148 -0
  81. package/client/clientListe/clientListe.js +1508 -0
  82. package/client/clientListe/clientListebundle.js +13164 -0
  83. package/client/clientListe/images/poubelle.png +0 -0
  84. package/client/clientListe/images/start.png +0 -0
  85. package/client/clientListe/images/stop.png +0 -0
  86. package/client/clientListe/images/submit.png +0 -0
  87. package/client/clientListe/sortable-theme-bootstrap.css +90 -0
  88. package/client/configurateur/configReact.js +273 -0
  89. package/client/configurateur/configReactbundle.js +295 -0
  90. package/client/configurateur/configurateur.css +95 -0
  91. package/client/configurateur/configurateur.html +48 -0
  92. package/client/configurateur/lib/jexcel.css +755 -0
  93. package/client/configurateur/lib/jexcel.js +14970 -0
  94. package/client/configurateur/lib/jsuites.css +2801 -0
  95. package/client/configurateur/lib/jsuites.js +11822 -0
  96. package/client/configurateur/lib/react-dom.production.min.js +239 -0
  97. package/client/configurateur/lib/react.production.min.js +32 -0
  98. package/client/configurateur/src/configReact.js +247 -0
  99. package/client/controleur/clientcontroleur.js +536 -0
  100. package/client/controleur/clientcontroleur.test.js +282 -0
  101. package/client/controleur/controleur.html +51 -0
  102. package/client/controleur/controleurbundle.js +565 -0
  103. package/client/controleur/stylecontroleur.css +236 -0
  104. package/client/controleurHH/controleurHH.html +71 -0
  105. package/client/controleurHH/controleurHH.js +252 -0
  106. package/client/controleurHH/styles/index.css +320 -0
  107. package/client/controleurHH/styles/material.css +11552 -0
  108. package/client/parametrage/paramReact.js +473 -0
  109. package/client/parametrage/paramReactbundle.js +500 -0
  110. package/client/parametrage/parametrage.css +111 -0
  111. package/client/parametrage/parametrage.html +163 -0
  112. package/client/parametrage/src/paramReact.js +459 -0
  113. package/client/score/hash.js +83 -0
  114. package/client/score/p5.min.js +3 -0
  115. package/client/score/parto1.js +1171 -0
  116. package/client/score/parto1bundle.js +1181 -0
  117. package/client/score/processing.min.js +431 -0
  118. package/client/score/score.html +15 -0
  119. package/client/score/score.js +34 -0
  120. package/client/simulateurListe/simulateurFork.js +750 -0
  121. package/client/simulateurListe/simulateurFork.mjs +681 -0
  122. package/client/simulateurListe/simulateurForkSansReorg.js +569 -0
  123. package/client/simulateurListe/simulateurListe.js +628 -0
  124. package/myReact/archive/Nodeemitvaluedlocal1.hh.js +52 -0
  125. package/myReact/archive/abort-parNode.js +79 -0
  126. package/myReact/archive/abroNode.js +169 -0
  127. package/myReact/archive/abroNode2.js +80 -0
  128. package/myReact/archive/atom.compile.hh.js +51 -0
  129. package/myReact/archive/await-countNode.js +67 -0
  130. package/myReact/archive/await-nowvalNode.js +44 -0
  131. package/myReact/archive/callHH.js +96 -0
  132. package/myReact/archive/emit-if2.hh.compiled.js +113 -0
  133. package/myReact/archive/every1Node.js +35 -0
  134. package/myReact/archive/if-runNode.js +74 -0
  135. package/myReact/archive/if1Node.js +43 -0
  136. package/myReact/archive/makeawait.js +0 -0
  137. package/myReact/archive/myReact.old.js +684 -0
  138. package/myReact/archive/orchestration.js +281 -0
  139. package/myReact/archive/orchestration1.js +132 -0
  140. package/myReact/archive/orchestration1.xml +465 -0
  141. package/myReact/archive/orchestration2.js +161 -0
  142. package/myReact/archive/orchestrationHH.mano.js +280 -0
  143. package/myReact/archive/orchestrationHHTest.js +428 -0
  144. package/myReact/archive/orchestrationHHTest.xml +234 -0
  145. package/myReact/archive/orchestrationHHTestRun.js +104 -0
  146. package/myReact/archive/orchestrationHHTestRun.xml +34 -0
  147. package/myReact/archive/orchestrationTest0.js +178 -0
  148. package/myReact/archive/orchestrationTest1.js +181 -0
  149. package/myReact/archive/orchestrationTest2.js +281 -0
  150. package/myReact/archive/run3pointsNode.js +59 -0
  151. package/myReact/archive/runNode.js +123 -0
  152. package/myReact/archive/runNode2.js +91 -0
  153. package/myReact/archive/testAwait1.js +141 -0
  154. package/myReact/archive/testAwait1.xml +86 -0
  155. package/myReact/archive/testEvery1.js +122 -0
  156. package/myReact/archive/testEvery1.xml +79 -0
  157. package/myReact/archive/testHH1.js +135 -0
  158. package/myReact/archive/testHH1.xml +86 -0
  159. package/myReact/archive/testHH1revu.js +104 -0
  160. package/myReact/archive/testHH2.js +122 -0
  161. package/myReact/archive/testHH2.xml +79 -0
  162. package/myReact/archive/testHH3.js +130 -0
  163. package/myReact/archive/testHH3.xml +86 -0
  164. package/myReact/archive/testHHabort.js +121 -0
  165. package/myReact/archive/testHHabort.xml +83 -0
  166. package/myReact/archive/testMakeawait.js +202 -0
  167. package/myReact/archive/testRun1.js +168 -0
  168. package/myReact/archive/testRun1.xml +142 -0
  169. package/myReact/archive/titi.js +28 -0
  170. package/myReact/archive/titi.xml +110 -0
  171. package/myReact/archive/toto.js +73 -0
  172. package/myReact/archive/toto.xml +198 -0
  173. package/myReact/archive/trap-await-parallelNode.js +123 -0
  174. package/myReact/inutiles/hiver2022.xml +804 -0
  175. package/myReact/inutiles/hopeNode.xml +459 -0
  176. package/myReact/inutiles/mars2022.xml +871 -0
  177. package/myReact/inutiles/mystique1.xml +318 -0
  178. package/myReact/inutiles/mystiqueOSC.xml +277 -0
  179. package/myReact/inutiles/opus5Node.xml +1271 -0
  180. package/myReact/inutiles/opus5NodeLinux.xml +1241 -0
  181. package/myReact/inutiles/orchestrationHH.xml +541 -0
  182. package/myReact/inutiles/orchestrationHH2.xml +547 -0
  183. package/myReact/inutiles/testHH.xml +95 -0
  184. package/myReact/inutiles/trouveLaPercuTenor.xml +349 -0
  185. package/myReact/myReact.js +744 -0
  186. package/myReact/myReact.min.js +1 -0
  187. package/myReact/orchestrationHH.js +311 -0
  188. package/myReact/orchestrationHH.mjs +436 -0
  189. package/myReact/orchestrationHH.mjs.map +1 -0
  190. package/package.json +46 -0
  191. package/serveur/OSCandMidi.mjs +361 -0
  192. package/serveur/computeScore.mjs +415 -0
  193. package/serveur/controleDAW.mjs +1149 -0
  194. package/serveur/defaultSession.csv +2 -0
  195. package/serveur/defaultSkiniParametres.js +119 -0
  196. package/serveur/gameOSC.mjs +96 -0
  197. package/serveur/groupeClientsSons.mjs +1014 -0
  198. package/serveur/ipConfig.json +24 -0
  199. package/serveur/ipConfig127.json +19 -0
  200. package/serveur/ipConfig75.json +17 -0
  201. package/serveur/ipConfigBH.json +19 -0
  202. package/serveur/ipConfigLocal.json +19 -0
  203. package/serveur/midiConfig.json +26 -0
  204. package/serveur/midiConfigBH.json +26 -0
  205. package/serveur/midiConfigVoid.json +3 -0
  206. package/serveur/midimix.mjs +570 -0
  207. package/serveur/saveParam.mjs +159 -0
  208. package/serveur/skiniParametres.good.js +132 -0
  209. package/serveur/skiniParametres.js +106 -0
  210. package/serveur/utilsHHSkini.hh.js +64 -0
  211. package/serveur/utilsSkini.mjs +137 -0
  212. package/serveur/websocketServer.mjs +2052 -0
  213. package/serveur/workerInterfaceZ.mjs +327 -0
  214. package/serveur/workerSynchro.mjs +49 -0
  215. package/skini.mjs +141 -0
@@ -0,0 +1,750 @@
1
+ /**
2
+ * @fileOverview
3
+ * <H3>CODE CLIENT DE SIMULATION D'UNE AUDIENCE
4
+ * UTILISANT LE CLIENT AVEC LISTE (clientListe)</H3>
5
+ * <BR>
6
+ * Scénario possibles:
7
+ * - Les clips sont appelés de façon aléatoire selon la liste disponible.
8
+ * Ceci correspond à une audience qui fait à peu n'importe quoi sur les clips
9
+ * disponibles, en limitant les répétitions.
10
+ * - Les listes de clips correpondant à des séquences de type. Dans le cas de
11
+ * définition de type, ceci correspond à une audience qui joue parfaitement le jeu.
12
+ *
13
+ * Le simulateur est un outil de production de musique générative selon un combinatoire
14
+ * contrôlée.
15
+ *
16
+ * @version 1.0
17
+ * @author Bertrand Petit-Hédelin <bertrand@hedelin.fr>
18
+ * @copyright (C) 2022 Bertrand Petit-Hédelin
19
+ *
20
+ * This program is free software: you can redistribute it and/or modify
21
+ * it under the terms of the GNU General Public License as published by
22
+ * the Free Software Foundation, either version 3 of the License, or
23
+ * any later version.
24
+ *
25
+ * This program is distributed in the hope that it will be useful,
26
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ * GNU General Public License for more details.
29
+ *
30
+ * You should have received a copy of the GNU General Public License
31
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
32
+ */
33
+ 'use strict'
34
+
35
+ var par;
36
+ var ws;
37
+ var ipConfig = require('../../serveur/ipConfig');
38
+ const WebSocket = require('ws');
39
+
40
+ var debug = false;
41
+ var debug1 = true;
42
+
43
+ // For creating list of patterns according to a type sequence
44
+ var processTypes = false;
45
+
46
+ var tempoMax, tempoMin, limiteDureeAttente, dureeAttente = 10;
47
+ var derniersPatternsJoues = [];
48
+ var derniersInstrumentsJoue = [-1, -1, -1];
49
+ var nbeInstruments = 100; // Attention c'est en dur...
50
+
51
+ function setTableDerniersPatterns() {
52
+ var tablederniersPatterns = [];
53
+ var tableVide = [-1, -1, -1]; // Ce tableau définit la taille de la "mémoire" pour les non répétitions de patterns
54
+
55
+ for (var i = 0; i < nbeInstruments; i++) {
56
+ tablederniersPatterns.push(tableVide);
57
+ }
58
+ return tablederniersPatterns;
59
+ }
60
+
61
+ function initTempi() {
62
+
63
+ if (par === undefined) {
64
+ console.log("WARN simulator : launch the simulator after loading a piece");
65
+ return;
66
+ }
67
+
68
+ console.log("------------------------------------------------");
69
+ if (par.tempoMax !== undefined) {
70
+ tempoMax = parseInt(par.tempoMax); // en ms
71
+ } else {
72
+ tempoMax = 500;
73
+ console.log("tempoMax par défaut")
74
+ }
75
+
76
+ if (par.tempoMin !== undefined) {
77
+ tempoMin = parseInt(par.tempoMin); // en ms
78
+ } else {
79
+ tempoMin = 100;
80
+ console.log("tempoMin par défaut")
81
+ }
82
+
83
+ if (par.limiteDureeAttente !== undefined) {
84
+ limiteDureeAttente = par.limiteDureeAttente; // en ms
85
+ } else {
86
+ limiteDureeAttente = 100;
87
+ console.log("tempoMin par défaut")
88
+ }
89
+
90
+ derniersPatternsJoues = setTableDerniersPatterns();
91
+ if (debug) console.log("derniersPatternsJoues: ", derniersPatternsJoues);
92
+
93
+ console.log("INFO simulateur : Paramètres tempo: Min=", tempoMin, " Max=", tempoMax, " limiteDureeAttente=", limiteDureeAttente);
94
+ };
95
+
96
+ if (ipConfig.websocketServeurPort !== undefined) {
97
+ var port = ipConfig.websocketServeurPort;
98
+ } else {
99
+ var port = 8080;
100
+ }
101
+
102
+ if (debug) console.log("----------------------------------------------\n");
103
+ if (debug) console.log("serveur:", ipConfig.serverIPAddress, " port:", ipConfig.websocketServeurPort);
104
+
105
+ var id = Math.floor((Math.random() * 1000000) + 1); // Pour identifier le client
106
+ var monGroupe = -1; // non initialisé
107
+ var DAWON = 0;
108
+ var pseudo = "sim" + id;
109
+ var listClips; // Devient une array avec toutes les infos sur les clips selectionnes
110
+ var nombreDePatternsPossible = 1; // Valeur par défaut qui peut être modifiée par l'orchestration
111
+
112
+ var numClip;
113
+ var msg = { // On met des valeurs pas defaut
114
+ type: "configuration",
115
+ text: "ECRAN_NOIR",
116
+ pseudo: "Anonyme",
117
+ value: 0,
118
+ };
119
+
120
+ var myArgs = process.argv.slice(2);
121
+ //console.log('myArgs: ', myArgs);
122
+
123
+ // Décodage du paramètre pour une simulation indépendante de l'audience
124
+ var jeSuisUneAudience = true;
125
+ for (var i = 0; i < myArgs.length; i++) {
126
+ if (myArgs[i] === "-sim") {
127
+ jeSuisUneAudience = false;
128
+ }
129
+ }
130
+
131
+ /*******************************************************************
132
+ * GESTION DES TYPES
133
+ * Traitement des listes reçues pour s'adapter à une séquence de types.
134
+ * En utilisant les types avec des tanks on n'a pas besoin de gérer
135
+ * la mémoires des patterns sélectionnés, ni de revoir les FIFOs.
136
+ *******************************************************************/
137
+ // Table of positions for the types in listOfPatterns
138
+ // The index correpond to the type.
139
+ var types = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
140
+ var listOfTypes = [[]];
141
+
142
+ function resetListOfTypes() {
143
+ listOfTypes = [[]];
144
+ for (i = 0; i < types.length; i++) {
145
+ listOfTypes.push([]);
146
+ }
147
+ }
148
+
149
+ resetListOfTypes();
150
+
151
+ /**
152
+ * Initialize the list of patterns according to their types
153
+ * The index correponds to the type.
154
+ * @param {Array} list
155
+ */
156
+ function setListOfTypes(list) {
157
+ // A remettre à 0 avant de faire des push.
158
+ resetListOfTypes();
159
+
160
+ for (var i = 0; i < list.length; i++) {
161
+ listOfTypes[list[i][7]].push(list[i][3]);
162
+ }
163
+ if (debug) console.log("simulateur: setListOfTypes:", listOfTypes);
164
+ }
165
+
166
+ function getRandomInt(max) {
167
+ return Math.floor(Math.random() * max);
168
+ }
169
+
170
+ /**
171
+ * Get randomly an element in a list and remove it
172
+ * from the list
173
+ * @param {Array} list
174
+ * @returns {*} an element of the list
175
+ */
176
+ function selectOnePattern(list) {
177
+ var randomIndex;
178
+ var selected;
179
+ randomIndex = getRandomInt(list.length);
180
+ selected = list[randomIndex];
181
+ list.splice(randomIndex, 1);
182
+ if (debug) console.log("Simulateur: selectOnePattern:", selected);
183
+ return selected;
184
+ }
185
+
186
+ function removePattern(list, patternName) {
187
+ for (var i = 0; i < list.length; i++) {
188
+ if (list[i][3] === patternName) {
189
+ list.splice(i, 1);
190
+ }
191
+ }
192
+ }
193
+
194
+ function removePatternInTypes(types, patternName) {
195
+ for (var i = 0; i < types.length; i++) {
196
+ for (var j = 0; j < types[i].length; j++) {
197
+ if (types[j] === patternName) {
198
+ if (debug) console.log("Simulateur: removePatternInTypes: ", patternName);
199
+ types[j].splice(j, 1);
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ function getPattern(list, patternName) {
206
+ if (debug) console.log("Simulateur: getPattern :", list, patternName, listOfTypes);
207
+ for (var i = 0; i < list.length; i++) {
208
+ if (list[i][3] === patternName) {
209
+ return list[i];
210
+ }
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Create a list of "selected patterns" according to
216
+ * a sequence described in types.
217
+ * @param {Array} list of present types
218
+ * @param {Array} types
219
+ * @param {Array} listOfPatterns
220
+ * @returns {Array} selected list of Skini notes
221
+ */
222
+ function getListOfPatternsSelected(list, types, listOfPatterns) {
223
+ var selected = [];
224
+ var indexTypes;
225
+ var patternSelected;
226
+ var numClips = [];
227
+ var gotAPattern;
228
+
229
+ if (debug) {
230
+ var testList = [];
231
+ for (var i = 0; i < listOfPatterns.length; i++) {
232
+ if (listOfPatterns[i] !== undefined) {
233
+ testList.push([listOfPatterns[i][0], listOfPatterns[i][7]]);
234
+ }
235
+ }
236
+ console.log("** simulateur: getListOfPatternsSelected: listOfPatterns:", testList);
237
+ }
238
+
239
+ if (debug) {
240
+ var testList = [];
241
+ for (var i = 0; i < list.length; i++) {
242
+ if (list[i] !== undefined) {
243
+ testList.push(list[i][0]);
244
+ }
245
+ }
246
+ console.log("** simulateur: getListOfPatternsSelected: listOfTypes:", testList);
247
+ }
248
+
249
+ for (var i = 0; i < types.length; i++) {
250
+ indexTypes = types[i];
251
+ if (list[indexTypes] !== undefined) {
252
+ if (list[indexTypes].length !== 0) {
253
+ patternSelected = selectOnePattern(list[indexTypes]);
254
+ gotAPattern = getPattern(listOfPatterns, patternSelected);
255
+ selected.push(gotAPattern);
256
+ removePattern(listOfPatterns, patternSelected);
257
+ removePatternInTypes(list, patternSelected);
258
+ }
259
+ }
260
+ }
261
+
262
+ if (debug) {
263
+ testList = [];
264
+ for (var i = 0; i < selected.length; i++) {
265
+ if (selected[i] !== undefined) {
266
+ testList.push([selected[i][0], selected[i][7]]);
267
+ }
268
+ }
269
+ console.log("** simulateur: getListOfPatternsSelected: selected:", testList, "\n");
270
+ }
271
+
272
+ // A ce niveau on a une liste des patterns, il nous faut juste la liste des notes
273
+ // limitée au nombre de patterns dans la liste à soumettre.
274
+ for (var i = 0; i < selected.length ; i++) {
275
+ if (selected[i] !== undefined) {
276
+ numClips.push(selected[i][0]);
277
+ }
278
+ }
279
+ return numClips;
280
+ }
281
+
282
+ /************************ NON REPETITION DES CLIPS ********************
283
+ Table des commandes donnée par les listes de patterns
284
+
285
+ 0= note, 1=note stop, 2=flag, 3=nom, 4=fichier son,
286
+ 5=instrument, 6=Slot, 7=type, 8=free, 9=groupe, 10=durée
287
+ 11= IP, 12= buffer, 13=niveau
288
+
289
+ **********************************************************************/
290
+
291
+ function isInList(element, list) {
292
+ for (var i = 0; i < list.length; i++) {
293
+ if (list[i] === element) return true;
294
+ }
295
+ return false;
296
+ }
297
+
298
+ function sendPseudo(texte) {
299
+ if (debug) console.log("sendPseudo: ", texte);
300
+ msg.type = "clientPseudo";
301
+ msg.pseudo = texte;
302
+ ws.send(JSON.stringify(msg));
303
+ }
304
+
305
+ /* --------------------------------------------------------------------
306
+ * On évite de reprendre un élément de la liste qui serait dans la mémoire.
307
+ * Nous avons les cas particuliers où la liste est de taille équivalente
308
+ * ou inferieure à la mémoire.
309
+ * Cette fonction retourne un élément de la liste en tenant compte de l'état de la mémoire.
310
+ * C'est utilisé pour les instruments et pour les patterns.
311
+ * --------------------------------------------------------------------*/
312
+ function selectRandomInList(memoire, liste) {
313
+ var selection;
314
+ var index;
315
+
316
+ if (liste === undefined) {
317
+ console.log("INFO: simuateurFork: selectRandomInList: liste undefined");
318
+ return undefined;
319
+ }
320
+
321
+ if (memoire === undefined) {
322
+ console.log("INFO: simuateurFork: selectRandomInList: memoire undefined");
323
+ return undefined;
324
+ }
325
+
326
+ if (debug) console.log("*** selectRandomInList:memoire:", memoire, "liste:", liste);
327
+
328
+ if (liste.length === 0) {
329
+ return undefined;
330
+ } else if (liste.length < 2) {
331
+ // Quand on a un seul élément pas la peine de se fatiguer.
332
+ return liste[0];
333
+ } else if (liste.length <= memoire.length) {
334
+ while (true) {
335
+ index = Math.floor(Math.random() * liste.length);
336
+ selection = liste[index];
337
+ if (selection === memoire[memoire.length - 1]) {
338
+ if (debug) console.log("reselecte A:", selection, index);
339
+ continue; // On refait un tour pour éviter une répétition immédiate
340
+ } else {
341
+ memoire.shift(selection); // Décale la mémoire
342
+ memoire.push(selection); // Mémorise le choix
343
+ return selection;
344
+ }
345
+ }
346
+ } else {
347
+ while (true) {
348
+ index = Math.floor(Math.random() * liste.length);
349
+ selection = liste[index];
350
+ if (!isInList(selection, memoire)) { // La selection n'est pas dans la mémoire
351
+ memoire.shift(selection); // Décale la mémoire
352
+ memoire.push(selection); // Mémorise le choix
353
+ if (debug) console.log("reselecte fin: ", selection, index);
354
+ return selection;
355
+ } else { // La sélection est dans la mémoire
356
+ if (debug) console.log("reselecte B:", selection, index);
357
+ continue; // On refait un tour
358
+ }
359
+ }
360
+ }
361
+ }
362
+
363
+ // Retourne laSelectionClip note MIDI (Skini) d'un pattern choisi au hasard
364
+ function selectNextClip() {
365
+ var selectionClip;
366
+ var listeSelectionClip = [];
367
+ var listeInstruments = [];
368
+ var instrument;
369
+
370
+ //Mettre à jour le nombre d'instruments donnés par la liste
371
+ for (var i = 0; i < listClips.length; i++) {
372
+ if (!isInList(listClips[i][5], listeInstruments)) {
373
+ listeInstruments.push(listClips[i][5]);
374
+ }
375
+ }
376
+ if (debug) console.log("*** selectNextClip:listeInstruments:", listeInstruments);
377
+
378
+ //Choisir un instrument au hasard, et pas toujours le même
379
+ instrument = selectRandomInList(derniersInstrumentsJoue, listeInstruments);
380
+ if (debug) console.log("*** selectNextClip:instrument:", instrument);
381
+ if (instrument === undefined) {
382
+ console.log("ERR:selectNextClip:instrument undefined");
383
+ return undefined;
384
+ }
385
+
386
+ //Choisir les commandes MIDI des patterns pour l'instrument sélectioné
387
+ for (var i = 0; i < listClips.length; i++) {
388
+ if (listClips[i][5] === instrument) {
389
+ listeSelectionClip.push(listClips[i][0]);
390
+ }
391
+ }
392
+ if (debug) console.log("*** selectNextClip:listeSelectionClip:", listeSelectionClip);
393
+
394
+ // Choisir un pattern pour l'instrument sélectionné
395
+ // Pas suffisant avec l'application de modèles sur la suite des patterns
396
+ // La sélection doit se faire en fonction des types.
397
+ selectionClip = selectRandomInList(derniersPatternsJoues[instrument], listeSelectionClip);
398
+ if (selectionClip === undefined) {
399
+ console.log("ERR:selectNextClip:selectionClip undefined");
400
+ return undefined;
401
+ }
402
+ if (debug) console.log("*** selectNextClip:selectionClip:", selectionClip);
403
+
404
+ return selectionClip;
405
+ }
406
+
407
+ /*********************************************
408
+
409
+ WEBSOCKET AVEC NODE JS
410
+
411
+ **********************************************/
412
+
413
+ function initWSSocket(port) {
414
+ var tempoInstantListClip = 0;
415
+
416
+ if (ws !== undefined) {
417
+ if (debug1) console.log("INFO: simulateurFork.js: close the socket");
418
+ ws.close();
419
+ }
420
+
421
+ ws = new WebSocket("ws://" + ipConfig.serverIPAddress + ":" + ipConfig.websocketServeurPort); // NODE JS
422
+
423
+ // Par défaut je suis hors audience
424
+ var monIdentite = "simulateur";
425
+ if (jeSuisUneAudience) monIdentite = "sim";
426
+
427
+ ws.onopen = function (event) {
428
+ if (debug) console.log("INFO: simulateurFork.js Websocket : ", "ws://" + ipConfig.serverIPAddress + ":" + port + "/hop/serv");
429
+ msg.type = "startSpectateur";
430
+ msg.text = monIdentite;
431
+ msg.id = id;
432
+ ws.send(JSON.stringify(msg));
433
+
434
+ msg.type = "getNombreDePatternsPossibleEnListe";
435
+ ws.send(JSON.stringify(msg));
436
+ };
437
+
438
+ //Traitement de la Réception sur le client
439
+ ws.onmessage = function (event) {
440
+ var msgRecu = JSON.parse(event.data);
441
+ //console.log( "Client: received [%s]", event.data );
442
+ switch (msgRecu.type) {
443
+
444
+ case "DAWON":
445
+ DAWON = msgRecu.value;
446
+ actionSurDAWON();
447
+ break;
448
+
449
+ case "DAWStatus":
450
+ if (debug) console.log("Reçu DAWStatus:", event.value);
451
+ DAWON = msgRecu.value;
452
+ actionSurDAWON();
453
+ break;
454
+
455
+ case "demandeDeSonParPseudo":
456
+ if (debug) console.log("Reçu Texte Broadcast demande de son par pseudo:", msgRecu.value);
457
+ break;
458
+
459
+ case "dureeAttente": // Quand le son a été demandé
460
+ if (debug) console.log("SimulatuerFork.js: dureeAttente:", msgRecu.text, msgRecu.son);
461
+ dureeAttente = parseInt(msgRecu.text);
462
+ break;
463
+
464
+ case "groupe":
465
+ //Si le simulateur doit être dissocicé de l'audience,
466
+ // il sera dans le dernier groupe de la table des possibles.
467
+ if (jeSuisUneAudience) {
468
+ // Le simulateur simule l'audience.
469
+ // Il se comporte comme tout le monde, avec le groupe que le serveur assigne
470
+ monGroupe = msgRecu.noDeGroupe;
471
+ if (debug) console.log("SIMULATION DE L'AUDIENCE");
472
+ } else if (!par.simulatorInAseperateGroup) {
473
+ // Je suis ne pas un simulateur de l'audience
474
+ // et la config n'a pas prévu de simulateur indépendant de l'audience.
475
+ // On force un comportement de simulateur d'audience.
476
+ console.log("WARN: le simulateur demande à être indépendant, mais ce n'est pas prévu dans la configuration");
477
+ monGroupe = msgRecu.noDeGroupe;
478
+ } else {
479
+ // La config a prévu un simulateur indépendant de l'audience
480
+ // et je ne suis pas un simulateur d'audience.
481
+ // Je définis mon groupe en m'attribuant donc le dernier groupe de client
482
+ // Ceci est redondant avec le serveur dans ce cas qui fournit aussi le même groupe
483
+ // resérvé.
484
+ console.log("SIMULATION INDEPENDANTE DE L'AUDIENCE");
485
+ monGroupe = par.nbeDeGroupesClients - 1;
486
+ }
487
+ if (debug1) console.log("INFO: Simulator in group:", monGroupe, "pseudo:", pseudo);
488
+ actionSurDAWON();
489
+ break;
490
+
491
+ case "groupeClientStatus":
492
+ if (debug) console.log("Reçu Broadcast: groupeClientStatus:", msgRecu, msgRecu.groupeClient);
493
+ if (msgRecu.groupeClient == monGroupe || msgRecu.groupeClient == 255) {
494
+ actionSurGroupeClientStatus(msgRecu.groupeName, msgRecu.status);
495
+ }
496
+ break;
497
+
498
+ case "infoPlayDAW":
499
+ if (debug) console.log("Reçu Texte Broadcast infoPlayDAW:", msgRecu.value);
500
+ break;
501
+
502
+ case "listClips":
503
+ listClips = msgRecu.listClips;
504
+ if (listClips === -1) {
505
+ if (debug) console.log("WS Recu : listClips: groupe de client inexistant", listClips);
506
+ break;
507
+ }
508
+
509
+ if (listClips === undefined) {
510
+ if (debug) console.log("WS Recu : listClips: undefined, pas de clip");
511
+ break;
512
+ }
513
+
514
+ if (listClips.length === 0) {
515
+ if (debug) console.log("WS Recu : listClips vide");
516
+ if (tempoMax === tempoMin) {
517
+ console.log("WARN: tempoMin and tempoMax must no be equal");
518
+ tempoInstantListClip = 10;
519
+ }
520
+ else {
521
+ tempoInstantListClip = Math.floor(tempoMin + (Math.random() * (tempoMax - tempoMin)));
522
+ }
523
+ if (debug) console.log("TEMPO INSTANT LIST CLIP:", tempoInstantListClip, tempoMax, tempoMin);
524
+ if (DAWON) setTimeout(function () {
525
+ selectListClips(); // Envoie une demande des clips dispos au serveur
526
+ },
527
+ tempoInstantListClip);
528
+ break;
529
+ }
530
+
531
+ // Selection de clips dans la liste
532
+ if (debug) console.log("\n--- Simulateur Recu : listClips 1ere ligne:", listClips[0][4], "Nombre clip dispo:", listClips.length);
533
+ var sequenceLocale = [];
534
+
535
+ if (processTypes) {
536
+ setListOfTypes(listClips);
537
+ sequenceLocale = getListOfPatternsSelected(listOfTypes, types, listClips);
538
+ if (debug1) console.log("Simulateur: sequence selon les types:", sequenceLocale);
539
+ } else {
540
+ for (var i = 0; i < nombreDePatternsPossible; i++) {
541
+ //Version qui évite trop de répétitions
542
+ numClip = selectNextClip();
543
+ sequenceLocale[i] = numClip;
544
+ // On a une liste
545
+ if (debug) console.log("--- Simulateur Recu : listClips: choisi", numClip, " : ", listClips[numClip][4], "\n");
546
+ }
547
+ }
548
+
549
+ // Emission de la liste
550
+ if (debug) console.log("-- sendPatternSequence: attente:", dureeAttente, limiteDureeAttente);
551
+ if (dureeAttente < limiteDureeAttente) { // On est dans des délais raisonnables
552
+ if (debug) console.log("-- sendPatternSequence", sequenceLocale, pseudo);
553
+ msg.type = "sendPatternSequence";
554
+ msg.patternSequence = sequenceLocale;
555
+ msg.pseudo = pseudo;
556
+ msg.groupe = monGroupe;
557
+ msg.idClient = id;
558
+ ws.send(JSON.stringify(msg));
559
+ } else {
560
+ // msg.type = "sendPatternSequence";
561
+ // msg.patternSequence = [];
562
+ // msg.pseudo = pseudo;
563
+ // msg.groupe = monGroupe;
564
+ // msg.idClient = id;
565
+ // ws.send(JSON.stringify(msg));
566
+ dureeAttente = 0;
567
+ }
568
+
569
+ tempoInstantListClip = Math.floor((Math.random() * (tempoMax - tempoMin)) + tempoMin);
570
+ if (debug) console.log("TEMPO INSTANT LIST CLIP:", tempoInstantListClip, pseudo);
571
+ if (DAWON) setTimeout(function () {
572
+ selectListClips();
573
+ },
574
+ tempoInstantListClip);
575
+ break;
576
+
577
+ case "listeDesTypes":
578
+ types = msgRecu.text.split(',');
579
+ for (var i = 0; i < types.length; i++) {
580
+ types[i] = parseInt(types[i]);
581
+ }
582
+ if (debug1) console.log("Simulator: List of Types:", types);
583
+ break;
584
+
585
+ case "message":
586
+ if (debug) console.log(msgRecu.text);
587
+ break;
588
+
589
+ case "nombreDePatternsPossibleEnListe":
590
+ if (debug) console.log("socket : nombreDePatternsPossibleEnListe: msgRecu: ", msgRecu.nombreDePatternsPossible);
591
+ var nombreDePatternsPossibleEnListe = msgRecu.nombreDePatternsPossible;
592
+ var flagFin = false;
593
+
594
+ // Mise à jour du suivi des longueurs de listes d'abord / au groupe
595
+ for (var i = 0; i < nombreDePatternsPossibleEnListe.length; i++) {
596
+ if (nombreDePatternsPossibleEnListe[i][1] === monGroupe) {
597
+ nombreDePatternsPossible = nombreDePatternsPossibleEnListe[i][0];
598
+ flagFin = true;
599
+ break;
600
+ }
601
+ }
602
+ if (!flagFin) {
603
+ // Sinon en fonction du broadcast 255
604
+ for (var i = 0; i < nombreDePatternsPossibleEnListe.length; i++) {
605
+ if (nombreDePatternsPossibleEnListe[i][1] === 255) {
606
+ nombreDePatternsPossible = nombreDePatternsPossibleEnListe[i][0];
607
+ break;
608
+ }
609
+ }
610
+ }
611
+ if (debug) console.log("Reçu socket : nombreDePatternsPossible:nombreSonsPossibleInit ", nombreDePatternsPossible);
612
+ break;
613
+
614
+ case "patternSequenceAck":
615
+ if (debug) console.log("Reçu socket : patternSequenceAck: score ", msgRecu.score);
616
+ break;
617
+
618
+ case "setListeDesTypes":
619
+ if (debug1) console.log("Simulator: Set the type list")
620
+ processTypes = true;
621
+ break;
622
+
623
+ case "texteServeur":
624
+ if (debug) console.log("Reçu Broadcast:", msgRecu.value);
625
+ break;
626
+
627
+ case "unsetListeDesTypes":
628
+ if (debug1) console.log("Simulator: Unset the type list")
629
+ processTypes = false;
630
+ break;
631
+
632
+ default: if (debug) console.log("Le simulateur reçoit un message inconnu", msgRecu);
633
+ break;
634
+ }
635
+ };
636
+
637
+ ws.onerror = function (event) {
638
+ console.log("simulateur.js : received ERROR on WS");
639
+ }
640
+
641
+ ws.onclose = function (event) {
642
+ console.log("INFO: simulateurFork.js : on CLOSE on WS");
643
+ }
644
+ }
645
+
646
+ //- Attention d'avoir initialisation avant de faire server.addEventListener('DAWStatus', function( event )---
647
+ // Cette fonction de remise à jour de l'affichage est appelée sur plusieurs évènements :
648
+ // onload, Modif DAW, Modif sur groupe de sons, reconnexion, rechargement de la page.
649
+
650
+ function initialisation() {
651
+ //var index = monGroupe;
652
+ //msg.pseudo = pseudo;
653
+ if (debug) console.log("simulateur.js:initialisation: PSEUDO ", pseudo);
654
+ sendPseudo(pseudo);
655
+ }
656
+ exports.initialisation = initialisation;
657
+
658
+ function init(port) {
659
+ //listenMachine = makeListenMachine();
660
+ initWSSocket(port);
661
+ }
662
+ exports.init = init;
663
+
664
+ function actionSurDAWON() {
665
+ if (DAWON == false) {
666
+ if (debug) console.log("simulateur.js:actionSurDAWON:false");
667
+ initialisation();
668
+ return;
669
+ }
670
+
671
+ if (debug) console.log("simulateur.js:actionSurDAWON:true:", DAWON);
672
+ initialisation(); //Pour le cas où le client recharge sa page en cours d'interaction
673
+ selectListClips(); // Pour le déclenchement de la simulation
674
+ }
675
+
676
+ function actionSurGroupeClientStatus(sons, status) {
677
+ if (DAWON == false) {
678
+ if (debug) console.log("simulateur.js:actionSurGroupeClientStatus:DAWON:false");
679
+ initialisation();
680
+ return;
681
+ }
682
+ if (debug) console.log("WS actionSurGroupeClientStatus:", monGroupe);
683
+
684
+ if (sons == "" || sons == undefined) {
685
+ } else {
686
+ if (status) {
687
+ }
688
+ }
689
+ }
690
+
691
+ //========== Controle des CLIPS =================================
692
+ function selectListClips() { // selecteurV2
693
+ if (debug) console.log("selectListClips: groupe", monGroupe);
694
+
695
+ msg.type = "selectAllClips";
696
+ msg.groupe = monGroupe;
697
+ ws.send(JSON.stringify(msg));
698
+ }
699
+
700
+ // Demande au serveur de lancer le clip
701
+ var compteurTest = 0;
702
+ function startClip(indexChoisi) {
703
+
704
+ if (indexChoisi == -1) return -1; // Protection sur un choix sans selection au départ
705
+ msg.pseudo = pseudo; //noms[index];
706
+
707
+ msg.type = "DAWStartClip";
708
+ msg.clipChoisi = listClips[indexChoisi];
709
+
710
+ compteurTest++;
711
+ console.log("startClip:", compteurTest, " :", listClips[indexChoisi][3], "par", pseudo);
712
+ //msg.pseudo = pseudo;
713
+ msg.groupe = monGroupe;
714
+ ws.send(JSON.stringify(msg));
715
+ indexChoisi = -1;
716
+ }
717
+ exports.startClip = startClip;
718
+
719
+ // ========================= Lancement du simulateur =================
720
+ process.on('message', (message) => {
721
+ // This is necessary, I dont know why. Otherwise I have an erro on message in the switch
722
+ // ReferenceError: Cannot access 'message' before initialization
723
+ var messageLocal = message;
724
+
725
+ if (debug) console.log("INFO: Simulator message : ", messageLocal);
726
+
727
+ switch (messageLocal.type) {
728
+ case 'START_SIMULATOR':
729
+ //console.log('Simulator received START message');
730
+ init(port);
731
+ setTimeout(() => selectListClips(), 1000);
732
+ let message = `Simulation Launched by ${pseudo}`;
733
+ process.send(message);
734
+ break;
735
+
736
+ case 'PARAMETERS':
737
+ if (debug) console.log("INFO: Simulator parameters : ", messageLocal.data.groupesDesSons[0]);
738
+ par = messageLocal.data;
739
+ initTempi();
740
+ break;
741
+
742
+ case 'STOP_SIMULATOR':
743
+ if (debug1) console.log("INFO: simulateurFork.js : Simulator Stopped");
744
+ ws.close();
745
+ process.exit(0);
746
+ break;
747
+
748
+ default: console.log("INFO: Fork Simulator: Type de message inconnu : ", messageLocal);
749
+ }
750
+ });