spessasynth_lib 0.0.1

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 (154) hide show
  1. package/.idea/modules.xml +8 -0
  2. package/.idea/spessasynth_lib.iml +12 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/copy_version.sh +38 -0
  5. package/index.js +73 -0
  6. package/package/@types/externals/stbvorbis_sync/stbvorbis_sync.min.d.ts +1 -0
  7. package/package/@types/index.d.ts +34 -0
  8. package/package/@types/midi_handler/midi_handler.d.ts +39 -0
  9. package/package/@types/midi_handler/web_midi_link.d.ts +12 -0
  10. package/package/@types/midi_parser/midi_data.d.ts +95 -0
  11. package/package/@types/midi_parser/midi_editor.d.ts +45 -0
  12. package/package/@types/midi_parser/midi_loader.d.ts +100 -0
  13. package/package/@types/midi_parser/midi_message.d.ts +154 -0
  14. package/package/@types/midi_parser/midi_writer.d.ts +6 -0
  15. package/package/@types/midi_parser/rmidi_writer.d.ts +9 -0
  16. package/package/@types/midi_parser/used_keys_loaded.d.ts +7 -0
  17. package/package/@types/sequencer/sequencer.d.ts +180 -0
  18. package/package/@types/sequencer/worklet_sequencer/sequencer_message.d.ts +28 -0
  19. package/package/@types/soundfont/read/generators.d.ts +98 -0
  20. package/package/@types/soundfont/read/instruments.d.ts +50 -0
  21. package/package/@types/soundfont/read/modulators.d.ts +73 -0
  22. package/package/@types/soundfont/read/presets.d.ts +87 -0
  23. package/package/@types/soundfont/read/riff_chunk.d.ts +31 -0
  24. package/package/@types/soundfont/read/samples.d.ts +134 -0
  25. package/package/@types/soundfont/read/zones.d.ts +141 -0
  26. package/package/@types/soundfont/soundfont.d.ts +76 -0
  27. package/package/@types/soundfont/write/ibag.d.ts +6 -0
  28. package/package/@types/soundfont/write/igen.d.ts +6 -0
  29. package/package/@types/soundfont/write/imod.d.ts +6 -0
  30. package/package/@types/soundfont/write/inst.d.ts +6 -0
  31. package/package/@types/soundfont/write/pbag.d.ts +6 -0
  32. package/package/@types/soundfont/write/pgen.d.ts +6 -0
  33. package/package/@types/soundfont/write/phdr.d.ts +6 -0
  34. package/package/@types/soundfont/write/pmod.d.ts +6 -0
  35. package/package/@types/soundfont/write/sdta.d.ts +11 -0
  36. package/package/@types/soundfont/write/shdr.d.ts +8 -0
  37. package/package/@types/soundfont/write/soundfont_trimmer.d.ts +6 -0
  38. package/package/@types/soundfont/write/write.d.ts +21 -0
  39. package/package/@types/synthetizer/audio_effects/effects_config.d.ts +29 -0
  40. package/package/@types/synthetizer/audio_effects/fancy_chorus.d.ts +93 -0
  41. package/package/@types/synthetizer/audio_effects/reverb.d.ts +7 -0
  42. package/package/@types/synthetizer/synth_event_handler.d.ts +161 -0
  43. package/package/@types/synthetizer/synthetizer.d.ts +294 -0
  44. package/package/@types/synthetizer/worklet_system/message_protocol/worklet_message.d.ts +89 -0
  45. package/package/@types/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.d.ts +134 -0
  46. package/package/@types/synthetizer/worklet_url.d.ts +5 -0
  47. package/package/@types/utils/buffer_to_wav.d.ts +8 -0
  48. package/package/@types/utils/byte_functions/big_endian.d.ts +13 -0
  49. package/package/@types/utils/byte_functions/little_endian.d.ts +35 -0
  50. package/package/@types/utils/byte_functions/string.d.ts +22 -0
  51. package/package/@types/utils/byte_functions/variable_length_quantity.d.ts +12 -0
  52. package/package/@types/utils/indexed_array.d.ts +21 -0
  53. package/package/@types/utils/loggin.d.ts +26 -0
  54. package/package/@types/utils/other.d.ts +32 -0
  55. package/package/LICENSE +26 -0
  56. package/package/README.md +84 -0
  57. package/package/externals/NOTICE +9 -0
  58. package/package/externals/libvorbis/@types/OggVorbisEncoder.d.ts +34 -0
  59. package/package/externals/libvorbis/OggVorbisEncoder.min.js +1 -0
  60. package/package/externals/stbvorbis_sync/@types/stbvorbis_sync.d.ts +12 -0
  61. package/package/externals/stbvorbis_sync/LICENSE +202 -0
  62. package/package/externals/stbvorbis_sync/stbvorbis_sync.min.js +1 -0
  63. package/package/index.js +73 -0
  64. package/package/midi_handler/README.md +3 -0
  65. package/package/midi_handler/midi_handler.js +118 -0
  66. package/package/midi_handler/web_midi_link.js +41 -0
  67. package/package/midi_parser/README.md +3 -0
  68. package/package/midi_parser/midi_data.js +121 -0
  69. package/package/midi_parser/midi_editor.js +557 -0
  70. package/package/midi_parser/midi_loader.js +502 -0
  71. package/package/midi_parser/midi_message.js +234 -0
  72. package/package/midi_parser/midi_writer.js +95 -0
  73. package/package/midi_parser/rmidi_writer.js +271 -0
  74. package/package/midi_parser/used_keys_loaded.js +172 -0
  75. package/package/package.json +43 -0
  76. package/package/sequencer/README.md +23 -0
  77. package/package/sequencer/sequencer.js +439 -0
  78. package/package/sequencer/worklet_sequencer/events.js +92 -0
  79. package/package/sequencer/worklet_sequencer/play.js +309 -0
  80. package/package/sequencer/worklet_sequencer/process_event.js +167 -0
  81. package/package/sequencer/worklet_sequencer/process_tick.js +85 -0
  82. package/package/sequencer/worklet_sequencer/sequencer_message.js +39 -0
  83. package/package/sequencer/worklet_sequencer/song_control.js +193 -0
  84. package/package/sequencer/worklet_sequencer/worklet_sequencer.js +218 -0
  85. package/package/soundfont/README.md +8 -0
  86. package/package/soundfont/read/generators.js +212 -0
  87. package/package/soundfont/read/instruments.js +125 -0
  88. package/package/soundfont/read/modulators.js +249 -0
  89. package/package/soundfont/read/presets.js +300 -0
  90. package/package/soundfont/read/riff_chunk.js +81 -0
  91. package/package/soundfont/read/samples.js +398 -0
  92. package/package/soundfont/read/zones.js +310 -0
  93. package/package/soundfont/soundfont.js +357 -0
  94. package/package/soundfont/write/ibag.js +39 -0
  95. package/package/soundfont/write/igen.js +75 -0
  96. package/package/soundfont/write/imod.js +46 -0
  97. package/package/soundfont/write/inst.js +34 -0
  98. package/package/soundfont/write/pbag.js +39 -0
  99. package/package/soundfont/write/pgen.js +77 -0
  100. package/package/soundfont/write/phdr.js +42 -0
  101. package/package/soundfont/write/pmod.js +46 -0
  102. package/package/soundfont/write/sdta.js +72 -0
  103. package/package/soundfont/write/shdr.js +54 -0
  104. package/package/soundfont/write/soundfont_trimmer.js +169 -0
  105. package/package/soundfont/write/write.js +180 -0
  106. package/package/synthetizer/README.md +6 -0
  107. package/package/synthetizer/audio_effects/effects_config.js +21 -0
  108. package/package/synthetizer/audio_effects/fancy_chorus.js +120 -0
  109. package/package/synthetizer/audio_effects/impulse_response_2.flac +0 -0
  110. package/package/synthetizer/audio_effects/reverb.js +24 -0
  111. package/package/synthetizer/synth_event_handler.js +156 -0
  112. package/package/synthetizer/synthetizer.js +766 -0
  113. package/package/synthetizer/worklet_processor.min.js +13 -0
  114. package/package/synthetizer/worklet_system/README.md +6 -0
  115. package/package/synthetizer/worklet_system/main_processor.js +363 -0
  116. package/package/synthetizer/worklet_system/message_protocol/handle_message.js +197 -0
  117. package/package/synthetizer/worklet_system/message_protocol/message_sending.js +74 -0
  118. package/package/synthetizer/worklet_system/message_protocol/worklet_message.js +121 -0
  119. package/package/synthetizer/worklet_system/minify_processor.sh +4 -0
  120. package/package/synthetizer/worklet_system/worklet_methods/controller_control.js +230 -0
  121. package/package/synthetizer/worklet_system/worklet_methods/data_entry.js +277 -0
  122. package/package/synthetizer/worklet_system/worklet_methods/note_off.js +109 -0
  123. package/package/synthetizer/worklet_system/worklet_methods/note_on.js +91 -0
  124. package/package/synthetizer/worklet_system/worklet_methods/program_control.js +183 -0
  125. package/package/synthetizer/worklet_system/worklet_methods/reset_controllers.js +177 -0
  126. package/package/synthetizer/worklet_system/worklet_methods/snapshot.js +129 -0
  127. package/package/synthetizer/worklet_system/worklet_methods/system_exclusive.js +272 -0
  128. package/package/synthetizer/worklet_system/worklet_methods/tuning_control.js +195 -0
  129. package/package/synthetizer/worklet_system/worklet_methods/vibrato_control.js +29 -0
  130. package/package/synthetizer/worklet_system/worklet_methods/voice_control.js +233 -0
  131. package/package/synthetizer/worklet_system/worklet_processor.js +9 -0
  132. package/package/synthetizer/worklet_system/worklet_utilities/lfo.js +23 -0
  133. package/package/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js +130 -0
  134. package/package/synthetizer/worklet_system/worklet_utilities/modulation_envelope.js +73 -0
  135. package/package/synthetizer/worklet_system/worklet_utilities/modulator_curves.js +86 -0
  136. package/package/synthetizer/worklet_system/worklet_utilities/stereo_panner.js +81 -0
  137. package/package/synthetizer/worklet_system/worklet_utilities/unit_converter.js +66 -0
  138. package/package/synthetizer/worklet_system/worklet_utilities/volume_envelope.js +265 -0
  139. package/package/synthetizer/worklet_system/worklet_utilities/wavetable_oscillator.js +83 -0
  140. package/package/synthetizer/worklet_system/worklet_utilities/worklet_modulator.js +234 -0
  141. package/package/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +116 -0
  142. package/package/synthetizer/worklet_system/worklet_utilities/worklet_voice.js +272 -0
  143. package/package/synthetizer/worklet_url.js +5 -0
  144. package/package/utils/README.md +4 -0
  145. package/package/utils/buffer_to_wav.js +101 -0
  146. package/package/utils/byte_functions/big_endian.js +28 -0
  147. package/package/utils/byte_functions/little_endian.js +74 -0
  148. package/package/utils/byte_functions/string.js +97 -0
  149. package/package/utils/byte_functions/variable_length_quantity.js +37 -0
  150. package/package/utils/encode_vorbis.js +30 -0
  151. package/package/utils/indexed_array.js +41 -0
  152. package/package/utils/loggin.js +79 -0
  153. package/package/utils/other.js +54 -0
  154. package/package.json +43 -0
