spessasynth_core 3.26.16 → 3.26.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_core",
3
- "version": "3.26.16",
3
+ "version": "3.26.17",
4
4
  "description": "MIDI and SoundFont2/DLS library with no compromises",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -32,18 +32,6 @@ export class Modulator
32
32
  */
33
33
  currentValue = 0;
34
34
 
35
- /**
36
- * The source enumeration for this modulator
37
- * @type {number}
38
- */
39
- sourceEnum;
40
-
41
- /**
42
- * The secondary source enumeration for this modulator
43
- * @type {number}
44
- */
45
- secondarySourceEnum;
46
-
47
35
  /**
48
36
  * The generator destination of this modulator
49
37
  * @type {generatorTypes}
@@ -72,9 +60,9 @@ export class Modulator
72
60
  */
73
61
  constructor(srcEnum, secSrcEnum, destination, amount, transformType)
74
62
  {
75
- this.sourceEnum = srcEnum;
63
+ const sourceEnum = srcEnum;
76
64
  this.modulatorDestination = destination;
77
- this.secondarySourceEnum = secSrcEnum;
65
+ const secondarySourceEnum = secSrcEnum;
78
66
  this.transformAmount = amount;
79
67
  this.transformType = transformType;
80
68
 
@@ -85,18 +73,18 @@ export class Modulator
85
73
  }
86
74
 
87
75
  // decode the source
88
- this.sourcePolarity = this.sourceEnum >> 9 & 1;
89
- this.sourceDirection = this.sourceEnum >> 8 & 1;
90
- this.sourceUsesCC = this.sourceEnum >> 7 & 1;
91
- this.sourceIndex = this.sourceEnum & 127;
92
- this.sourceCurveType = this.sourceEnum >> 10 & 3;
76
+ this.sourcePolarity = sourceEnum >> 9 & 1;
77
+ this.sourceDirection = sourceEnum >> 8 & 1;
78
+ this.sourceUsesCC = sourceEnum >> 7 & 1;
79
+ this.sourceIndex = sourceEnum & 127;
80
+ this.sourceCurveType = sourceEnum >> 10 & 3;
93
81
 
94
82
  // decode the secondary source
95
- this.secSrcPolarity = this.secondarySourceEnum >> 9 & 1;
96
- this.secSrcDirection = this.secondarySourceEnum >> 8 & 1;
97
- this.secSrcUsesCC = this.secondarySourceEnum >> 7 & 1;
98
- this.secSrcIndex = this.secondarySourceEnum & 127;
99
- this.secSrcCurveType = this.secondarySourceEnum >> 10 & 3;
83
+ this.secSrcPolarity = secondarySourceEnum >> 9 & 1;
84
+ this.secSrcDirection = secondarySourceEnum >> 8 & 1;
85
+ this.secSrcUsesCC = secondarySourceEnum >> 7 & 1;
86
+ this.secSrcIndex = secondarySourceEnum & 127;
87
+ this.secSrcCurveType = secondarySourceEnum >> 10 & 3;
100
88
 
101
89
  /**
102
90
  * Indicates if the given modulator is chorus or reverb effects modulator.
@@ -111,10 +99,10 @@ export class Modulator
111
99
  */
112
100
  this.isEffectModulator =
113
101
  (
114
- this.sourceEnum === 0x00DB
115
- || this.sourceEnum === 0x00DD
102
+ sourceEnum === 0x00DB
103
+ || sourceEnum === 0x00DD
116
104
  )
