jclic 2.1.21 → 2.1.22

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 (173) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/jclic-node.js +1 -1
  3. package/dist/jclic-node.js.map +1 -1
  4. package/dist/jclic.min.js +2 -2
  5. package/dist/jclic.min.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/GlobalData.js +1 -1
  8. package/dist/1078.jclic-node.js +0 -282
  9. package/dist/1078.jclic-node.js.map +0 -1
  10. package/dist/1196.jclic-node.js +0 -808
  11. package/dist/1196.jclic-node.js.map +0 -1
  12. package/dist/1253.jclic-node.js +0 -1432
  13. package/dist/1253.jclic-node.js.map +0 -1
  14. package/dist/13.jclic-node.js +0 -103
  15. package/dist/13.jclic-node.js.map +0 -1
  16. package/dist/1567.jclic-node.js +0 -2313
  17. package/dist/1567.jclic-node.js.map +0 -1
  18. package/dist/1588.jclic-node.js +0 -602
  19. package/dist/1588.jclic-node.js.map +0 -1
  20. package/dist/1725.jclic-node.js +0 -836
  21. package/dist/1725.jclic-node.js.map +0 -1
  22. package/dist/1731.jclic-node.js +0 -438
  23. package/dist/1731.jclic-node.js.map +0 -1
  24. package/dist/1842.jclic-node.js +0 -651
  25. package/dist/1842.jclic-node.js.map +0 -1
  26. package/dist/2160.jclic-node.js +0 -1016
  27. package/dist/2160.jclic-node.js.map +0 -1
  28. package/dist/222.jclic-node.js +0 -129
  29. package/dist/222.jclic-node.js.map +0 -1
  30. package/dist/2316.jclic-node.js +0 -949
  31. package/dist/2316.jclic-node.js.map +0 -1
  32. package/dist/2355.jclic-node.js +0 -371
  33. package/dist/2355.jclic-node.js.map +0 -1
  34. package/dist/2366.jclic-node.js +0 -431
  35. package/dist/2366.jclic-node.js.map +0 -1
  36. package/dist/2379.jclic-node.js +0 -202
  37. package/dist/2379.jclic-node.js.map +0 -1
  38. package/dist/2437.jclic-node.js +0 -450
  39. package/dist/2437.jclic-node.js.map +0 -1
  40. package/dist/2531.jclic-node.js +0 -869
  41. package/dist/2531.jclic-node.js.map +0 -1
  42. package/dist/2608.jclic-node.js +0 -160
  43. package/dist/2608.jclic-node.js.map +0 -1
  44. package/dist/2715.jclic-node.js +0 -554
  45. package/dist/2715.jclic-node.js.map +0 -1
  46. package/dist/277.jclic-node.js +0 -22
  47. package/dist/277.jclic-node.js.map +0 -1
  48. package/dist/2921.jclic-node.js +0 -660
  49. package/dist/2921.jclic-node.js.map +0 -1
  50. package/dist/2952.jclic-node.js +0 -101
  51. package/dist/2952.jclic-node.js.map +0 -1
  52. package/dist/3018.jclic-node.js +0 -421
  53. package/dist/3018.jclic-node.js.map +0 -1
  54. package/dist/3019.jclic-node.js +0 -682
  55. package/dist/3019.jclic-node.js.map +0 -1
  56. package/dist/3231.jclic-node.js +0 -274
  57. package/dist/3231.jclic-node.js.map +0 -1
  58. package/dist/331.jclic-node.js +0 -115
  59. package/dist/331.jclic-node.js.map +0 -1
  60. package/dist/3391.jclic-node.js +0 -276
  61. package/dist/3391.jclic-node.js.map +0 -1
  62. package/dist/3502.jclic-node.js +0 -671
  63. package/dist/3502.jclic-node.js.map +0 -1
  64. package/dist/3653.jclic-node.js +0 -982
  65. package/dist/3653.jclic-node.js.map +0 -1
  66. package/dist/371.jclic.min.js +0 -2
  67. package/dist/371.jclic.min.js.map +0 -1
  68. package/dist/3856.jclic-node.js +0 -575
  69. package/dist/3856.jclic-node.js.map +0 -1
  70. package/dist/4112.jclic-node.js +0 -659
  71. package/dist/4112.jclic-node.js.map +0 -1
  72. package/dist/4123.jclic-node.js +0 -910
  73. package/dist/4123.jclic-node.js.map +0 -1
  74. package/dist/427.jclic-node.js +0 -894
  75. package/dist/427.jclic-node.js.map +0 -1
  76. package/dist/4483.jclic-node.js +0 -327
  77. package/dist/4483.jclic-node.js.map +0 -1
  78. package/dist/4548.jclic-node.js +0 -1078
  79. package/dist/4548.jclic-node.js.map +0 -1
  80. package/dist/466.jclic-node.js +0 -99
  81. package/dist/466.jclic-node.js.map +0 -1
  82. package/dist/485.jclic-node.js +0 -783
  83. package/dist/485.jclic-node.js.map +0 -1
  84. package/dist/4921.jclic-node.js +0 -500
  85. package/dist/4921.jclic-node.js.map +0 -1
  86. package/dist/5091.jclic-node.js +0 -239
  87. package/dist/5091.jclic-node.js.map +0 -1
  88. package/dist/520.jclic-node.js +0 -550
  89. package/dist/520.jclic-node.js.map +0 -1
  90. package/dist/5312.jclic-node.js +0 -1126
  91. package/dist/5312.jclic-node.js.map +0 -1
  92. package/dist/5338.jclic-node.js +0 -212
  93. package/dist/5338.jclic-node.js.map +0 -1
  94. package/dist/5344.jclic-node.js +0 -229
  95. package/dist/5344.jclic-node.js.map +0 -1
  96. package/dist/5550.jclic-node.js +0 -238
  97. package/dist/5550.jclic-node.js.map +0 -1
  98. package/dist/5626.jclic-node.js +0 -614
  99. package/dist/5626.jclic-node.js.map +0 -1
  100. package/dist/5977.jclic-node.js +0 -1081
  101. package/dist/5977.jclic-node.js.map +0 -1
  102. package/dist/6148.jclic-node.js +0 -345
  103. package/dist/6148.jclic-node.js.map +0 -1
  104. package/dist/6176.jclic-node.js +0 -481
  105. package/dist/6176.jclic-node.js.map +0 -1
  106. package/dist/6221.jclic-node.js +0 -1072
  107. package/dist/6221.jclic-node.js.map +0 -1
  108. package/dist/6238.jclic-node.js +0 -718
  109. package/dist/6238.jclic-node.js.map +0 -1
  110. package/dist/6454.jclic-node.js +0 -1413
  111. package/dist/6454.jclic-node.js.map +0 -1
  112. package/dist/6565.jclic-node.js +0 -294
  113. package/dist/6565.jclic-node.js.map +0 -1
  114. package/dist/6579.jclic-node.js +0 -719
  115. package/dist/6579.jclic-node.js.map +0 -1
  116. package/dist/6715.jclic-node.js +0 -148
  117. package/dist/6715.jclic-node.js.map +0 -1
  118. package/dist/6777.jclic-node.js +0 -171
  119. package/dist/6777.jclic-node.js.map +0 -1
  120. package/dist/6782.jclic-node.js +0 -1611
  121. package/dist/6782.jclic-node.js.map +0 -1
  122. package/dist/6847.jclic-node.js +0 -601
  123. package/dist/6847.jclic-node.js.map +0 -1
  124. package/dist/6856.jclic-node.js +0 -252
  125. package/dist/6856.jclic-node.js.map +0 -1
  126. package/dist/696.jclic-node.js +0 -1821
  127. package/dist/696.jclic-node.js.map +0 -1
  128. package/dist/698.jclic-node.js +0 -583
  129. package/dist/698.jclic-node.js.map +0 -1
  130. package/dist/704.jclic-node.js +0 -80
  131. package/dist/704.jclic-node.js.map +0 -1
  132. package/dist/7046.jclic-node.js +0 -735
  133. package/dist/7046.jclic-node.js.map +0 -1
  134. package/dist/7220.jclic-node.js +0 -156
  135. package/dist/7220.jclic-node.js.map +0 -1
  136. package/dist/7257.jclic-node.js +0 -931
  137. package/dist/7257.jclic-node.js.map +0 -1
  138. package/dist/743.jclic-node.js +0 -583
  139. package/dist/743.jclic-node.js.map +0 -1
  140. package/dist/757.jclic-node.js +0 -1072
  141. package/dist/757.jclic-node.js.map +0 -1
  142. package/dist/7781.jclic-node.js +0 -202
  143. package/dist/7781.jclic-node.js.map +0 -1
  144. package/dist/7912.jclic-node.js +0 -2103
  145. package/dist/7912.jclic-node.js.map +0 -1
  146. package/dist/827.jclic-node.js +0 -708
  147. package/dist/827.jclic-node.js.map +0 -1
  148. package/dist/8276.jclic-node.js +0 -409
  149. package/dist/8276.jclic-node.js.map +0 -1
  150. package/dist/8322.jclic-node.js +0 -498
  151. package/dist/8322.jclic-node.js.map +0 -1
  152. package/dist/8641.jclic-node.js +0 -360
  153. package/dist/8641.jclic-node.js.map +0 -1
  154. package/dist/8837.jclic-node.js +0 -651
  155. package/dist/8837.jclic-node.js.map +0 -1
  156. package/dist/8895.jclic-node.js +0 -151
  157. package/dist/8895.jclic-node.js.map +0 -1
  158. package/dist/9072.jclic-node.js +0 -1285
  159. package/dist/9072.jclic-node.js.map +0 -1
  160. package/dist/9078.jclic-node.js +0 -935
  161. package/dist/9078.jclic-node.js.map +0 -1
  162. package/dist/9103.jclic-node.js +0 -718
  163. package/dist/9103.jclic-node.js.map +0 -1
  164. package/dist/9359.jclic-node.js +0 -145
  165. package/dist/9359.jclic-node.js.map +0 -1
  166. package/dist/9409.jclic-node.js +0 -921
  167. package/dist/9409.jclic-node.js.map +0 -1
  168. package/dist/9513.jclic-node.js +0 -720
  169. package/dist/9513.jclic-node.js.map +0 -1
  170. package/dist/9704.jclic-node.js +0 -81
  171. package/dist/9704.jclic-node.js.map +0 -1
  172. package/dist/9950.jclic-node.js +0 -827
  173. package/dist/9950.jclic-node.js.map +0 -1
