spessasynth_lib 3.20.12 → 3.20.16

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.
@@ -116,9 +116,9 @@ export class BasicMIDI {
116
116
  */
117
117
  tracks: MidiMessage[][];
118
118
  /**
119
- * Coverts ticks to time in seconds
120
- * @param ticks {number}
121
- * @returns {number}
119
+ * Converts ticks to time in seconds
120
+ * @param ticks {number} time in MIDI ticks
121
+ * @returns {number} time in seconds
122
122
  * @protected
123
123
  */
124
124
  protected _ticksToSeconds(ticks: number): number;
@@ -126,21 +126,29 @@ export class BasicMIDI
126
126
  }
127
127
 
128
128
  /**
129
- * Coverts ticks to time in seconds
130
- * @param ticks {number}
131
- * @returns {number}
129
+ * Converts ticks to time in seconds
130
+ * @param ticks {number} time in MIDI ticks
131
+ * @returns {number} time in seconds
132
132
  * @protected
133
133
  */
134
- _ticksToSeconds(ticks)
135
- {
136
- if (ticks <= 0) {
137
- return 0;
134
+ _ticksToSeconds(ticks) {
135
+ let totalSeconds = 0;
136
+
137
+ while (ticks > 0)
138
+ {
139
+ // tempo changes are reversed so the first element is the last tempo change and the last element is the first tempo change
140
+ // (always at tick 0 and tempo 120)
141
+ // find the last tempo change that has occurred
142
+ let tempo = this.tempoChanges.find(v => v.ticks < ticks);
143
+
144
+ // calculate the difference and tempo time
145
+ let timeSinceLastTempo = ticks - tempo.ticks;
146
+ totalSeconds += (timeSinceLastTempo * 60) / (tempo.tempo * this.timeDivision);
147
+ ticks -= timeSinceLastTempo;
138
148
  }
139
149
 
140
- // find the last tempo change that has occured
141
- let tempo = this.tempoChanges.find(v => v.ticks < ticks);
142
-
143
- let timeSinceLastTempo = ticks - tempo.ticks;
144
- return this._ticksToSeconds(ticks - timeSinceLastTempo) + (timeSinceLastTempo * 60) / (tempo.tempo * this.timeDivision);
150
+ return totalSeconds;
145
151
  }
152
+
153
+
146
154
  }
@@ -427,6 +427,12 @@ class MIDI extends BasicMIDI
427
427
  consoleColors.value);
428
428
  }
429
429
 
430
+ SpessaSynthInfo(`%cAll tracks parsed correctly!`,
431
+ consoleColors.recognized);
432
+
433
+ SpessaSynthGroupCollapsed(`%cCorrecting loops, ports and detecting notes...`,
434
+ consoleColors.info)
435
+
430
436
  const firstNoteOns = [];
431
437
  for(const t of this.tracks)
432
438
  {
@@ -438,10 +444,12 @@ class MIDI extends BasicMIDI
438
444
  }
439
445
  this.firstNoteOn = Math.min(...firstNoteOns);
440
446
 
441
- SpessaSynthInfo(`%cMIDI file parsed. Total tick time: %c${this.lastVoiceEventTick}`,
447
+ SpessaSynthInfo(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,
442
448
  consoleColors.info,
443
- consoleColors.recognized);
444
- SpessaSynthGroupEnd();
449
+ consoleColors.recognized,
450
+ consoleColors.info);
451
+
452
+
445
453
 
446
454
  if(loopStart !== null && loopEnd === null)
447
455
  {
@@ -461,6 +469,18 @@ class MIDI extends BasicMIDI
461
469
  }
462
470
  }
463
471
 
472
+ /**
473
+ *
474
+ * @type {{start: number, end: number}}
475
+ */
476
+ this.loop = {start: loopStart, end: loopEnd};
477
+
478
+ SpessaSynthInfo(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,
479
+ consoleColors.info,
480
+ consoleColors.recognized,
481
+ consoleColors.info,
482
+ consoleColors.recognized);
483
+
464
484
  // fix midi ports:
465
485
  // midi tracks without ports will have a value of -1
466
486
  // if all ports have a value of -1, set it to 0, otherwise take the first midi port and replace all -1 with it