117
- && this.secondarySourceEnum === 0x0
105
+ && secondarySourceEnum === 0x0
118
106
  && (
119
107
  this.modulatorDestination === generatorTypes.reverbEffectsSend
120
108
  || this.modulatorDestination === generatorTypes.chorusEffectsSend
@@ -128,8 +116,8 @@ export class Modulator
128
116
  static copy(modulator)
129
117
  {
130
118
  return new Modulator(
131
- modulator.sourceEnum,
132
- modulator.secondarySourceEnum,
119
+ modulator.getSourceEnum(),
120
+ modulator.getSecSrcEnum(),
133
121
  modulator.modulatorDestination,
134
122
  modulator.transformAmount,
135
123
  modulator.transformType
@@ -144,9 +132,19 @@ export class Modulator
144
132
  */
145
133
  static isIdentical(mod1, mod2, checkAmount = false)
146
134
  {
147
- return (mod1.sourceEnum === mod2.sourceEnum)
135
+ return (mod1.sourceIndex === mod2.sourceIndex)
136
+ && (mod1.sourceUsesCC === mod2.sourceUsesCC)
137
+ && (mod1.sourcePolarity === mod2.sourcePolarity)
138
+ && (mod1.sourceDirection === mod2.sourceDirection)
139
+ && (mod1.sourceCurveType === mod2.sourceCurveType)
140
+
141
+ && (mod1.secSrcIndex === mod2.secSrcIndex)
142
+ && (mod1.secSrcUsesCC === mod2.secSrcUsesCC)
143
+ && (mod1.secSrcPolarity === mod2.secSrcPolarity)
144
+ && (mod1.secSrcDirection === mod2.secSrcDirection)
145
+ && (mod1.secSrcCurveType === mod2.secSrcCurveType)
146
+
148
147
  && (mod1.modulatorDestination === mod2.modulatorDestination)
149
- && (mod1.secondarySourceEnum === mod2.secondarySourceEnum)
150
148
  && (mod1.transformType === mod2.transformType)
151
149
  && (!checkAmount || (mod1.transformAmount === mod2.transformAmount));
152
150
  }
@@ -194,6 +192,28 @@ export class Modulator
194
192
  \n\n`;
195
193
  }
196
194
 
195
+ getSourceEnum()
196
+ {
197
+ return getModSourceEnum(
198
+ this.sourceCurveType,
199
+ this.sourcePolarity,
200
+ this.sourceDirection,
201
+ this.sourceUsesCC,
202
+ this.sourceIndex
203
+ );
204
+ }
205
+
206
+ getSecSrcEnum()
207
+ {
208
+ return getModSourceEnum(
209
+ this.secSrcCurveType,
210
+ this.secSrcPolarity,
211
+ this.secSrcDirection,
212
+ this.secSrcUsesCC,
213
+ this.secSrcIndex
214
+ );
215
+ }
216
+
197
217
  /**
198
218
  * Sum transform and create a NEW modulator
199
219
  * @param modulator {Modulator}
@@ -202,8 +222,8 @@ export class Modulator
202
222
  sumTransform(modulator)
203
223
  {
204
224
  return new Modulator(
205
- this.sourceEnum,
206
- this.secondarySourceEnum,
225
+ this.getSourceEnum(),
226
+ this.getSecSrcEnum(),
207
227
  this.modulatorDestination,
208
228
  this.transformAmount + modulator.transformAmount,
209
229
  this.transformType
@@ -16,8 +16,16 @@ export function getIBAG()
16
16
  let modulatorIndex = 0;
17
17
  for (const inst of this.instruments)
18
18
  {
19
+ // ensure that the first zone is global
20
+ const zones = inst.instrumentZones.filter(z => !z.isGlobal);
21
+ const global = inst.instrumentZones.filter(z => z.isGlobal);
22
+ // only take the first one
23
+ if (global?.[0])
24
+ {
25
+ zones.unshift(global?.[0]);
26
+ }
19
27
  inst.instrumentZoneIndex = zoneID;
20
- for (const ibag of inst.instrumentZones)
28
+ for (const ibag of zones)
21
29
  {
22
30
  ibag.zoneID = zoneID;
23
31
  writeWord(ibagdata, generatorIndex);
@@ -24,7 +24,7 @@ export function getIGEN()
24
24
  );
25
25
  // add sample and ranges if necessary
26
26
  // unshift vel then key (to make key first) and the instrument is last
27
- if (z.velRange.max !== 127 || z.velRange.min !== 0)
27
+ if (z.hasVelRange)
28
28
  {
29
29
  z.generators.unshift(new Generator(
30
30
  generatorTypes.velRange,
@@ -32,7 +32,7 @@ export function getIGEN()
32
32
  false
33
33
  ));
34
34
  }
35
- if (z.keyRange.max !== 127 || z.keyRange.min !== 0)
35
+ if (z.hasKeyRange)
36
36
  {
37
37
  z.generators.unshift(new Generator(
38
38
  generatorTypes.keyRange,
@@ -25,10 +25,10 @@ export function getIMOD()
25
25
  ibag.modulatorZoneStartIndex = imodIndex;
26
26
  for (const mod of ibag.modulators)
27
27
  {
28
- writeWord(imoddata, mod.sourceEnum);
28
+ writeWord(imoddata, mod.getSourceEnum());
29
29
  writeWord(imoddata, mod.modulatorDestination);
30
30
  writeWord(imoddata, mod.transformAmount);
31
- writeWord(imoddata, mod.secondarySourceEnum);
31
+ writeWord(imoddata, mod.getSecSrcEnum());
32
32
  writeWord(imoddata, mod.transformType);
33
33
  imodIndex++;
34
34
  }
@@ -16,8 +16,16 @@ export function getPBAG()
16
16
  let modulatorIndex = 0;
17
17
  for (const preset of this.presets)
18
18
  {
19
+ // ensure that the first zone is global
20
+ const zones = preset.presetZones.filter(z => !z.isGlobal);
21
+ const global = preset.presetZones.filter(z => z.isGlobal);
22
+ // only take the first one
23
+ if (global?.[0])
24
+ {
25
+ zones.unshift(global?.[0]);
26
+ }
19
27
  preset.presetZoneStartIndex = zoneID;
20
- for (const pbag of preset.presetZones)
28
+ for (const pbag of zones)
21
29
  {
22
30
  pbag.zoneID = zoneID;
23
31
  writeWord(pbagdata, generatorIndex);
@@ -24,7 +24,7 @@ export function getPGEN()
24
24
  g.generatorType !== generatorTypes.velRange
25
25
  );
26
26
  // unshift vel then key and instrument is last
27
- if (z.velRange.max !== 127 || z.velRange.min !== 0)
27
+ if (z.hasVelRange)
28
28
  {
29
29
  z.generators.unshift(new Generator(
30
30
  generatorTypes.velRange,
@@ -32,7 +32,7 @@ export function getPGEN()
32
32
  false
33
33
  ));
34
34
  }
35
- if (z.keyRange.max !== 127 || z.keyRange.min !== 0)
35
+ if (z.hasKeyRange)
36
36
  {
37
37
  z.generators.unshift(new Generator(
38
38
  generatorTypes.keyRange,
@@ -25,10 +25,10 @@ export function getPMOD()
25
25
  pbag.modulatorZoneStartIndex = pmodIndex;
26
26
  for (const mod of pbag.modulators)
27
27
  {
28
- writeWord(pmoddata, mod.sourceEnum);
28
+ writeWord(pmoddata, mod.getSourceEnum());
29
29
  writeWord(pmoddata, mod.modulatorDestination);
30
30
  writeWord(pmoddata, mod.transformAmount);
31
- writeWord(pmoddata, mod.secondarySourceEnum);
31
+ writeWord(pmoddata, mod.getSecSrcEnum());
32
32
  writeWord(pmoddata, mod.transformType);
33
33
  pmodIndex++;
34
34
  }
@@ -112,10 +112,10 @@ export function write(options = DEFAULT_WRITE_OPTIONS)
112
112
  const dmoddata = new IndexedByteArray(dmodsize);
113
113
  for (const mod of mods)
114
114
  {
115
- writeWord(dmoddata, mod.sourceEnum);
115
+ writeWord(dmoddata, mod.getSourceEnum());
116
116
  writeWord(dmoddata, mod.modulatorDestination);
117
117
  writeWord(dmoddata, mod.transformAmount);
118
- writeWord(dmoddata, mod.secondarySourceEnum);
118
+ writeWord(dmoddata, mod.getSecSrcEnum());
119
119
  writeWord(dmoddata, mod.transformType);
120
120
  }
121
121