@@ -0,0 +1,97 @@
1
+ import { IndexedByteArray } from '../indexed_array.js'
2
+
3
+ /**
4
+ * @param dataArray {IndexedByteArray}
5
+ * @param bytes {number}
6
+ * @param encoding {string} the textElement encoding
7
+ * @param trimEnd {boolean} if we should trim once we reach an invalid byte
8
+ * @returns {string}
9
+ */
10
+ export function readBytesAsString(dataArray, bytes, encoding = undefined, trimEnd = true) {
11
+ if (!encoding)
12
+ {
13
+ let finished = false
14
+ let string = ''
15
+ for (let i = 0; i < bytes; i++)
16
+ {
17
+ let byte = dataArray[dataArray.currentIndex++]
18
+ if (finished)
19
+ {
20
+ continue
21
+ }
22
+ if (byte < 32 || byte > 127)
23
+ {
24
+ if (trimEnd)
25
+ {
26
+ finished = true
27
+ continue
28
+ }
29
+ else
30
+ {
31
+ if (byte === 0)
32
+ {
33
+ finished = true;
34
+ continue;
35
+ }
36
+ }
37
+ }
38
+ string += String.fromCharCode(byte)
39
+ }
40
+ return string
41
+ }
42
+ else
43
+ {
44
+ let byteBuffer = dataArray.slice(dataArray.currentIndex, dataArray.currentIndex + bytes)
45
+ dataArray.currentIndex += bytes
46
+ let decoder = new TextDecoder(encoding)
47
+ return decoder.decode(byteBuffer.buffer)
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @param string {string}
53
+ * @param padLength {number}
54
+ * @returns {IndexedByteArray}
55
+ */
56
+ export function getStringBytes(string, padLength = 0)
57
+ {
58
+ let len = string.length;
59
+ if(padLength > 0)
60
+ {
61
+ len = padLength;
62
+ }
63
+ const arr = new IndexedByteArray(len);
64
+ writeStringAsBytes(arr, string, padLength);
65
+ return arr;
66
+ }
67
+
68
+ /**
69
+ * @param string {string}
70
+ * @param outArray {IndexedByteArray}
71
+ * @param padLength {number}
72
+ * @returns {IndexedByteArray} modified IN PLACE
73
+ */
74
+ export function writeStringAsBytes(outArray, string, padLength = 0)
75
+ {
76
+ if(padLength > 0)
77
+ {
78
+ if(string.length > padLength)
79
+ {
80
+ string = string.slice(0, padLength);
81
+ }
82
+ }
83
+ for (let i = 0; i < string.length; i++)
84
+ {
85
+ outArray[outArray.currentIndex++] = string.charCodeAt(i);
86
+ }
87
+
88
+ // pad with zeros if needed
89
+ if(padLength > string.length)
90
+ {
91
+ for (let i = 0; i < padLength - string.length; i++)
92
+ {
93
+ outArray[outArray.currentIndex++] = 0;
94
+ }
95
+ }
96
+ return outArray
97
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Reads VLQ From a MIDI byte array
3
+ * @param MIDIbyteArray {IndexedByteArray}
4
+ * @returns {number}
5
+ */
6
+ export function readVariableLengthQuantity(MIDIbyteArray) {
7
+ let out = 0
8
+ while (MIDIbyteArray) {
9
+ const byte = MIDIbyteArray[MIDIbyteArray.currentIndex++]
10
+ // extract the first 7 bytes
11
+ out = (out << 7) | (byte & 127)
12
+
13
+ // if the last byte isn't 1, stop reading
14
+ if ((byte >> 7) !== 1) {
15
+ break
16
+ }
17
+ }
18
+ return out
19
+ }
20
+
21
+ /**
22
+ * Write a VLQ from a number to a byte array
23
+ * @param number {number}
24
+ * @returns {number[]}
25
+ */
26
+ export function writeVariableLengthQuantity(number) {
27
+ // Add the first byte
28
+ let bytes = [number & 127]
29
+ number >>= 7
30
+
31
+ // Continue processing the remaining bytes
32
+ while (number > 0) {
33
+ bytes.unshift((number & 127) | 128)
34
+ number >>= 7
35
+ }
36
+ return bytes
37
+ }
@@ -0,0 +1,30 @@
1
+ import { libvorbis } from '../externals/libvorbis/OggVorbisEncoder.min.js'
2
+
3
+ /**
4
+ * @typedef {function} EncodeVorbisFunction
5
+ * @param channelAudioData {Float32Array[]}
6
+ * @param sampleRate {number}
7
+ * @param channels {number}
8
+ * @param quality {number} -0.1 to 1
9
+ * @returns {Uint8Array}
10
+ */
11
+ export function encodeVorbis(channelAudioData, channels, sampleRate, quality)
12
+ {
13
+ // https://github.com/higuma/ogg-vorbis-encoder-js
14
+ //libvorbis.init();
15
+ const encoder = new libvorbis.OggVorbisEncoder(sampleRate, channels, quality);
16
+ encoder.encode(channelAudioData);
17
+ /**
18
+ * @type {Uint8Array[]}
19
+ */
20
+ const arrs = encoder.finish();
21
+ const outLen = arrs.reduce((l, c) => l + c.length, 0);
22
+ const out = new Uint8Array(outLen);
23
+ let offset = 0;
24
+ for(const a of arrs)
25
+ {
26
+ out.set(a, offset);
27
+ offset += a.length;
28
+ }
29
+ return out;
30
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * indexed_array.js
3
+ * purpose: exteds Uint8Array with a currentIndex property
4
+ */
5
+
6
+ export class IndexedByteArray extends Uint8Array
7
+ {
8
+ /**
9
+ * Creates a new instance of an Uint8Array with a currentIndex property
10
+ * @param args {any} same as for Uint8Array
11
+ */
12
+ constructor(args)
13
+ {
14
+ super(args);
15
+ this.currentIndex = 0;
16
+ }
17
+
18
+ /**
19
+ * The current index of the array
20
+ * @type {number}
21
+ */
22
+ currentIndex;
23
+ }
24
+
25
+
26
+ /**
27
+ * @param arrs {(IndexedByteArray|Uint8Array)[]}
28
+ * @returns {IndexedByteArray|Uint8Array}
29
+ */
30
+ export function combineArrays(arrs)
31
+ {
32
+ const length = arrs.reduce((sum, current) => sum + current.length, 0);
33
+ const newArr = new IndexedByteArray(length);
34
+ let offset = 0;
35
+ for(const arr of arrs)
36
+ {
37
+ newArr.set(arr, offset);
38
+ offset += arr.length;
39
+ }
40
+ return newArr;
41
+ }
@@ -0,0 +1,79 @@
1
+ let ENABLE_INFO = true;
2
+ let ENABLE_WARN = true;
3
+ let ENABLE_GROUP = true;
4
+ let ENABLE_TABLE = true;
5
+
6
+ /**
7
+ * Enables or disables looging
8
+ * @param enableInfo {boolean} - enables info
9
+ * @param enableWarn {boolean} - enables warning
10
+ * @param enableGroup {boolean} - enables groups
11
+ * @param enableTable {boolean} - enables tables
12
+ */
13
+ export function SpessaSynthLogging(enableInfo, enableWarn, enableGroup, enableTable)
14
+ {
15
+ ENABLE_INFO = enableInfo;
16
+ ENABLE_WARN = enableWarn;
17
+ ENABLE_GROUP = enableGroup;
18
+ ENABLE_TABLE = enableTable;
19
+ }
20
+
21
+ /**
22
+ * @param message {...any}
23
+ */
24
+ export function SpessaSynthInfo(...message)
25
+ {
26
+ if(ENABLE_INFO)
27
+ {
28
+ console.info(...message);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @param message {...any}
34
+ */
35
+ export function SpessaSynthWarn(...message)
36
+ {
37
+ if(ENABLE_WARN)
38
+ {
39
+ console.warn(...message);
40
+ }
41
+ }
42
+
43
+ export function SpessaSynthTable(...args)
44
+ {
45
+ if(ENABLE_TABLE)
46
+ {
47
+ console.table(...args);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @param message {...any} the message
53
+ */
54
+ export function SpessaSynthGroup(...message)
55
+ {
56
+ if(ENABLE_GROUP)
57
+ {
58
+ console.group(...message);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * @param message {...any} the message
64
+ */
65
+ export function SpessaSynthGroupCollapsed(...message)
66
+ {
67
+ if(ENABLE_GROUP)
68
+ {
69
+ console.groupCollapsed(...message);
70
+ }
71
+ }
72
+
73
+ export function SpessaSynthGroupEnd()
74
+ {
75
+ if(ENABLE_GROUP)
76
+ {
77
+ console.groupEnd();
78
+ }
79
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * other.js
3
+ * purpose: contains some useful functions that don't belong in any specific category
4
+ */
5
+
6
+ /**
7
+ * Formats the given seconds to nice readable time
8
+ * @param totalSeconds {number} time in seconds
9
+ * @return {{seconds: number, minutes: number, time: string}}
10
+ */
11
+ export function formatTime(totalSeconds) {
12
+ totalSeconds = Math.floor(totalSeconds);
13
+ let minutes = Math.floor(totalSeconds / 60);
14
+ let seconds = Math.round(totalSeconds - (minutes * 60));
15
+ return {"minutes": minutes, "seconds": seconds, "time": `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`}
16
+ }
17
+
18
+ /**
19
+ * @param fileName {string}
20
+ * @returns {string}
21
+ */
22
+ export function formatTitle(fileName)
23
+ {
24
+ return fileName
25
+ .trim()
26
+ .replaceAll(".mid", "")
27
+ .replaceAll(".rmi", "")
28
+ .replaceAll("_", " ");
29
+ }
30
+
31
+ /**
32
+ * Does what it says
33
+ * @param arr {number[]}
34
+ * @returns {string}
35
+ */
36
+ export function arrayToHexString(arr) {
37
+ let hexString = '';
38
+
39
+ for (let i = 0; i < arr.length; i++) {
40
+ const hex = arr[i].toString(16).padStart(2, '0').toUpperCase();
41
+ hexString += hex;
42
+ hexString += ' ';
43
+ }
44
+
45
+ return hexString;
46
+ }
47
+
48
+ export const consoleColors = {
49
+ warn: "color: orange;",
50
+ unrecognized: "color: red;",
51
+ info: "color: aqua;",
52
+ recognized: "color: lime",
53
+ value: "color: yellow; background-color: black;"
54
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "spessasynth_lib",
3
+ "version": "0.0.1",
4
+ "description": "No compromise SoundFont and MIDI library and player",
5
+ "browser": "index.js",
6
+ "types": "@types/index.d.ts",
7
+ "type": "module",
8
+ "directories": {
9
+ "lib": "lib"
10
+ },
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/spessasus/SpessaSynth.git"
17
+ },
18
+ "keywords": [
19
+ "soundfont",
20
+ "synthesizer",
21
+ "synth",
22
+ "sf2",
23
+ "sf3",
24
+ "midi",
25
+ "midi-player",
26
+ "web-audio-api",
27
+ "web-midi-api",
28
+ "player",
29
+ "soundfont2",
30
+ "soundfont3"
31
+ ],
32
+ "author": {
33
+ "name": "spessasus",
34
+ "email": "spesekspesek@gmail.com",
35
+ "url": "https://github.com/spessasus"
36
+ },
37
+ "license": "(MIT AND Apache-2.0)",
38
+ "bugs": {
39
+ "url": "https://github.com/spessasus/SpessaSynth/issues",
40
+ "email": "spesekspesek@gmail.com"
41
+ },
42
+ "homepage": "https://github.com/spessasus/SpessaSynth#readme"
43
+ }