@@ -481,12 +501,14 @@ class MIDI extends BasicMIDI
481
501
  {
482
502
  this.midiPortChannelOffsets = [0];
483
503
  }
484
-
485
- /**
486
- *
487
- * @type {{start: number, end: number}}
488
- */
489
- this.loop = {start: loopStart, end: loopEnd};
504
+ if(this.midiPortChannelOffsets.length < 2)
505
+ {
506
+ SpessaSynthInfo(`%cNo additional MIDI Ports detected.`, consoleColors.info);
507
+ }
508
+ else
509
+ {
510
+ SpessaSynthInfo(`%cMIDI Ports detected!`, consoleColors.recognized);
511
+ }
490
512
 
491
513
  // midi name
492
514
  if(!nameDetected)
@@ -528,6 +550,8 @@ class MIDI extends BasicMIDI
528
550
  // if midiName is "", use the file name
529
551
  if(this.midiName.length === 0)
530
552
  {
553
+ SpessaSynthInfo(`%cNo name detected. Using the alt name!`,
554
+ consoleColors.info);
531
555
  this.midiName = formatTitle(fileName);
532
556
  // encode it too
533
557
  this.rawMidiName = new Uint8Array(this.midiName.length);
@@ -536,7 +560,12 @@ class MIDI extends BasicMIDI
536
560
  this.rawMidiName[i] = this.midiName.charCodeAt(i);
537
561
  }
538
562
  }
539
-
563
+ else
564
+ {
565
+ SpessaSynthInfo(`%cMIDI Name detected! %c"${this.midiName}"`,
566
+ consoleColors.info,
567
+ consoleColors.recognized)
568
+ }
540
569
  // reverse the tempo changes
541
570
  this.tempoChanges.reverse();
542
571
 
@@ -545,6 +574,14 @@ class MIDI extends BasicMIDI
545
574
  * @type {number}
546
575
  */
547
576
  this.duration = this._ticksToSeconds(this.lastVoiceEventTick);
577
+
578
+ SpessaSynthGroupEnd();
579
+ SpessaSynthInfo(`%cMIDI file parsed. Total tick time: %c${this.lastVoiceEventTick}%c, total seconds time: %c${this.duration}`,
580
+ consoleColors.info,
581
+ consoleColors.recognized,
582
+ consoleColors.info,
583
+ consoleColors.recognized);
584
+ SpessaSynthGroupEnd();
548
585
  }
549
586
 
550
587
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spessasynth_lib",
3
- "version": "3.20.12",
3
+ "version": "3.20.16",
4
4
  "description": "MIDI and SoundFont2 or DLS Synthesizer library with no compromises",
5
5
  "browser": "index.js",
6
6
  "types": "@types/index.d.ts",
@@ -79,11 +79,7 @@ export function readArticulation(chunk, disableVibrato)
79
79
  const scale = readLittleEndian(artData, 4) | 0;
80
80
  const value = scale >> 16; // convert it to 16 bit as soundfont uses that
81
81
 
82
- // if(destination === DLSDestinations.volEnvDecay)
83
- // {
84
- // console.log(scale, value)
85
- // }
86
- //modulatorConverterDebug(source, control, destination, value, transform);
82
+ // modulatorConverterDebug(source, control, destination, value, transform);
87
83
  // interpret this somehow...
88
84
  // if source and control are both zero, it's a generator
89
85
  if(source === 0 && control === 0 && transform === 0)
@@ -138,7 +138,7 @@ generatorLimits[generatorTypes.startloopAddrsCoarseOffset] = {min: -32768, max:
138
138
  generatorLimits[generatorTypes.keyNum] = {min: -1, max: 127, def: -1};
139
139
  generatorLimits[generatorTypes.velocity] = {min: -1, max: 127, def: -1};
140
140
 
141
- generatorLimits[generatorTypes.initialAttenuation] = {min: -250, max: 1440, def: 0}; // soundblaster allows 10dB of gain (divide by 0.4)
141
+ generatorLimits[generatorTypes.initialAttenuation] = {min: 0, max: 1440, def: 0}; // soundblaster allows 10dB of gain (divide by 0.4)
142
142
 
143
143
  generatorLimits[generatorTypes.endloopAddrsCoarseOffset] = {min: -32768, max: 32768, def: 0};
144
144