audio-mixer-engine 0.9.2 → 0.9.3

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.
@@ -1,15 +1,15 @@
1
- function u(a) {
2
- return { all: a = a || /* @__PURE__ */ new Map(), on: function(l, U) {
3
- var F = a.get(l);
4
- F ? F.push(U) : a.set(l, [U]);
1
+ function u(t) {
2
+ return { all: t = t || /* @__PURE__ */ new Map(), on: function(l, U) {
3
+ var F = t.get(l);
4
+ F ? F.push(U) : t.set(l, [U]);
5
5
  }, off: function(l, U) {
6
- var F = a.get(l);
7
- F && (U ? F.splice(F.indexOf(U) >>> 0, 1) : a.set(l, []));
6
+ var F = t.get(l);
7
+ F && (U ? F.splice(F.indexOf(U) >>> 0, 1) : t.set(l, []));
8
8
  }, emit: function(l, U) {
9
- var F = a.get(l);
9
+ var F = t.get(l);
10
10
  F && F.slice().map(function(Z) {
11
11
  Z(U);
12
- }), (F = a.get("*")) && F.slice().map(function(Z) {
12
+ }), (F = t.get("*")) && F.slice().map(function(Z) {
13
13
  Z(l, U);
14
14
  });
15
15
  } };
@@ -514,7 +514,7 @@ const e = {
514
514
  helicopter: 125,
515
515
  applause: 126,
516
516
  gunshot: 127
517
- }, p = Object.entries(e).reduce((a, [l, U]) => (a[U] = l, a), {});
517
+ }, p = Object.entries(e).reduce((t, [l, U]) => (t[U] = l, t), {});
518
518
  class i {
519
519
  /**
520
520
  * Map common instrument names to MIDI program numbers
@@ -1548,8 +1548,8 @@ class M {
1548
1548
  let m;
1549
1549
  m = R + U * 4 * V.numerator / V.denominator;
1550
1550
  const b = V.numerator, n = [], c = U * (4 / V.denominator);
1551
- for (let t = 0; t < b; t++) {
1552
- const B = R + t * c, G = this._ticksToTime(B, l);
1551
+ for (let a = 0; a < b; a++) {
1552
+ const B = R + a * c, G = this._ticksToTime(B, l);
1553
1553
  n.push(G);
1554
1554
  }
1555
1555
  Q.push({
@@ -1647,13 +1647,13 @@ class M {
1647
1647
  velocity: n.velocity
1648
1648
  };
1649
1649
  else if (n.type === "noteOff" && b[n.noteNumber]) {
1650
- const c = b[n.noteNumber], t = n.tick - c.tick;
1650
+ const c = b[n.noteNumber], a = n.tick - c.tick;
1651
1651
  Z.push({
1652
1652
  pitch: n.noteNumber,
1653
1653
  name: this._midiNoteToName(n.noteNumber),
1654
1654
  startTick: c.tick,
1655
1655
  endTick: n.tick,
1656
- duration: t,
1656
+ duration: a,
1657
1657
  startTime: this._ticksToTime(c.tick, U),
1658
1658
  endTime: this._ticksToTime(n.tick, U),
1659
1659
  velocity: c.velocity,
@@ -1952,7 +1952,7 @@ class z {
1952
1952
  const m = Z[W];
1953
1953
  let b = V[Q], n = b.sig[0];
1954
1954
  for (; n < m && Q + 1 < V.length; ) {
1955
- const c = V[Q + 1], t = [
1955
+ const c = V[Q + 1], a = [
1956
1956
  b.sig[0] + c.sig[0],
1957
1957
  // Total beats
1958
1958
  b.sig[1]
@@ -1962,16 +1962,16 @@ class z {
1962
1962
  ...c.beats || []
1963
1963
  ];
1964
1964
  b = {
1965
- sig: t,
1965
+ sig: a,
1966
1966
  beats: B
1967
- }, V[Q] = b, V.splice(Q + 1, 1), n = t[0];
1967
+ }, V[Q] = b, V.splice(Q + 1, 1), n = a[0];
1968
1968
  }
1969
1969
  if (n > m) {
1970
- const c = m, t = n - m, B = b.beats ? b.beats.slice(0, c) : [], G = b.beats ? b.beats.slice(c) : [], h = {
1970
+ const c = m, a = n - m, B = b.beats ? b.beats.slice(0, c) : [], G = b.beats ? b.beats.slice(c) : [], h = {
1971
1971
  sig: [c, b.sig[1]],
1972
1972
  beats: B
1973
1973
  }, J = {
1974
- sig: [t, b.sig[1]],
1974
+ sig: [a, b.sig[1]],
1975
1975
  beats: G
1976
1976
  };
1977
1977
  V[Q] = h, V.splice(Q + 1, 0, J), b = h;
@@ -1989,13 +1989,13 @@ class z {
1989
1989
  for (; d < l.length; ) {
1990
1990
  const b = l[d], n = b.barNumber, c = Z[n] !== void 0 ? Z[n] : 4;
1991
1991
  Z[n] === void 0 && (Z[n] = c);
1992
- const t = [];
1992
+ const a = [];
1993
1993
  for (let G = 0; G < c; G++)
1994
- t.push(m), m += W;
1994
+ a.push(m), m += W;
1995
1995
  const B = {
1996
1996
  sig: [c, 4],
1997
1997
  // Default to quarter notes
1998
- beats: t
1998
+ beats: a
1999
1999
  };
2000
2000
  this._generateBeatsForBar(F, b, B, c), d++;
2001
2001
  }
@@ -2905,11 +2905,12 @@ class K {
2905
2905
  console.warn("Metronome output not available - master gain not created");
2906
2906
  return;
2907
2907
  }
2908
+ const U = this.audioEngine.getMetronomeAnalyser();
2908
2909
  try {
2909
2910
  l.disconnect();
2910
2911
  } catch {
2911
2912
  }
2912
- this.metronomeMasterGain = this.audioEngine.audioContext.createGain(), this.metronomeMasterGain.gain.value = 1, l.connect(this.metronomeMasterGain), console.log("Metronome master gain node created and connected");
2913
+ this.metronomeMasterGain = this.audioEngine.audioContext.createGain(), this.metronomeMasterGain.gain.value = 1, l.connect(this.metronomeMasterGain), U ? (l.connect(U), console.log("Metronome master gain node created and connected (analyser reconnected)")) : console.log("Metronome master gain node created and connected (no analyser)");
2913
2914
  }
2914
2915
  /**
2915
2916
  * Set up silent calibration (set gain to 0 for inaudible measurement)
@@ -3560,11 +3561,11 @@ class K {
3560
3561
  Z
3561
3562
  );
3562
3563
  if (c) {
3563
- const t = c.latencyMs;
3564
- V.push(t), console.log(`Measurement ${b + 1}/${l}: ${t.toFixed(1)}ms (RMS: ${c.rms.toFixed(4)}, peak: ${c.peak.toFixed(4)})`);
3564
+ const a = c.latencyMs;
3565
+ V.push(a), console.log(`Measurement ${b + 1}/${l}: ${a.toFixed(1)}ms (RMS: ${c.rms.toFixed(4)}, peak: ${c.peak.toFixed(4)})`);
3565
3566
  } else
3566
3567
  console.warn(`Measurement ${b + 1}/${l}: detection timeout (no signal above ${F} threshold)`);
3567
- await new Promise((t) => setTimeout(t, 300));
3568
+ await new Promise((a) => setTimeout(a, 300));
3568
3569
  }
3569
3570
  if (V.length === 0)
3570
3571
  throw new Error(`Failed to detect any metronome onsets. Try lowering threshold (current: ${F}) or check audio routing.`);
@@ -3605,12 +3606,12 @@ class K {
3605
3606
  return;
3606
3607
  }
3607
3608
  l.getFloatTimeDomainData(R);
3608
- let t = 0, B = 0;
3609
+ let a = 0, B = 0;
3609
3610
  for (let h = 0; h < V; h++) {
3610
3611
  const J = Math.abs(R[h]);
3611
- t += R[h] * R[h], J > B && (B = J);
3612
+ a += R[h] * R[h], J > B && (B = J);
3612
3613
  }
3613
- const G = Math.sqrt(t / V);
3614
+ const G = Math.sqrt(a / V);
3614
3615
  if (G >= Z) {
3615
3616
  clearInterval(n);
3616
3617
  const h = d.currentTime, J = (h - U) * 1e3;
@@ -3642,12 +3643,12 @@ class K {
3642
3643
  return;
3643
3644
  }
3644
3645
  l.getFloatTimeDomainData(V);
3645
- let t = 0, B = 0;
3646
+ let a = 0, B = 0;
3646
3647
  for (let J = 0; J < d; J++) {
3647
3648
  const N = Math.abs(V[J]);
3648
- t += V[J] * V[J], N > B && (B = N);
3649
+ a += V[J] * V[J], N > B && (B = N);
3649
3650
  }
3650
- const G = Math.sqrt(t / d), h = Q.currentTime;
3651
+ const G = Math.sqrt(a / d), h = Q.currentTime;
3651
3652
  R.push({
3652
3653
  time: h,
3653
3654
  relativeTime: (h - U) * 1e3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "audio-mixer-engine",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Audio engine library for audio mixer applications with MIDI parsing, playback, and synthesis",
5
5
  "main": "dist/audio-mixer-engine.cjs.js",
6
6
  "module": "dist/audio-mixer-engine.es.js",
@@ -843,6 +843,9 @@ export default class PlaybackManager {
843
843
  return;
844
844
  }
845
845
 
846
+ // Get analyser before disconnecting (we need to preserve this connection)
847
+ const analyser = this.audioEngine.getMetronomeAnalyser();
848
+
846
849
  // Disconnect metronome from destination (it auto-connects in base AudioEngine)
847
850
  // We need exclusive routing through the master gain for calibration control
848
851
  try {
@@ -858,7 +861,13 @@ export default class PlaybackManager {
858
861
  // Connect: audioEngine metronome output -> master gain (external code connects to this)
859
862
  metronomeOutput.connect(this.metronomeMasterGain);
860
863
 
861
- console.log('Metronome master gain node created and connected');
864
+ // Reconnect analyser for latency measurement (disconnect() removed this connection)
865
+ if (analyser) {
866
+ metronomeOutput.connect(analyser);
867
+ console.log('Metronome master gain node created and connected (analyser reconnected)');
868
+ } else {
869
+ console.log('Metronome master gain node created and connected (no analyser)');
870
+ }
862
871
  }
863
872
 
864
873
  /**