spessasynth_lib 3.24.40 → 3.25.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.
- package/LICENSE +202 -26
- package/README.md +3 -1
- package/midi_parser/midi_editor.js +5 -16
- package/midi_parser/rmidi_writer.js +64 -33
- package/midi_parser/used_keys_loaded.js +47 -32
- package/package.json +2 -2
- package/sequencer/sequencer.js +0 -1
- package/synthetizer/synthetizer.js +48 -1
- package/synthetizer/worklet_processor.min.js +12 -12
- package/synthetizer/worklet_system/main_processor.js +17 -2
- package/synthetizer/worklet_system/message_protocol/handle_message.js +3 -0
- package/synthetizer/worklet_system/message_protocol/worklet_message.js +5 -6
- package/synthetizer/worklet_system/snapshot/channel_snapshot.js +1 -1
- package/synthetizer/worklet_system/snapshot/synthesizer_snapshot.js +1 -1
- package/synthetizer/worklet_system/worklet_methods/controller_control/controller_change.js +67 -131
- package/synthetizer/worklet_system/worklet_methods/controller_control/reset_controllers.js +2 -2
- package/synthetizer/worklet_system/worklet_methods/system_exclusive.js +6 -6
- package/synthetizer/worklet_system/worklet_utilities/worklet_processor_channel.js +35 -2
- package/utils/sysex_detector.js +46 -0
- package/utils/xg_hacks.js +128 -0
- /package/externals/{NOTICE → stbvorbis_sync/NOTICE} +0 -0
package/LICENSE
CHANGED
|
@@ -1,26 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -155,4 +155,6 @@ Supported formats list:
|
|
|
155
155
|
|
|
156
156
|
# License
|
|
157
157
|
Copyright © 2025 Spessasus
|
|
158
|
-
|
|
158
|
+
Licensed under the Apache-2.0 License.
|
|
159
|
+
|
|
160
|
+
SoundFont® is a registered trademark of Creative Technology Ltd.
|
|
@@ -5,6 +5,7 @@ import { consoleColors } from "../utils/other.js";
|
|
|
5
5
|
|
|
6
6
|
import { customControllers } from "../synthetizer/worklet_system/worklet_utilities/controller_tables.js";
|
|
7
7
|
import { DEFAULT_PERCUSSION } from "../synthetizer/synth_constants.js";
|
|
8
|
+
import { isGMOn, isGSOn, isXGOn } from "../utils/sysex_detector.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @param ticks {number}
|
|
@@ -450,12 +451,7 @@ export function modifyMIDI(
|
|
|
450
451
|
|
|
451
452
|
case messageTypes.systemExclusive:
|
|
452
453
|
// check for xg on
|
|
453
|
-
if (
|
|
454
|
-
e.messageData[0] === 0x43 && // Yamaha
|
|
455
|
-
e.messageData[2] === 0x4C && // XG ON
|
|
456
|
-
e.messageData[5] === 0x7E &&
|
|
457
|
-
e.messageData[6] === 0x00
|
|
458
|
-
)
|
|
454
|
+
if (isXGOn(e))
|
|
459
455
|
{
|
|
460
456
|
SpessaSynthInfo("%cXG system on detected", consoleColors.info);
|
|
461
457
|
system = "xg";
|
|
@@ -479,11 +475,7 @@ export function modifyMIDI(
|
|
|
479
475
|
}
|
|
480
476
|
else
|
|
481
477
|
// check for GS on
|
|
482
|
-
if (
|
|
483
|
-
e.messageData[0] === 0x41 // roland
|
|
484
|
-
&& e.messageData[2] === 0x42 // GS
|
|
485
|
-
&& e.messageData[6] === 0x7F // Mode set
|
|
486
|
-
)
|
|
478
|
+
if (isGSOn(e))
|
|
487
479
|
{
|
|
488
480
|
// that's a GS on, we're done here
|
|
489
481
|
addedGs = true;
|
|
@@ -495,10 +487,7 @@ export function modifyMIDI(
|
|
|
495
487
|
}
|
|
496
488
|
else
|
|
497
489
|
// check for GM/2 on
|
|
498
|
-
if (
|
|
499
|
-
e.messageData[0] === 0x7E // non realtime
|
|
500
|
-
&& e.messageData[2] === 0x09 // gm system
|
|
501
|
-
)
|
|
490
|
+
if (isGMOn(e))
|
|
502
491
|
{
|
|
503
492
|
// that's a GM/2 system change, remove it!
|
|
504
493
|
SpessaSynthInfo(
|
|
@@ -511,7 +500,7 @@ export function modifyMIDI(
|
|
|
511
500
|
}
|
|
512
501
|
}
|
|
513
502
|
// check for gs
|
|
514
|
-
if (!addedGs)
|
|
503
|
+
if (!addedGs && desiredProgramChanges.length > 0)
|
|
515
504
|
{
|
|
516
505
|
// gs is not on, add it on the first track at index 0 (or 1 if track name is first)
|
|
517
506
|
let index = 0;
|
|
@@ -7,6 +7,8 @@ import { SpessaSynthGroup, SpessaSynthGroupEnd, SpessaSynthInfo } from "../utils
|
|
|
7
7
|
import { consoleColors } from "../utils/other.js";
|
|
8
8
|
import { writeLittleEndian } from "../utils/byte_functions/little_endian.js";
|
|
9
9
|
import { DEFAULT_PERCUSSION } from "../synthetizer/synth_constants.js";
|
|
10
|
+
import { chooseBank, parseBankSelect } from "../utils/xg_hacks.js";
|
|
11
|
+
import { isGMOn, isGSDrumsOn, isGSOn, isXGOn } from "../utils/sysex_detector.js";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* @enum {string}
|
|
@@ -122,6 +124,7 @@ export function writeRMIDI(
|
|
|
122
124
|
* program: number,
|
|
123
125
|
* drums: boolean,
|
|
124
126
|
* lastBank: MIDIMessage,
|
|
127
|
+
* lastBankLSB: MIDIMessage,
|
|
125
128
|
* hasBankSelect: boolean
|
|
126
129
|
* }[]}
|
|
127
130
|
*/
|
|
@@ -132,6 +135,7 @@ export function writeRMIDI(
|
|
|
132
135
|
program: 0,
|
|
133
136
|
drums: i % 16 === DEFAULT_PERCUSSION, // drums appear on 9 every 16 channels,
|
|
134
137
|
lastBank: undefined,
|
|
138
|
+
lastBankLSB: undefined,
|
|
135
139
|
hasBankSelect: false
|
|
136
140
|
});
|
|
137
141
|
}
|
|
@@ -166,37 +170,18 @@ export function writeRMIDI(
|
|
|
166
170
|
if (status === messageTypes.systemExclusive)
|
|
167
171
|
{
|
|
168
172
|
// check for drum sysex
|
|
169
|
-
if (
|
|
170
|
-
e.messageData[0] !== 0x41 || // roland
|
|
171
|
-
e.messageData[2] !== 0x42 || // GS
|
|
172
|
-
e.messageData[3] !== 0x12 || // GS
|
|
173
|
-
e.messageData[4] !== 0x40 || // system parameter
|
|
174
|
-
(e.messageData[5] & 0x10) === 0 || // part parameter
|
|
175
|
-
e.messageData[6] !== 0x15 // drum part
|
|
176
|
-
)
|
|
173
|
+
if (!isGSDrumsOn(e))
|
|
177
174
|
{
|
|
178
175
|
// check for XG
|
|
179
|
-
if (
|
|
180
|
-
e.messageData[0] === 0x43 && // yamaha
|
|
181
|
-
e.messageData[2] === 0x4C && // sXG ON
|
|
182
|
-
e.messageData[5] === 0x7E &&
|
|
183
|
-
e.messageData[6] === 0x00
|
|
184
|
-
)
|
|
176
|
+
if (isXGOn(e))
|
|
185
177
|
{
|
|
186
178
|
system = "xg";
|
|
187
179
|
}
|
|
188
|
-
else if (
|
|
189
|
-
e.messageData[0] === 0x41 // roland
|
|
190
|
-
&& e.messageData[2] === 0x42 // GS
|
|
191
|
-
&& e.messageData[6] === 0x7F // Mode set
|
|
192
|
-
)
|
|
180
|
+
else if (isGSOn(e))
|
|
193
181
|
{
|
|
194
182
|
system = "gs";
|
|
195
183
|
}
|
|
196
|
-
else if (
|
|
197
|
-
e.messageData[0] === 0x7E // non realtime
|
|
198
|
-
&& e.messageData[2] === 0x09 // gm system
|
|
199
|
-
)
|
|
184
|
+
else if (isGMOn(e))
|
|
200
185
|
{
|
|
201
186
|
system = "gm";
|
|
202
187
|
unwantedSystems.push({
|
|
@@ -213,6 +198,9 @@ export function writeRMIDI(
|
|
|
213
198
|
|
|
214
199
|
// program change
|
|
215
200
|
const chNum = (e.messageStatusByte & 0xF) + portOffset;
|
|
201
|
+
/**
|
|
202
|
+
* @type {{program: number, drums: boolean, lastBank: MIDIMessage, lastBankLSB: MIDIMessage, hasBankSelect: boolean}}
|
|
203
|
+
*/
|
|
216
204
|
const channel = channelsInfo[chNum];
|
|
217
205
|
if (status === messageTypes.programChange)
|
|
218
206
|
{
|
|
@@ -236,15 +224,24 @@ export function writeRMIDI(
|
|
|
236
224
|
channel.program = e.messageData[0];
|
|
237
225
|
// check if this preset exists for program and bank
|
|
238
226
|
const realBank = Math.max(0, channel.lastBank?.messageData[1] - mid.bankOffset); // make sure to take the previous bank offset into account
|
|
239
|
-
|
|
227
|
+
let bank = channel.drums ? 128 : realBank;
|
|
240
228
|
if (channel.lastBank === undefined)
|
|
241
229
|
{
|
|
242
230
|
continue;
|
|
243
231
|
}
|
|
244
|
-
if (system === "xg"
|
|
232
|
+
if (system === "xg")
|
|
245
233
|
{
|
|
246
|
-
|
|
247
|
-
|
|
234
|
+
if (channel.drums)
|
|
235
|
+
{
|
|
236
|
+
// drums override: set the bank to 127
|
|
237
|
+
channelsInfo[chNum].lastBank.messageData[1] = 127;
|
|
238
|
+
}
|
|
239
|
+
else
|
|
240
|
+
{
|
|
241
|
+
// potential bank lsb override
|
|
242
|
+
const bankLSB = (channel?.lastBankLSB?.messageData[1] - mid.bankOffset) || 0;
|
|
243
|
+
bank = chooseBank(bank, bankLSB);
|
|
244
|
+
}
|
|
248
245
|
}
|
|
249
246
|
|
|
250
247
|
if (soundfont.presets.findIndex(p => p.bank === bank && p.program === e.messageData[0]) === -1)
|
|
@@ -252,6 +249,10 @@ export function writeRMIDI(
|
|
|
252
249
|
// no preset with this bank. find this program with any bank
|
|
253
250
|
const targetBank = (soundfont.presets.find(p => p.program === e.messageData[0])?.bank + bankOffset) || bankOffset;
|
|
254
251
|
channel.lastBank.messageData[1] = targetBank;
|
|
252
|
+
if (channel?.lastBankLSB?.messageData)
|
|
253
|
+
{
|
|
254
|
+
channel.lastBankLSB.messageData[1] = targetBank;
|
|
255
|
+
}
|
|
255
256
|
SpessaSynthInfo(
|
|
256
257
|
`%cNo preset %c${bank}:${e.messageData[0]}%c. Changing bank to ${targetBank}.`,
|
|
257
258
|
consoleColors.info,
|
|
@@ -265,6 +266,10 @@ export function writeRMIDI(
|
|
|
265
266
|
let drumBank = system === "xg" ? 127 : 0;
|
|
266
267
|
const newBank = (bank === 128 ? drumBank : realBank) + bankOffset;
|
|
267
268
|
channel.lastBank.messageData[1] = newBank;
|
|
269
|
+
if (channel?.lastBankLSB?.messageData)
|
|
270
|
+
{
|
|
271
|
+
channel.lastBankLSB.messageData[1] = channel.lastBankLSB.messageData[1] - mid.bankOffset + bankOffset;
|
|
272
|
+
}
|
|
268
273
|
SpessaSynthInfo(
|
|
269
274
|
`%cPreset %c${bank}:${e.messageData[0]}%c exists. Changing bank to ${newBank}.`,
|
|
270
275
|
consoleColors.info,
|
|
@@ -274,19 +279,45 @@ export function writeRMIDI(
|
|
|
274
279
|
}
|
|
275
280
|
continue;
|
|
276
281
|
}
|
|
277
|
-
|
|
278
|
-
|
|
282
|
+
|
|
283
|
+
// controller change
|
|
284
|
+
// we only care about bank-selects
|
|
285
|
+
const isLSB = e.messageData[0] === midiControllers.lsbForControl0BankSelect;
|
|
286
|
+
if (e.messageData[0] !== midiControllers.bankSelect && !isLSB)
|
|
279
287
|
{
|
|
280
288
|
continue;
|
|
281
289
|
}
|
|
282
290
|
// bank select
|
|
283
291
|
channel.hasBankSelect = true;
|
|
284
|
-
|
|
292
|
+
const bankNumber = e.messageData[1];
|
|
293
|
+
// interpret
|
|
294
|
+
const intepretation = parseBankSelect(
|
|
295
|
+
channel?.lastBank?.messageData[1] || 0,
|
|
296
|
+
bankNumber,
|
|
297
|
+
system,
|
|
298
|
+
isLSB,
|
|
299
|
+
channel.drums,
|
|
300
|
+
chNum
|
|
301
|
+
);
|
|
302
|
+
if (intepretation.drumsStatus === 2)
|
|
285
303
|
{
|
|
286
|
-
|
|
287
|
-
|
|
304
|
+
channel.drums = true;
|
|
305
|
+
}
|
|
306
|
+
else if (intepretation.drumsStatus === 1)
|
|
307
|
+
{
|
|
308
|
+
channel.drums = false;
|
|
309
|
+
}
|
|
310
|
+
if (bankNumber === intepretation.newBank || channel.drums)
|
|
311
|
+
{
|
|
312
|
+
if (isLSB)
|
|
313
|
+
{
|
|
314
|
+
channel.lastBankLSB = e;
|
|
315
|
+
}
|
|
316
|
+
else
|
|
317
|
+
{
|
|
318
|
+
channel.lastBank = e;
|
|
319
|
+
}
|
|
288
320
|
}
|
|
289
|
-
channel.lastBank = e;
|
|
290
321
|
}
|
|
291
322
|
|
|
292
323
|
// add missing bank selects
|
|
@@ -2,6 +2,8 @@ import { SpessaSynthGroupCollapsed, SpessaSynthGroupEnd, SpessaSynthInfo } from
|
|
|
2
2
|
import { consoleColors } from "../utils/other.js";
|
|
3
3
|
import { messageTypes, midiControllers } from "./midi_message.js";
|
|
4
4
|
import { DEFAULT_PERCUSSION } from "../synthetizer/synth_constants.js";
|
|
5
|
+
import { chooseBank, parseBankSelect } from "../utils/xg_hacks.js";
|
|
6
|
+
import { isGSDrumsOn, isXGOn } from "../utils/sysex_detector.js";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Gets the used programs and keys for this MIDI file with a given sound bank
|
|
@@ -19,7 +21,7 @@ export function getUsedProgramsAndKeys(soundfont)
|
|
|
19
21
|
// Find every bank:program combo and every key:velocity for each. Make sure to care about ports and drums
|
|
20
22
|
const channelsAmount = 16 + mid.midiPortChannelOffsets.reduce((max, cur) => cur > max ? cur : max);
|
|
21
23
|
/**
|
|
22
|
-
* @type {{program: number, bank: number, drums: boolean, string: string}[]}
|
|
24
|
+
* @type {{program: number, bank: number, bankLSB: number, drums: boolean, string: string}[]}
|
|
23
25
|
*/
|
|
24
26
|
const channelPresets = [];
|
|
25
27
|
for (let i = 0; i < channelsAmount; i++)
|
|
@@ -28,6 +30,7 @@ export function getUsedProgramsAndKeys(soundfont)
|
|
|
28
30
|
channelPresets.push({
|
|
29
31
|
program: 0,
|
|
30
32
|
bank: bank,
|
|
33
|
+
bankLSB: 0,
|
|
31
34
|
drums: i % 16 === DEFAULT_PERCUSSION, // drums appear on 9 every 16 channels,
|
|
32
35
|
string: `${bank}:0`
|
|
33
36
|
});
|
|
@@ -35,9 +38,11 @@ export function getUsedProgramsAndKeys(soundfont)
|
|
|
35
38
|
|
|
36
39
|
function updateString(ch)
|
|
37
40
|
{
|
|
41
|
+
const bank = chooseBank(ch.bank, ch.bankLSB);
|
|
38
42
|
// check if this exists in the soundfont
|
|
39
|
-
let exists = soundfont.getPreset(
|
|
43
|
+
let exists = soundfont.getPreset(bank, ch.program);
|
|
40
44
|
ch.bank = exists.bank;
|
|
45
|
+
ch.bankLSB = 0;
|
|
41
46
|
ch.program = exists.program;
|
|
42
47
|
ch.string = ch.bank + ":" + ch.program;
|
|
43
48
|
if (!usedProgramsAndKeys[ch.string])
|
|
@@ -124,7 +129,8 @@ export function getUsedProgramsAndKeys(soundfont)
|
|
|
124
129
|
break;
|
|
125
130
|
|
|
126
131
|
case messageTypes.controllerChange:
|
|
127
|
-
|
|
132
|
+
const isLSB = event.messageData[0] === midiControllers.lsbForControl0BankSelect;
|
|
133
|
+
if (event.messageData[0] !== midiControllers.bankSelect && !isLSB)
|
|
128
134
|
{
|
|
129
135
|
// we only care about bank select
|
|
130
136
|
continue;
|
|
@@ -136,24 +142,46 @@ export function getUsedProgramsAndKeys(soundfont)
|
|
|
136
142
|
}
|
|
137
143
|
const bank = event.messageData[1];
|
|
138
144
|
const realBank = Math.max(0, bank - mid.bankOffset);
|
|
139
|
-
|
|
145
|
+
// interpret the bank
|
|
146
|
+
const intepretation = parseBankSelect(
|
|
147
|
+
ch.bank,
|
|
148
|
+
realBank,
|
|
149
|
+
system,
|
|
150
|
+
isLSB,
|
|
151
|
+
ch.drums,
|
|
152
|
+
channel
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
switch (intepretation.drumsStatus)
|
|
140
156
|
{
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
case 0:
|
|
158
|
+
// no change
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
case 1:
|
|
162
|
+
// drums changed to off
|
|
145
163
|
// drum change is a program change
|
|
146
|
-
ch.drums =
|
|
147
|
-
ch.bank =
|
|
164
|
+
ch.drums = false;
|
|
165
|
+
ch.bank = realBank;
|
|
148
166
|
updateString(ch);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
167
|
+
break;
|
|
168
|
+
|
|
169
|
+
case 2:
|
|
170
|
+
// drums changed to on
|
|
171
|
+
// drum change is a program change
|
|
172
|
+
ch.drums = true;
|
|
173
|
+
ch.bank = 128;
|
|
174
|
+
updateString(ch);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (isLSB)
|
|
178
|
+
{
|
|
179
|
+
ch.bankLSB = intepretation.newBank;
|
|
180
|
+
}
|
|
181
|
+
else
|
|
182
|
+
{
|
|
183
|
+
ch.bank = ch.drums ? 128 : intepretation.newBank;
|
|
155
184
|
}
|
|
156
|
-
channelPresets[channel].bank = realBank;
|
|
157
185
|
// do not update the data, bank change doesn't change the preset
|
|
158
186
|
break;
|
|
159
187
|
|
|
@@ -169,23 +197,10 @@ export function getUsedProgramsAndKeys(soundfont)
|
|
|
169
197
|
|
|
170
198
|
case messageTypes.systemExclusive:
|
|
171
199
|
// check for drum sysex
|
|
172
|
-
if (
|
|
173
|
-
event.messageData[0] !== 0x41 || // roland
|
|
174
|
-
event.messageData[2] !== 0x42 || // GS
|
|
175
|
-
event.messageData[3] !== 0x12 || // GS
|
|
176
|
-
event.messageData[4] !== 0x40 || // system parameter
|
|
177
|
-
(event.messageData[5] & 0x10) === 0 || // part parameter
|
|
178
|
-
event.messageData[6] !== 0x15 // drum pars
|
|
179
|
-
|
|
180
|
-
)
|
|
200
|
+
if (!isGSDrumsOn(event))
|
|
181
201
|
{
|
|
182
202
|
// check for XG
|
|
183
|
-
if (
|
|
184
|
-
event.messageData[0] === 0x43 && // yamaha
|
|
185
|
-
event.messageData[2] === 0x4C && // sXG ON
|
|
186
|
-
event.messageData[5] === 0x7E &&
|
|
187
|
-
event.messageData[6] === 0x00
|
|
188
|
-
)
|
|
203
|
+
if (isXGOn(event))
|
|
189
204
|
{
|
|
190
205
|
system = "xg";
|
|
191
206
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spessasynth_lib",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.25.1",
|
|
4
4
|
"description": "MIDI and SoundFont2/DLS library with no compromises",
|
|
5
5
|
"browser": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"email": "spesekspesek@gmail.com",
|
|
35
35
|
"url": "https://github.com/spessasus"
|
|
36
36
|
},
|
|
37
|
-
"license": "
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://github.com/spessasus/SpessaSynth/issues",
|
|
40
40
|
"email": "spesekspesek@gmail.com"
|
package/sequencer/sequencer.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { MIDI } from "../midi_parser/midi_loader.js";
|
|
2
1
|
import { Synthetizer } from "../synthetizer/synthetizer.js";
|
|
3
2
|
import { messageTypes } from "../midi_parser/midi_message.js";
|
|
4
3
|
import { workletMessageType } from "../synthetizer/worklet_system/message_protocol/worklet_message.js";
|