spessasynth_lib 3.27.8 → 4.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 (34) hide show
  1. package/README.md +48 -47
  2. package/dist/index.d.ts +1328 -0
  3. package/dist/index.js +3212 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/spessasynth_processor.min.js +21 -0
  6. package/dist/spessasynth_processor.min.js.map +7 -0
  7. package/package.json +26 -14
  8. package/index.js +0 -29
  9. package/src/external_midi/README.md +0 -4
  10. package/src/external_midi/midi_handler.js +0 -130
  11. package/src/external_midi/web_midi_link.js +0 -43
  12. package/src/sequencer/README.md +0 -30
  13. package/src/sequencer/default_sequencer_options.js +0 -9
  14. package/src/sequencer/midi_data.js +0 -67
  15. package/src/sequencer/sequencer.js +0 -813
  16. package/src/sequencer/sequencer_message.js +0 -53
  17. package/src/synthetizer/README.md +0 -30
  18. package/src/synthetizer/audio_effects/effects_config.js +0 -25
  19. package/src/synthetizer/audio_effects/fancy_chorus.js +0 -166
  20. package/src/synthetizer/audio_effects/rb_compressed.min.js +0 -1
  21. package/src/synthetizer/audio_effects/reverb.js +0 -35
  22. package/src/synthetizer/audio_effects/reverb_as_binary.js +0 -18
  23. package/src/synthetizer/key_modifier_manager.js +0 -113
  24. package/src/synthetizer/sfman_message.js +0 -9
  25. package/src/synthetizer/synth_event_handler.js +0 -217
  26. package/src/synthetizer/synth_soundfont_manager.js +0 -115
  27. package/src/synthetizer/synthetizer.js +0 -1033
  28. package/src/synthetizer/worklet_message.js +0 -121
  29. package/src/synthetizer/worklet_processor.js +0 -654
  30. package/src/synthetizer/worklet_url.js +0 -18
  31. package/src/utils/buffer_to_wav.js +0 -40
  32. package/src/utils/fill_with_defaults.js +0 -21
  33. package/src/utils/other.js +0 -11
  34. package/synthetizer/worklet_processor.min.js +0 -22
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.27.8",
3
+ "version": "4.0.1",
4
4
  "description": "MIDI and SoundFont2/DLS library for the browsers with no compromises",
5
- "browser": "index.js",
6
5
  "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
7
9
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "node build_scripts/build.js",
10
- "debug": "node build_scripts/debug_enable.js",
11
- "release": "node build_scripts/debug_disable.js",
12
- "build:pages": "node build_scripts/build_pages.js",
13
- "build:examples": "node examples/build_examples.js",
14
- "build:docs": "node build_scripts/build_docs.js"
10
+ "build": "npm run test:types && npm run local-build && npm run build:pages",
11
+ "local-build": "npm run build:npm && npm pack",
12
+ "build:npm": "tsx build_scripts/build_npm.ts",
13
+ "build:pages": "tsx build_scripts/build_pages.ts",
14
+ "test:types": "eslint src/ && tsc -b",
15
+ "debug": "tsx build_scripts/debug_enable.ts",
16
+ "release": "tsx build_scripts/debug_disable.ts"
15
17
  },
16
18
  "repository": {
17
19
  "type": "git",
18
20
  "url": "git+https://github.com/spessasus/spessasynth_lib.git"
19
21
  },
20
- "main": "index.js",
21
22
  "keywords": [
22
23
  "soundfont",
23
24
  "synthesizer",
@@ -37,9 +38,10 @@
37
38
  "audio-buffer-to-wav"
38
39
  ],
39
40
  "files": [
40
- "src",
41
- "synthetizer/worklet_processor.min.js",
42
- "index.js"
41
+ "dist",
42
+ "LICENSE",
43
+ "README.md",
44
+ "package.json"
43
45
  ],
44
46
  "author": {
45
47
  "name": "spessasus",
@@ -53,7 +55,17 @@
53
55
  },