@@ -1,276 +0,0 @@
1
- "use strict";
2
- exports.id = 3391;
3
- exports.ids = [3391];
4
- exports.modules = {
5
-
6
- /***/ 3391:
7
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8
-
9
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
10
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
11
- /* harmony export */ });
12
- /* unused harmony export MidiAudioPlayer */
13
- /* harmony import */ var _francesc_basic_midi_player_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5428);
14
- /* harmony import */ var _francesc_basic_midi_player_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_francesc_basic_midi_player_js__WEBPACK_IMPORTED_MODULE_0__);
15
- /* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1253);
16
- /**
17
- * File : media/MidiAudioPlayer.js
18
- * Created : 11/10/2018
19
- * By : Francesc Busquets <francesc@gmail.com>
20
- *
21
- * JClic.js
22
- * An HTML5 player of JClic activities
23
- * https://projectestac.github.io/jclic.js
24
- *
25
- * @source https://github.com/projectestac/jclic.js
26
- *
27
- * @license EUPL-1.2
28
- * @licstart
29
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
30
- *
31
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
32
- * the European Commission- subsequent versions of the EUPL (the "Licence");
33
- * You may not use this work except in compliance with the Licence.
34
- *
35
- * You may obtain a copy of the Licence at:
36
- * https://joinup.ec.europa.eu/software/page/eupl
37
- *
38
- * Unless required by applicable law or agreed to in writing, software
39
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
40
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
41
- * Licence for the specific language governing permissions and limitations
42
- * under the Licence.
43
- * @licend
44
- * @module
45
- */
46
-
47
- /* global window */
48
-
49
-
50
-
51
-
52
- // TODO: Use multiple instruments, at least one for each track
53
- // TODO: Use multiple midi channels (currently flattened to a single channel)
54
- // TODO: Use of channel 10 for percussion instruments
55
- // TODO: ... build a real MIDI player!!
56
-
57
- /**
58
- * A simple MIDI player based on MidiPlayerJS
59
- * https://github.com/grimmdude/MidiPlayerJS
60
- * See also: http://www.midijs.net (https://github.com/babelsberg/babelsberg-js/tree/master/midijs)
61
- */
62
- class MidiAudioPlayer {
63
- /**
64
- * MidiAudioPlayer constructor
65
- * @param {external:ArrayBuffer} data - The MIDI file content, in ArrayBuffer format
66
- * @param {object} [options={}] - Optional params related to the type of soundfont used. Valid options inside this object are:<br>
67
- * - `MIDISoundFontObject`: An object containing the full soundfont data. When this param is provided, no other one will be used.
68
- * - `MIDISoundFontBase`: The URL used as base for the current collection of MIDI soundfonts. Defaults to `https://clic.xtec.cat/dist/jclic.js/soundfonts/MusyngKite`
69
- * - `MIDISoundFontName`: The MIDI instrument name. Defaults to `acoustic_grand_piano`. See [MIDI.js Soundfonts](https://github.com/gleitz/midi-js-soundfonts) for full lists of MIDI instrument names.
70
- * - `MIDISoundFontExtension`: An extension to be added to `MIDISoundFontName` in order to build the full file name of the soundfont JS file. Defaults to `-mp3.js`
71
- */
72
- constructor(data, options = {}) {
73
- const AudioContext = window && (window.AudioContext || window.webkitAudioContext);
74
- if (AudioContext) {
75
- // Build instrument on first call to constructor
76
- MidiAudioPlayer.prepareInstrument(options, new AudioContext());
77
- this.data = data;
78
- this.player = new (_francesc_basic_midi_player_js__WEBPACK_IMPORTED_MODULE_0___default().Player)(ev => this.playEvent(ev));
79
- if (this.player)
80
- this.player.loadArrayBuffer(data);
81
- }
82
- }
83
-
84
- /**
85
- * Initializes the soundfont instrument, loading data from GitHub
86
- * NOTE: This will not work when off-line!
87
- * TODO: Provided a basic, simple, static soundfont
88
- * @param {object} options - Optional param with options related to the MIDI soundfont. See details in `constructor` description.
89
- * @param {external:AudioContext} audioContext - The AudioContext object (see: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext)
90
- */
91
- static prepareInstrument(options = {}, audioContext) {
92
- if (MidiAudioPlayer.loadingInstrument === false) {
93
- MidiAudioPlayer.loadingInstrument = true;
94
- MidiAudioPlayer.audioContext = audioContext;
95
- _francesc_basic_midi_player_js__WEBPACK_IMPORTED_MODULE_0___default().Soundfont.instrument(
96
- MidiAudioPlayer.audioContext,
97
- options.MIDISoundFontObject || MidiAudioPlayer.MIDISoundFontObject ||
98
- `${options.MIDISoundFontBase || MidiAudioPlayer.MIDISoundFontBase}/${options.MIDISoundFontName || MidiAudioPlayer.MIDISoundFontName}${options.MIDISoundFontExtension || MidiAudioPlayer.MIDISoundFontExtension}`)
99
- .then(instrument => {
100
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .log */ .Rm)('info', 'MIDI soundfont instrument loaded');
101
- MidiAudioPlayer.instrument = instrument;
102
- })
103
- .catch(err => {
104
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .log */ .Rm)('error', `Error loading soundfont base instrument: ${err}`);
105
- });
106
- }
107
- }
108
-
109
- /**
110
- * Pauses the player
111
- */
112
- pause() {
113
- if (this.player) {
114
- this.player.pause();
115
- this.startedNotes = [];
116
- }
117
- }
118
-
119
- /**
120
- * Starts or resumes playing
121
- */
122
- play() {
123
- if (this.player) {
124
- this.startedNotes = [];
125
- this.player.play();
126
- }
127
- }
128
-
129
- /**
130
- * Gets the ' paused' state of the current player
131
- * @returns boolean
132
- */
133
- get paused() {
134
- return this.player && !this.player.isPlaying();
135
- }
136
-
137
- /**
138
- * Checks if the current player has ended or is already playing
139
- * @returns boolean
140
- */
141
- get ended() {
142
- return this.player && this.player.getSongTimeRemaining() <= 0;
143
- }
144
-
145
- /**
146
- * Gets the current time
147
- * @returns number
148
- */
149
- get currentTime() {
150
- return this.player && (this.player.getSongTime() * 1000) || 0;
151
- }
152
-
153
- /**
154
- * Sets the current time of this player (in milliseconds)
155
- * @param {number} time - The time position where the player pointer must be placed
156
- */
157
- set currentTime(time) {
158
- if (this.player)
159
- this.player.skipToSeconds(time / 1000);
160
- }
161
-
162
- /**
163
- * Plays a MIDI event
164
- * @param {object} ev - The event data. See http://grimmdude.com/MidiPlayerJS/docs/index.html for details
165
- */
166
- playEvent(ev) {
167
- if (this.player && MidiAudioPlayer.instrument) {
168
- // Check for specific interval
169
- if (this.playTo > 0 && this.currentTime >= this.playTo)
170
- this.pause();
171
- // Set main volume
172
- else if (ev.name === 'Controller Change' && ev.number === 7)
173
- this.mainVolume = ev.value / 127;
174
- // Process 'Note on' messages. Max gain set to 2.0 for better results with the used soundfont
175
- else if (ev.name === 'Note on' && ev.velocity > 0)
176
- this.startedNotes[ev.noteNumber] = MidiAudioPlayer.instrument.play(ev.noteName, MidiAudioPlayer.audioContext.currentTime, { gain: 2 * (this.mainVolume * ev.velocity / 100) });
177
- // Process 'Note off' messages
178
- else if (ev.name === 'Note off' && ev.noteNumber && this.startedNotes[ev.noteNumber]) {
179
- this.startedNotes[ev.noteNumber].stop();
180
- delete (this.startedNotes[ev.noteNumber]);
181
- }
182
- }
183
- }
184
- }
185
-
186
- Object.assign(MidiAudioPlayer.prototype, {
187
- /**
188
- * The MIDI file data used by this MIDI player
189
- * @name module:media/MidiAudioPlayer.MidiAudioPlayer#data
190
- * @type {external:ArrayBuffer} */
191
- data: null,
192
- /**
193
- * The grimmdude's MidiPlayer used by this player
194
- * @name module:media/MidiAudioPlayer.MidiAudioPlayer#player
195
- * @type {external:MidiPlayerJS} */
196
- player: null,
197
- /**
198
- * When >0, time position at which the music must end
199
- * @name module:media/MidiAudioPlayer.MidiAudioPlayer#playTo
200
- * @type {number} */
201
- playTo: 0,
202
- /**
203
- * Main volume of this track (set with a MIDI message of type `Controller Change` #7)
204
- * @name module:media/MidiAudioPlayer.MidiAudioPlayer#mainVolume
205
- * @type {number} */
206
- mainVolume: 1.0,
207
- /**
208
- * This array is used when processing 'Note off' events to stop notes that are currently playing.
209
- * It contains a collection of 'instrument.play' instances, one for each active note
210
- * @name module:media/MidiAudioPlayer.MidiAudioPlayer#startedNotes
211
- * @type {function[]} */
212
- startedNotes: [],
213
- });
214
-
215
- /**
216
- * The {@link external:AudioContext} used by this MIDI player.
217
- * @type {external:AudioContext}
218
- */
219
- MidiAudioPlayer.audioContext = null;
220
-
221
- /**
222
- * The "Instrument" object used by this MIDI player.
223
- * See: https://github.com/danigb/soundfont-player
224
- * @type {external:Instrument}
225
- */
226
- MidiAudioPlayer.instrument = null;
227
-
228
- /**
229
- * A flag used to avoid re-entrant calls to {@link module:media/MidiAudioPlayer.MidiAudioPlayer#prepareInstrument prepareInstrument}
230
- * @type {boolean}
231
- */
232
- MidiAudioPlayer.loadingInstrument = false;
233
-
234
- /**
235
- * An object containing the full soundfont data used by {@link module:media/MidiAudioPlayer.MidiAudioPlayer#instrument instrument}
236
- * When this member is set, no other settings related to the sounfFont will be used.
237
- * This value can be overwritten by the global parameter `MIDISoundFontObject`
238
- * @type {object}
239
- */
240
- MidiAudioPlayer.MIDISoundFontObject = null;
241
-
242
- /**
243
- * The URL used as base for the current collection of MIDI soundfonts.
244
- * This value can be overwritten by the global parameter `MIDISoundFontBase`
245
- * @type {string}
246
- */
247
- MidiAudioPlayer.MIDISoundFontBase = 'https://clic.xtec.cat/dist/jclic.js/soundfonts/MusyngKite';
248
- // Alternative sites are:
249
- // 'https://clic.xtec.cat/dist/jclic.js/soundfonts/FluidR3_GM'
250
- // 'https://raw.githubusercontent.com/gleitz/midi-js-soundfonts/gh-pages/FluidR3_GM'
251
- // 'https://raw.githubusercontent.com/gleitz/midi-js-soundfonts/gh-pages/MusyngKite'
252
-
253
- /**
254
- * The MIDI instrument name.
255
- * This value can be overwritten by the global parameter `MIDISoundFontName`
256
- * See [MIDI.js Soundfonts](https://github.com/gleitz/midi-js-soundfonts) for full lists of MIDI instrument names.
257
- * @type {string}
258
- */
259
- MidiAudioPlayer.MIDISoundFontName = 'acoustic_grand_piano';
260
-
261
- /**
262
- * An extension to be added to `MIDISoundFontName` in order to build the full file name of the soundfont JS file.
263
- * Current valid options are `-mp3.js` and `-ogg.js`
264
- * This value can be overwritten by the global parameter `MIDISoundFontExtension`
265
- * @type {string}
266
- */
267
- MidiAudioPlayer.MIDISoundFontExtension = '-mp3.js';
268
-
269
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MidiAudioPlayer);
270
-
271
-
272
- /***/ })
273
-
274
- };
275
- ;
276
- //# sourceMappingURL=3391.jclic-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"3391.jclic-node.js","mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEwD;AACtB;;AAElC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA,aAAa,sBAAsB;AACnC,aAAa,QAAQ,WAAW;AAChC;AACA;AACA;AACA;AACA;AACA,gCAAgC;AAChC;AACA;AACA;AACA;AACA;AACA,wBAAwB,8EAAiB;AACzC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,uBAAuB;AACpC;AACA,uCAAuC;AACvC;AACA;AACA;AACA,MAAM,+EAAoB;AAC1B;AACA;AACA,WAAW,+DAA+D,GAAG,+DAA+D,EAAE,yEAAyE;AACvN;AACA,UAAU,wDAAG;AACb;AACA,SAAS;AACT;AACA,UAAU,wDAAG,sDAAsD,IAAI;AACvE,SAAS;AACT;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oIAAoI,iDAAiD;AACrL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,sBAAsB;AAClC;AACA;AACA;AACA;AACA,YAAY,uBAAuB;AACnC;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA;AACA,YAAY,YAAY;AACxB;AACA,CAAC;;AAED;AACA,QAAQ,6BAA6B;AACrC,UAAU;AACV;AACA;;AAEA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA,6CAA6C;AAC7C,UAAU;AACV;AACA;;AAEA;AACA,yDAAyD;AACzD;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA,iEAAe,eAAe,EAAC","sources":["webpack://jclic/./src/media/MidiAudioPlayer.js"],"sourcesContent":["/**\n * File : media/MidiAudioPlayer.js\n * Created : 11/10/2018\n * By : Francesc Busquets <francesc@gmail.com>\n *\n * JClic.js\n * An HTML5 player of JClic activities\n * https://projectestac.github.io/jclic.js\n *\n * @source https://github.com/projectestac/jclic.js\n *\n * @license EUPL-1.2\n * @licstart\n * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)\n *\n * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by\n * the European Commission- subsequent versions of the EUPL (the \"Licence\");\n * You may not use this work except in compliance with the Licence.\n *\n * You may obtain a copy of the Licence at:\n * https://joinup.ec.europa.eu/software/page/eupl\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the Licence is distributed on an \"AS IS\" basis, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * Licence for the specific language governing permissions and limitations\n * under the Licence.\n * @licend\n * @module\n */\n\n/* global window */\n\nimport MidiPlayer from '@francesc/basic-midi-player-js';\nimport { log } from '../Utils.js';\n\n// TODO: Use multiple instruments, at least one for each track\n// TODO: Use multiple midi channels (currently flattened to a single channel)\n// TODO: Use of channel 10 for percussion instruments\n// TODO: ... build a real MIDI player!!\n\n/**\n * A simple MIDI player based on MidiPlayerJS\n * https://github.com/grimmdude/MidiPlayerJS\n * See also: http://www.midijs.net (https://github.com/babelsberg/babelsberg-js/tree/master/midijs)\n */\nexport class MidiAudioPlayer {\n /**\n * MidiAudioPlayer constructor\n * @param {external:ArrayBuffer} data - The MIDI file content, in ArrayBuffer format\n * @param {object} [options={}] - Optional params related to the type of soundfont used. Valid options inside this object are:<br>\n * - `MIDISoundFontObject`: An object containing the full soundfont data. When this param is provided, no other one will be used.\n * - `MIDISoundFontBase`: The URL used as base for the current collection of MIDI soundfonts. Defaults to `https://clic.xtec.cat/dist/jclic.js/soundfonts/MusyngKite`\n * - `MIDISoundFontName`: The MIDI instrument name. Defaults to `acoustic_grand_piano`. See [MIDI.js Soundfonts](https://github.com/gleitz/midi-js-soundfonts) for full lists of MIDI instrument names.\n * - `MIDISoundFontExtension`: An extension to be added to `MIDISoundFontName` in order to build the full file name of the soundfont JS file. Defaults to `-mp3.js`\n */\n constructor(data, options = {}) {\n const AudioContext = window && (window.AudioContext || window.webkitAudioContext);\n if (AudioContext) {\n // Build instrument on first call to constructor\n MidiAudioPlayer.prepareInstrument(options, new AudioContext());\n this.data = data;\n this.player = new MidiPlayer.Player(ev => this.playEvent(ev));\n if (this.player)\n this.player.loadArrayBuffer(data);\n }\n }\n\n /**\n * Initializes the soundfont instrument, loading data from GitHub\n * NOTE: This will not work when off-line!\n * TODO: Provided a basic, simple, static soundfont\n * @param {object} options - Optional param with options related to the MIDI soundfont. See details in `constructor` description.\n * @param {external:AudioContext} audioContext - The AudioContext object (see: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext)\n */\n static prepareInstrument(options = {}, audioContext) {\n if (MidiAudioPlayer.loadingInstrument === false) {\n MidiAudioPlayer.loadingInstrument = true;\n MidiAudioPlayer.audioContext = audioContext;\n MidiPlayer.Soundfont.instrument(\n MidiAudioPlayer.audioContext,\n options.MIDISoundFontObject || MidiAudioPlayer.MIDISoundFontObject ||\n `${options.MIDISoundFontBase || MidiAudioPlayer.MIDISoundFontBase}/${options.MIDISoundFontName || MidiAudioPlayer.MIDISoundFontName}${options.MIDISoundFontExtension || MidiAudioPlayer.MIDISoundFontExtension}`)\n .then(instrument => {\n log('info', 'MIDI soundfont instrument loaded');\n MidiAudioPlayer.instrument = instrument;\n })\n .catch(err => {\n log('error', `Error loading soundfont base instrument: ${err}`);\n });\n }\n }\n\n /**\n * Pauses the player\n */\n pause() {\n if (this.player) {\n this.player.pause();\n this.startedNotes = [];\n }\n }\n\n /**\n * Starts or resumes playing\n */\n play() {\n if (this.player) {\n this.startedNotes = [];\n this.player.play();\n }\n }\n\n /**\n * Gets the ' paused' state of the current player\n * @returns boolean\n */\n get paused() {\n return this.player && !this.player.isPlaying();\n }\n\n /**\n * Checks if the current player has ended or is already playing\n * @returns boolean\n */\n get ended() {\n return this.player && this.player.getSongTimeRemaining() <= 0;\n }\n\n /**\n * Gets the current time\n * @returns number\n */\n get currentTime() {\n return this.player && (this.player.getSongTime() * 1000) || 0;\n }\n\n /**\n * Sets the current time of this player (in milliseconds)\n * @param {number} time - The time position where the player pointer must be placed\n */\n set currentTime(time) {\n if (this.player)\n this.player.skipToSeconds(time / 1000);\n }\n\n /**\n * Plays a MIDI event\n * @param {object} ev - The event data. See http://grimmdude.com/MidiPlayerJS/docs/index.html for details\n */\n playEvent(ev) {\n if (this.player && MidiAudioPlayer.instrument) {\n // Check for specific interval\n if (this.playTo > 0 && this.currentTime >= this.playTo)\n this.pause();\n // Set main volume\n else if (ev.name === 'Controller Change' && ev.number === 7)\n this.mainVolume = ev.value / 127;\n // Process 'Note on' messages. Max gain set to 2.0 for better results with the used soundfont\n else if (ev.name === 'Note on' && ev.velocity > 0)\n this.startedNotes[ev.noteNumber] = MidiAudioPlayer.instrument.play(ev.noteName, MidiAudioPlayer.audioContext.currentTime, { gain: 2 * (this.mainVolume * ev.velocity / 100) });\n // Process 'Note off' messages\n else if (ev.name === 'Note off' && ev.noteNumber && this.startedNotes[ev.noteNumber]) {\n this.startedNotes[ev.noteNumber].stop();\n delete (this.startedNotes[ev.noteNumber]);\n }\n }\n }\n}\n\nObject.assign(MidiAudioPlayer.prototype, {\n /**\n * The MIDI file data used by this MIDI player\n * @name module:media/MidiAudioPlayer.MidiAudioPlayer#data\n * @type {external:ArrayBuffer} */\n data: null,\n /**\n * The grimmdude's MidiPlayer used by this player\n * @name module:media/MidiAudioPlayer.MidiAudioPlayer#player\n * @type {external:MidiPlayerJS} */\n player: null,\n /**\n * When >0, time position at which the music must end\n * @name module:media/MidiAudioPlayer.MidiAudioPlayer#playTo\n * @type {number} */\n playTo: 0,\n /**\n * Main volume of this track (set with a MIDI message of type `Controller Change` #7)\n * @name module:media/MidiAudioPlayer.MidiAudioPlayer#mainVolume\n * @type {number} */\n mainVolume: 1.0,\n /**\n * This array is used when processing 'Note off' events to stop notes that are currently playing.\n * It contains a collection of 'instrument.play' instances, one for each active note\n * @name module:media/MidiAudioPlayer.MidiAudioPlayer#startedNotes\n * @type {function[]} */\n startedNotes: [],\n});\n\n/**\n * The {@link external:AudioContext} used by this MIDI player.\n * @type {external:AudioContext}\n */\nMidiAudioPlayer.audioContext = null;\n\n/**\n * The \"Instrument\" object used by this MIDI player.\n * See: https://github.com/danigb/soundfont-player\n * @type {external:Instrument}\n */\nMidiAudioPlayer.instrument = null;\n\n/**\n * A flag used to avoid re-entrant calls to {@link module:media/MidiAudioPlayer.MidiAudioPlayer#prepareInstrument prepareInstrument}\n * @type {boolean}\n */\nMidiAudioPlayer.loadingInstrument = false;\n\n/**\n * An object containing the full soundfont data used by {@link module:media/MidiAudioPlayer.MidiAudioPlayer#instrument instrument}\n * When this member is set, no other settings related to the sounfFont will be used.\n * This value can be overwritten by the global parameter `MIDISoundFontObject`\n * @type {object}\n */\nMidiAudioPlayer.MIDISoundFontObject = null;\n\n/**\n * The URL used as base for the current collection of MIDI soundfonts.\n * This value can be overwritten by the global parameter `MIDISoundFontBase`\n * @type {string}\n */\nMidiAudioPlayer.MIDISoundFontBase = 'https://clic.xtec.cat/dist/jclic.js/soundfonts/MusyngKite';\n// Alternative sites are:\n// 'https://clic.xtec.cat/dist/jclic.js/soundfonts/FluidR3_GM'\n// 'https://raw.githubusercontent.com/gleitz/midi-js-soundfonts/gh-pages/FluidR3_GM'\n// 'https://raw.githubusercontent.com/gleitz/midi-js-soundfonts/gh-pages/MusyngKite'\n\n/**\n * The MIDI instrument name.\n * This value can be overwritten by the global parameter `MIDISoundFontName`\n * See [MIDI.js Soundfonts](https://github.com/gleitz/midi-js-soundfonts) for full lists of MIDI instrument names.\n * @type {string}\n */\nMidiAudioPlayer.MIDISoundFontName = 'acoustic_grand_piano';\n\n/**\n * An extension to be added to `MIDISoundFontName` in order to build the full file name of the soundfont JS file.\n * Current valid options are `-mp3.js` and `-ogg.js`\n * This value can be overwritten by the global parameter `MIDISoundFontExtension`\n * @type {string}\n */\nMidiAudioPlayer.MIDISoundFontExtension = '-mp3.js';\n\nexport default MidiAudioPlayer;\n"],"names":[],"sourceRoot":""}