54
56
  "homepage": "https://github.com/spessasus/spessasynth_lib#readme",
55
57
  "devDependencies": {
56
- "esbuild": "^0.25.2"
58
+ "@eslint/js": "^9.32.0",
59
+ "@types/audioworklet": "^0.0.81",
60
+ "@types/node": "^24.1.0",
61
+ "esbuild": "^0.25.8",
62
+ "eslint": "^9.32.0",
63
+ "globals": "^16.3.0",
64
+ "prettier": "^3.6.2",
65
+ "tsup": "^8.5.0",
66
+ "tsx": "^4.20.5",
67
+ "typescript": "^5.8.3",
68
+ "typescript-eslint": "^8.38.0"
57
69
  },
58
70
  "dependencies": {
59
71
  "spessasynth_core": "latest"
package/index.js DELETED
@@ -1,29 +0,0 @@
1
- // Import modules
2
-
3
- import { Synthetizer } from "./src/synthetizer/synthetizer.js";
4
- import { Sequencer } from "./src/sequencer/sequencer.js";
5
- import { getReverbProcessor } from "./src/synthetizer/audio_effects/reverb.js";
6
- import { FancyChorus } from "./src/synthetizer/audio_effects/fancy_chorus.js";
7
- import { audioBufferToWav } from "./src/utils/buffer_to_wav.js";
8
- import { MIDIDeviceHandler } from "./src/external_midi/midi_handler.js";
9
- import { WebMIDILinkHandler } from "./src/external_midi/web_midi_link.js";
10
- import { DEFAULT_SYNTH_CONFIG } from "./src/synthetizer/audio_effects/effects_config.js";
11
- import { WORKLET_URL_ABSOLUTE } from "./src/synthetizer/worklet_url.js";
12
-
13
- // Export modules
14
- export {
15
- // Synthesizer and Sequencer
16
- Sequencer,
17
- Synthetizer,
18
- DEFAULT_SYNTH_CONFIG,
19
-
20
- // Effects
21
- getReverbProcessor,
22
- FancyChorus,
23
-
24
- // Utilities
25
- audioBufferToWav,
26
- MIDIDeviceHandler,
27
- WebMIDILinkHandler,
28
- WORKLET_URL_ABSOLUTE
29
- };
@@ -1,4 +0,0 @@
1
- ## This is the MIDI handling folder.
2
-
3
- The code here is responsible for dealing with MIDI Inputs and outputs
4
- and also for the WebMidiLink functionality.
@@ -1,130 +0,0 @@
1
- import { Synthetizer } from "../synthetizer/synthetizer.js";
2
- import { SpessaSynthCoreUtils as util } from "spessasynth_core";
3
- import { consoleColors } from "../utils/other.js";
4
-
5
- /**
6
- * midi_handler.js
7
- * purpose: handles the connection between MIDI devices and synthesizer/sequencer via Web MIDI API
8
- */
9
-
10
- const NO_INPUT = null;
11
-
12
- // noinspection JSUnusedGlobalSymbols
13
- /**
14
- * A class for handling MIDI devices
15
- */
16
- export class MIDIDeviceHandler
17
- {
18
- /**
19
- * @returns {Promise<boolean>} if succeeded
20
- */
21
- async createMIDIDeviceHandler()
22
- {
23
- /**
24
- * @type {MIDIInput}
25
- */
26
- this.selectedInput = NO_INPUT;
27
- /**
28
- * @type {MIDIOutput}
29
- */
30
- this.selectedOutput = NO_INPUT;
31
- if (navigator.requestMIDIAccess)
32
- {
33
- // prepare the midi access
34
- try
35
- {
36
- const response = await navigator.requestMIDIAccess({ sysex: true, software: true });
37
- this.inputs = response.inputs;
38
- this.outputs = response.outputs;
39
- util.SpessaSynthInfo("%cMIDI handler created!", consoleColors.recognized);
40
- return true;
41
- }
42
- catch (e)
43
- {
44
- util.SpessaSynthWarn(`Could not get MIDI Devices:`, e);
45
- this.inputs = [];
46
- this.outputs = [];
47
- return false;
48
- }
49
- }
50
- else
51
- {
52
- util.SpessaSynthWarn("Web MIDI Api not supported!", consoleColors.unrecognized);
53
- this.inputs = [];
54
- this.outputs = [];
55
- return false;
56
- }
57
- }
58
-
59
- /**
60
- * Connects the sequencer to a given MIDI output port
61
- * @param output {MIDIOutput}
62
- * @param seq {Sequencer}
63
- */
64
- connectMIDIOutputToSeq(output, seq)
65
- {
66
- this.selectedOutput = output;
67
- seq.connectMidiOutput(output);
68
- util.SpessaSynthInfo(
69
- `%cPlaying MIDI to %c${output.name}`,
70
- consoleColors.info,
71
- consoleColors.recognized
72
- );
73
- }
74
-
75
- /**
76
- * Disconnects a midi output port from the sequencer
77
- * @param seq {Sequencer}
78
- */
79
- disconnectSeqFromMIDI(seq)
80
- {
81
- this.selectedOutput = NO_INPUT;
82
- seq.connectMidiOutput(undefined);
83
- util.SpessaSynthInfo(
84
- "%cDisconnected from MIDI out.",
85
- consoleColors.info
86
- );
87
- }
88
-
89
- /**
90
- * Connects a MIDI input to the synthesizer
91
- * @param input {MIDIInput}
92
- * @param synth {Synthetizer}
93
- */
94
- connectDeviceToSynth(input, synth)
95
- {
96
- this.selectedInput = input;
97
- input.onmidimessage = event =>
98
- {
99
- synth.sendMessage(event.data);
100
- };
101
- util.SpessaSynthInfo(
102
- `%cListening for messages on %c${input.name}`,
103
- consoleColors.info,
104
- consoleColors.recognized
105
- );
106
- }
107
-
108
- /**
109
- * @param input {MIDIInput}
110
- */
111
- disconnectDeviceFromSynth(input)
112
- {
113
- this.selectedInput = NO_INPUT;
114
- input.onmidimessage = undefined;
115
- util.SpessaSynthInfo(
116
- `%cDisconnected from %c${input.name}`,
117
- consoleColors.info,
118
- consoleColors.recognized
119
- );
120
- }
121
-
122
- disconnectAllDevicesFromSynth()
123
- {
124
- this.selectedInput = NO_INPUT;
125
- for (const i of this.inputs)
126
- {
127
- i[1].onmidimessage = undefined;
128
- }
129
- }
130
- }
@@ -1,43 +0,0 @@
1
- import { Synthetizer } from "../synthetizer/synthetizer.js";
2
- import { consoleColors } from "../utils/other.js";
3
- import { SpessaSynthCoreUtils } from "spessasynth_core";
4
-
5
- /**
6
- * web_midi_link.js
7
- * purpose: handles the web midi link connection to the synthesizer
8
- * https://www.g200kg.com/en/docs/webmidilink/
9
- */
10
-
11
- export class WebMIDILinkHandler
12
- {
13
- /**
14
- * @param synth {Synthetizer} the synth to play to
15
- */
16
- constructor(synth)
17
- {
18
-
19
- window.addEventListener("message", msg =>
20
- {
21
- if (typeof msg.data !== "string")
22
- {
23
- return;
24
- }
25
- /**
26
- * @type {string[]}
27
- */
28
- const data = msg.data.split(",");
29
- if (data[0] !== "midi")
30
- {
31
- return;
32
- }
33
-
34
- data.shift(); // remove MIDI
35
-
36
- const midiData = data.map(byte => parseInt(byte, 16));
37
-
38
- synth.sendMessage(midiData);
39
- });
40
-
41
- SpessaSynthCoreUtils.SpessaSynthInfo("%cWeb MIDI Link handler created!", consoleColors.recognized);
42
- }
43
- }
@@ -1,30 +0,0 @@
1
- ## This is the sequencer's folder.
2
-
3
- The code here is responsible for wrapping the `SpessaSynthSequencer` from `spessasynth_core`.
4
-
5
- ### Message protocol:
6
-
7
- #### Message structure
8
-
9
- ```js
10
- const message = {
11
- messageType: number, // WorkletSequencerMessageType
12
- messageData: any // any
13
- }
14
- ```
15
-
16
- #### To worklet
17
-
18
- Sequencer uses `Synthetizer`'s `post` method to post a message with `messageData` set to
19
- `workletMessageType.sequencerSpecific`.
20
- The `messageData` is set to the sequencer's message.
21
-
22
- #### From worklet
23
-
24
- `WorkletSequencer` uses `SpessaSynthProcessor`'s post to send a message with `messageData` set to
25
- `returnMessageType.sequencerSpecific`.
26
- The `messageData` is set to the sequencer's return message.
27
-
28
- ### Process tick
29
-
30
- `processTick` is called every time the `process` method is called via `sequencer.processTick()` every rendering quantum.
@@ -1,9 +0,0 @@
1
- /**
2
- * @type {SequencerOptions}
3
- */
4
- export const DEFAULT_SEQUENCER_OPTIONS = {
5
- skipToFirstNoteOn: true,
6
- autoPlay: true,
7
- preservePlaybackState: false,
8
- initialPlaybackRate: 1
9
- };
@@ -1,67 +0,0 @@
1
- import { BasicMIDI, MIDISequenceData } from "spessasynth_core";
2
-
3
- /**
4
- * A simplified version of the MIDI, accessible at all times from the Sequencer.
5
- * Use getMIDI() to get the actual sequence.
6
- * This class contains all properties that MIDI does, except for tracks and the embedded soundfont.
7
- */
8
- export class MIDIData extends MIDISequenceData
9
- {
10
-
11
- /**
12
- * A boolean indicating if the MIDI file contains an embedded soundfont.
13
- * If the embedded soundfont is undefined, this will be false.
14
- * @type {boolean}
15
- */
16
- isEmbedded = false;
17
-
18
- /**
19
- * Constructor that copies data from a BasicMIDI instance.
20
- * @param {BasicMIDI} midi - The BasicMIDI instance to copy data from.
21
- */
22
- constructor(midi)
23
- {
24
- super();
25
- this._copyFromSequence(midi);
26
-
27
- // Set isEmbedded based on the presence of an embeddedSoundFont
28
- this.isEmbedded = midi.embeddedSoundFont !== undefined;
29
- }
30
- }
31
-
32
-
33
- /**
34
- * Temporary MIDI data used when the MIDI is not loaded.
35
- * @type {MIDIData}
36
- */
37
- export const DUMMY_MIDI_DATA = Object.assign({
38
- duration: 99999,
39
- firstNoteOn: 0,
40
- loop: {
41
- start: 0,
42
- end: 123456
43
- },
44
-
45
- lastVoiceEventTick: 123456,
46
- lyrics: [],
47
- lyricsTicks: [],
48
- copyright: "",
49
- midiPorts: [],
50
- midiPortChannelOffsets: [],
51
- tracksAmount: 0,
52
- tempoChanges: [{ ticks: 0, tempo: 120 }],
53
- trackNames: [],
54
- fileName: "NOT_LOADED.mid",
55
- midiName: "Loading...",
56
- rawMidiName: new Uint8Array([76, 111, 97, 100, 105, 110, 103, 46, 46, 46]), // "Loading..."
57
- usedChannelsOnTrack: [],
58
- timeDivision: 0,
59
- keyRange: { min: 0, max: 127 },
60
- isEmbedded: false,
61
- isKaraokeFile: false,
62
- isMultiPort: false,
63
- RMIDInfo: {},
64
- bankOffset: 0,
65
- midiNameUsesFileName: false,
66
- format: 0
67
- }, MIDIData.prototype);