midiwire 0.11.2 → 0.11.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.
@@ -675,7 +675,7 @@ class Z extends H {
675
675
  s ? E = [240, ...t, 247] : E = t, this.send(E);
676
676
  }
677
677
  }
678
- const C = {
678
+ const o = {
679
679
  // Core controller events
680
680
  READY: "ready",
681
681
  ERROR: "error",
@@ -806,23 +806,23 @@ class z extends H {
806
806
  }), await this.connection.requestAccess(), this.connection.on(U.DEVICE_CHANGE, async ({ state: t, type: s, device: E }) => {
807
807
  try {
808
808
  if (t === "connected")
809
- s === "output" ? this.emit(C.DEV_OUT_CONNECTED, E) : s === "input" && this.emit(C.DEV_IN_CONNECTED, E);
809
+ s === "output" ? this.emit(o.DEV_OUT_CONNECTED, E) : s === "input" && this.emit(o.DEV_IN_CONNECTED, E);
810
810
  else if (t === "disconnected") {
811
811
  if (s === "output" && E) {
812
812
  const e = this.connection.getCurrentOutput();
813
- e && e.id === E.id ? await this._disconnectOutput() : this.emit(C.DEV_OUT_DISCONNECTED, E);
813
+ e && e.id === E.id ? await this._disconnectOutput() : this.emit(o.DEV_OUT_DISCONNECTED, E);
814
814
  }
815
815
  if (s === "input" && E) {
816
816
  const e = this.connection.getCurrentInput();
817
- e && e.id === E.id ? await this._disconnectInput() : this.emit(C.DEV_IN_DISCONNECTED, E);
817
+ e && e.id === E.id ? await this._disconnectInput() : this.emit(o.DEV_IN_DISCONNECTED, E);
818
818
  }
819
819
  }
820
820
  } catch (e) {
821
- console.error("Error in device change handler:", e), this.emit(C.ERROR, e);
821
+ console.error("Error in device change handler:", e), this.emit(o.ERROR, e);
822
822
  }
823
- }), this.options.autoConnect && await this.connection.connect(this.options.output), this.options.input !== void 0 && await this._connectInput(this.options.input), this.initialized = !0, this.emit(C.READY, this), this.options.onReady?.(this);
823
+ }), this.options.autoConnect && await this.connection.connect(this.options.output), this.options.input !== void 0 && await this._connectInput(this.options.input), this.initialized = !0, this.emit(o.READY, this), this.options.onReady?.(this);
824
824
  } catch (t) {
825
- throw this.emit(C.ERROR, t), this.options.onError?.(t), t;
825
+ throw this.emit(o.ERROR, t), this.options.onError?.(t), t;
826
826
  }
827
827
  }
828
828
  /**
@@ -1351,7 +1351,7 @@ class z extends H {
1351
1351
  }
1352
1352
  };
1353
1353
  }
1354
- const { cc: a } = s, o = (d) => {
1354
+ const { cc: a } = s, C = (d) => {
1355
1355
  const T = parseFloat(d.target.value);
1356
1356
  if (Number.isNaN(T)) return;
1357
1357
  const f = x(T, e, _, r), I = i === void 0 ? this.options.outputChannel : i;
@@ -1360,13 +1360,13 @@ class z extends H {
1360
1360
  let h = null;
1361
1361
  const N = S > 0 ? (d) => {
1362
1362
  h && clearTimeout(h), h = setTimeout(() => {
1363
- o(d), h = null;
1363
+ C(d), h = null;
1364
1364
  }, S);
1365
- } : o;
1365
+ } : C;
1366
1366
  return t.addEventListener("input", N), t.addEventListener("change", N), {
1367
1367
  element: t,
1368
1368
  config: P,
1369
- handler: o,
1369
+ handler: C,
1370
1370
  destroy: () => {
1371
1371
  h && clearTimeout(h), t.removeEventListener("input", N), t.removeEventListener("change", N);
1372
1372
  }
@@ -1387,7 +1387,7 @@ class z extends H {
1387
1387
  async destroy() {
1388
1388
  for (const t of this.bindings.values())
1389
1389
  t.destroy();
1390
- this.bindings.clear(), this.state.controlChange.clear(), this.state.programChange.clear(), this.state.pitchBend.clear(), this.state.monoPressure.clear(), this.state.polyPressure.clear(), await this._disconnect(), this.initialized = !1, this.emit(C.DESTROYED), this.removeAllListeners();
1390
+ this.bindings.clear(), this.state.controlChange.clear(), this.state.programChange.clear(), this.state.pitchBend.clear(), this.state.monoPressure.clear(), this.state.polyPressure.clear(), await this._disconnect(), this.initialized = !1, this.emit(o.DESTROYED), this.removeAllListeners();
1391
1391
  }
1392
1392
  /**
1393
1393
  * Connect to MIDI output device
@@ -1415,7 +1415,7 @@ class z extends H {
1415
1415
  async _connectInput(t) {
1416
1416
  await this.connection.connectInput(t, (s) => {
1417
1417
  this._handleMIDIMessage(s);
1418
- }), this.emit(C.DEV_IN_CONNECTED, this.connection.getCurrentInput());
1418
+ }), this.emit(o.DEV_IN_CONNECTED, this.connection.getCurrentInput());
1419
1419
  }
1420
1420
  /**
1421
1421
  * Disconnect from MIDI input device
@@ -1424,7 +1424,7 @@ class z extends H {
1424
1424
  */
1425
1425
  async _disconnectInput() {
1426
1426
  const t = this.connection.getCurrentInput();
1427
- this.connection.disconnectInput(), this.emit(C.DEV_IN_DISCONNECTED, t);
1427
+ this.connection.disconnectInput(), this.emit(o.DEV_IN_DISCONNECTED, t);
1428
1428
  }
1429
1429
  /**
1430
1430
  * Connect to MIDI output device
@@ -1433,7 +1433,7 @@ class z extends H {
1433
1433
  * @returns {Promise<void>}
1434
1434
  */
1435
1435
  async _connectOutput(t) {
1436
- await this.connection.connect(t), this.emit(C.DEV_OUT_CONNECTED, this.connection.getCurrentOutput());
1436
+ await this.connection.connect(t), this.emit(o.DEV_OUT_CONNECTED, this.connection.getCurrentOutput());
1437
1437
  }
1438
1438
  /**
1439
1439
  * Disconnect from MIDI output device
@@ -1442,7 +1442,7 @@ class z extends H {
1442
1442
  */
1443
1443
  async _disconnectOutput() {
1444
1444
  const t = this.connection.getCurrentOutput();
1445
- this.connection.disconnectOutput(), this.emit(C.DEV_OUT_DISCONNECTED, t);
1445
+ this.connection.disconnectOutput(), this.emit(o.DEV_OUT_DISCONNECTED, t);
1446
1446
  }
1447
1447
  /**
1448
1448
  * Get current output device information
@@ -1499,7 +1499,7 @@ class z extends H {
1499
1499
  if (!this.initialized) return;
1500
1500
  t = O(Math.round(t), 0, 127), s = O(Math.round(s), 0, 127), E = O(Math.round(E), 1, 16);
1501
1501
  const e = 144 + (E - 1);
1502
- this.connection.send([e, t, s]), this.emit(C.CH_NOTE_ON_SEND, { note: t, velocity: s, channel: E });
1502
+ this.connection.send([e, t, s]), this.emit(o.CH_NOTE_ON_SEND, { note: t, velocity: s, channel: E });
1503
1503
  }
1504
1504
  /**
1505
1505
  * Send Note Off message
@@ -1513,7 +1513,7 @@ class z extends H {
1513
1513
  if (!this.initialized) return;
1514
1514
  t = O(Math.round(t), 0, 127), E = O(Math.round(E), 0, 127), s = O(Math.round(s), 1, 16);
1515
1515
  const e = 144 + (s - 1);
1516
- this.connection.send([e, t, E]), this.emit(C.CH_NOTE_OFF_SEND, { note: t, channel: s, velocity: E });
1516
+ this.connection.send([e, t, E]), this.emit(o.CH_NOTE_OFF_SEND, { note: t, channel: s, velocity: E });
1517
1517
  }
1518
1518
  /**
1519
1519
  * Send Control Change message
@@ -1532,7 +1532,7 @@ class z extends H {
1532
1532
  const e = 176 + (E - 1);
1533
1533
  this.connection.send([e, t, s]);
1534
1534
  const _ = `${E}:${t}`;
1535
- this.state.controlChange.set(_, s), this.emit(C.CH_CC_SEND, { cc: t, value: s, channel: E });
1535
+ this.state.controlChange.set(_, s), this.emit(o.CH_CC_SEND, { cc: t, value: s, channel: E });
1536
1536
  }
1537
1537
  /**
1538
1538
  * Send Program Change message
@@ -1545,7 +1545,7 @@ class z extends H {
1545
1545
  if (!this.initialized) return;
1546
1546
  t = O(Math.round(t), 0, 127), s = O(Math.round(s), 1, 16);
1547
1547
  const E = 192 + (s - 1);
1548
- this.connection.send([E, t]), this.state.programChange.set(s.toString(), t), this.emit(C.CH_PC_SEND, { program: t, channel: s });
1548
+ this.connection.send([E, t]), this.state.programChange.set(s.toString(), t), this.emit(o.CH_PC_SEND, { program: t, channel: s });
1549
1549
  }
1550
1550
  /**
1551
1551
  * Get current Program Change value for channel
@@ -1578,7 +1578,7 @@ class z extends H {
1578
1578
  if (!this.initialized) return;
1579
1579
  t = O(Math.round(t), 0, 16383), s = O(Math.round(s), 1, 16);
1580
1580
  const E = 224 + (s - 1), e = t & 127, _ = t >> 7 & 127;
1581
- this.connection.send([E, e, _]), this.state.pitchBend.set(s.toString(), t), this.emit(C.CH_PITCH_BEND_SEND, { value: t, channel: s });
1581
+ this.connection.send([E, e, _]), this.state.pitchBend.set(s.toString(), t), this.emit(o.CH_PITCH_BEND_SEND, { value: t, channel: s });
1582
1582
  }
1583
1583
  /**
1584
1584
  * Get current Pitch Bend value for a channel
@@ -1600,7 +1600,7 @@ class z extends H {
1600
1600
  if (!this.initialized) return;
1601
1601
  t = O(Math.round(t), 0, 127), s = O(Math.round(s), 1, 16);
1602
1602
  const E = 208 + (s - 1);
1603
- this.connection.send([E, t]), this.state.monoPressure.set(s.toString(), t), this.emit(C.CH_MONO_PRESS_SEND, { pressure: t, channel: s });
1603
+ this.connection.send([E, t]), this.state.monoPressure.set(s.toString(), t), this.emit(o.CH_MONO_PRESS_SEND, { pressure: t, channel: s });
1604
1604
  }
1605
1605
  /**
1606
1606
  * Get current Channel Pressure (Aftertouch) value for a channel
@@ -1625,7 +1625,7 @@ class z extends H {
1625
1625
  const e = 160 + (E - 1);
1626
1626
  this.connection.send([e, t, s]);
1627
1627
  const _ = `${E}:${t}`;
1628
- this.state.polyPressure.set(_, s), this.emit(C.CH_POLY_PRESS_SEND, { note: t, pressure: s, channel: E });
1628
+ this.state.polyPressure.set(_, s), this.emit(o.CH_POLY_PRESS_SEND, { note: t, pressure: s, channel: E });
1629
1629
  }
1630
1630
  /**
1631
1631
  * Get current Polyphonic Pressure (Aftertouch) value for a specific note on a channel
@@ -1649,13 +1649,13 @@ class z extends H {
1649
1649
  if (t !== void 0) {
1650
1650
  t = O(Math.round(t), 1, 16);
1651
1651
  const s = 176 + (t - 1);
1652
- this.connection.send([s, 120, 0]), this.emit(C.CH_ALL_SOUNDS_OFF_SEND, { channel: t });
1652
+ this.connection.send([s, 120, 0]), this.emit(o.CH_ALL_SOUNDS_OFF_SEND, { channel: t });
1653
1653
  } else {
1654
1654
  for (let s = 1; s <= 16; s++) {
1655
1655
  const E = 176 + (s - 1);
1656
1656
  this.connection.send([E, 120, 0]);
1657
1657
  }
1658
- this.emit(C.CH_ALL_SOUNDS_OFF_SEND, { channel: null });
1658
+ this.emit(o.CH_ALL_SOUNDS_OFF_SEND, { channel: null });
1659
1659
  }
1660
1660
  }
1661
1661
  /**
@@ -1669,13 +1669,13 @@ class z extends H {
1669
1669
  if (t !== void 0) {
1670
1670
  t = O(Math.round(t), 1, 16);
1671
1671
  const s = 176 + (t - 1);
1672
- this.connection.send([s, 121, 0]), this.emit(C.CH_RESET_CONTROLLERS_SEND, { channel: t });
1672
+ this.connection.send([s, 121, 0]), this.emit(o.CH_RESET_CONTROLLERS_SEND, { channel: t });
1673
1673
  } else {
1674
1674
  for (let s = 1; s <= 16; s++) {
1675
1675
  const E = 176 + (s - 1);
1676
1676
  this.connection.send([E, 121, 0]);
1677
1677
  }
1678
- this.emit(C.CH_RESET_CONTROLLERS_SEND, { channel: null });
1678
+ this.emit(o.CH_RESET_CONTROLLERS_SEND, { channel: null });
1679
1679
  }
1680
1680
  }
1681
1681
  /**
@@ -1690,13 +1690,13 @@ class z extends H {
1690
1690
  if (s !== void 0) {
1691
1691
  s = O(Math.round(s), 1, 16);
1692
1692
  const e = 176 + (s - 1);
1693
- this.connection.send([e, 122, E]), this.emit(C.CH_LOCAL_CONTROL_SEND, { enabled: t, channel: s });
1693
+ this.connection.send([e, 122, E]), this.emit(o.CH_LOCAL_CONTROL_SEND, { enabled: t, channel: s });
1694
1694
  } else {
1695
1695
  for (let e = 1; e <= 16; e++) {
1696
1696
  const _ = 176 + (e - 1);
1697
1697
  this.connection.send([_, 122, E]);
1698
1698
  }
1699
- this.emit(C.CH_LOCAL_CONTROL_SEND, { enabled: t, channel: null });
1699
+ this.emit(o.CH_LOCAL_CONTROL_SEND, { enabled: t, channel: null });
1700
1700
  }
1701
1701
  }
1702
1702
  /**
@@ -1710,13 +1710,13 @@ class z extends H {
1710
1710
  if (t !== void 0) {
1711
1711
  t = O(Math.round(t), 1, 16);
1712
1712
  const s = 176 + (t - 1);
1713
- this.connection.send([s, 123, 0]), this.emit(C.CH_ALL_NOTES_OFF_SEND, { channel: t });
1713
+ this.connection.send([s, 123, 0]), this.emit(o.CH_ALL_NOTES_OFF_SEND, { channel: t });
1714
1714
  } else {
1715
1715
  for (let s = 1; s <= 16; s++) {
1716
1716
  const E = 176 + (s - 1);
1717
1717
  this.connection.send([E, 123, 0]);
1718
1718
  }
1719
- this.emit(C.CH_ALL_NOTES_OFF_SEND, { channel: null });
1719
+ this.emit(o.CH_ALL_NOTES_OFF_SEND, { channel: null });
1720
1720
  }
1721
1721
  }
1722
1722
  /**
@@ -1730,13 +1730,13 @@ class z extends H {
1730
1730
  if (t !== void 0) {
1731
1731
  t = O(Math.round(t), 1, 16);
1732
1732
  const s = 176 + (t - 1);
1733
- this.connection.send([s, 124, 0]), this.emit(C.CH_OMNI_OFF_SEND, { channel: t });
1733
+ this.connection.send([s, 124, 0]), this.emit(o.CH_OMNI_OFF_SEND, { channel: t });
1734
1734
  } else {
1735
1735
  for (let s = 1; s <= 16; s++) {
1736
1736
  const E = 176 + (s - 1);
1737
1737
  this.connection.send([E, 124, 0]);
1738
1738
  }
1739
- this.emit(C.CH_OMNI_OFF_SEND, { channel: null });
1739
+ this.emit(o.CH_OMNI_OFF_SEND, { channel: null });
1740
1740
  }
1741
1741
  }
1742
1742
  /**
@@ -1750,13 +1750,13 @@ class z extends H {
1750
1750
  if (t !== void 0) {
1751
1751
  t = O(Math.round(t), 1, 16);
1752
1752
  const s = 176 + (t - 1);
1753
- this.connection.send([s, 125, 0]), this.emit(C.CH_OMNI_ON_SEND, { channel: t });
1753
+ this.connection.send([s, 125, 0]), this.emit(o.CH_OMNI_ON_SEND, { channel: t });
1754
1754
  } else {
1755
1755
  for (let s = 1; s <= 16; s++) {
1756
1756
  const E = 176 + (s - 1);
1757
1757
  this.connection.send([E, 125, 0]);
1758
1758
  }
1759
- this.emit(C.CH_OMNI_ON_SEND, { channel: null });
1759
+ this.emit(o.CH_OMNI_ON_SEND, { channel: null });
1760
1760
  }
1761
1761
  }
1762
1762
  /**
@@ -1770,13 +1770,13 @@ class z extends H {
1770
1770
  if (t = Math.max(0, Math.min(16, Math.round(t))), s !== void 0) {
1771
1771
  s = O(Math.round(s), 1, 16);
1772
1772
  const E = 176 + (s - 1);
1773
- this.connection.send([E, 126, t]), this.emit(C.CH_MONO_ON_SEND, { channels: t, channel: s });
1773
+ this.connection.send([E, 126, t]), this.emit(o.CH_MONO_ON_SEND, { channels: t, channel: s });
1774
1774
  } else {
1775
1775
  for (let E = 1; E <= 16; E++) {
1776
1776
  const e = 176 + (E - 1);
1777
1777
  this.connection.send([e, 126, t]);
1778
1778
  }
1779
- this.emit(C.CH_MONO_ON_SEND, { channels: t, channel: null });
1779
+ this.emit(o.CH_MONO_ON_SEND, { channels: t, channel: null });
1780
1780
  }
1781
1781
  }
1782
1782
  /**
@@ -1790,13 +1790,13 @@ class z extends H {
1790
1790
  if (t !== void 0) {
1791
1791
  t = O(Math.round(t), 1, 16);
1792
1792
  const s = 176 + (t - 1);
1793
- this.connection.send([s, 127, 0]), this.emit(C.CH_POLY_ON_SEND, { channel: t });
1793
+ this.connection.send([s, 127, 0]), this.emit(o.CH_POLY_ON_SEND, { channel: t });
1794
1794
  } else {
1795
1795
  for (let s = 1; s <= 16; s++) {
1796
1796
  const E = 176 + (s - 1);
1797
1797
  this.connection.send([E, 127, 0]);
1798
1798
  }
1799
- this.emit(C.CH_POLY_ON_SEND, { channel: null });
1799
+ this.emit(o.CH_POLY_ON_SEND, { channel: null });
1800
1800
  }
1801
1801
  }
1802
1802
  /**
@@ -1818,7 +1818,7 @@ class z extends H {
1818
1818
  console.warn("SysEx not enabled. Initialize with sysex: true");
1819
1819
  return;
1820
1820
  }
1821
- this.connection.sendSysEx(t, s), this.emit(C.SYS_EX_SEND, { data: t, includeWrapper: s });
1821
+ this.connection.sendSysEx(t, s), this.emit(o.SYS_EX_SEND, { data: t, includeWrapper: s });
1822
1822
  }
1823
1823
  /**
1824
1824
  * Send MIDI Timing Clock message (System Real-Time)
@@ -1956,50 +1956,50 @@ class z extends H {
1956
1956
  _handleMIDIMessage(t) {
1957
1957
  const [s, E, e] = t.data, _ = s & 240, i = (s & 15) + 1;
1958
1958
  if (s === 248) {
1959
- this.emit(C.SYS_CLOCK_RECV, {
1959
+ this.emit(o.SYS_CLOCK_RECV, {
1960
1960
  timestamp: t.midiwire
1961
1961
  });
1962
1962
  return;
1963
1963
  }
1964
1964
  if (s === 250) {
1965
- this.emit(C.SYS_START_RECV, {
1965
+ this.emit(o.SYS_START_RECV, {
1966
1966
  timestamp: t.midiwire
1967
1967
  });
1968
1968
  return;
1969
1969
  }
1970
1970
  if (s === 251) {
1971
- this.emit(C.SYS_CONTINUE_RECV, {
1971
+ this.emit(o.SYS_CONTINUE_RECV, {
1972
1972
  timestamp: t.midiwire
1973
1973
  });
1974
1974
  return;
1975
1975
  }
1976
1976
  if (s === 252) {
1977
- this.emit(C.SYS_STOP_RECV, {
1977
+ this.emit(o.SYS_STOP_RECV, {
1978
1978
  timestamp: t.midiwire
1979
1979
  });
1980
1980
  return;
1981
1981
  }
1982
1982
  if (s === 254) {
1983
- this.emit(C.SYS_ACT_SENSE_RECV, {
1983
+ this.emit(o.SYS_ACT_SENSE_RECV, {
1984
1984
  timestamp: t.midiwire
1985
1985
  });
1986
1986
  return;
1987
1987
  }
1988
1988
  if (s === 255) {
1989
- this.emit(C.SYS_RESET_RECV, {
1989
+ this.emit(o.SYS_RESET_RECV, {
1990
1990
  timestamp: t.midiwire
1991
1991
  });
1992
1992
  return;
1993
1993
  }
1994
1994
  if (s === 240) {
1995
- this.emit(C.SYS_EX_RECV, {
1995
+ this.emit(o.SYS_EX_RECV, {
1996
1996
  data: Array.from(t.data),
1997
1997
  timestamp: t.midiwire
1998
1998
  });
1999
1999
  return;
2000
2000
  }
2001
2001
  if (s === 241) {
2002
- this.emit(C.SYS_MTC_RECV, {
2002
+ this.emit(o.SYS_MTC_RECV, {
2003
2003
  data: E,
2004
2004
  timestamp: t.midiwire
2005
2005
  });
@@ -2007,27 +2007,27 @@ class z extends H {
2007
2007
  }
2008
2008
  if (s === 242) {
2009
2009
  const r = E + (e << 7);
2010
- this.emit(C.SYS_SONG_POS_RECV, {
2010
+ this.emit(o.SYS_SONG_POS_RECV, {
2011
2011
  position: r,
2012
2012
  timestamp: t.midiwire
2013
2013
  });
2014
2014
  return;
2015
2015
  }
2016
2016
  if (s === 243) {
2017
- this.emit(C.SYS_SONG_SEL_RECV, {
2017
+ this.emit(o.SYS_SONG_SEL_RECV, {
2018
2018
  song: E,
2019
2019
  timestamp: t.midiwire
2020
2020
  });
2021
2021
  return;
2022
2022
  }
2023
2023
  if (s === 246) {
2024
- this.emit(C.SYS_TUNE_REQ_RECV, {
2024
+ this.emit(o.SYS_TUNE_REQ_RECV, {
2025
2025
  timestamp: t.midiwire
2026
2026
  });
2027
2027
  return;
2028
2028
  }
2029
2029
  if (s === 247) {
2030
- this.emit(C.MIDI_RAW, {
2030
+ this.emit(o.MIDI_RAW, {
2031
2031
  status: s,
2032
2032
  data: [E, e],
2033
2033
  channel: i,
@@ -2037,7 +2037,7 @@ class z extends H {
2037
2037
  }
2038
2038
  if (_ === 176) {
2039
2039
  const r = `${i}:${E}`;
2040
- this.state.controlChange.set(r, e), this.emit(C.CH_CC_RECV, {
2040
+ this.state.controlChange.set(r, e), this.emit(o.CH_CC_RECV, {
2041
2041
  cc: E,
2042
2042
  value: e,
2043
2043
  channel: i
@@ -2045,7 +2045,7 @@ class z extends H {
2045
2045
  return;
2046
2046
  }
2047
2047
  if (_ === 192) {
2048
- this.state.programChange.set(i.toString(), E), this.emit(C.CH_PC_RECV, {
2048
+ this.state.programChange.set(i.toString(), E), this.emit(o.CH_PC_RECV, {
2049
2049
  program: E,
2050
2050
  channel: i
2051
2051
  });
@@ -2053,14 +2053,14 @@ class z extends H {
2053
2053
  }
2054
2054
  if (_ === 224) {
2055
2055
  const r = E + (e << 7);
2056
- this.state.pitchBend.set(i.toString(), r), this.emit(C.CH_PITCH_BEND_RECV, {
2056
+ this.state.pitchBend.set(i.toString(), r), this.emit(o.CH_PITCH_BEND_RECV, {
2057
2057
  value: r,
2058
2058
  channel: i
2059
2059
  });
2060
2060
  return;
2061
2061
  }
2062
2062
  if (_ === 208) {
2063
- this.state.monoPressure.set(i.toString(), E), this.emit(C.CH_MONO_PRESS_RECV, {
2063
+ this.state.monoPressure.set(i.toString(), E), this.emit(o.CH_MONO_PRESS_RECV, {
2064
2064
  pressure: E,
2065
2065
  channel: i
2066
2066
  });
@@ -2068,7 +2068,7 @@ class z extends H {
2068
2068
  }
2069
2069
  if (_ === 160) {
2070
2070
  const r = `${i}:${E}`;
2071
- this.state.polyPressure.set(r, e), this.emit(C.CH_POLY_PRESS_RECV, {
2071
+ this.state.polyPressure.set(r, e), this.emit(o.CH_POLY_PRESS_RECV, {
2072
2072
  note: E,
2073
2073
  pressure: e,
2074
2074
  channel: i
@@ -2076,7 +2076,7 @@ class z extends H {
2076
2076
  return;
2077
2077
  }
2078
2078
  if (_ === 144 && e > 0) {
2079
- this.emit(C.CH_NOTE_ON_RECV, {
2079
+ this.emit(o.CH_NOTE_ON_RECV, {
2080
2080
  note: E,
2081
2081
  velocity: e,
2082
2082
  channel: i
@@ -2084,13 +2084,13 @@ class z extends H {
2084
2084
  return;
2085
2085
  }
2086
2086
  if (_ === 128 || _ === 144 && e === 0) {
2087
- this.emit(C.CH_NOTE_OFF_RECV, {
2087
+ this.emit(o.CH_NOTE_OFF_RECV, {
2088
2088
  note: E,
2089
2089
  channel: i
2090
2090
  });
2091
2091
  return;
2092
2092
  }
2093
- this.emit(C.MIDI_RAW, {
2093
+ this.emit(o.MIDI_RAW, {
2094
2094
  status: s,
2095
2095
  data: [E, e],
2096
2096
  channel: i,
@@ -2159,7 +2159,7 @@ class z extends H {
2159
2159
  if (!t || !t.channels)
2160
2160
  throw new L("Invalid patch format", "patch");
2161
2161
  const s = t.version || "1.0";
2162
- s === "1.0" ? await this._applyPatchV1(t) : (console.warn(`Unknown patch version: ${s}. Attempting to apply as v1.0`), await this._applyPatchV1(t)), this.emit(C.PATCH_LOADED, { patch: t });
2162
+ s === "1.0" ? await this._applyPatchV1(t) : (console.warn(`Unknown patch version: ${s}. Attempting to apply as v1.0`), await this._applyPatchV1(t)), this.emit(o.PATCH_LOADED, { patch: t });
2163
2163
  }
2164
2164
  /**
2165
2165
  * Apply patch data for version 1.0 format
@@ -2215,7 +2215,7 @@ class z extends H {
2215
2215
  _savePatch(t, s = null) {
2216
2216
  const E = s || this._getPatch(t), e = `midiwire_patch_${t}`;
2217
2217
  try {
2218
- return localStorage.setItem(e, JSON.stringify(E)), this.emit(C.PATCH_SAVED, { name: t, patch: E }), e;
2218
+ return localStorage.setItem(e, JSON.stringify(E)), this.emit(o.PATCH_SAVED, { name: t, patch: E }), e;
2219
2219
  } catch (_) {
2220
2220
  throw console.error("Failed to save patch:", _), _;
2221
2221
  }
@@ -2233,7 +2233,7 @@ class z extends H {
2233
2233
  if (!E)
2234
2234
  return null;
2235
2235
  const e = JSON.parse(E);
2236
- return this.emit(C.PATCH_LOADED, { name: t, patch: e }), e;
2236
+ return this.emit(o.PATCH_LOADED, { name: t, patch: e }), e;
2237
2237
  } catch (E) {
2238
2238
  return console.error("Failed to load patch:", E), null;
2239
2239
  }
@@ -2247,7 +2247,7 @@ class z extends H {
2247
2247
  _deletePatch(t) {
2248
2248
  const s = `midiwire_patch_${t}`;
2249
2249
  try {
2250
- return localStorage.removeItem(s), this.emit(C.PATCH_DELETED, { name: t }), !0;
2250
+ return localStorage.removeItem(s), this.emit(o.PATCH_DELETED, { name: t }), !0;
2251
2251
  } catch (E) {
2252
2252
  return console.error("Failed to delete patch:", E), !1;
2253
2253
  }
@@ -2307,12 +2307,12 @@ class q {
2307
2307
  const { output: E, input: e, channel: _ } = t, i = this._resolveSelector(E), r = this._resolveSelector(e), u = this._resolveSelector(_);
2308
2308
  if (this._setupDeviceChangeListeners({ output: i, input: r }, s.onDeviceListChange), i) {
2309
2309
  await this._populateOutputDeviceList(i);
2310
- const S = s.onConnect ? async (a, o) => s.onConnect({ midi: a, device: o, type: "output" }) : void 0, P = s.onDisconnect ? async (a) => s.onDisconnect({ midi: a, type: "output" }) : void 0;
2310
+ const S = s.onConnect ? async (a, C) => s.onConnect({ midi: a, device: C, type: "output" }) : void 0, P = s.onDisconnect ? async (a) => s.onDisconnect({ midi: a, type: "output" }) : void 0;
2311
2311
  this._connectOutputDeviceSelection(i, S, P);
2312
2312
  }
2313
2313
  if (r) {
2314
2314
  await this._populateInputDeviceList(r);
2315
- const S = s.onConnect ? async (a, o) => s.onConnect({ midi: a, device: o, type: "input" }) : void 0, P = s.onDisconnect ? async (a) => s.onDisconnect({ midi: a, type: "input" }) : void 0;
2315
+ const S = s.onConnect ? async (a, C) => s.onConnect({ midi: a, device: C, type: "input" }) : void 0, P = s.onDisconnect ? async (a) => s.onDisconnect({ midi: a, type: "input" }) : void 0;
2316
2316
  this._connectInputDeviceSelection(r, S, P);
2317
2317
  }
2318
2318
  return u && this._connectChannelSelection(u, "output"), this.midi;
@@ -2349,13 +2349,13 @@ class q {
2349
2349
  * @param {Function} [onDeviceListChange] - Callback when device list changes
2350
2350
  */
2351
2351
  _setupDeviceChangeListeners(t = {}, s) {
2352
- !this.midi || this._listenersInitialized || (this._listenersInitialized = !0, this.midi.on(C.DEV_OUT_CONNECTED, async (E) => {
2352
+ !this.midi || this._listenersInitialized || (this._listenersInitialized = !0, this.midi.on(o.DEV_OUT_CONNECTED, async (E) => {
2353
2353
  this.updateStatus(`Output device connected: ${E?.name || "Unknown"}`, "connected"), t.output && await this._populateOutputDeviceList(t.output), s && s();
2354
- }), this.midi.on(C.DEV_OUT_DISCONNECTED, async (E) => {
2354
+ }), this.midi.on(o.DEV_OUT_DISCONNECTED, async (E) => {
2355
2355
  this.updateStatus(`Output device disconnected: ${E?.name || "Unknown"}`, "error"), this.currentOutput && E?.name === this.currentOutput.name && (this.currentOutput = null, this.updateConnectionStatus(), t.output && (t.output.value = "")), t.output && await this._populateOutputDeviceList(t.output), s && s();
2356
- }), this.midi.on(C.DEV_IN_CONNECTED, async (E) => {
2356
+ }), this.midi.on(o.DEV_IN_CONNECTED, async (E) => {
2357
2357
  this.updateStatus(`Input device connected: ${E?.name || "Unknown"}`, "connected"), t.input && await this._populateInputDeviceList(t.input), s && s();
2358
- }), this.midi.on(C.DEV_IN_DISCONNECTED, async (E) => {
2358
+ }), this.midi.on(o.DEV_IN_DISCONNECTED, async (E) => {
2359
2359
  this.updateStatus(`Input device disconnected: ${E?.name || "Unknown"}`, "error"), t.input && (t.input.value = "", await this._populateInputDeviceList(t.input)), s && s();
2360
2360
  }));
2361
2361
  }
@@ -2708,6 +2708,8 @@ class n {
2708
2708
  static DEFAULT_FREQ_COARSE = 1;
2709
2709
  static DEFAULT_ALGORITHM = 0;
2710
2710
  static DEFAULT_FEEDBACK = 0;
2711
+ static DEFAULT_OSC_SYNC = 1;
2712
+ static DEFAULT_LFO_KEY_SYNC = 1;
2711
2713
  // MIDI notes
2712
2714
  static MIDI_OCTAVE_OFFSET = -2;
2713
2715
  // For displaying MIDI notes (MIDI 0 = C-2)
@@ -2976,7 +2978,7 @@ class n {
2976
2978
  const i = _ * n.UNPACKED_OP_SIZE;
2977
2979
  s[i + n.UNPACKED_OP_EG_RATE_1] = n.DEFAULT_EG_RATE, s[i + n.UNPACKED_OP_EG_RATE_2] = n.DEFAULT_EG_RATE, s[i + n.UNPACKED_OP_EG_RATE_3] = n.DEFAULT_EG_RATE, s[i + n.UNPACKED_OP_EG_RATE_4] = n.DEFAULT_EG_RATE, s[i + n.UNPACKED_OP_EG_LEVEL_1] = n.DEFAULT_EG_LEVEL_MAX, s[i + n.UNPACKED_OP_EG_LEVEL_2] = n.DEFAULT_EG_LEVEL_MAX, s[i + n.UNPACKED_OP_EG_LEVEL_3] = n.DEFAULT_EG_LEVEL_MAX, s[i + n.UNPACKED_OP_EG_LEVEL_4] = n.DEFAULT_EG_LEVEL_MIN, s[i + n.UNPACKED_OP_BREAK_POINT] = n.DEFAULT_BREAK_POINT, s[i + n.UNPACKED_OP_L_SCALE_DEPTH] = 0, s[i + n.UNPACKED_OP_R_SCALE_DEPTH] = 0, s[i + n.UNPACKED_OP_L_CURVE] = 0, s[i + n.UNPACKED_OP_R_CURVE] = 0, s[i + n.UNPACKED_OP_RATE_SCALING] = 0, s[i + n.UNPACKED_OP_DETUNE] = n.DEFAULT_DETUNE, s[i + n.UNPACKED_OP_AMP_MOD_SENS] = 0, s[i + n.UNPACKED_OP_KEY_VEL_SENS] = 0, s[i + n.UNPACKED_OP_OUTPUT_LEVEL] = n.DEFAULT_OUTPUT_LEVEL, s[i + n.UNPACKED_OP_MODE] = 0, s[i + n.UNPACKED_OP_FREQ_COARSE] = n.DEFAULT_FREQ_COARSE, s[i + n.UNPACKED_OP_OSC_DETUNE] = 0, s[i + n.UNPACKED_OP_FREQ_FINE] = 0;
2978
2980
  }
2979
- s[n.UNPACKED_PITCH_EG_RATE_1] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_RATE_2] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_RATE_3] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_RATE_4] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_LEVEL_1] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_PITCH_EG_LEVEL_2] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_PITCH_EG_LEVEL_3] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_PITCH_EG_LEVEL_4] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_ALGORITHM] = n.DEFAULT_ALGORITHM, s[n.UNPACKED_FEEDBACK] = n.DEFAULT_FEEDBACK, s[n.UNPACKED_OSC_SYNC] = 0, s[n.UNPACKED_LFO_SPEED] = n.DEFAULT_LFO_SPEED, s[n.UNPACKED_LFO_DELAY] = 0, s[n.UNPACKED_LFO_PM_DEPTH] = 0, s[n.UNPACKED_LFO_AM_DEPTH] = 0, s[n.UNPACKED_LFO_KEY_SYNC] = 0, s[n.UNPACKED_LFO_WAVE] = 0, s[n.UNPACKED_LFO_PM_SENS] = n.DEFAULT_LFO_PM_SENS, s[n.UNPACKED_AMP_MOD_SENS] = 0, s[n.UNPACKED_TRANSPOSE] = n.TRANSPOSE_CENTER, s[n.UNPACKED_EG_BIAS_SENS] = 0;
2981
+ s[n.UNPACKED_PITCH_EG_RATE_1] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_RATE_2] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_RATE_3] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_RATE_4] = n.DEFAULT_EG_RATE, s[n.UNPACKED_PITCH_EG_LEVEL_1] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_PITCH_EG_LEVEL_2] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_PITCH_EG_LEVEL_3] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_PITCH_EG_LEVEL_4] = n.DEFAULT_PITCH_EG_LEVEL, s[n.UNPACKED_ALGORITHM] = n.DEFAULT_ALGORITHM, s[n.UNPACKED_FEEDBACK] = n.DEFAULT_FEEDBACK, s[n.UNPACKED_OSC_SYNC] = n.DEFAULT_OSC_SYNC, s[n.UNPACKED_LFO_SPEED] = n.DEFAULT_LFO_SPEED, s[n.UNPACKED_LFO_DELAY] = 0, s[n.UNPACKED_LFO_PM_DEPTH] = 0, s[n.UNPACKED_LFO_AM_DEPTH] = 0, s[n.UNPACKED_LFO_KEY_SYNC] = n.DEFAULT_LFO_KEY_SYNC, s[n.UNPACKED_LFO_WAVE] = 0, s[n.UNPACKED_LFO_PM_SENS] = n.DEFAULT_LFO_PM_SENS, s[n.UNPACKED_AMP_MOD_SENS] = 0, s[n.UNPACKED_TRANSPOSE] = n.TRANSPOSE_CENTER, s[n.UNPACKED_EG_BIAS_SENS] = 0;
2980
2982
  const E = "Init Voice";
2981
2983
  for (let _ = 0; _ < n.NAME_LENGTH; _++)
2982
2984
  s[n.UNPACKED_NAME_START + _] = _ < E.length ? E.charCodeAt(_) : n.CHAR_SPACE;
@@ -3026,8 +3028,8 @@ class n {
3026
3028
  P[n.UNPACKED_PITCH_EG_RATE_1] = r[a++], P[n.UNPACKED_PITCH_EG_RATE_2] = r[a++], P[n.UNPACKED_PITCH_EG_RATE_3] = r[a++], P[n.UNPACKED_PITCH_EG_RATE_4] = r[a++], P[n.UNPACKED_PITCH_EG_LEVEL_1] = r[a++], P[n.UNPACKED_PITCH_EG_LEVEL_2] = r[a++], P[n.UNPACKED_PITCH_EG_LEVEL_3] = r[a++], P[n.UNPACKED_PITCH_EG_LEVEL_4] = r[a++], P[n.UNPACKED_ALGORITHM] = r[a++], P[n.UNPACKED_FEEDBACK] = r[a++], P[n.UNPACKED_OSC_SYNC] = r[a++], P[n.UNPACKED_LFO_SPEED] = r[a++], P[n.UNPACKED_LFO_DELAY] = r[a++], P[n.UNPACKED_LFO_PM_DEPTH] = r[a++], P[n.UNPACKED_LFO_AM_DEPTH] = r[a++], P[n.UNPACKED_LFO_KEY_SYNC] = r[a++], P[n.UNPACKED_LFO_WAVE] = r[a++], P[n.UNPACKED_LFO_PM_SENS] = r[a++], P[n.UNPACKED_TRANSPOSE] = r[a++];
3027
3029
  for (let h = 0; h < n.NAME_LENGTH; h++)
3028
3030
  P[n.UNPACKED_NAME_START + h] = r[a++];
3029
- const o = n.pack(P);
3030
- s(new n(o, 0));
3031
+ const C = n.pack(P);
3032
+ s(new n(C, 0));
3031
3033
  } catch (i) {
3032
3034
  E(i);
3033
3035
  }
@@ -3090,12 +3092,12 @@ class n {
3090
3092
  static fromJSON(t, s = 0) {
3091
3093
  if (!t || typeof t != "object")
3092
3094
  throw new c("Invalid JSON: expected object", "json", t);
3093
- const E = new Uint8Array(n.UNPACKED_SIZE), e = (a, o, h, N = 0, d = 127) => {
3094
- if (o == null)
3095
- throw new c(`Missing required parameter: ${h}`, h, o);
3096
- const T = Number(o);
3095
+ const E = new Uint8Array(n.UNPACKED_SIZE), e = (a, C, h, N = 0, d = 127) => {
3096
+ if (C == null)
3097
+ throw new c(`Missing required parameter: ${h}`, h, C);
3098
+ const T = Number(C);
3097
3099
  if (Number.isNaN(T))
3098
- throw new c(`Invalid parameter value for ${h}: ${o}`, h, o);
3100
+ throw new c(`Invalid parameter value for ${h}: ${C}`, h, C);
3099
3101
  if (T < N || T > d)
3100
3102
  throw new c(
3101
3103
  `Parameter ${h} out of range: ${T} (must be ${N}-${d})`,
@@ -3104,10 +3106,10 @@ class n {
3104
3106
  );
3105
3107
  E[a] = Math.floor(T);
3106
3108
  }, _ = (a) => {
3107
- const o = { "-LN": 0, "-EX": 1, "+EX": 2, "+LN": 3 };
3108
- return o[a] !== void 0 ? o[a] : 0;
3109
+ const C = { "-LN": 0, "-EX": 1, "+EX": 2, "+LN": 3 };
3110
+ return C[a] !== void 0 ? C[a] : 0;
3109
3111
  }, i = (a) => {
3110
- const o = {
3112
+ const C = {
3111
3113
  TRIANGLE: 0,
3112
3114
  "SAW DOWN": 1,
3113
3115
  "SAW UP": 2,
@@ -3115,31 +3117,31 @@ class n {
3115
3117
  SINE: 4,
3116
3118
  "SAMPLE & HOLD": 5
3117
3119
  };
3118
- return o[a] !== void 0 ? o[a] : 0;
3120
+ return C[a] !== void 0 ? C[a] : 0;
3119
3121
  }, r = (a) => {
3120
3122
  if (!a || typeof a != "string") return 60;
3121
- const o = a.trim().match(/^([A-G]#?)(-?\d+)$/);
3122
- if (!o) return 60;
3123
- const [, h, N] = o, d = parseInt(N, 10), f = { C: 0, "C#": 1, D: 2, "D#": 3, E: 4, F: 5, "F#": 6, G: 7, "G#": 8, A: 9, "A#": 10, B: 11 }[h.toUpperCase()];
3123
+ const C = a.trim().match(/^([A-G]#?)(-?\d+)$/);
3124
+ if (!C) return 60;
3125
+ const [, h, N] = C, d = parseInt(N, 10), f = { C: 0, "C#": 1, D: 2, "D#": 3, E: 4, F: 5, "F#": 6, G: 7, "G#": 8, A: 9, "A#": 10, B: 11 }[h.toUpperCase()];
3124
3126
  return f === void 0 ? 60 : (d - n.MIDI_OCTAVE_OFFSET) * 12 + f;
3125
3127
  };
3126
3128
  if (!Array.isArray(t.operators))
3127
3129
  throw new c("Invalid operators array: expected array", "operators", t.operators);
3128
3130
  for (let a = 0; a < t.operators.length; a++) {
3129
- const o = t.operators[a];
3130
- if (!o || typeof o != "object")
3131
- throw new c(`Invalid operator data at index ${a}`, `operators[${a}]`, o);
3132
- if (!o.eg || !Array.isArray(o.eg.rates) || o.eg.rates.length !== 4)
3131
+ const C = t.operators[a];
3132
+ if (!C || typeof C != "object")
3133
+ throw new c(`Invalid operator data at index ${a}`, `operators[${a}]`, C);
3134
+ if (!C.eg || !Array.isArray(C.eg.rates) || C.eg.rates.length !== 4)
3133
3135
  throw new c(
3134
3136
  `Invalid EG rates for operator ${a}`,
3135
3137
  `operators[${a}].eg.rates`,
3136
- o.eg?.rates
3138
+ C.eg?.rates
3137
3139
  );
3138
- if (!o.eg || !Array.isArray(o.eg.levels) || o.eg.levels.length !== 4)
3140
+ if (!C.eg || !Array.isArray(C.eg.levels) || C.eg.levels.length !== 4)
3139
3141
  throw new c(
3140
3142
  `Invalid EG levels for operator ${a}`,
3141
3143
  `operators[${a}].eg.levels`,
3142
- o.eg?.levels
3144
+ C.eg?.levels
3143
3145
  );
3144
3146
  }
3145
3147
  if (t.operators.length !== n.NUM_OPERATORS)
@@ -3149,58 +3151,58 @@ class n {
3149
3151
  t.operators
3150
3152
  );
3151
3153
  for (let a = 0; a < n.NUM_OPERATORS; a++) {
3152
- const o = t.operators[a], h = a * n.UNPACKED_OP_SIZE;
3153
- if (!o.eg || !Array.isArray(o.eg.rates) || o.eg.rates.length !== 4)
3154
+ const C = t.operators[a], h = a * n.UNPACKED_OP_SIZE;
3155
+ if (!C.eg || !Array.isArray(C.eg.rates) || C.eg.rates.length !== 4)
3154
3156
  throw new c(
3155
3157
  `Invalid EG rates for operator ${a}`,
3156
3158
  `operators[${a}].eg.rates`,
3157
- o.eg?.rates
3159
+ C.eg?.rates
3158
3160
  );
3159
- if (e(h + n.UNPACKED_OP_EG_RATE_1, o.eg.rates[0], `operators[${a}].eg.rates[0]`, 0, 99), e(h + n.UNPACKED_OP_EG_RATE_2, o.eg.rates[1], `operators[${a}].eg.rates[1]`, 0, 99), e(h + n.UNPACKED_OP_EG_RATE_3, o.eg.rates[2], `operators[${a}].eg.rates[2]`, 0, 99), e(h + n.UNPACKED_OP_EG_RATE_4, o.eg.rates[3], `operators[${a}].eg.rates[3]`, 0, 99), !o.eg || !Array.isArray(o.eg.levels) || o.eg.levels.length !== 4)
3161
+ if (e(h + n.UNPACKED_OP_EG_RATE_1, C.eg.rates[0], `operators[${a}].eg.rates[0]`, 0, 99), e(h + n.UNPACKED_OP_EG_RATE_2, C.eg.rates[1], `operators[${a}].eg.rates[1]`, 0, 99), e(h + n.UNPACKED_OP_EG_RATE_3, C.eg.rates[2], `operators[${a}].eg.rates[2]`, 0, 99), e(h + n.UNPACKED_OP_EG_RATE_4, C.eg.rates[3], `operators[${a}].eg.rates[3]`, 0, 99), !C.eg || !Array.isArray(C.eg.levels) || C.eg.levels.length !== 4)
3160
3162
  throw new c(
3161
3163
  `Invalid EG levels for operator ${a}`,
3162
3164
  `operators[${a}].eg.levels`,
3163
- o.eg?.levels
3165
+ C.eg?.levels
3164
3166
  );
3165
- e(h + n.UNPACKED_OP_EG_LEVEL_1, o.eg.levels[0], `operators[${a}].eg.levels[0]`, 0, 99), e(h + n.UNPACKED_OP_EG_LEVEL_2, o.eg.levels[1], `operators[${a}].eg.levels[1]`, 0, 99), e(h + n.UNPACKED_OP_EG_LEVEL_3, o.eg.levels[2], `operators[${a}].eg.levels[2]`, 0, 99), e(h + n.UNPACKED_OP_EG_LEVEL_4, o.eg.levels[3], `operators[${a}].eg.levels[3]`, 0, 99);
3166
- const N = r(o.key?.breakPoint) - n.MIDI_BREAK_POINT_OFFSET;
3167
+ e(h + n.UNPACKED_OP_EG_LEVEL_1, C.eg.levels[0], `operators[${a}].eg.levels[0]`, 0, 99), e(h + n.UNPACKED_OP_EG_LEVEL_2, C.eg.levels[1], `operators[${a}].eg.levels[1]`, 0, 99), e(h + n.UNPACKED_OP_EG_LEVEL_3, C.eg.levels[2], `operators[${a}].eg.levels[2]`, 0, 99), e(h + n.UNPACKED_OP_EG_LEVEL_4, C.eg.levels[3], `operators[${a}].eg.levels[3]`, 0, 99);
3168
+ const N = r(C.key?.breakPoint) - n.MIDI_BREAK_POINT_OFFSET;
3167
3169
  e(h + n.UNPACKED_OP_BREAK_POINT, N, `operators[${a}].key.breakPoint`, 0, 127), e(
3168
3170
  h + n.UNPACKED_OP_L_SCALE_DEPTH,
3169
- o.scale?.left?.depth || 0,
3171
+ C.scale?.left?.depth || 0,
3170
3172
  `operators[${a}].scale.left.depth`,
3171
3173
  0,
3172
3174
  99
3173
3175
  ), e(
3174
3176
  h + n.UNPACKED_OP_R_SCALE_DEPTH,
3175
- o.scale?.right?.depth || 0,
3177
+ C.scale?.right?.depth || 0,
3176
3178
  `operators[${a}].scale.right.depth`,
3177
3179
  0,
3178
3180
  99
3179
- ), E[h + n.UNPACKED_OP_L_CURVE] = _(o.scale?.left?.curve || "-LN"), E[h + n.UNPACKED_OP_R_CURVE] = _(o.scale?.right?.curve || "-LN"), e(
3181
+ ), E[h + n.UNPACKED_OP_L_CURVE] = _(C.scale?.left?.curve || "-LN"), E[h + n.UNPACKED_OP_R_CURVE] = _(C.scale?.right?.curve || "-LN"), e(
3180
3182
  h + n.UNPACKED_OP_RATE_SCALING,
3181
- o.key?.scaling || 0,
3183
+ C.key?.scaling || 0,
3182
3184
  `operators[${a}].key.scaling`,
3183
3185
  0,
3184
3186
  7
3185
3187
  );
3186
- const d = Number(o.osc?.detune) || 0;
3188
+ const d = Number(C.osc?.detune) || 0;
3187
3189
  e(h + n.UNPACKED_OP_DETUNE, d + 7, `operators[${a}].osc.detune`, 0, 14), e(
3188
3190
  h + n.UNPACKED_OP_AMP_MOD_SENS,
3189
- o.output?.ampModSens || 0,
3191
+ C.output?.ampModSens || 0,
3190
3192
  `operators[${a}].output.ampModSens`,
3191
3193
  0,
3192
3194
  3
3193
3195
  ), e(
3194
3196
  h + n.UNPACKED_OP_OUTPUT_LEVEL,
3195
- o.output?.level || 0,
3197
+ C.output?.level || 0,
3196
3198
  `operators[${a}].output.level`,
3197
3199
  0,
3198
3200
  99
3199
3201
  );
3200
- const T = o.osc?.freq?.mode?.toUpperCase() === "FIXED" ? 1 : 0, f = Number(o.osc?.freq?.coarse) || 0, I = Number(o.osc?.freq?.fine) || 0;
3202
+ const T = C.osc?.freq?.mode?.toUpperCase() === "FIXED" ? 1 : 0, f = Number(C.osc?.freq?.coarse) || 0, I = Number(C.osc?.freq?.fine) || 0;
3201
3203
  E[h + n.UNPACKED_OP_MODE] = T, e(h + n.UNPACKED_OP_FREQ_COARSE, f, `operators[${a}].osc.freq.coarse`, 0, 31), e(h + n.UNPACKED_OP_FREQ_FINE, I, `operators[${a}].osc.freq.fine`, 0, 15), e(
3202
3204
  h + n.UNPACKED_OP_KEY_VEL_SENS,
3203
- o.key?.velocity || 0,
3205
+ C.key?.velocity || 0,
3204
3206
  `operators[${a}].key.velocity`,
3205
3207
  0,
3206
3208
  7
@@ -3685,10 +3687,10 @@ function at(A) {
3685
3687
  function At(A) {
3686
3688
  return Number.isInteger(A) && A >= 0 && A <= 127;
3687
3689
  }
3688
- function ot(A) {
3690
+ function Ct(A) {
3689
3691
  return Number.isInteger(A) && A >= 0 && A <= 127;
3690
3692
  }
3691
- function Ct(A) {
3693
+ function ot(A) {
3692
3694
  return Number.isInteger(A) && A >= 0 && A <= 127;
3693
3695
  }
3694
3696
  function Pt(A) {
@@ -3751,8 +3753,8 @@ async function W(A = {}) {
3751
3753
  export {
3752
3754
  U as CONN,
3753
3755
  U as CONNECTION_EVENTS,
3754
- C as CONTROLLER_EVENTS,
3755
- C as CTRL,
3756
+ o as CONTROLLER_EVENTS,
3757
+ o as CTRL,
3756
3758
  l as DX7Bank,
3757
3759
  b as DX7Error,
3758
3760
  m as DX7ParseError,
@@ -3785,11 +3787,11 @@ export {
3785
3787
  rt as isValidCC,
3786
3788
  _t as isValidChannel,
3787
3789
  At as isValidMIDIValue,
3788
- ot as isValidNote,
3790
+ Ct as isValidNote,
3789
3791
  ut as isValidPitchBend,
3790
3792
  lt as isValidPitchBendBytes,
3791
3793
  Pt as isValidProgramChange,
3792
- Ct as isValidVelocity,
3794
+ ot as isValidVelocity,
3793
3795
  $ as normalize14BitValue,
3794
3796
  x as normalizeValue,
3795
3797
  J as noteNameToNumber,
@@ -1 +1 @@
1
- (function(l,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(l=typeof globalThis<"u"?globalThis:l||self,p(l.MIDIControls={}))})(this,(function(l){"use strict";class p{constructor(t,s="[data-midi-cc]"){this.controller=t,this.selector=s,this.observer=null}bindAll(){document.querySelectorAll(this.selector==="[data-midi-cc]"?"[data-midi-cc], [data-midi-msb][data-midi-lsb]":this.selector).forEach(s=>{if(s.hasAttribute("data-midi-bound"))return;const e=this._parseAttributes(s);e&&(this.controller.bind(s,e),s.setAttribute("data-midi-bound","true"))})}enableAutoBinding(){if(this.observer)return;const t=this.selector==="[data-midi-cc]"?"[data-midi-cc], [data-midi-msb][data-midi-lsb]":this.selector;this.observer=new MutationObserver(s=>{s.forEach(e=>{e.addedNodes.forEach(E=>{if(E.nodeType===Node.ELEMENT_NODE){if(E.matches?.(t)){const _=this._parseAttributes(E);_&&!E.hasAttribute("data-midi-bound")&&(this.controller.bind(E,_),E.setAttribute("data-midi-bound","true"))}E.querySelectorAll&&E.querySelectorAll(t).forEach(i=>{if(!i.hasAttribute("data-midi-bound")){const r=this._parseAttributes(i);r&&(this.controller.bind(i,r),i.setAttribute("data-midi-bound","true"))}})}}),e.removedNodes.forEach(E=>{E.nodeType===Node.ELEMENT_NODE&&(E.hasAttribute?.("data-midi-bound")&&this.controller.unbind(E),E.querySelectorAll&&E.querySelectorAll("[data-midi-bound]").forEach(i=>{this.controller.unbind(i)}))})})}),this.observer.observe(document.body,{childList:!0,subtree:!0})}disableAutoBinding(){this.observer&&(this.observer.disconnect(),this.observer=null)}_parseAttributes(t){const s=parseInt(t.dataset.midiMsb,10),e=parseInt(t.dataset.midiLsb,10);if(!Number.isNaN(s)&&!Number.isNaN(e)&&s>=0&&s<=127&&e>=0&&e<=127){const _=parseInt(t.dataset.midiCc,10);return!Number.isNaN(_)&&_>=0&&_<=127&&console.warn(`Element has both 7-bit (data-midi-cc="${_}") and 14-bit (data-midi-msb="${s}" data-midi-lsb="${e}") CC attributes. 14-bit takes precedence.`,t),{msb:s,lsb:e,is14Bit:!0,channel:parseInt(t.dataset.midiChannel,10)||void 0,min:parseFloat(t.getAttribute("min"))||0,max:parseFloat(t.getAttribute("max"))||127,invert:t.dataset.midiInvert==="true",label:t.dataset.midiLabel}}const E=parseInt(t.dataset.midiCc,10);return!Number.isNaN(E)&&E>=0&&E<=127?{cc:E,channel:parseInt(t.dataset.midiChannel,10)||void 0,min:parseFloat(t.getAttribute("min"))||0,max:parseFloat(t.getAttribute("max"))||127,invert:t.dataset.midiInvert==="true",label:t.dataset.midiLabel}:((t.dataset.midiCc!==void 0||t.dataset.midiMsb!==void 0&&t.dataset.midiLsb!==void 0)&&console.warn("Invalid MIDI configuration on element:",t),null)}destroy(){this.disableAutoBinding()}}class m extends Error{constructor(t,s){super(t),this.name="MIDIError",this.code=s,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class g extends m{constructor(t,s){super(t,"MIDI_ACCESS_ERROR"),this.name="MIDIAccessError",this.reason=s}}class G extends m{constructor(t){super(t,"MIDI_CONNECTION_ERROR"),this.name="MIDIConnectionError"}}class L extends m{constructor(t,s,e){super(t,"MIDI_DEVICE_ERROR"),this.name="MIDIDeviceError",this.deviceType=s,this.deviceId=e}}class R extends m{constructor(t,s){super(t,"MIDI_VALIDATION_ERROR"),this.name="MIDIValidationError",this.validationType=s}}class F extends Error{constructor(t,s){super(t),this.name="DX7Error",this.code=s,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class M extends F{constructor(t,s,e){super(t,"DX7_PARSE_ERROR"),this.name="DX7ParseError",this.parseType=s,this.offset=e}}class d extends F{constructor(t,s,e){super(t,"DX7_VALIDATION_ERROR"),this.name="DX7ValidationError",this.validationType=s,this.value=e}}function c(C,t,s){return Math.max(t,Math.min(s,C))}function H(C,t,s,e=!1){const E=(C-t)/(s-t),i=(e?1-E:E)*127;return c(Math.round(i),0,127)}function W(C,t,s,e=!1){let E=c(C,0,127)/127;return e&&(E=1-E),t+E*(s-t)}function Q(C){const t={C:0,"C#":1,DB:1,D:2,"D#":3,EB:3,E:4,F:5,"F#":6,GB:6,G:7,"G#":8,AB:8,A:9,"A#":10,BB:10,B:11},s=C.match(/^([A-G][#b]?)(-?\d+)$/i);if(!s)throw new R(`Invalid note name: ${C}`,"note",C);const[,e,E]=s,_=t[e.toUpperCase()];if(_===void 0)throw new R(`Invalid note: ${e}`,"note",e);const i=(parseInt(E,10)+1)*12+_;return c(i,0,127)}function J(C,t=!1){const E=t?["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"]:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],_=Math.floor(C/12)-1;return`${E[C%12]}${_}`}function j(C){const t=69+12*Math.log2(C/440);return c(Math.round(t),0,127)}function k(C){return 440*2**((C-69)/12)}function V(C){return{0:"Bank Select",1:"Modulation",2:"Breath Controller",4:"Foot Controller",5:"Portamento Time",7:"Volume",8:"Balance",10:"Pan",11:"Expression",64:"Sustain Pedal",65:"Portamento",66:"Sostenuto",67:"Soft Pedal",68:"Legato",71:"Resonance",72:"Release Time",73:"Attack Time",74:"Cutoff",75:"Decay Time",76:"Vibrato Rate",77:"Vibrato Depth",78:"Vibrato Delay",84:"Portamento Control",91:"Reverb",92:"Tremolo",93:"Chorus",94:"Detune",95:"Phaser",120:"All Sound Off",121:"Reset All Controllers",123:"All Notes Off"}[C]||`CC ${C}`}function v(C){const t=c(Math.round(C),0,16383);return{msb:t>>7&127,lsb:t&127}}function w(C,t){return c(C,0,127)<<7|c(t,0,127)}function B(C,t,s,e=!1){const E=(C-t)/(s-t),i=(e?1-E:E)*16383;return v(i)}function X(C,t,s,e,E=!1){let i=w(C,t)/16383;return E&&(i=1-i),s+i*(e-s)}class b{constructor(){this.events=new Map}on(t,s){return this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(s),()=>this.off(t,s)}once(t,s){const e=(...E)=>{s(...E),this.off(t,e)};this.on(t,e)}off(t,s){if(!this.events.has(t))return;const e=this.events.get(t),E=e.indexOf(s);E>-1&&e.splice(E,1),e.length===0&&this.events.delete(t)}emit(t,s){if(!this.events.has(t))return;[...this.events.get(t)].forEach(E=>{try{E(s)}catch(_){console.error(`Error in event handler for "${t}":`,_)}})}removeAllListeners(t){t?this.events.delete(t):this.events.clear()}}const U={DEVICE_CHANGE:"device-change",IN_DEV_CONNECTED:"in-dev-connected",IN_DEV_DISCONNECTED:"in-dev-disconnected",OUT_DEV_CONNECTED:"out-dev-connected",OUT_DEV_DISCONNECTED:"out-dev-disconnected"};class Y extends b{constructor(t={}){super(),this.options={sysex:!1,...t},this.midiAccess=null,this.output=null,this.input=null}async requestAccess(){if(!navigator.requestMIDIAccess)throw new g("Web MIDI API is not supported in this browser","unsupported");try{this.midiAccess=await navigator.requestMIDIAccess({sysex:this.options.sysex}),this.midiAccess.onstatechange=t=>{const s=t.port,e=t.port.state;this.emit(U.DEVICE_CHANGE,{port:s,state:e,type:s.type,device:{id:s.id,name:s.name,manufacturer:s.manufacturer||"Unknown"}}),e==="disconnected"?s.type==="input"?(this.emit(U.IN_DEV_DISCONNECTED,{device:s}),this.input&&this.input.id===s.id&&(this.input=null)):s.type==="output"&&(this.emit(U.OUT_DEV_DISCONNECTED,{device:s}),this.output&&this.output.id===s.id&&(this.output=null)):e==="connected"&&(s.type==="input"?this.emit(U.IN_DEV_CONNECTED,{device:s}):s.type==="output"&&this.emit(U.OUT_DEV_CONNECTED,{device:s}))}}catch(t){throw t.name==="SecurityError"?new g("MIDI access denied. SysEx requires user permission.","denied"):new g(`Failed to get MIDI access: ${t.message}`,"failed")}}async connect(t){if(!this.midiAccess)throw new G("MIDI access not initialized. Call requestAccess() first.");const s=Array.from(this.midiAccess.outputs.values());if(s.length===0)throw new L("No MIDI output devices available","output");if(t===void 0){this.output=s[0];return}if(typeof t=="number"){if(t<0||t>=s.length)throw new L(`Output index ${t} out of range (0-${s.length-1})`,"output",t);this.output=s[t];return}if(this.output=s.find(e=>e.name===t||e.id===t),!this.output){const e=s.map(E=>E.name).join(", ");throw new L(`MIDI output "${t}" not found. Available: ${e}`,"output",t)}}async connectInput(t,s){if(!this.midiAccess)throw new G("MIDI access not initialized. Call requestAccess() first.");if(typeof s!="function")throw new R("onMessage callback must be a function","callback");const e=Array.from(this.midiAccess.inputs.values());if(e.length===0)throw new L("No MIDI input devices available","input");if(this.input&&(this.input.onmidimessage=null),t===void 0)this.input=e[0];else if(typeof t=="number"){if(t<0||t>=e.length)throw new L(`Input index ${t} out of range (0-${e.length-1})`,"input",t);this.input=e[t]}else if(this.input=e.find(E=>E.name===t||E.id===t),!this.input){const E=e.map(_=>_.name).join(", ");throw new L(`MIDI input "${t}" not found. Available: ${E}`,"input",t)}this.input.onmidimessage=E=>{s(E)}}disconnectOutput(){this.output=null}disconnectInput(){this.input&&(this.input.onmidimessage=null,this.input=null)}disconnect(){this.disconnectOutput(),this.disconnectInput()}isConnected(){return this.output!==null}getCurrentOutput(){return this.output?{id:this.output.id,name:this.output.name,manufacturer:this.output.manufacturer||"Unknown"}:null}getCurrentInput(){return this.input?{id:this.input.id,name:this.input.name,manufacturer:this.input.manufacturer||"Unknown"}:null}getOutputs(){if(!this.midiAccess)return[];const t=[];return this.midiAccess.outputs.forEach(s=>{s.state==="connected"&&t.push({id:s.id,name:s.name,manufacturer:s.manufacturer||"Unknown"})}),t}getInputs(){if(!this.midiAccess)return[];const t=[];return this.midiAccess.inputs.forEach(s=>{s.state==="connected"&&t.push({id:s.id,name:s.name,manufacturer:s.manufacturer||"Unknown"})}),t}send(t,s=null){if(!this.output){console.warn("No MIDI output connected. Call connect() first.");return}try{const e=new Uint8Array(t);s===null?this.output.send(e):this.output.send(e,s)}catch(e){console.error("Failed to send MIDI message:",e)}}sendSysEx(t,s=!1){if(!this.options.sysex){console.warn("SysEx not enabled. Initialize with sysex: true");return}let e;s?e=[240,...t,247]:e=t,this.send(e)}}const o={READY:"ready",ERROR:"error",DESTROYED:"destroyed",DEV_OUT_CONNECTED:"dev-out-connected",DEV_OUT_DISCONNECTED:"dev-out-disconnected",DEV_IN_CONNECTED:"dev-in-connected",DEV_IN_DISCONNECTED:"dev-in-disconnected",CH_CC_SEND:"ch-cc-send",CH_CC_RECV:"ch-cc-recv",CH_NOTE_ON_SEND:"ch-note-on-send",CH_NOTE_ON_RECV:"ch-note-on-recv",CH_NOTE_OFF_SEND:"ch-note-off-send",CH_NOTE_OFF_RECV:"ch-note-off-recv",CH_PC_SEND:"ch-pc-send",CH_PC_RECV:"ch-pc-recv",CH_PITCH_BEND_SEND:"ch-pitch-bend-send",CH_PITCH_BEND_RECV:"ch-pitch-bend-recv",CH_MONO_PRESS_SEND:"ch-mono-press-send",CH_MONO_PRESS_RECV:"ch-mono-press-recv",CH_POLY_PRESS_SEND:"ch-poly-press-send",CH_POLY_PRESS_RECV:"ch-poly-press-recv",CH_ALL_SOUNDS_OFF_SEND:"ch-all-sounds-off-send",CH_RESET_CONTROLLERS_SEND:"ch-reset-controllers-send",CH_LOCAL_CONTROL_SEND:"ch-local-control-send",CH_ALL_NOTES_OFF_SEND:"ch-all-notes-off-send",CH_OMNI_OFF_SEND:"ch-omni-off-send",CH_OMNI_ON_SEND:"ch-omni-on-send",CH_MONO_ON_SEND:"ch-mono-on-send",CH_POLY_ON_SEND:"ch-poly-on-send",SYS_EX_SEND:"sys-ex-send",SYS_EX_RECV:"sys-ex-recv",SYS_CLOCK_RECV:"sys-clock-recv",SYS_START_RECV:"sys-start-recv",SYS_CONTINUE_RECV:"sys-continue-recv",SYS_STOP_RECV:"sys-stop-recv",SYS_MTC_RECV:"sys-mtc-recv",SYS_SONG_POS_RECV:"sys-song-pos-recv",SYS_SONG_SEL_RECV:"sys-song-sel-recv",SYS_TUNE_REQ_RECV:"sys-tune-req-recv",SYS_ACT_SENSE_RECV:"sys-act-sense-recv",SYS_RESET_RECV:"sys-reset-recv",MIDI_RAW:"midi-raw",PATCH_SAVED:"patch-saved",PATCH_LOADED:"patch-loaded",PATCH_DELETED:"patch-deleted"};class x extends b{constructor(t={}){super(),this.options={inputChannel:1,outputChannel:1,autoConnect:!0,sysex:!1,...t},this.connection=null,this.bindings=new Map,this.state={controlChange:new Map,programChange:new Map,pitchBend:new Map,monoPressure:new Map,polyPressure:new Map},this.initialized=!1,this._initNamespaces()}async init(){if(this.initialized){console.warn("MIDI Controller already initialized");return}try{this.connection=new Y({sysex:this.options.sysex}),await this.connection.requestAccess(),this.connection.on(U.DEVICE_CHANGE,async({state:t,type:s,device:e})=>{try{if(t==="connected")s==="output"?this.emit(o.DEV_OUT_CONNECTED,e):s==="input"&&this.emit(o.DEV_IN_CONNECTED,e);else if(t==="disconnected"){if(s==="output"&&e){const E=this.connection.getCurrentOutput();E&&E.id===e.id?await this._disconnectOutput():this.emit(o.DEV_OUT_DISCONNECTED,e)}if(s==="input"&&e){const E=this.connection.getCurrentInput();E&&E.id===e.id?await this._disconnectInput():this.emit(o.DEV_IN_DISCONNECTED,e)}}}catch(E){console.error("Error in device change handler:",E),this.emit(o.ERROR,E)}}),this.options.autoConnect&&await this.connection.connect(this.options.output),this.options.input!==void 0&&await this._connectInput(this.options.input),this.initialized=!0,this.emit(o.READY,this),this.options.onReady?.(this)}catch(t){throw this.emit(o.ERROR,t),this.options.onError?.(t),t}}_initNamespaces(){this.device={connect:this._connect.bind(this),disconnect:this._disconnect.bind(this),connectInput:this._connectInput.bind(this),disconnectInput:this._disconnectInput.bind(this),connectOutput:this._connectOutput.bind(this),disconnectOutput:this._disconnectOutput.bind(this),getCurrentOutput:this._getCurrentOutput.bind(this),getCurrentInput:this._getCurrentInput.bind(this),getOutputs:this._getOutputs.bind(this),getInputs:this._getInputs.bind(this)},this.channel={sendNoteOn:this._sendNoteOn.bind(this),sendNoteOff:this._sendNoteOff.bind(this),sendCC:this._sendCC.bind(this),getCC:this._getCC.bind(this),sendPC:this._sendPC.bind(this),getPC:this._getPC.bind(this),sendPitchBend:this._sendPitchBend.bind(this),getPitchBend:this._getPitchBend.bind(this),sendMonoPressure:this._sendMonoPressure.bind(this),getMonoPressure:this._getMonoPressure.bind(this),sendPolyPressure:this._sendPolyPressure.bind(this),getPolyPressure:this._getPolyPressure.bind(this),allSoundsOff:this._allSoundsOff.bind(this),resetControllers:this._resetControllers.bind(this),localControl:this._localControl.bind(this),allNotesOff:this._allNotesOff.bind(this),omniOff:this._omniOff.bind(this),omniOn:this._omniOn.bind(this),monoOn:this._monoOn.bind(this),polyOn:this._polyOn.bind(this)},this.system={sendEx:(function(t,s=!1){return this._sendSysEx(t,s)}).bind(this),sendClock:this._sendClock.bind(this),start:this._sendStart.bind(this),continue:this._sendContinue.bind(this),stop:this._sendStop.bind(this),sendMTC:this._sendMTC.bind(this),sendSongPosition:this._sendSongPosition.bind(this),sendSongSelect:this._sendSongSelect.bind(this),sendTuneRequest:this._sendTuneRequest.bind(this),sendActiveSensing:this._sendActiveSensing.bind(this),sendSystemReset:this._sendSystemReset.bind(this)},this.patch={get:this._getPatch.bind(this),set:this._setPatch.bind(this),save:this._savePatch.bind(this),load:this._loadPatch.bind(this),delete:this._deletePatch.bind(this),list:this._listPatches.bind(this)}}bind(t,s,e={}){if(!t)return console.warn("Cannot bind: element is null or undefined"),()=>{};const E=this._createBinding(t,s,e);return this.bindings.set(t,E),this.initialized&&this.connection?.isConnected()&&E.handler({target:t}),()=>this.unbind(t)}_createBinding(t,s,e={}){const{min:E=parseFloat(t.getAttribute("min"))||0,max:_=parseFloat(t.getAttribute("max"))||127,channel:i,invert:r=!1,onInput:h=void 0}=s,{debounce:S=0}=e,P={...s,min:E,max:_,invert:r,onInput:h};if(i!==void 0&&(P.channel=i),s.is14Bit){const{msb:T,lsb:I}=s,f=y=>{const z=parseFloat(y.target.value);if(Number.isNaN(z))return;const{msb:ht,lsb:Nt}=B(z,E,_,r),q=i||this.options.outputChannel;this._sendCC(T,ht,q),this._sendCC(I,Nt,q)};let K=null;const D=S>0?y=>{K&&clearTimeout(K),K=setTimeout(()=>{f(y),K=null},S)}:f;return t.addEventListener("input",D),t.addEventListener("change",D),{element:t,config:P,handler:f,destroy:()=>{K&&clearTimeout(K),t.removeEventListener("input",D),t.removeEventListener("change",D)}}}const{cc:a}=s,A=T=>{const I=parseFloat(T.target.value);if(Number.isNaN(I))return;const f=H(I,E,_,r),K=i===void 0?this.options.outputChannel:i;this._sendCC(a,f,K)};let N=null;const O=S>0?T=>{N&&clearTimeout(N),N=setTimeout(()=>{A(T),N=null},S)}:A;return t.addEventListener("input",O),t.addEventListener("change",O),{element:t,config:P,handler:A,destroy:()=>{N&&clearTimeout(N),t.removeEventListener("input",O),t.removeEventListener("change",O)}}}unbind(t){const s=this.bindings.get(t);s&&(s.destroy(),this.bindings.delete(t))}async destroy(){for(const t of this.bindings.values())t.destroy();this.bindings.clear(),this.state.controlChange.clear(),this.state.programChange.clear(),this.state.pitchBend.clear(),this.state.monoPressure.clear(),this.state.polyPressure.clear(),await this._disconnect(),this.initialized=!1,this.emit(o.DESTROYED),this.removeAllListeners()}async _connect(t){t?await this.connection.connect(t):this.options.output!==void 0?await this.connection.connect(this.options.output):this.options.autoConnect&&await this.connection.connect()}async _disconnect(){this.connection.disconnect()}async _connectInput(t){await this.connection.connectInput(t,s=>{this._handleMIDIMessage(s)}),this.emit(o.DEV_IN_CONNECTED,this.connection.getCurrentInput())}async _disconnectInput(){const t=this.connection.getCurrentInput();this.connection.disconnectInput(),this.emit(o.DEV_IN_DISCONNECTED,t)}async _connectOutput(t){await this.connection.connect(t),this.emit(o.DEV_OUT_CONNECTED,this.connection.getCurrentOutput())}async _disconnectOutput(){const t=this.connection.getCurrentOutput();this.connection.disconnectOutput(),this.emit(o.DEV_OUT_DISCONNECTED,t)}_getCurrentOutput(){return this.connection?.getCurrentOutput()||null}_getCurrentInput(){return this.connection?.getCurrentInput()||null}_getOutputs(){return this.connection?.getOutputs()||[]}_getInputs(){return this.connection?.getInputs()||[]}send(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send(t)}_sendNoteOn(t,s=64,e=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),0,127),e=c(Math.round(e),1,16);const E=144+(e-1);this.connection.send([E,t,s]),this.emit(o.CH_NOTE_ON_SEND,{note:t,velocity:s,channel:e})}_sendNoteOff(t,s=this.options.outputChannel,e=0){if(!this.initialized)return;t=c(Math.round(t),0,127),e=c(Math.round(e),0,127),s=c(Math.round(s),1,16);const E=144+(s-1);this.connection.send([E,t,e]),this.emit(o.CH_NOTE_OFF_SEND,{note:t,channel:s,velocity:e})}_sendCC(t,s,e=this.options.outputChannel){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,127),s=c(Math.round(s),0,127),e=c(Math.round(e),1,16);const E=176+(e-1);this.connection.send([E,t,s]);const _=`${e}:${t}`;this.state.controlChange.set(_,s),this.emit(o.CH_CC_SEND,{cc:t,value:s,channel:e})}_sendPC(t,s=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),1,16);const e=192+(s-1);this.connection.send([e,t]),this.state.programChange.set(s.toString(),t),this.emit(o.CH_PC_SEND,{program:t,channel:s})}_getPC(t=this.options.inputChannel){return this.state.programChange.get(t.toString())}_getCC(t,s=this.options.inputChannel){const e=`${s}:${t}`;return this.state.controlChange.get(e)}_sendPitchBend(t,s=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,16383),s=c(Math.round(s),1,16);const e=224+(s-1),E=t&127,_=t>>7&127;this.connection.send([e,E,_]),this.state.pitchBend.set(s.toString(),t),this.emit(o.CH_PITCH_BEND_SEND,{value:t,channel:s})}_getPitchBend(t=this.options.inputChannel){return this.state.pitchBend.get(t.toString())}_sendMonoPressure(t,s=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),1,16);const e=208+(s-1);this.connection.send([e,t]),this.state.monoPressure.set(s.toString(),t),this.emit(o.CH_MONO_PRESS_SEND,{pressure:t,channel:s})}_getMonoPressure(t=this.options.inputChannel){return this.state.monoPressure.get(t.toString())}_sendPolyPressure(t,s,e=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),0,127),e=c(Math.round(e),1,16);const E=160+(e-1);this.connection.send([E,t,s]);const _=`${e}:${t}`;this.state.polyPressure.set(_,s),this.emit(o.CH_POLY_PRESS_SEND,{note:t,pressure:s,channel:e})}_getPolyPressure(t,s=this.options.inputChannel){const e=`${s}:${t}`;return this.state.polyPressure.get(e)}_allSoundsOff(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,120,0]),this.emit(o.CH_ALL_SOUNDS_OFF_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,120,0])}this.emit(o.CH_ALL_SOUNDS_OFF_SEND,{channel:null})}}_resetControllers(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,121,0]),this.emit(o.CH_RESET_CONTROLLERS_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,121,0])}this.emit(o.CH_RESET_CONTROLLERS_SEND,{channel:null})}}_localControl(t,s){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}const e=t?127:0;if(s!==void 0){s=c(Math.round(s),1,16);const E=176+(s-1);this.connection.send([E,122,e]),this.emit(o.CH_LOCAL_CONTROL_SEND,{enabled:t,channel:s})}else{for(let E=1;E<=16;E++){const _=176+(E-1);this.connection.send([_,122,e])}this.emit(o.CH_LOCAL_CONTROL_SEND,{enabled:t,channel:null})}}_allNotesOff(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,123,0]),this.emit(o.CH_ALL_NOTES_OFF_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,123,0])}this.emit(o.CH_ALL_NOTES_OFF_SEND,{channel:null})}}_omniOff(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,124,0]),this.emit(o.CH_OMNI_OFF_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,124,0])}this.emit(o.CH_OMNI_OFF_SEND,{channel:null})}}_omniOn(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,125,0]),this.emit(o.CH_OMNI_ON_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,125,0])}this.emit(o.CH_OMNI_ON_SEND,{channel:null})}}_monoOn(t=1,s){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t=Math.max(0,Math.min(16,Math.round(t))),s!==void 0){s=c(Math.round(s),1,16);const e=176+(s-1);this.connection.send([e,126,t]),this.emit(o.CH_MONO_ON_SEND,{channels:t,channel:s})}else{for(let e=1;e<=16;e++){const E=176+(e-1);this.connection.send([E,126,t])}this.emit(o.CH_MONO_ON_SEND,{channels:t,channel:null})}}_polyOn(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,127,0]),this.emit(o.CH_POLY_ON_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,127,0])}this.emit(o.CH_POLY_ON_SEND,{channel:null})}}_sendSysEx(t,s=!1){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(!this.options.sysex){console.warn("SysEx not enabled. Initialize with sysex: true");return}this.connection.sendSysEx(t,s),this.emit(o.SYS_EX_SEND,{data:t,includeWrapper:s})}_sendClock(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([248])}_sendStart(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([250])}_sendContinue(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([251])}_sendStop(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([252])}_sendMTC(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,127),this.connection.send([241,t])}_sendSongPosition(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,16383);const s=t&127,e=t>>7&127;this.connection.send([242,s,e])}_sendSongSelect(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,127),this.connection.send([243,t])}_sendTuneRequest(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([246])}_sendActiveSensing(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([254])}_sendSystemReset(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([255])}_handleMIDIMessage(t){const[s,e,E]=t.data,_=s&240,i=(s&15)+1;if(s===248){this.emit(o.SYS_CLOCK_RECV,{timestamp:t.midiwire});return}if(s===250){this.emit(o.SYS_START_RECV,{timestamp:t.midiwire});return}if(s===251){this.emit(o.SYS_CONTINUE_RECV,{timestamp:t.midiwire});return}if(s===252){this.emit(o.SYS_STOP_RECV,{timestamp:t.midiwire});return}if(s===254){this.emit(o.SYS_ACT_SENSE_RECV,{timestamp:t.midiwire});return}if(s===255){this.emit(o.SYS_RESET_RECV,{timestamp:t.midiwire});return}if(s===240){this.emit(o.SYS_EX_RECV,{data:Array.from(t.data),timestamp:t.midiwire});return}if(s===241){this.emit(o.SYS_MTC_RECV,{data:e,timestamp:t.midiwire});return}if(s===242){const r=e+(E<<7);this.emit(o.SYS_SONG_POS_RECV,{position:r,timestamp:t.midiwire});return}if(s===243){this.emit(o.SYS_SONG_SEL_RECV,{song:e,timestamp:t.midiwire});return}if(s===246){this.emit(o.SYS_TUNE_REQ_RECV,{timestamp:t.midiwire});return}if(s===247){this.emit(o.MIDI_RAW,{status:s,data:[e,E],channel:i,timestamp:t.midiwire});return}if(_===176){const r=`${i}:${e}`;this.state.controlChange.set(r,E),this.emit(o.CH_CC_RECV,{cc:e,value:E,channel:i});return}if(_===192){this.state.programChange.set(i.toString(),e),this.emit(o.CH_PC_RECV,{program:e,channel:i});return}if(_===224){const r=e+(E<<7);this.state.pitchBend.set(i.toString(),r),this.emit(o.CH_PITCH_BEND_RECV,{value:r,channel:i});return}if(_===208){this.state.monoPressure.set(i.toString(),e),this.emit(o.CH_MONO_PRESS_RECV,{pressure:e,channel:i});return}if(_===160){const r=`${i}:${e}`;this.state.polyPressure.set(r,E),this.emit(o.CH_POLY_PRESS_RECV,{note:e,pressure:E,channel:i});return}if(_===144&&E>0){this.emit(o.CH_NOTE_ON_RECV,{note:e,velocity:E,channel:i});return}if(_===128||_===144&&E===0){this.emit(o.CH_NOTE_OFF_RECV,{note:e,channel:i});return}this.emit(o.MIDI_RAW,{status:s,data:[e,E],channel:i,timestamp:t.midiwire})}_getPatch(t="Unnamed Patch"){const s={name:t,device:this._getCurrentOutput()?.name||null,timestamp:new Date().toISOString(),version:"1.0",channels:{},settings:{}};for(const[e,E]of this.state.controlChange.entries()){const[_,i]=e.split(":").map(Number);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].ccs[i]=E}for(const[e,E]of this.state.programChange.entries()){const _=parseInt(e,10);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].program=E}for(const[e,E]of this.state.pitchBend.entries()){const _=parseInt(e,10);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].pitchBend=E}for(const[e,E]of this.state.monoPressure.entries()){const _=parseInt(e,10);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].monoPressure=E}for(const[e,E]of this.state.polyPressure.entries()){const[_,i]=e.split(":").map(Number),r=parseInt(_,10);s.channels[r]||(s.channels[r]={ccs:{},notes:{}}),s.channels[r].polyPressure||(s.channels[r].polyPressure={}),s.channels[r].polyPressure[i]=E}for(const[e,E]of this.bindings.entries()){const{config:_}=E;if(_.cc){const i=`cc${_.cc}`;s.settings[i]={min:_.min,max:_.max,invert:_.invert||!1,is14Bit:_.is14Bit||!1,label:e.getAttribute?.("data-midi-label")||null,elementId:e.id||null}}}return s}async _setPatch(t){if(!t||!t.channels)throw new R("Invalid patch format","patch");const s=t.version||"1.0";s==="1.0"?await this._applyPatchV1(t):(console.warn(`Unknown patch version: ${s}. Attempting to apply as v1.0`),await this._applyPatchV1(t)),this.emit(o.PATCH_LOADED,{patch:t})}async _applyPatchV1(t){for(const[s,e]of Object.entries(t.channels)){const E=parseInt(s,10);if(e.ccs)for(const[_,i]of Object.entries(e.ccs)){const r=parseInt(_,10);this._sendCC(r,i,E)}if(e.program!==void 0&&this._sendPC(e.program,E),e.pitchBend!==void 0&&this._sendPitchBend(e.pitchBend,E),e.monoPressure!==void 0&&this._sendMonoPressure(e.monoPressure,E),e.polyPressure)for(const[_,i]of Object.entries(e.polyPressure)){const r=parseInt(_,10);this._sendPolyPressure(r,i,E)}if(e.notes)for(const[_,i]of Object.entries(e.notes)){const r=parseInt(_,10);i>0?this._sendNoteOn(r,i,E):this._sendNoteOff(r,E)}}if(t.settings)for(const[s,e]of Object.entries(t.settings))for(const[E,_]of this.bindings.entries())_.config.cc?.toString()===s.replace("cc","")&&(E.min!==void 0&&e.min!==void 0&&(E.min=String(e.min)),E.max!==void 0&&e.max!==void 0&&(E.max=String(e.max)));for(const[s,e]of this.bindings.entries()){const{config:E}=e;if(E.cc!==void 0){const _=E.channel||this.options.inputChannel,i=t.channels[_];if(i?.ccs){const r=i.ccs[E.cc];if(r!==void 0){const h=E.min!==void 0?E.min:parseFloat(s.getAttribute?.("min"))||0,S=E.max!==void 0?E.max:parseFloat(s.getAttribute?.("max"))||127,P=E.invert||!1;let a;P?a=S-r/127*(S-h):a=h+r/127*(S-h),E.onInput&&typeof E.onInput=="function"?E.onInput(a):(s.value=a,s.dispatchEvent(new Event("input",{bubbles:!0})))}}}}}_savePatch(t,s=null){const e=s||this._getPatch(t),E=`midiwire_patch_${t}`;try{return localStorage.setItem(E,JSON.stringify(e)),this.emit(o.PATCH_SAVED,{name:t,patch:e}),E}catch(_){throw console.error("Failed to save patch:",_),_}}_loadPatch(t){const s=`midiwire_patch_${t}`;try{const e=localStorage.getItem(s);if(!e)return null;const E=JSON.parse(e);return this.emit(o.PATCH_LOADED,{name:t,patch:E}),E}catch(e){return console.error("Failed to load patch:",e),null}}_deletePatch(t){const s=`midiwire_patch_${t}`;try{return localStorage.removeItem(s),this.emit(o.PATCH_DELETED,{name:t}),!0}catch(e){return console.error("Failed to delete patch:",e),!1}}_listPatches(){const t=[];try{for(let s=0;s<localStorage.length;s++){const e=localStorage.key(s);if(e?.startsWith("midiwire_patch_")){const E=e.replace("midiwire_patch_",""),_=this._loadPatch(E);_&&t.push({name:E,patch:_})}}}catch(s){console.error("Failed to list patches:",s)}return t.sort((s,e)=>s.name.localeCompare(e.name))}}class ${constructor(t={}){this.midi=t.midiController||null,this.onStatusUpdate=t.onStatusUpdate||(()=>{}),this.onConnectionUpdate=t.onConnectionUpdate||(()=>{}),this.channel=t.channel||1,this.currentOutput=null,this.currentInput=null,this.isConnecting=!1}async setupSelectors(t={},s={}){if(!this.midi)throw new Error("MIDI controller not initialized. Pass midiController in constructor options.");const{output:e,input:E,channel:_}=t,i=this._resolveSelector(e),r=this._resolveSelector(E),h=this._resolveSelector(_);if(this._setupDeviceChangeListeners({output:i,input:r},s.onDeviceListChange),i){await this._populateOutputDeviceList(i);const S=s.onConnect?async(a,A)=>s.onConnect({midi:a,device:A,type:"output"}):void 0,P=s.onDisconnect?async a=>s.onDisconnect({midi:a,type:"output"}):void 0;this._connectOutputDeviceSelection(i,S,P)}if(r){await this._populateInputDeviceList(r);const S=s.onConnect?async(a,A)=>s.onConnect({midi:a,device:A,type:"input"}):void 0,P=s.onDisconnect?async a=>s.onDisconnect({midi:a,type:"input"}):void 0;this._connectInputDeviceSelection(r,S,P)}return h&&this._connectChannelSelection(h,"output"),this.midi}updateStatus(t,s=""){this.onStatusUpdate(t,s)}updateConnectionStatus(){this.onConnectionUpdate(this.currentOutput,this.currentInput,this.midi)}_setupDeviceChangeListeners(t={},s){!this.midi||this._listenersInitialized||(this._listenersInitialized=!0,this.midi.on(o.DEV_OUT_CONNECTED,async e=>{this.updateStatus(`Output device connected: ${e?.name||"Unknown"}`,"connected"),t.output&&await this._populateOutputDeviceList(t.output),s&&s()}),this.midi.on(o.DEV_OUT_DISCONNECTED,async e=>{this.updateStatus(`Output device disconnected: ${e?.name||"Unknown"}`,"error"),this.currentOutput&&e?.name===this.currentOutput.name&&(this.currentOutput=null,this.updateConnectionStatus(),t.output&&(t.output.value="")),t.output&&await this._populateOutputDeviceList(t.output),s&&s()}),this.midi.on(o.DEV_IN_CONNECTED,async e=>{this.updateStatus(`Input device connected: ${e?.name||"Unknown"}`,"connected"),t.input&&await this._populateInputDeviceList(t.input),s&&s()}),this.midi.on(o.DEV_IN_DISCONNECTED,async e=>{this.updateStatus(`Input device disconnected: ${e?.name||"Unknown"}`,"error"),t.input&&(t.input.value="",await this._populateInputDeviceList(t.input)),s&&s()}))}_resolveSelector(t){if(typeof t=="string"){const s=document.querySelector(t);return s||console.warn(`MIDIDeviceManager: Selector "${t}" not found`),s}return t||null}_getOutputDevices(){return this.midi?this.midi.device.getOutputs():[]}_getInputDevices(){return this.midi?this.midi.device.getInputs():[]}_connectOutputDeviceSelection(t,s,e){!t||!this.midi||t.addEventListener("change",async E=>{if(this.isConnecting)return;this.isConnecting=!0;const _=E.target.value;if(!_){this.currentOutput&&this.midi&&(await this.midi.device.disconnectOutput(),this.currentOutput=null,this.updateStatus("Output device disconnected",""),this.updateConnectionStatus()),this.isConnecting=!1,e&&await e(this.midi);return}try{if(await this.midi.device.connectOutput(parseInt(_,10)),this.currentOutput=this.midi.device.getCurrentOutput(),this.currentOutput){const r=this.midi.device.getOutputs().findIndex(h=>h.id===this.currentOutput.id);r!==-1&&(t.value=r.toString())}this.updateConnectionStatus(),s&&await s(this.midi,this.currentOutput)}catch(i){this.updateStatus(`Output connection failed: ${i.message}`,"error")}finally{this.isConnecting=!1}})}_connectInputDeviceSelection(t,s,e){!t||!this.midi||t.addEventListener("change",async E=>{const _=E.target.value;if(!_){this.midi&&(await this.midi.device.disconnectInput(),this.updateStatus("Input device disconnected",""),this.updateConnectionStatus()),e&&await e(this.midi);return}if(!this.isConnecting){this.isConnecting=!0;try{await this.midi.device.connectInput(parseInt(_,10));const i=this.midi.device.getCurrentInput();this.updateConnectionStatus(),s&&await s(this.midi,i)}catch(i){this.updateStatus(`Input connection failed: ${i.message}`,"error")}finally{this.isConnecting=!1}}})}_populateDeviceList(t,s,e,E,_){if(s.length>0){if(t.innerHTML='<option value="">Select a device</option>'+s.map((i,r)=>`<option value="${r}">${i.name}</option>`).join(""),e){const i=s.findIndex(r=>r.name===e.name);i!==-1?t.value=i.toString():(t.value="",_&&(this.currentOutput=null,this.updateConnectionStatus()))}else t.value="";t.disabled=!1,_&&!this.currentOutput&&this.updateStatus("Select a device")}else t.innerHTML='<option value="">No devices connected</option>',t.disabled=!0,_&&this.updateStatus("No devices connected","error");E&&E()}async _populateOutputDeviceList(t,s){if(!t||!this.midi)return;const e=this._getOutputDevices();this._populateDeviceList(t,e,this.currentOutput,s,!0)}async _populateInputDeviceList(t,s){if(!t||!this.midi)return;const e=this._getInputDevices(),E=this.midi.device.getCurrentInput();this._populateDeviceList(t,e,E,s,!1)}_connectChannelSelection(t,s){if(!t||!this.midi)return;const e=s==="input"?"inputChannel":"outputChannel";t.addEventListener("change",E=>{this.midi&&(this.midi.options[e]=parseInt(E.target.value,10),this.updateConnectionStatus())})}}class n{static PACKED_SIZE=128;static PACKED_OP_SIZE=17;static NUM_OPERATORS=6;static PACKED_OP_EG_RATE_1=0;static PACKED_OP_EG_RATE_2=1;static PACKED_OP_EG_RATE_3=2;static PACKED_OP_EG_RATE_4=3;static PACKED_OP_EG_LEVEL_1=4;static PACKED_OP_EG_LEVEL_2=5;static PACKED_OP_EG_LEVEL_3=6;static PACKED_OP_EG_LEVEL_4=7;static PACKED_OP_BREAK_POINT=8;static PACKED_OP_L_SCALE_DEPTH=9;static PACKED_OP_R_SCALE_DEPTH=10;static PACKED_OP_CURVES=11;static PACKED_OP_RATE_SCALING=12;static PACKED_OP_MOD_SENS=13;static PACKED_OP_OUTPUT_LEVEL=14;static PACKED_OP_MODE_FREQ=15;static PACKED_OP_DETUNE_FINE=16;static PACKED_PITCH_EG_RATE_1=102;static PACKED_PITCH_EG_RATE_2=103;static PACKED_PITCH_EG_RATE_3=104;static PACKED_PITCH_EG_RATE_4=105;static PACKED_PITCH_EG_LEVEL_1=106;static PACKED_PITCH_EG_LEVEL_2=107;static PACKED_PITCH_EG_LEVEL_3=108;static PACKED_PITCH_EG_LEVEL_4=109;static OFFSET_ALGORITHM=110;static OFFSET_FEEDBACK=111;static OFFSET_LFO_SPEED=112;static OFFSET_LFO_DELAY=113;static OFFSET_LFO_PM_DEPTH=114;static OFFSET_LFO_AM_DEPTH=115;static OFFSET_LFO_SYNC_WAVE=116;static OFFSET_TRANSPOSE=117;static OFFSET_AMP_MOD_SENS=118;static OFFSET_EG_BIAS_SENS=119;static PACKED_NAME_START=118;static NAME_LENGTH=10;static UNPACKED_SIZE=169;static UNPACKED_OP_SIZE=23;static UNPACKED_OP_EG_RATE_1=0;static UNPACKED_OP_EG_RATE_2=1;static UNPACKED_OP_EG_RATE_3=2;static UNPACKED_OP_EG_RATE_4=3;static UNPACKED_OP_EG_LEVEL_1=4;static UNPACKED_OP_EG_LEVEL_2=5;static UNPACKED_OP_EG_LEVEL_3=6;static UNPACKED_OP_EG_LEVEL_4=7;static UNPACKED_OP_BREAK_POINT=8;static UNPACKED_OP_L_SCALE_DEPTH=9;static UNPACKED_OP_R_SCALE_DEPTH=10;static UNPACKED_OP_L_CURVE=11;static UNPACKED_OP_R_CURVE=12;static UNPACKED_OP_RATE_SCALING=13;static UNPACKED_OP_DETUNE=14;static UNPACKED_OP_AMP_MOD_SENS=15;static UNPACKED_OP_OUTPUT_LEVEL=16;static UNPACKED_OP_MODE=17;static UNPACKED_OP_KEY_VEL_SENS=18;static UNPACKED_OP_FREQ_COARSE=19;static UNPACKED_OP_OSC_DETUNE=20;static UNPACKED_OP_FREQ_FINE=21;static UNPACKED_PITCH_EG_RATE_1=138;static UNPACKED_PITCH_EG_RATE_2=139;static UNPACKED_PITCH_EG_RATE_3=140;static UNPACKED_PITCH_EG_RATE_4=141;static UNPACKED_PITCH_EG_LEVEL_1=142;static UNPACKED_PITCH_EG_LEVEL_2=143;static UNPACKED_PITCH_EG_LEVEL_3=144;static UNPACKED_PITCH_EG_LEVEL_4=145;static UNPACKED_ALGORITHM=146;static UNPACKED_FEEDBACK=147;static UNPACKED_OSC_SYNC=148;static UNPACKED_LFO_SPEED=149;static UNPACKED_LFO_DELAY=150;static UNPACKED_LFO_PM_DEPTH=151;static UNPACKED_LFO_AM_DEPTH=152;static UNPACKED_LFO_KEY_SYNC=153;static UNPACKED_LFO_WAVE=154;static UNPACKED_LFO_PM_SENS=155;static UNPACKED_AMP_MOD_SENS=156;static UNPACKED_TRANSPOSE=157;static UNPACKED_EG_BIAS_SENS=158;static UNPACKED_NAME_START=159;static VCED_SIZE=163;static VCED_HEADER_SIZE=6;static VCED_DATA_SIZE=155;static VCED_SYSEX_START=240;static VCED_YAMAHA_ID=67;static VCED_SUB_STATUS=0;static VCED_FORMAT_SINGLE=0;static VCED_BYTE_COUNT_MSB=1;static VCED_BYTE_COUNT_LSB=27;static VCED_SYSEX_END=247;static MASK_7BIT=127;static MASK_2BIT=3;static MASK_3BIT=7;static MASK_4BIT=15;static MASK_5BIT=31;static MASK_1BIT=1;static TRANSPOSE_CENTER=24;static CHAR_YEN=92;static CHAR_ARROW_RIGHT=126;static CHAR_ARROW_LEFT=127;static CHAR_REPLACEMENT_Y=89;static CHAR_REPLACEMENT_GT=62;static CHAR_REPLACEMENT_LT=60;static CHAR_SPACE=32;static CHAR_MIN_PRINTABLE=32;static CHAR_MAX_PRINTABLE=126;static DEFAULT_EG_RATE=99;static DEFAULT_EG_LEVEL_MAX=99;static DEFAULT_EG_LEVEL_MIN=0;static DEFAULT_BREAK_POINT=0;static DEFAULT_OUTPUT_LEVEL=99;static DEFAULT_PITCH_EG_LEVEL=50;static DEFAULT_LFO_SPEED=35;static DEFAULT_LFO_PM_SENS=3;static DEFAULT_DETUNE=7;static DEFAULT_FREQ_COARSE=1;static DEFAULT_ALGORITHM=0;static DEFAULT_FEEDBACK=0;static MIDI_OCTAVE_OFFSET=-2;static MIDI_BREAK_POINT_OFFSET=21;constructor(t,s=0){if(t.length!==n.PACKED_SIZE)throw new d(`Invalid voice data length: expected ${n.PACKED_SIZE} bytes, got ${t.length}`,"length",t.length);this.index=s,this.data=new Uint8Array(t),this.name=this._extractName(),this._unpackedCache=null}_extractName(){const t=this.data.subarray(n.PACKED_NAME_START,n.PACKED_NAME_START+n.NAME_LENGTH);return Array.from(t).map(e=>{let E=e&n.MASK_7BIT;return E===n.CHAR_YEN&&(E=n.CHAR_REPLACEMENT_Y),E===n.CHAR_ARROW_RIGHT&&(E=n.CHAR_REPLACEMENT_GT),E===n.CHAR_ARROW_LEFT&&(E=n.CHAR_REPLACEMENT_LT),(E<n.CHAR_MIN_PRINTABLE||E>n.CHAR_MAX_PRINTABLE)&&(E=n.CHAR_SPACE),String.fromCharCode(E)}).join("").trim()}getParameter(t){if(t<0||t>=n.PACKED_SIZE)throw new d(`Parameter offset out of range: ${t} (must be 0-${n.PACKED_SIZE-1})`,"offset",t);return this.data[t]&n.MASK_7BIT}getUnpackedParameter(t){if(t<0||t>=n.UNPACKED_SIZE)throw new d(`Unpacked parameter offset out of range: ${t} (must be 0-${n.UNPACKED_SIZE-1})`,"offset",t);return this._unpackedCache||(this._unpackedCache=this.unpack()),this._unpackedCache[t]&n.MASK_7BIT}setParameter(t,s){if(t<0||t>=n.PACKED_SIZE)throw new d(`Parameter offset out of range: ${t} (must be 0-${n.PACKED_SIZE-1})`,"offset",t);this.data[t]=s&n.MASK_7BIT,this._unpackedCache=null,t>=n.PACKED_NAME_START&&t<n.PACKED_NAME_START+n.NAME_LENGTH&&(this.name=this._extractName())}unpack(){const t=this.data,s=new Uint8Array(n.UNPACKED_SIZE);return this._unpackOperators(t,s),this._unpackPitchEG(t,s),this._unpackGlobalParams(t,s),this._unpackName(t,s),s}_unpackOperators(t,s){for(let e=0;e<n.NUM_OPERATORS;e++){const E=(n.NUM_OPERATORS-1-e)*n.PACKED_OP_SIZE,_=e*n.UNPACKED_OP_SIZE;this._unpackOperator(t,s,E,_)}}_unpackOperator(t,s,e,E){this._unpackOperatorEG(t,s,e,E),this._unpackOperatorScaling(t,s,e,E),this._unpackOperatorPackedParams(t,s,e,E),this._unpackOperatorFrequency(t,s,e,E)}_unpackOperatorEG(t,s,e,E){s[E+n.UNPACKED_OP_EG_RATE_1]=t[e+n.PACKED_OP_EG_RATE_1]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_RATE_2]=t[e+n.PACKED_OP_EG_RATE_2]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_RATE_3]=t[e+n.PACKED_OP_EG_RATE_3]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_RATE_4]=t[e+n.PACKED_OP_EG_RATE_4]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_1]=t[e+n.PACKED_OP_EG_LEVEL_1]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_2]=t[e+n.PACKED_OP_EG_LEVEL_2]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_3]=t[e+n.PACKED_OP_EG_LEVEL_3]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_4]=t[e+n.PACKED_OP_EG_LEVEL_4]&n.MASK_7BIT}_unpackOperatorScaling(t,s,e,E){s[E+n.UNPACKED_OP_BREAK_POINT]=t[e+n.PACKED_OP_BREAK_POINT]&n.MASK_7BIT,s[E+n.UNPACKED_OP_L_SCALE_DEPTH]=t[e+n.PACKED_OP_L_SCALE_DEPTH]&n.MASK_7BIT,s[E+n.UNPACKED_OP_R_SCALE_DEPTH]=t[e+n.PACKED_OP_R_SCALE_DEPTH]&n.MASK_7BIT}_unpackOperatorPackedParams(t,s,e,E){const _=t[e+n.PACKED_OP_CURVES]&n.MASK_7BIT;s[E+n.UNPACKED_OP_L_CURVE]=_&n.MASK_2BIT,s[E+n.UNPACKED_OP_R_CURVE]=_>>2&n.MASK_2BIT;const i=t[e+n.PACKED_OP_RATE_SCALING]&n.MASK_7BIT;s[E+n.UNPACKED_OP_RATE_SCALING]=i&n.MASK_3BIT,s[E+n.UNPACKED_OP_DETUNE]=i>>3&n.MASK_4BIT;const r=t[e+n.PACKED_OP_MOD_SENS]&n.MASK_7BIT;s[E+n.UNPACKED_OP_AMP_MOD_SENS]=r&n.MASK_2BIT,s[E+n.UNPACKED_OP_KEY_VEL_SENS]=r>>2&n.MASK_3BIT,s[E+n.UNPACKED_OP_OUTPUT_LEVEL]=t[e+n.PACKED_OP_OUTPUT_LEVEL]&n.MASK_7BIT}_unpackOperatorFrequency(t,s,e,E){const _=t[e+n.PACKED_OP_MODE_FREQ]&n.MASK_7BIT;s[E+n.UNPACKED_OP_MODE]=_&n.MASK_1BIT,s[E+n.UNPACKED_OP_FREQ_COARSE]=_>>1&n.MASK_5BIT;const i=t[e+n.PACKED_OP_DETUNE_FINE]&n.MASK_7BIT;s[E+n.UNPACKED_OP_OSC_DETUNE]=i&n.MASK_3BIT,s[E+n.UNPACKED_OP_FREQ_FINE]=i>>3&n.MASK_4BIT}_unpackPitchEG(t,s){s[n.UNPACKED_PITCH_EG_RATE_1]=t[n.PACKED_PITCH_EG_RATE_1]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_RATE_2]=t[n.PACKED_PITCH_EG_RATE_2]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_RATE_3]=t[n.PACKED_PITCH_EG_RATE_3]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_RATE_4]=t[n.PACKED_PITCH_EG_RATE_4]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_1]=t[n.PACKED_PITCH_EG_LEVEL_1]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_2]=t[n.PACKED_PITCH_EG_LEVEL_2]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_3]=t[n.PACKED_PITCH_EG_LEVEL_3]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_4]=t[n.PACKED_PITCH_EG_LEVEL_4]&n.MASK_7BIT}_unpackGlobalParams(t,s){s[n.UNPACKED_ALGORITHM]=t[n.OFFSET_ALGORITHM]&n.MASK_5BIT;const e=t[n.OFFSET_FEEDBACK]&n.MASK_7BIT;s[n.UNPACKED_FEEDBACK]=e&n.MASK_3BIT,s[n.UNPACKED_OSC_SYNC]=e>>3&n.MASK_1BIT,s[n.UNPACKED_LFO_SPEED]=t[n.OFFSET_LFO_SPEED]&n.MASK_7BIT,s[n.UNPACKED_LFO_DELAY]=t[n.OFFSET_LFO_DELAY]&n.MASK_7BIT,s[n.UNPACKED_LFO_PM_DEPTH]=t[n.OFFSET_LFO_PM_DEPTH]&n.MASK_7BIT,s[n.UNPACKED_LFO_AM_DEPTH]=t[n.OFFSET_LFO_AM_DEPTH]&n.MASK_7BIT;const E=t[n.OFFSET_LFO_SYNC_WAVE]&n.MASK_7BIT;s[n.UNPACKED_LFO_KEY_SYNC]=E&n.MASK_1BIT,s[n.UNPACKED_LFO_WAVE]=E>>1&n.MASK_3BIT,s[n.UNPACKED_LFO_PM_SENS]=E>>4&n.MASK_3BIT,s[n.UNPACKED_AMP_MOD_SENS]=t[n.OFFSET_AMP_MOD_SENS]&n.MASK_7BIT,s[n.UNPACKED_TRANSPOSE]=t[n.OFFSET_TRANSPOSE]&n.MASK_7BIT,s[n.UNPACKED_EG_BIAS_SENS]=t[n.OFFSET_EG_BIAS_SENS]&n.MASK_7BIT}_unpackName(t,s){for(let e=0;e<n.NAME_LENGTH;e++)s[n.UNPACKED_NAME_START+e]=t[n.PACKED_NAME_START+e]&n.MASK_7BIT}static pack(t){if(t.length!==n.UNPACKED_SIZE)throw new d(`Invalid unpacked data length: expected ${n.UNPACKED_SIZE} bytes, got ${t.length}`,"length",t.length);const s=new Uint8Array(n.PACKED_SIZE);return n._packOperators(t,s),n._packPitchEG(t,s),n._packGlobalParams(t,s),n._packName(t,s),s}static _packOperators(t,s){for(let e=0;e<n.NUM_OPERATORS;e++){const E=e*n.UNPACKED_OP_SIZE,_=(n.NUM_OPERATORS-1-e)*n.PACKED_OP_SIZE;n._packOperator(t,s,E,_)}}static _packOperator(t,s,e,E){n._packOperatorEG(t,s,e,E),n._packOperatorScaling(t,s,e,E),n._packOperatorPackedParams(t,s,e,E),n._packOperatorFrequency(t,s,e,E)}static _packOperatorEG(t,s,e,E){s[E+n.PACKED_OP_EG_RATE_1]=t[e+n.UNPACKED_OP_EG_RATE_1],s[E+n.PACKED_OP_EG_RATE_2]=t[e+n.UNPACKED_OP_EG_RATE_2],s[E+n.PACKED_OP_EG_RATE_3]=t[e+n.UNPACKED_OP_EG_RATE_3],s[E+n.PACKED_OP_EG_RATE_4]=t[e+n.UNPACKED_OP_EG_RATE_4],s[E+n.PACKED_OP_EG_LEVEL_1]=t[e+n.UNPACKED_OP_EG_LEVEL_1],s[E+n.PACKED_OP_EG_LEVEL_2]=t[e+n.UNPACKED_OP_EG_LEVEL_2],s[E+n.PACKED_OP_EG_LEVEL_3]=t[e+n.UNPACKED_OP_EG_LEVEL_3],s[E+n.PACKED_OP_EG_LEVEL_4]=t[e+n.UNPACKED_OP_EG_LEVEL_4]}static _packOperatorScaling(t,s,e,E){s[E+n.PACKED_OP_BREAK_POINT]=t[e+n.UNPACKED_OP_BREAK_POINT],s[E+n.PACKED_OP_L_SCALE_DEPTH]=t[e+n.UNPACKED_OP_L_SCALE_DEPTH],s[E+n.PACKED_OP_R_SCALE_DEPTH]=t[e+n.UNPACKED_OP_R_SCALE_DEPTH]}static _packOperatorPackedParams(t,s,e,E){const _=t[e+n.UNPACKED_OP_L_CURVE]&n.MASK_2BIT,i=t[e+n.UNPACKED_OP_R_CURVE]&n.MASK_2BIT;s[E+n.PACKED_OP_CURVES]=_|i<<2;const r=t[e+n.UNPACKED_OP_RATE_SCALING]&n.MASK_3BIT,h=t[e+n.UNPACKED_OP_DETUNE]&n.MASK_4BIT;s[E+n.PACKED_OP_RATE_SCALING]=r|h<<3;const S=t[e+n.UNPACKED_OP_AMP_MOD_SENS]&n.MASK_2BIT,P=t[e+n.UNPACKED_OP_KEY_VEL_SENS]&n.MASK_3BIT;s[E+n.PACKED_OP_MOD_SENS]=S|P<<2,s[E+n.PACKED_OP_OUTPUT_LEVEL]=t[e+n.UNPACKED_OP_OUTPUT_LEVEL]}static _packOperatorFrequency(t,s,e,E){const _=t[e+n.UNPACKED_OP_MODE]&n.MASK_1BIT,i=t[e+n.UNPACKED_OP_FREQ_COARSE]&n.MASK_5BIT;s[E+n.PACKED_OP_MODE_FREQ]=_|i<<1;const r=t[e+n.UNPACKED_OP_OSC_DETUNE]&n.MASK_3BIT,h=t[e+n.UNPACKED_OP_FREQ_FINE]&n.MASK_4BIT;s[E+n.PACKED_OP_DETUNE_FINE]=r|h<<3}static _packPitchEG(t,s){s[n.PACKED_PITCH_EG_RATE_1]=t[n.UNPACKED_PITCH_EG_RATE_1],s[n.PACKED_PITCH_EG_RATE_2]=t[n.UNPACKED_PITCH_EG_RATE_2],s[n.PACKED_PITCH_EG_RATE_3]=t[n.UNPACKED_PITCH_EG_RATE_3],s[n.PACKED_PITCH_EG_RATE_4]=t[n.UNPACKED_PITCH_EG_RATE_4],s[n.PACKED_PITCH_EG_LEVEL_1]=t[n.UNPACKED_PITCH_EG_LEVEL_1],s[n.PACKED_PITCH_EG_LEVEL_2]=t[n.UNPACKED_PITCH_EG_LEVEL_2],s[n.PACKED_PITCH_EG_LEVEL_3]=t[n.UNPACKED_PITCH_EG_LEVEL_3],s[n.PACKED_PITCH_EG_LEVEL_4]=t[n.UNPACKED_PITCH_EG_LEVEL_4]}static _packGlobalParams(t,s){s[n.OFFSET_ALGORITHM]=t[n.UNPACKED_ALGORITHM];const e=t[n.UNPACKED_FEEDBACK]&n.MASK_3BIT,E=t[n.UNPACKED_OSC_SYNC]&n.MASK_1BIT;s[n.OFFSET_FEEDBACK]=e|E<<3,s[n.OFFSET_LFO_SPEED]=t[n.UNPACKED_LFO_SPEED],s[n.OFFSET_LFO_DELAY]=t[n.UNPACKED_LFO_DELAY],s[n.OFFSET_LFO_PM_DEPTH]=t[n.UNPACKED_LFO_PM_DEPTH],s[n.OFFSET_LFO_AM_DEPTH]=t[n.UNPACKED_LFO_AM_DEPTH];const _=t[n.UNPACKED_LFO_KEY_SYNC]&n.MASK_1BIT,i=t[n.UNPACKED_LFO_WAVE]&n.MASK_3BIT,r=t[n.UNPACKED_LFO_PM_SENS]&n.MASK_3BIT;s[n.OFFSET_LFO_SYNC_WAVE]=_|i<<1|r<<4,s[n.OFFSET_AMP_MOD_SENS]=t[n.UNPACKED_AMP_MOD_SENS],s[n.OFFSET_TRANSPOSE]=t[n.UNPACKED_TRANSPOSE],s[n.OFFSET_EG_BIAS_SENS]=t[n.UNPACKED_EG_BIAS_SENS]}static _packName(t,s){for(let e=0;e<n.NAME_LENGTH;e++)s[n.PACKED_NAME_START+e]=t[n.UNPACKED_NAME_START+e]}static createDefault(t=0){const s=new Uint8Array(n.UNPACKED_SIZE);for(let _=0;_<n.NUM_OPERATORS;_++){const i=_*n.UNPACKED_OP_SIZE;s[i+n.UNPACKED_OP_EG_RATE_1]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_RATE_2]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_RATE_3]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_RATE_4]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_LEVEL_1]=n.DEFAULT_EG_LEVEL_MAX,s[i+n.UNPACKED_OP_EG_LEVEL_2]=n.DEFAULT_EG_LEVEL_MAX,s[i+n.UNPACKED_OP_EG_LEVEL_3]=n.DEFAULT_EG_LEVEL_MAX,s[i+n.UNPACKED_OP_EG_LEVEL_4]=n.DEFAULT_EG_LEVEL_MIN,s[i+n.UNPACKED_OP_BREAK_POINT]=n.DEFAULT_BREAK_POINT,s[i+n.UNPACKED_OP_L_SCALE_DEPTH]=0,s[i+n.UNPACKED_OP_R_SCALE_DEPTH]=0,s[i+n.UNPACKED_OP_L_CURVE]=0,s[i+n.UNPACKED_OP_R_CURVE]=0,s[i+n.UNPACKED_OP_RATE_SCALING]=0,s[i+n.UNPACKED_OP_DETUNE]=n.DEFAULT_DETUNE,s[i+n.UNPACKED_OP_AMP_MOD_SENS]=0,s[i+n.UNPACKED_OP_KEY_VEL_SENS]=0,s[i+n.UNPACKED_OP_OUTPUT_LEVEL]=n.DEFAULT_OUTPUT_LEVEL,s[i+n.UNPACKED_OP_MODE]=0,s[i+n.UNPACKED_OP_FREQ_COARSE]=n.DEFAULT_FREQ_COARSE,s[i+n.UNPACKED_OP_OSC_DETUNE]=0,s[i+n.UNPACKED_OP_FREQ_FINE]=0}s[n.UNPACKED_PITCH_EG_RATE_1]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_RATE_2]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_RATE_3]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_RATE_4]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_LEVEL_1]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_PITCH_EG_LEVEL_2]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_PITCH_EG_LEVEL_3]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_PITCH_EG_LEVEL_4]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_ALGORITHM]=n.DEFAULT_ALGORITHM,s[n.UNPACKED_FEEDBACK]=n.DEFAULT_FEEDBACK,s[n.UNPACKED_OSC_SYNC]=0,s[n.UNPACKED_LFO_SPEED]=n.DEFAULT_LFO_SPEED,s[n.UNPACKED_LFO_DELAY]=0,s[n.UNPACKED_LFO_PM_DEPTH]=0,s[n.UNPACKED_LFO_AM_DEPTH]=0,s[n.UNPACKED_LFO_KEY_SYNC]=0,s[n.UNPACKED_LFO_WAVE]=0,s[n.UNPACKED_LFO_PM_SENS]=n.DEFAULT_LFO_PM_SENS,s[n.UNPACKED_AMP_MOD_SENS]=0,s[n.UNPACKED_TRANSPOSE]=n.TRANSPOSE_CENTER,s[n.UNPACKED_EG_BIAS_SENS]=0;const e="Init Voice";for(let _=0;_<n.NAME_LENGTH;_++)s[n.UNPACKED_NAME_START+_]=_<e.length?e.charCodeAt(_):n.CHAR_SPACE;const E=n.pack(s);return new n(E,t)}static fromUnpacked(t,s=0){const e=n.pack(t);return new n(e,s)}static async fromFile(t){return new Promise((s,e)=>{const E=new FileReader;E.onload=_=>{try{const i=new Uint8Array(_.target.result);if(i[0]!==n.VCED_SYSEX_START||i[1]!==n.VCED_YAMAHA_ID||i[2]!==n.VCED_SUB_STATUS||i[3]!==n.VCED_FORMAT_SINGLE||i[4]!==n.VCED_BYTE_COUNT_MSB||i[5]!==n.VCED_BYTE_COUNT_LSB)throw new M("Invalid VCED header","header",0);const r=i.subarray(n.VCED_HEADER_SIZE,n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE),h=i[n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE],S=u._calculateChecksum(r,n.VCED_DATA_SIZE);h!==S&&console.warn(`DX7 VCED checksum mismatch (expected ${S.toString(16)}, got ${h.toString(16)}). This is common with vintage SysEx files.`);const P=new Uint8Array(n.UNPACKED_SIZE);let a=0;for(let N=0;N<n.NUM_OPERATORS;N++){const O=(n.NUM_OPERATORS-1-N)*n.UNPACKED_OP_SIZE;P[O+n.UNPACKED_OP_EG_RATE_1]=r[a++],P[O+n.UNPACKED_OP_EG_RATE_2]=r[a++],P[O+n.UNPACKED_OP_EG_RATE_3]=r[a++],P[O+n.UNPACKED_OP_EG_RATE_4]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_1]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_2]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_3]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_4]=r[a++],P[O+n.UNPACKED_OP_BREAK_POINT]=r[a++],P[O+n.UNPACKED_OP_L_SCALE_DEPTH]=r[a++],P[O+n.UNPACKED_OP_R_SCALE_DEPTH]=r[a++],P[O+n.UNPACKED_OP_L_CURVE]=r[a++],P[O+n.UNPACKED_OP_R_CURVE]=r[a++],P[O+n.UNPACKED_OP_RATE_SCALING]=r[a++],P[O+n.UNPACKED_OP_DETUNE]=r[a++];const T=r[a++];P[O+n.UNPACKED_OP_AMP_MOD_SENS]=T&n.MASK_2BIT,P[O+n.UNPACKED_OP_KEY_VEL_SENS]=T>>2&n.MASK_3BIT,P[O+n.UNPACKED_OP_OUTPUT_LEVEL]=r[a++],P[O+n.UNPACKED_OP_MODE]=r[a++],P[O+n.UNPACKED_OP_FREQ_COARSE]=r[a++],P[O+n.UNPACKED_OP_FREQ_FINE]=r[a++],P[O+n.UNPACKED_OP_OSC_DETUNE]=r[a++]}P[n.UNPACKED_PITCH_EG_RATE_1]=r[a++],P[n.UNPACKED_PITCH_EG_RATE_2]=r[a++],P[n.UNPACKED_PITCH_EG_RATE_3]=r[a++],P[n.UNPACKED_PITCH_EG_RATE_4]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_1]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_2]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_3]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_4]=r[a++],P[n.UNPACKED_ALGORITHM]=r[a++],P[n.UNPACKED_FEEDBACK]=r[a++],P[n.UNPACKED_OSC_SYNC]=r[a++],P[n.UNPACKED_LFO_SPEED]=r[a++],P[n.UNPACKED_LFO_DELAY]=r[a++],P[n.UNPACKED_LFO_PM_DEPTH]=r[a++],P[n.UNPACKED_LFO_AM_DEPTH]=r[a++],P[n.UNPACKED_LFO_KEY_SYNC]=r[a++],P[n.UNPACKED_LFO_WAVE]=r[a++],P[n.UNPACKED_LFO_PM_SENS]=r[a++],P[n.UNPACKED_TRANSPOSE]=r[a++];for(let N=0;N<n.NAME_LENGTH;N++)P[n.UNPACKED_NAME_START+N]=r[a++];const A=n.pack(P);s(new n(A,0))}catch(i){e(i)}},E.onerror=()=>e(new Error("Failed to read file")),E.readAsArrayBuffer(t)})}static fromSysEx(t,s=0){const e=t instanceof Uint8Array?t:new Uint8Array(t);let E;if(e[0]===n.VCED_SYSEX_START){if(e[0]!==n.VCED_SYSEX_START||e[1]!==n.VCED_YAMAHA_ID||e[2]!==n.VCED_SUB_STATUS||e[3]!==n.VCED_FORMAT_SINGLE||e[4]!==n.VCED_BYTE_COUNT_MSB||e[5]!==n.VCED_BYTE_COUNT_LSB)throw new M("Invalid VCED header","header",0);E=e.subarray(n.VCED_HEADER_SIZE,n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE)}else if(e.length===n.PACKED_SIZE)E=e;else throw new d(`Invalid data length: expected ${n.PACKED_SIZE} or ${n.VCED_SIZE} bytes, got ${e.length}`,"length",e.length);if(E.length!==n.VCED_DATA_SIZE&&E.length!==n.PACKED_SIZE)throw new d(`Invalid voice data length: expected ${n.VCED_DATA_SIZE} or ${n.PACKED_SIZE} bytes, got ${E.length}`,"length",E.length);if(E.length===n.VCED_DATA_SIZE){const _=new Uint8Array(n.UNPACKED_SIZE);let i=0;for(let h=0;h<n.NUM_OPERATORS;h++){const S=(n.NUM_OPERATORS-1-h)*n.UNPACKED_OP_SIZE;_[S+n.UNPACKED_OP_EG_RATE_1]=E[i++],_[S+n.UNPACKED_OP_EG_RATE_2]=E[i++],_[S+n.UNPACKED_OP_EG_RATE_3]=E[i++],_[S+n.UNPACKED_OP_EG_RATE_4]=E[i++],_[S+n.UNPACKED_OP_EG_LEVEL_1]=E[i++],_[S+n.UNPACKED_OP_EG_LEVEL_2]=E[i++],_[S+n.UNPACKED_OP_EG_LEVEL_3]=E[i++],_[S+n.UNPACKED_OP_EG_LEVEL_4]=E[i++],_[S+n.UNPACKED_OP_BREAK_POINT]=E[i++],_[S+n.UNPACKED_OP_L_SCALE_DEPTH]=E[i++],_[S+n.UNPACKED_OP_R_SCALE_DEPTH]=E[i++],_[S+n.UNPACKED_OP_L_CURVE]=E[i++],_[S+n.UNPACKED_OP_R_CURVE]=E[i++],_[S+n.UNPACKED_OP_RATE_SCALING]=E[i++],_[S+n.UNPACKED_OP_DETUNE]=E[i++];const P=E[i++];_[S+n.UNPACKED_OP_AMP_MOD_SENS]=P&n.MASK_2BIT,_[S+n.UNPACKED_OP_KEY_VEL_SENS]=P>>2&n.MASK_3BIT,_[S+n.UNPACKED_OP_OUTPUT_LEVEL]=E[i++],_[S+n.UNPACKED_OP_MODE]=E[i++],_[S+n.UNPACKED_OP_FREQ_COARSE]=E[i++],_[S+n.UNPACKED_OP_FREQ_FINE]=E[i++],_[S+n.UNPACKED_OP_OSC_DETUNE]=E[i++]}_[n.UNPACKED_PITCH_EG_RATE_1]=E[i++],_[n.UNPACKED_PITCH_EG_RATE_2]=E[i++],_[n.UNPACKED_PITCH_EG_RATE_3]=E[i++],_[n.UNPACKED_PITCH_EG_RATE_4]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_1]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_2]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_3]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_4]=E[i++],_[n.UNPACKED_ALGORITHM]=E[i++],_[n.UNPACKED_FEEDBACK]=E[i++],_[n.UNPACKED_OSC_SYNC]=E[i++],_[n.UNPACKED_LFO_SPEED]=E[i++],_[n.UNPACKED_LFO_DELAY]=E[i++],_[n.UNPACKED_LFO_PM_DEPTH]=E[i++],_[n.UNPACKED_LFO_AM_DEPTH]=E[i++],_[n.UNPACKED_LFO_KEY_SYNC]=E[i++],_[n.UNPACKED_LFO_WAVE]=E[i++],_[n.UNPACKED_LFO_PM_SENS]=E[i++],_[n.UNPACKED_TRANSPOSE]=E[i++];for(let h=0;h<n.NAME_LENGTH;h++)_[n.UNPACKED_NAME_START+h]=E[i++];const r=n.pack(_);return new n(r,s)}return new n(E,s)}static fromJSON(t,s=0){if(!t||typeof t!="object")throw new d("Invalid JSON: expected object","json",t);const e=new Uint8Array(n.UNPACKED_SIZE),E=(a,A,N,O=0,T=127)=>{if(A==null)throw new d(`Missing required parameter: ${N}`,N,A);const I=Number(A);if(Number.isNaN(I))throw new d(`Invalid parameter value for ${N}: ${A}`,N,A);if(I<O||I>T)throw new d(`Parameter ${N} out of range: ${I} (must be ${O}-${T})`,N,I);e[a]=Math.floor(I)},_=a=>{const A={"-LN":0,"-EX":1,"+EX":2,"+LN":3};return A[a]!==void 0?A[a]:0},i=a=>{const A={TRIANGLE:0,"SAW DOWN":1,"SAW UP":2,SQUARE:3,SINE:4,"SAMPLE & HOLD":5};return A[a]!==void 0?A[a]:0},r=a=>{if(!a||typeof a!="string")return 60;const A=a.trim().match(/^([A-G]#?)(-?\d+)$/);if(!A)return 60;const[,N,O]=A,T=parseInt(O,10),f={C:0,"C#":1,D:2,"D#":3,E:4,F:5,"F#":6,G:7,"G#":8,A:9,"A#":10,B:11}[N.toUpperCase()];return f===void 0?60:(T-n.MIDI_OCTAVE_OFFSET)*12+f};if(!Array.isArray(t.operators))throw new d("Invalid operators array: expected array","operators",t.operators);for(let a=0;a<t.operators.length;a++){const A=t.operators[a];if(!A||typeof A!="object")throw new d(`Invalid operator data at index ${a}`,`operators[${a}]`,A);if(!A.eg||!Array.isArray(A.eg.rates)||A.eg.rates.length!==4)throw new d(`Invalid EG rates for operator ${a}`,`operators[${a}].eg.rates`,A.eg?.rates);if(!A.eg||!Array.isArray(A.eg.levels)||A.eg.levels.length!==4)throw new d(`Invalid EG levels for operator ${a}`,`operators[${a}].eg.levels`,A.eg?.levels)}if(t.operators.length!==n.NUM_OPERATORS)throw new d(`Invalid operators array: expected ${n.NUM_OPERATORS} operators`,"operators",t.operators);for(let a=0;a<n.NUM_OPERATORS;a++){const A=t.operators[a],N=a*n.UNPACKED_OP_SIZE;if(!A.eg||!Array.isArray(A.eg.rates)||A.eg.rates.length!==4)throw new d(`Invalid EG rates for operator ${a}`,`operators[${a}].eg.rates`,A.eg?.rates);if(E(N+n.UNPACKED_OP_EG_RATE_1,A.eg.rates[0],`operators[${a}].eg.rates[0]`,0,99),E(N+n.UNPACKED_OP_EG_RATE_2,A.eg.rates[1],`operators[${a}].eg.rates[1]`,0,99),E(N+n.UNPACKED_OP_EG_RATE_3,A.eg.rates[2],`operators[${a}].eg.rates[2]`,0,99),E(N+n.UNPACKED_OP_EG_RATE_4,A.eg.rates[3],`operators[${a}].eg.rates[3]`,0,99),!A.eg||!Array.isArray(A.eg.levels)||A.eg.levels.length!==4)throw new d(`Invalid EG levels for operator ${a}`,`operators[${a}].eg.levels`,A.eg?.levels);E(N+n.UNPACKED_OP_EG_LEVEL_1,A.eg.levels[0],`operators[${a}].eg.levels[0]`,0,99),E(N+n.UNPACKED_OP_EG_LEVEL_2,A.eg.levels[1],`operators[${a}].eg.levels[1]`,0,99),E(N+n.UNPACKED_OP_EG_LEVEL_3,A.eg.levels[2],`operators[${a}].eg.levels[2]`,0,99),E(N+n.UNPACKED_OP_EG_LEVEL_4,A.eg.levels[3],`operators[${a}].eg.levels[3]`,0,99);const O=r(A.key?.breakPoint)-n.MIDI_BREAK_POINT_OFFSET;E(N+n.UNPACKED_OP_BREAK_POINT,O,`operators[${a}].key.breakPoint`,0,127),E(N+n.UNPACKED_OP_L_SCALE_DEPTH,A.scale?.left?.depth||0,`operators[${a}].scale.left.depth`,0,99),E(N+n.UNPACKED_OP_R_SCALE_DEPTH,A.scale?.right?.depth||0,`operators[${a}].scale.right.depth`,0,99),e[N+n.UNPACKED_OP_L_CURVE]=_(A.scale?.left?.curve||"-LN"),e[N+n.UNPACKED_OP_R_CURVE]=_(A.scale?.right?.curve||"-LN"),E(N+n.UNPACKED_OP_RATE_SCALING,A.key?.scaling||0,`operators[${a}].key.scaling`,0,7);const T=Number(A.osc?.detune)||0;E(N+n.UNPACKED_OP_DETUNE,T+7,`operators[${a}].osc.detune`,0,14),E(N+n.UNPACKED_OP_AMP_MOD_SENS,A.output?.ampModSens||0,`operators[${a}].output.ampModSens`,0,3),E(N+n.UNPACKED_OP_OUTPUT_LEVEL,A.output?.level||0,`operators[${a}].output.level`,0,99);const I=A.osc?.freq?.mode?.toUpperCase()==="FIXED"?1:0,f=Number(A.osc?.freq?.coarse)||0,K=Number(A.osc?.freq?.fine)||0;e[N+n.UNPACKED_OP_MODE]=I,E(N+n.UNPACKED_OP_FREQ_COARSE,f,`operators[${a}].osc.freq.coarse`,0,31),E(N+n.UNPACKED_OP_FREQ_FINE,K,`operators[${a}].osc.freq.fine`,0,15),E(N+n.UNPACKED_OP_KEY_VEL_SENS,A.key?.velocity||0,`operators[${a}].key.velocity`,0,7)}if(!t.pitchEG||!Array.isArray(t.pitchEG.rates)||t.pitchEG.rates.length!==4)throw new d("Invalid pitch EG rates","pitchEG.rates",t.pitchEG?.rates);if(!t.pitchEG||!Array.isArray(t.pitchEG.levels)||t.pitchEG.levels.length!==4)throw new d("Invalid pitch EG levels","pitchEG.levels",t.pitchEG?.levels);if(E(n.UNPACKED_PITCH_EG_RATE_1,t.pitchEG.rates[0],"pitchEG.rates[0]",0,99),E(n.UNPACKED_PITCH_EG_RATE_2,t.pitchEG.rates[1],"pitchEG.rates[1]",0,99),E(n.UNPACKED_PITCH_EG_RATE_3,t.pitchEG.rates[2],"pitchEG.rates[2]",0,99),E(n.UNPACKED_PITCH_EG_RATE_4,t.pitchEG.rates[3],"pitchEG.rates[3]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_1,t.pitchEG.levels[0],"pitchEG.levels[0]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_2,t.pitchEG.levels[1],"pitchEG.levels[1]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_3,t.pitchEG.levels[2],"pitchEG.levels[2]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_4,t.pitchEG.levels[3],"pitchEG.levels[3]",0,99),!t.lfo||typeof t.lfo!="object")throw new d("Invalid LFO data","lfo",t.lfo);if(E(n.UNPACKED_LFO_SPEED,t.lfo.speed,"lfo.speed",0,99),E(n.UNPACKED_LFO_DELAY,t.lfo.delay,"lfo.delay",0,99),E(n.UNPACKED_LFO_PM_DEPTH,t.lfo.pmDepth,"lfo.pmDepth",0,99),E(n.UNPACKED_LFO_AM_DEPTH,t.lfo.amDepth,"lfo.amDepth",0,99),e[n.UNPACKED_LFO_KEY_SYNC]=t.lfo.keySync?1:0,e[n.UNPACKED_LFO_WAVE]=i(t.lfo.wave),!t.global||typeof t.global!="object")throw new d("Invalid global data","global",t.global);const h=Number(t.global.algorithm)||1;E(n.UNPACKED_ALGORITHM,h-1,"global.algorithm",0,31),E(n.UNPACKED_FEEDBACK,t.global.feedback,"global.feedback",0,7),e[n.UNPACKED_OSC_SYNC]=t.global.oscKeySync?1:0,E(n.UNPACKED_LFO_PM_SENS,t.global.pitchModSens,"global.pitchModSens",0,7);const S=Number(t.global.transpose)||0;E(n.UNPACKED_TRANSPOSE,S+n.TRANSPOSE_CENTER,"global.transpose",0,127),E(n.UNPACKED_AMP_MOD_SENS,t.global.ampModSens||0,"global.ampModSens",0,3),E(n.UNPACKED_EG_BIAS_SENS,t.global.egBiasSens||0,"global.egBiasSens",0,7);const P=t.name||"";for(let a=0;a<n.NAME_LENGTH;a++)e[n.UNPACKED_NAME_START+a]=a<P.length?P.charCodeAt(a):n.CHAR_SPACE;return n.fromUnpacked(e,s)}toSysEx(){const t=this.unpack(),s=new Uint8Array(n.VCED_SIZE);let e=0;s[e++]=n.VCED_SYSEX_START,s[e++]=n.VCED_YAMAHA_ID,s[e++]=n.VCED_SUB_STATUS,s[e++]=n.VCED_FORMAT_SINGLE,s[e++]=n.VCED_BYTE_COUNT_MSB,s[e++]=n.VCED_BYTE_COUNT_LSB;for(let _=n.NUM_OPERATORS-1;_>=0;_--){const i=_*n.UNPACKED_OP_SIZE;s[e++]=t[i+n.UNPACKED_OP_EG_RATE_1],s[e++]=t[i+n.UNPACKED_OP_EG_RATE_2],s[e++]=t[i+n.UNPACKED_OP_EG_RATE_3],s[e++]=t[i+n.UNPACKED_OP_EG_RATE_4],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_1],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_2],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_3],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_4],s[e++]=t[i+n.UNPACKED_OP_BREAK_POINT],s[e++]=t[i+n.UNPACKED_OP_L_SCALE_DEPTH],s[e++]=t[i+n.UNPACKED_OP_R_SCALE_DEPTH],s[e++]=t[i+n.UNPACKED_OP_L_CURVE],s[e++]=t[i+n.UNPACKED_OP_R_CURVE],s[e++]=t[i+n.UNPACKED_OP_RATE_SCALING],s[e++]=t[i+n.UNPACKED_OP_DETUNE];const r=t[i+n.UNPACKED_OP_AMP_MOD_SENS]&n.MASK_2BIT,h=t[i+n.UNPACKED_OP_KEY_VEL_SENS]&n.MASK_3BIT;s[e++]=r|h<<2,s[e++]=t[i+n.UNPACKED_OP_OUTPUT_LEVEL],s[e++]=t[i+n.UNPACKED_OP_MODE],s[e++]=t[i+n.UNPACKED_OP_FREQ_COARSE],s[e++]=t[i+n.UNPACKED_OP_OSC_DETUNE],s[e++]=t[i+n.UNPACKED_OP_FREQ_FINE]}s[e++]=t[n.UNPACKED_PITCH_EG_RATE_1],s[e++]=t[n.UNPACKED_PITCH_EG_RATE_2],s[e++]=t[n.UNPACKED_PITCH_EG_RATE_3],s[e++]=t[n.UNPACKED_PITCH_EG_RATE_4],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_1],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_2],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_3],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_4],s[e++]=t[n.UNPACKED_ALGORITHM],s[e++]=t[n.UNPACKED_FEEDBACK],s[e++]=t[n.UNPACKED_OSC_SYNC],s[e++]=t[n.UNPACKED_LFO_SPEED],s[e++]=t[n.UNPACKED_LFO_DELAY],s[e++]=t[n.UNPACKED_LFO_PM_DEPTH],s[e++]=t[n.UNPACKED_LFO_AM_DEPTH],s[e++]=t[n.UNPACKED_LFO_KEY_SYNC],s[e++]=t[n.UNPACKED_LFO_WAVE],s[e++]=t[n.UNPACKED_LFO_PM_SENS],s[e++]=t[n.UNPACKED_TRANSPOSE];for(let _=0;_<n.NAME_LENGTH;_++)s[e++]=t[n.UNPACKED_NAME_START+_];const E=s.subarray(n.VCED_HEADER_SIZE,n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE);return s[e++]=u._calculateChecksum(E,n.VCED_DATA_SIZE),s[e++]=n.VCED_SYSEX_END,s}toJSON(){const t=this.unpack(),s=[],e=i=>["-LN","-EX","+EX","+LN"][i]||"UNKNOWN",E=i=>["TRIANGLE","SAW DOWN","SAW UP","SQUARE","SINE","SAMPLE & HOLD"][i]||"UNKNOWN",_=i=>{const r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],h=Math.floor(i/12)+n.MIDI_OCTAVE_OFFSET;return`${r[i%12]}${h}`};for(let i=0;i<n.NUM_OPERATORS;i++){const r=i*n.UNPACKED_OP_SIZE,h=t[r+n.UNPACKED_OP_MODE]===0?"RATIO":"FIXED";s.push({id:i+1,osc:{detune:t[r+n.UNPACKED_OP_OSC_DETUNE],freq:{coarse:t[r+n.UNPACKED_OP_FREQ_COARSE],fine:t[r+n.UNPACKED_OP_FREQ_FINE],mode:h}},eg:{rates:[t[r+n.UNPACKED_OP_EG_RATE_1],t[r+n.UNPACKED_OP_EG_RATE_2],t[r+n.UNPACKED_OP_EG_RATE_3],t[r+n.UNPACKED_OP_EG_RATE_4]],levels:[t[r+n.UNPACKED_OP_EG_LEVEL_1],t[r+n.UNPACKED_OP_EG_LEVEL_2],t[r+n.UNPACKED_OP_EG_LEVEL_3],t[r+n.UNPACKED_OP_EG_LEVEL_4]]},key:{velocity:t[r+n.UNPACKED_OP_KEY_VEL_SENS],scaling:t[r+n.UNPACKED_OP_RATE_SCALING],breakPoint:_(t[r+n.UNPACKED_OP_BREAK_POINT]+n.MIDI_BREAK_POINT_OFFSET)},output:{level:t[r+n.UNPACKED_OP_OUTPUT_LEVEL],ampModSens:t[r+n.UNPACKED_OP_AMP_MOD_SENS]},scale:{left:{depth:t[r+n.UNPACKED_OP_L_SCALE_DEPTH],curve:e(t[r+n.UNPACKED_OP_L_CURVE])},right:{depth:t[r+n.UNPACKED_OP_R_SCALE_DEPTH],curve:e(t[r+n.UNPACKED_OP_R_CURVE])}}})}return{name:this.name||"(Empty)",operators:s,pitchEG:{rates:[t[n.UNPACKED_PITCH_EG_RATE_1],t[n.UNPACKED_PITCH_EG_RATE_2],t[n.UNPACKED_PITCH_EG_RATE_3],t[n.UNPACKED_PITCH_EG_RATE_4]],levels:[t[n.UNPACKED_PITCH_EG_LEVEL_1],t[n.UNPACKED_PITCH_EG_LEVEL_2],t[n.UNPACKED_PITCH_EG_LEVEL_3],t[n.UNPACKED_PITCH_EG_LEVEL_4]]},lfo:{speed:t[n.UNPACKED_LFO_SPEED],delay:t[n.UNPACKED_LFO_DELAY],pmDepth:t[n.UNPACKED_LFO_PM_DEPTH],amDepth:t[n.UNPACKED_LFO_AM_DEPTH],keySync:t[n.UNPACKED_LFO_KEY_SYNC]===1,wave:E(t[n.UNPACKED_LFO_WAVE])},global:{algorithm:t[n.UNPACKED_ALGORITHM]+1,feedback:t[n.UNPACKED_FEEDBACK],oscKeySync:t[n.UNPACKED_OSC_SYNC]===1,pitchModSens:t[n.UNPACKED_LFO_PM_SENS],transpose:t[n.UNPACKED_TRANSPOSE]-n.TRANSPOSE_CENTER}}}}class u{static SYSEX_START=240;static SYSEX_END=247;static SYSEX_YAMAHA_ID=67;static SYSEX_SUB_STATUS=0;static SYSEX_FORMAT_32_VOICES=9;static SYSEX_BYTE_COUNT_MSB=32;static SYSEX_BYTE_COUNT_LSB=0;static SYSEX_HEADER=[u.SYSEX_START,u.SYSEX_YAMAHA_ID,u.SYSEX_SUB_STATUS,u.SYSEX_FORMAT_32_VOICES,u.SYSEX_BYTE_COUNT_MSB,u.SYSEX_BYTE_COUNT_LSB];static SYSEX_HEADER_SIZE=6;static VOICE_DATA_SIZE=4096;static SYSEX_SIZE=4104;static VOICE_SIZE=128;static NUM_VOICES=32;static CHECKSUM_MODULO=128;static MASK_7BIT=127;constructor(t,s=""){if(this.voices=new Array(u.NUM_VOICES),this.name=s,t)this._load(t);else for(let e=0;e<u.NUM_VOICES;e++)this.voices[e]=n.createDefault(e)}static _calculateChecksum(t,s){let e=0;for(let E=0;E<s;E++)e+=t[E];return u.CHECKSUM_MODULO-e%u.CHECKSUM_MODULO&u.MASK_7BIT}_load(t){const s=t instanceof Uint8Array?t:new Uint8Array(t);let e,E=0;if(s[0]===u.SYSEX_START){const i=s.subarray(0,u.SYSEX_HEADER_SIZE),r=u.SYSEX_HEADER;for(let h=0;h<u.SYSEX_HEADER_SIZE;h++)if(i[h]!==r[h])throw new M(`Invalid SysEx header at position ${h}: expected ${r[h].toString(16)}, got ${i[h].toString(16)}`,"header",h);e=s.subarray(u.SYSEX_HEADER_SIZE,u.SYSEX_HEADER_SIZE+u.VOICE_DATA_SIZE),E=u.SYSEX_HEADER_SIZE}else if(s.length===u.VOICE_DATA_SIZE)e=s;else throw new d(`Invalid data length: expected ${u.VOICE_DATA_SIZE} or ${u.SYSEX_SIZE} bytes, got ${s.length}`,"length",s.length);if(e.length!==u.VOICE_DATA_SIZE)throw new d(`Invalid voice data length: expected ${u.VOICE_DATA_SIZE} bytes, got ${e.length}`,"length",e.length);const _=u.SYSEX_HEADER_SIZE+u.VOICE_DATA_SIZE;if(E>0&&s.length>=_+1){const i=s[_],r=u._calculateChecksum(e,u.VOICE_DATA_SIZE);i!==r&&console.warn(`DX7 checksum mismatch (expected ${r.toString(16)}, got ${i.toString(16)}). This is common with vintage SysEx files and the data is likely still valid.`)}this.voices=new Array(u.NUM_VOICES);for(let i=0;i<u.NUM_VOICES;i++){const r=i*u.VOICE_SIZE,h=e.subarray(r,r+u.VOICE_SIZE);this.voices[i]=new n(h,i)}}replaceVoice(t,s){if(t<0||t>=u.NUM_VOICES)throw new d(`Invalid voice index: ${t}`,"index",t);const e=new Uint8Array(s.data);this.voices[t]=new n(e,t)}addVoice(t){for(let s=0;s<this.voices.length;s++){const e=this.voices[s];if(e.name===""||e.name==="Init Voice")return this.replaceVoice(s,t),s}return-1}getVoices(){return this.voices}getVoice(t){return t<0||t>=this.voices.length?null:this.voices[t]}getVoiceNames(){return this.voices.map(t=>t.name)}findVoiceByName(t){const s=t.toLowerCase();return this.voices.find(e=>e.name.toLowerCase().includes(s))||null}static async fromFile(t){return new Promise((s,e)=>{const E=new FileReader;E.onload=async _=>{try{const i=t.name||"",r=new Uint8Array(_.target.result);if(r[0]===u.SYSEX_START&&r[3]===n.VCED_FORMAT_SINGLE)e(new M("This is a single voice file. Use DX7Voice.fromFile() instead.","format",3));else{const h=i.replace(/\.[^/.]+$/,""),S=new u(_.target.result,h);s(S)}}catch(i){e(i)}},E.onerror=()=>e(new Error("Failed to read file")),E.readAsArrayBuffer(t)})}static fromSysEx(t,s=""){return new u(t,s)}static fromJSON(t){if(!t||typeof t!="object")throw new d("Invalid JSON: expected object","json",t);const s=new u;if(s.name=t.name||"",!Array.isArray(t.voices))throw new d("Invalid voices array","voices",t.voices);t.voices.length!==u.NUM_VOICES&&console.warn(`Bank JSON has ${t.voices.length} voices, expected ${u.NUM_VOICES}. Missing voices will be filled with defaults.`);const e=Math.min(t.voices.length,u.NUM_VOICES);for(let E=0;E<e;E++){const _=t.voices[E];if(!_||typeof _!="object"){console.warn(`Invalid voice data at index ${E}, using default voice`);continue}try{const{index:i,...r}=_,h=n.fromJSON(r,E);s.replaceVoice(E,h)}catch(i){console.warn(`Failed to load voice at index ${E}: ${i.message}, using default voice`)}}return s}toSysEx(){const t=new Uint8Array(u.SYSEX_SIZE);let s=0;u.SYSEX_HEADER.forEach(E=>{t[s++]=E});for(const E of this.voices)for(let _=0;_<u.VOICE_SIZE;_++)t[s++]=E.data[_];const e=t.subarray(u.SYSEX_HEADER_SIZE,u.SYSEX_HEADER_SIZE+u.VOICE_DATA_SIZE);return t[s++]=u._calculateChecksum(e,u.VOICE_DATA_SIZE),t[s++]=u.SYSEX_END,t}toJSON(){const t=this.voices.map((s,e)=>{const E=s.toJSON();return{index:e+1,...E}});return{version:"1.0",name:this.name||"",voices:t}}}function tt(C){return C[0]!==240||C[C.length-1]!==247?null:{manufacturerId:C[1],payload:C.slice(2,-1),raw:C}}function nt(C,t){return[240,C,...t,247]}function st(C){return C.length>=2&&C[0]===240&&C[C.length-1]===247}function et(C){const t=[];for(let s=0;s<C.length;s+=7){const e=C.slice(s,s+7);let E=0;const _=[];for(let i=0;i<e.length;i++){const r=e[i];r&128&&(E|=1<<i),_.push(r&127)}t.push(E,..._)}return t}function Et(C){const t=[];for(let s=0;s<C.length;s+=8){const e=C[s],E=Math.min(7,C.length-s-1);for(let _=0;_<E;_++){let i=C[s+1+_];e&1<<_&&(i|=128),t.push(i)}}return t}function it(C){return Number.isInteger(C)&&C>=1&&C<=16}function _t(C){return Number.isInteger(C)&&C>=0&&C<=127}function rt(C){return Number.isInteger(C)&&C>=0&&C<=31}function at(C){return Number.isInteger(C)&&C>=0&&C<=127}function Ct(C){return Number.isInteger(C)&&C>=0&&C<=127}function At(C){return Number.isInteger(C)&&C>=0&&C<=127}function ot(C){return Number.isInteger(C)&&C>=0&&C<=127}function Pt(C){return Number.isInteger(C)&&C>=0&&C<=16383}function ut(C,t){return Number.isInteger(C)&&C>=0&&C<=127&&Number.isInteger(t)&&t>=0&&t<=127}async function lt(C={}){const{onStatusUpdate:t,onConnectionUpdate:s,inputChannel:e=1,outputChannel:E=1,output:_,sysex:i,onReady:r,onError:h,selector:S,watchDOM:P,...a}=C,N=await Z({autoConnect:!1,sysex:i,inputChannel:e,outputChannel:E,selector:S||"[data-midi-cc]",watchDOM:P,onError:h,...a}),O=new $({midiController:N,onStatusUpdate:t||(()=>{}),onConnectionUpdate:s||(()=>{}),channel:E});if(_)try{await N.device.connectOutput(_),O.currentOutput=N.device.getCurrentOutput(),O.updateConnectionStatus()}catch(T){h?h(T):console.error("Failed to connect to MIDI device:",T.message)}return r&&r(N,O),O}async function Z(C={}){const t=new x(C);await t.init();const s=C.selector||"[data-midi-cc]";{const e=new p(t,s);e.bindAll(),C.watchDOM&&e.enableAutoBinding(),t._binder=e}return t}l.CONN=U,l.CONNECTION_EVENTS=U,l.CONTROLLER_EVENTS=o,l.CTRL=o,l.DX7Bank=u,l.DX7Error=F,l.DX7ParseError=M,l.DX7ValidationError=d,l.DX7Voice=n,l.DataAttributeBinder=p,l.EventEmitter=b,l.MIDIAccessError=g,l.MIDIConnection=Y,l.MIDIConnectionError=G,l.MIDIController=x,l.MIDIDeviceError=L,l.MIDIDeviceManager=$,l.MIDIError=m,l.MIDIValidationError=R,l.clamp=c,l.createMIDIController=Z,l.createMIDIDeviceManager=lt,l.createSysEx=nt,l.decode14BitValue=w,l.decode7Bit=Et,l.denormalize14BitValue=X,l.denormalizeValue=W,l.encode14BitValue=v,l.encode7Bit=et,l.frequencyToNote=j,l.getCCName=V,l.isSysEx=st,l.isValid14BitCC=rt,l.isValidCC=_t,l.isValidChannel=it,l.isValidMIDIValue=at,l.isValidNote=Ct,l.isValidPitchBend=Pt,l.isValidPitchBendBytes=ut,l.isValidProgramChange=ot,l.isValidVelocity=At,l.normalize14BitValue=B,l.normalizeValue=H,l.noteNameToNumber=Q,l.noteNumberToName=J,l.noteToFrequency=k,l.parseSysEx=tt,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(l,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(l=typeof globalThis<"u"?globalThis:l||self,p(l.MIDIControls={}))})(this,(function(l){"use strict";class p{constructor(t,s="[data-midi-cc]"){this.controller=t,this.selector=s,this.observer=null}bindAll(){document.querySelectorAll(this.selector==="[data-midi-cc]"?"[data-midi-cc], [data-midi-msb][data-midi-lsb]":this.selector).forEach(s=>{if(s.hasAttribute("data-midi-bound"))return;const e=this._parseAttributes(s);e&&(this.controller.bind(s,e),s.setAttribute("data-midi-bound","true"))})}enableAutoBinding(){if(this.observer)return;const t=this.selector==="[data-midi-cc]"?"[data-midi-cc], [data-midi-msb][data-midi-lsb]":this.selector;this.observer=new MutationObserver(s=>{s.forEach(e=>{e.addedNodes.forEach(E=>{if(E.nodeType===Node.ELEMENT_NODE){if(E.matches?.(t)){const _=this._parseAttributes(E);_&&!E.hasAttribute("data-midi-bound")&&(this.controller.bind(E,_),E.setAttribute("data-midi-bound","true"))}E.querySelectorAll&&E.querySelectorAll(t).forEach(i=>{if(!i.hasAttribute("data-midi-bound")){const r=this._parseAttributes(i);r&&(this.controller.bind(i,r),i.setAttribute("data-midi-bound","true"))}})}}),e.removedNodes.forEach(E=>{E.nodeType===Node.ELEMENT_NODE&&(E.hasAttribute?.("data-midi-bound")&&this.controller.unbind(E),E.querySelectorAll&&E.querySelectorAll("[data-midi-bound]").forEach(i=>{this.controller.unbind(i)}))})})}),this.observer.observe(document.body,{childList:!0,subtree:!0})}disableAutoBinding(){this.observer&&(this.observer.disconnect(),this.observer=null)}_parseAttributes(t){const s=parseInt(t.dataset.midiMsb,10),e=parseInt(t.dataset.midiLsb,10);if(!Number.isNaN(s)&&!Number.isNaN(e)&&s>=0&&s<=127&&e>=0&&e<=127){const _=parseInt(t.dataset.midiCc,10);return!Number.isNaN(_)&&_>=0&&_<=127&&console.warn(`Element has both 7-bit (data-midi-cc="${_}") and 14-bit (data-midi-msb="${s}" data-midi-lsb="${e}") CC attributes. 14-bit takes precedence.`,t),{msb:s,lsb:e,is14Bit:!0,channel:parseInt(t.dataset.midiChannel,10)||void 0,min:parseFloat(t.getAttribute("min"))||0,max:parseFloat(t.getAttribute("max"))||127,invert:t.dataset.midiInvert==="true",label:t.dataset.midiLabel}}const E=parseInt(t.dataset.midiCc,10);return!Number.isNaN(E)&&E>=0&&E<=127?{cc:E,channel:parseInt(t.dataset.midiChannel,10)||void 0,min:parseFloat(t.getAttribute("min"))||0,max:parseFloat(t.getAttribute("max"))||127,invert:t.dataset.midiInvert==="true",label:t.dataset.midiLabel}:((t.dataset.midiCc!==void 0||t.dataset.midiMsb!==void 0&&t.dataset.midiLsb!==void 0)&&console.warn("Invalid MIDI configuration on element:",t),null)}destroy(){this.disableAutoBinding()}}class m extends Error{constructor(t,s){super(t),this.name="MIDIError",this.code=s,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class g extends m{constructor(t,s){super(t,"MIDI_ACCESS_ERROR"),this.name="MIDIAccessError",this.reason=s}}class G extends m{constructor(t){super(t,"MIDI_CONNECTION_ERROR"),this.name="MIDIConnectionError"}}class L extends m{constructor(t,s,e){super(t,"MIDI_DEVICE_ERROR"),this.name="MIDIDeviceError",this.deviceType=s,this.deviceId=e}}class R extends m{constructor(t,s){super(t,"MIDI_VALIDATION_ERROR"),this.name="MIDIValidationError",this.validationType=s}}class F extends Error{constructor(t,s){super(t),this.name="DX7Error",this.code=s,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class M extends F{constructor(t,s,e){super(t,"DX7_PARSE_ERROR"),this.name="DX7ParseError",this.parseType=s,this.offset=e}}class d extends F{constructor(t,s,e){super(t,"DX7_VALIDATION_ERROR"),this.name="DX7ValidationError",this.validationType=s,this.value=e}}function c(C,t,s){return Math.max(t,Math.min(s,C))}function H(C,t,s,e=!1){const E=(C-t)/(s-t),i=(e?1-E:E)*127;return c(Math.round(i),0,127)}function W(C,t,s,e=!1){let E=c(C,0,127)/127;return e&&(E=1-E),t+E*(s-t)}function Q(C){const t={C:0,"C#":1,DB:1,D:2,"D#":3,EB:3,E:4,F:5,"F#":6,GB:6,G:7,"G#":8,AB:8,A:9,"A#":10,BB:10,B:11},s=C.match(/^([A-G][#b]?)(-?\d+)$/i);if(!s)throw new R(`Invalid note name: ${C}`,"note",C);const[,e,E]=s,_=t[e.toUpperCase()];if(_===void 0)throw new R(`Invalid note: ${e}`,"note",e);const i=(parseInt(E,10)+1)*12+_;return c(i,0,127)}function J(C,t=!1){const E=t?["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"]:["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],_=Math.floor(C/12)-1;return`${E[C%12]}${_}`}function j(C){const t=69+12*Math.log2(C/440);return c(Math.round(t),0,127)}function k(C){return 440*2**((C-69)/12)}function V(C){return{0:"Bank Select",1:"Modulation",2:"Breath Controller",4:"Foot Controller",5:"Portamento Time",7:"Volume",8:"Balance",10:"Pan",11:"Expression",64:"Sustain Pedal",65:"Portamento",66:"Sostenuto",67:"Soft Pedal",68:"Legato",71:"Resonance",72:"Release Time",73:"Attack Time",74:"Cutoff",75:"Decay Time",76:"Vibrato Rate",77:"Vibrato Depth",78:"Vibrato Delay",84:"Portamento Control",91:"Reverb",92:"Tremolo",93:"Chorus",94:"Detune",95:"Phaser",120:"All Sound Off",121:"Reset All Controllers",123:"All Notes Off"}[C]||`CC ${C}`}function v(C){const t=c(Math.round(C),0,16383);return{msb:t>>7&127,lsb:t&127}}function w(C,t){return c(C,0,127)<<7|c(t,0,127)}function B(C,t,s,e=!1){const E=(C-t)/(s-t),i=(e?1-E:E)*16383;return v(i)}function X(C,t,s,e,E=!1){let i=w(C,t)/16383;return E&&(i=1-i),s+i*(e-s)}class b{constructor(){this.events=new Map}on(t,s){return this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(s),()=>this.off(t,s)}once(t,s){const e=(...E)=>{s(...E),this.off(t,e)};this.on(t,e)}off(t,s){if(!this.events.has(t))return;const e=this.events.get(t),E=e.indexOf(s);E>-1&&e.splice(E,1),e.length===0&&this.events.delete(t)}emit(t,s){if(!this.events.has(t))return;[...this.events.get(t)].forEach(E=>{try{E(s)}catch(_){console.error(`Error in event handler for "${t}":`,_)}})}removeAllListeners(t){t?this.events.delete(t):this.events.clear()}}const U={DEVICE_CHANGE:"device-change",IN_DEV_CONNECTED:"in-dev-connected",IN_DEV_DISCONNECTED:"in-dev-disconnected",OUT_DEV_CONNECTED:"out-dev-connected",OUT_DEV_DISCONNECTED:"out-dev-disconnected"};class Y extends b{constructor(t={}){super(),this.options={sysex:!1,...t},this.midiAccess=null,this.output=null,this.input=null}async requestAccess(){if(!navigator.requestMIDIAccess)throw new g("Web MIDI API is not supported in this browser","unsupported");try{this.midiAccess=await navigator.requestMIDIAccess({sysex:this.options.sysex}),this.midiAccess.onstatechange=t=>{const s=t.port,e=t.port.state;this.emit(U.DEVICE_CHANGE,{port:s,state:e,type:s.type,device:{id:s.id,name:s.name,manufacturer:s.manufacturer||"Unknown"}}),e==="disconnected"?s.type==="input"?(this.emit(U.IN_DEV_DISCONNECTED,{device:s}),this.input&&this.input.id===s.id&&(this.input=null)):s.type==="output"&&(this.emit(U.OUT_DEV_DISCONNECTED,{device:s}),this.output&&this.output.id===s.id&&(this.output=null)):e==="connected"&&(s.type==="input"?this.emit(U.IN_DEV_CONNECTED,{device:s}):s.type==="output"&&this.emit(U.OUT_DEV_CONNECTED,{device:s}))}}catch(t){throw t.name==="SecurityError"?new g("MIDI access denied. SysEx requires user permission.","denied"):new g(`Failed to get MIDI access: ${t.message}`,"failed")}}async connect(t){if(!this.midiAccess)throw new G("MIDI access not initialized. Call requestAccess() first.");const s=Array.from(this.midiAccess.outputs.values());if(s.length===0)throw new L("No MIDI output devices available","output");if(t===void 0){this.output=s[0];return}if(typeof t=="number"){if(t<0||t>=s.length)throw new L(`Output index ${t} out of range (0-${s.length-1})`,"output",t);this.output=s[t];return}if(this.output=s.find(e=>e.name===t||e.id===t),!this.output){const e=s.map(E=>E.name).join(", ");throw new L(`MIDI output "${t}" not found. Available: ${e}`,"output",t)}}async connectInput(t,s){if(!this.midiAccess)throw new G("MIDI access not initialized. Call requestAccess() first.");if(typeof s!="function")throw new R("onMessage callback must be a function","callback");const e=Array.from(this.midiAccess.inputs.values());if(e.length===0)throw new L("No MIDI input devices available","input");if(this.input&&(this.input.onmidimessage=null),t===void 0)this.input=e[0];else if(typeof t=="number"){if(t<0||t>=e.length)throw new L(`Input index ${t} out of range (0-${e.length-1})`,"input",t);this.input=e[t]}else if(this.input=e.find(E=>E.name===t||E.id===t),!this.input){const E=e.map(_=>_.name).join(", ");throw new L(`MIDI input "${t}" not found. Available: ${E}`,"input",t)}this.input.onmidimessage=E=>{s(E)}}disconnectOutput(){this.output=null}disconnectInput(){this.input&&(this.input.onmidimessage=null,this.input=null)}disconnect(){this.disconnectOutput(),this.disconnectInput()}isConnected(){return this.output!==null}getCurrentOutput(){return this.output?{id:this.output.id,name:this.output.name,manufacturer:this.output.manufacturer||"Unknown"}:null}getCurrentInput(){return this.input?{id:this.input.id,name:this.input.name,manufacturer:this.input.manufacturer||"Unknown"}:null}getOutputs(){if(!this.midiAccess)return[];const t=[];return this.midiAccess.outputs.forEach(s=>{s.state==="connected"&&t.push({id:s.id,name:s.name,manufacturer:s.manufacturer||"Unknown"})}),t}getInputs(){if(!this.midiAccess)return[];const t=[];return this.midiAccess.inputs.forEach(s=>{s.state==="connected"&&t.push({id:s.id,name:s.name,manufacturer:s.manufacturer||"Unknown"})}),t}send(t,s=null){if(!this.output){console.warn("No MIDI output connected. Call connect() first.");return}try{const e=new Uint8Array(t);s===null?this.output.send(e):this.output.send(e,s)}catch(e){console.error("Failed to send MIDI message:",e)}}sendSysEx(t,s=!1){if(!this.options.sysex){console.warn("SysEx not enabled. Initialize with sysex: true");return}let e;s?e=[240,...t,247]:e=t,this.send(e)}}const o={READY:"ready",ERROR:"error",DESTROYED:"destroyed",DEV_OUT_CONNECTED:"dev-out-connected",DEV_OUT_DISCONNECTED:"dev-out-disconnected",DEV_IN_CONNECTED:"dev-in-connected",DEV_IN_DISCONNECTED:"dev-in-disconnected",CH_CC_SEND:"ch-cc-send",CH_CC_RECV:"ch-cc-recv",CH_NOTE_ON_SEND:"ch-note-on-send",CH_NOTE_ON_RECV:"ch-note-on-recv",CH_NOTE_OFF_SEND:"ch-note-off-send",CH_NOTE_OFF_RECV:"ch-note-off-recv",CH_PC_SEND:"ch-pc-send",CH_PC_RECV:"ch-pc-recv",CH_PITCH_BEND_SEND:"ch-pitch-bend-send",CH_PITCH_BEND_RECV:"ch-pitch-bend-recv",CH_MONO_PRESS_SEND:"ch-mono-press-send",CH_MONO_PRESS_RECV:"ch-mono-press-recv",CH_POLY_PRESS_SEND:"ch-poly-press-send",CH_POLY_PRESS_RECV:"ch-poly-press-recv",CH_ALL_SOUNDS_OFF_SEND:"ch-all-sounds-off-send",CH_RESET_CONTROLLERS_SEND:"ch-reset-controllers-send",CH_LOCAL_CONTROL_SEND:"ch-local-control-send",CH_ALL_NOTES_OFF_SEND:"ch-all-notes-off-send",CH_OMNI_OFF_SEND:"ch-omni-off-send",CH_OMNI_ON_SEND:"ch-omni-on-send",CH_MONO_ON_SEND:"ch-mono-on-send",CH_POLY_ON_SEND:"ch-poly-on-send",SYS_EX_SEND:"sys-ex-send",SYS_EX_RECV:"sys-ex-recv",SYS_CLOCK_RECV:"sys-clock-recv",SYS_START_RECV:"sys-start-recv",SYS_CONTINUE_RECV:"sys-continue-recv",SYS_STOP_RECV:"sys-stop-recv",SYS_MTC_RECV:"sys-mtc-recv",SYS_SONG_POS_RECV:"sys-song-pos-recv",SYS_SONG_SEL_RECV:"sys-song-sel-recv",SYS_TUNE_REQ_RECV:"sys-tune-req-recv",SYS_ACT_SENSE_RECV:"sys-act-sense-recv",SYS_RESET_RECV:"sys-reset-recv",MIDI_RAW:"midi-raw",PATCH_SAVED:"patch-saved",PATCH_LOADED:"patch-loaded",PATCH_DELETED:"patch-deleted"};class x extends b{constructor(t={}){super(),this.options={inputChannel:1,outputChannel:1,autoConnect:!0,sysex:!1,...t},this.connection=null,this.bindings=new Map,this.state={controlChange:new Map,programChange:new Map,pitchBend:new Map,monoPressure:new Map,polyPressure:new Map},this.initialized=!1,this._initNamespaces()}async init(){if(this.initialized){console.warn("MIDI Controller already initialized");return}try{this.connection=new Y({sysex:this.options.sysex}),await this.connection.requestAccess(),this.connection.on(U.DEVICE_CHANGE,async({state:t,type:s,device:e})=>{try{if(t==="connected")s==="output"?this.emit(o.DEV_OUT_CONNECTED,e):s==="input"&&this.emit(o.DEV_IN_CONNECTED,e);else if(t==="disconnected"){if(s==="output"&&e){const E=this.connection.getCurrentOutput();E&&E.id===e.id?await this._disconnectOutput():this.emit(o.DEV_OUT_DISCONNECTED,e)}if(s==="input"&&e){const E=this.connection.getCurrentInput();E&&E.id===e.id?await this._disconnectInput():this.emit(o.DEV_IN_DISCONNECTED,e)}}}catch(E){console.error("Error in device change handler:",E),this.emit(o.ERROR,E)}}),this.options.autoConnect&&await this.connection.connect(this.options.output),this.options.input!==void 0&&await this._connectInput(this.options.input),this.initialized=!0,this.emit(o.READY,this),this.options.onReady?.(this)}catch(t){throw this.emit(o.ERROR,t),this.options.onError?.(t),t}}_initNamespaces(){this.device={connect:this._connect.bind(this),disconnect:this._disconnect.bind(this),connectInput:this._connectInput.bind(this),disconnectInput:this._disconnectInput.bind(this),connectOutput:this._connectOutput.bind(this),disconnectOutput:this._disconnectOutput.bind(this),getCurrentOutput:this._getCurrentOutput.bind(this),getCurrentInput:this._getCurrentInput.bind(this),getOutputs:this._getOutputs.bind(this),getInputs:this._getInputs.bind(this)},this.channel={sendNoteOn:this._sendNoteOn.bind(this),sendNoteOff:this._sendNoteOff.bind(this),sendCC:this._sendCC.bind(this),getCC:this._getCC.bind(this),sendPC:this._sendPC.bind(this),getPC:this._getPC.bind(this),sendPitchBend:this._sendPitchBend.bind(this),getPitchBend:this._getPitchBend.bind(this),sendMonoPressure:this._sendMonoPressure.bind(this),getMonoPressure:this._getMonoPressure.bind(this),sendPolyPressure:this._sendPolyPressure.bind(this),getPolyPressure:this._getPolyPressure.bind(this),allSoundsOff:this._allSoundsOff.bind(this),resetControllers:this._resetControllers.bind(this),localControl:this._localControl.bind(this),allNotesOff:this._allNotesOff.bind(this),omniOff:this._omniOff.bind(this),omniOn:this._omniOn.bind(this),monoOn:this._monoOn.bind(this),polyOn:this._polyOn.bind(this)},this.system={sendEx:(function(t,s=!1){return this._sendSysEx(t,s)}).bind(this),sendClock:this._sendClock.bind(this),start:this._sendStart.bind(this),continue:this._sendContinue.bind(this),stop:this._sendStop.bind(this),sendMTC:this._sendMTC.bind(this),sendSongPosition:this._sendSongPosition.bind(this),sendSongSelect:this._sendSongSelect.bind(this),sendTuneRequest:this._sendTuneRequest.bind(this),sendActiveSensing:this._sendActiveSensing.bind(this),sendSystemReset:this._sendSystemReset.bind(this)},this.patch={get:this._getPatch.bind(this),set:this._setPatch.bind(this),save:this._savePatch.bind(this),load:this._loadPatch.bind(this),delete:this._deletePatch.bind(this),list:this._listPatches.bind(this)}}bind(t,s,e={}){if(!t)return console.warn("Cannot bind: element is null or undefined"),()=>{};const E=this._createBinding(t,s,e);return this.bindings.set(t,E),this.initialized&&this.connection?.isConnected()&&E.handler({target:t}),()=>this.unbind(t)}_createBinding(t,s,e={}){const{min:E=parseFloat(t.getAttribute("min"))||0,max:_=parseFloat(t.getAttribute("max"))||127,channel:i,invert:r=!1,onInput:h=void 0}=s,{debounce:N=0}=e,P={...s,min:E,max:_,invert:r,onInput:h};if(i!==void 0&&(P.channel=i),s.is14Bit){const{msb:T,lsb:I}=s,f=y=>{const z=parseFloat(y.target.value);if(Number.isNaN(z))return;const{msb:ht,lsb:St}=B(z,E,_,r),q=i||this.options.outputChannel;this._sendCC(T,ht,q),this._sendCC(I,St,q)};let K=null;const D=N>0?y=>{K&&clearTimeout(K),K=setTimeout(()=>{f(y),K=null},N)}:f;return t.addEventListener("input",D),t.addEventListener("change",D),{element:t,config:P,handler:f,destroy:()=>{K&&clearTimeout(K),t.removeEventListener("input",D),t.removeEventListener("change",D)}}}const{cc:a}=s,A=T=>{const I=parseFloat(T.target.value);if(Number.isNaN(I))return;const f=H(I,E,_,r),K=i===void 0?this.options.outputChannel:i;this._sendCC(a,f,K)};let S=null;const O=N>0?T=>{S&&clearTimeout(S),S=setTimeout(()=>{A(T),S=null},N)}:A;return t.addEventListener("input",O),t.addEventListener("change",O),{element:t,config:P,handler:A,destroy:()=>{S&&clearTimeout(S),t.removeEventListener("input",O),t.removeEventListener("change",O)}}}unbind(t){const s=this.bindings.get(t);s&&(s.destroy(),this.bindings.delete(t))}async destroy(){for(const t of this.bindings.values())t.destroy();this.bindings.clear(),this.state.controlChange.clear(),this.state.programChange.clear(),this.state.pitchBend.clear(),this.state.monoPressure.clear(),this.state.polyPressure.clear(),await this._disconnect(),this.initialized=!1,this.emit(o.DESTROYED),this.removeAllListeners()}async _connect(t){t?await this.connection.connect(t):this.options.output!==void 0?await this.connection.connect(this.options.output):this.options.autoConnect&&await this.connection.connect()}async _disconnect(){this.connection.disconnect()}async _connectInput(t){await this.connection.connectInput(t,s=>{this._handleMIDIMessage(s)}),this.emit(o.DEV_IN_CONNECTED,this.connection.getCurrentInput())}async _disconnectInput(){const t=this.connection.getCurrentInput();this.connection.disconnectInput(),this.emit(o.DEV_IN_DISCONNECTED,t)}async _connectOutput(t){await this.connection.connect(t),this.emit(o.DEV_OUT_CONNECTED,this.connection.getCurrentOutput())}async _disconnectOutput(){const t=this.connection.getCurrentOutput();this.connection.disconnectOutput(),this.emit(o.DEV_OUT_DISCONNECTED,t)}_getCurrentOutput(){return this.connection?.getCurrentOutput()||null}_getCurrentInput(){return this.connection?.getCurrentInput()||null}_getOutputs(){return this.connection?.getOutputs()||[]}_getInputs(){return this.connection?.getInputs()||[]}send(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send(t)}_sendNoteOn(t,s=64,e=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),0,127),e=c(Math.round(e),1,16);const E=144+(e-1);this.connection.send([E,t,s]),this.emit(o.CH_NOTE_ON_SEND,{note:t,velocity:s,channel:e})}_sendNoteOff(t,s=this.options.outputChannel,e=0){if(!this.initialized)return;t=c(Math.round(t),0,127),e=c(Math.round(e),0,127),s=c(Math.round(s),1,16);const E=144+(s-1);this.connection.send([E,t,e]),this.emit(o.CH_NOTE_OFF_SEND,{note:t,channel:s,velocity:e})}_sendCC(t,s,e=this.options.outputChannel){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,127),s=c(Math.round(s),0,127),e=c(Math.round(e),1,16);const E=176+(e-1);this.connection.send([E,t,s]);const _=`${e}:${t}`;this.state.controlChange.set(_,s),this.emit(o.CH_CC_SEND,{cc:t,value:s,channel:e})}_sendPC(t,s=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),1,16);const e=192+(s-1);this.connection.send([e,t]),this.state.programChange.set(s.toString(),t),this.emit(o.CH_PC_SEND,{program:t,channel:s})}_getPC(t=this.options.inputChannel){return this.state.programChange.get(t.toString())}_getCC(t,s=this.options.inputChannel){const e=`${s}:${t}`;return this.state.controlChange.get(e)}_sendPitchBend(t,s=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,16383),s=c(Math.round(s),1,16);const e=224+(s-1),E=t&127,_=t>>7&127;this.connection.send([e,E,_]),this.state.pitchBend.set(s.toString(),t),this.emit(o.CH_PITCH_BEND_SEND,{value:t,channel:s})}_getPitchBend(t=this.options.inputChannel){return this.state.pitchBend.get(t.toString())}_sendMonoPressure(t,s=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),1,16);const e=208+(s-1);this.connection.send([e,t]),this.state.monoPressure.set(s.toString(),t),this.emit(o.CH_MONO_PRESS_SEND,{pressure:t,channel:s})}_getMonoPressure(t=this.options.inputChannel){return this.state.monoPressure.get(t.toString())}_sendPolyPressure(t,s,e=this.options.outputChannel){if(!this.initialized)return;t=c(Math.round(t),0,127),s=c(Math.round(s),0,127),e=c(Math.round(e),1,16);const E=160+(e-1);this.connection.send([E,t,s]);const _=`${e}:${t}`;this.state.polyPressure.set(_,s),this.emit(o.CH_POLY_PRESS_SEND,{note:t,pressure:s,channel:e})}_getPolyPressure(t,s=this.options.inputChannel){const e=`${s}:${t}`;return this.state.polyPressure.get(e)}_allSoundsOff(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,120,0]),this.emit(o.CH_ALL_SOUNDS_OFF_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,120,0])}this.emit(o.CH_ALL_SOUNDS_OFF_SEND,{channel:null})}}_resetControllers(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,121,0]),this.emit(o.CH_RESET_CONTROLLERS_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,121,0])}this.emit(o.CH_RESET_CONTROLLERS_SEND,{channel:null})}}_localControl(t,s){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}const e=t?127:0;if(s!==void 0){s=c(Math.round(s),1,16);const E=176+(s-1);this.connection.send([E,122,e]),this.emit(o.CH_LOCAL_CONTROL_SEND,{enabled:t,channel:s})}else{for(let E=1;E<=16;E++){const _=176+(E-1);this.connection.send([_,122,e])}this.emit(o.CH_LOCAL_CONTROL_SEND,{enabled:t,channel:null})}}_allNotesOff(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,123,0]),this.emit(o.CH_ALL_NOTES_OFF_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,123,0])}this.emit(o.CH_ALL_NOTES_OFF_SEND,{channel:null})}}_omniOff(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,124,0]),this.emit(o.CH_OMNI_OFF_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,124,0])}this.emit(o.CH_OMNI_OFF_SEND,{channel:null})}}_omniOn(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,125,0]),this.emit(o.CH_OMNI_ON_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,125,0])}this.emit(o.CH_OMNI_ON_SEND,{channel:null})}}_monoOn(t=1,s){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t=Math.max(0,Math.min(16,Math.round(t))),s!==void 0){s=c(Math.round(s),1,16);const e=176+(s-1);this.connection.send([e,126,t]),this.emit(o.CH_MONO_ON_SEND,{channels:t,channel:s})}else{for(let e=1;e<=16;e++){const E=176+(e-1);this.connection.send([E,126,t])}this.emit(o.CH_MONO_ON_SEND,{channels:t,channel:null})}}_polyOn(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(t!==void 0){t=c(Math.round(t),1,16);const s=176+(t-1);this.connection.send([s,127,0]),this.emit(o.CH_POLY_ON_SEND,{channel:t})}else{for(let s=1;s<=16;s++){const e=176+(s-1);this.connection.send([e,127,0])}this.emit(o.CH_POLY_ON_SEND,{channel:null})}}_sendSysEx(t,s=!1){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}if(!this.options.sysex){console.warn("SysEx not enabled. Initialize with sysex: true");return}this.connection.sendSysEx(t,s),this.emit(o.SYS_EX_SEND,{data:t,includeWrapper:s})}_sendClock(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([248])}_sendStart(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([250])}_sendContinue(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([251])}_sendStop(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([252])}_sendMTC(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,127),this.connection.send([241,t])}_sendSongPosition(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,16383);const s=t&127,e=t>>7&127;this.connection.send([242,s,e])}_sendSongSelect(t){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}t=c(Math.round(t),0,127),this.connection.send([243,t])}_sendTuneRequest(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([246])}_sendActiveSensing(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([254])}_sendSystemReset(){if(!this.initialized){console.warn("MIDI not initialized. Call init() first.");return}this.connection.send([255])}_handleMIDIMessage(t){const[s,e,E]=t.data,_=s&240,i=(s&15)+1;if(s===248){this.emit(o.SYS_CLOCK_RECV,{timestamp:t.midiwire});return}if(s===250){this.emit(o.SYS_START_RECV,{timestamp:t.midiwire});return}if(s===251){this.emit(o.SYS_CONTINUE_RECV,{timestamp:t.midiwire});return}if(s===252){this.emit(o.SYS_STOP_RECV,{timestamp:t.midiwire});return}if(s===254){this.emit(o.SYS_ACT_SENSE_RECV,{timestamp:t.midiwire});return}if(s===255){this.emit(o.SYS_RESET_RECV,{timestamp:t.midiwire});return}if(s===240){this.emit(o.SYS_EX_RECV,{data:Array.from(t.data),timestamp:t.midiwire});return}if(s===241){this.emit(o.SYS_MTC_RECV,{data:e,timestamp:t.midiwire});return}if(s===242){const r=e+(E<<7);this.emit(o.SYS_SONG_POS_RECV,{position:r,timestamp:t.midiwire});return}if(s===243){this.emit(o.SYS_SONG_SEL_RECV,{song:e,timestamp:t.midiwire});return}if(s===246){this.emit(o.SYS_TUNE_REQ_RECV,{timestamp:t.midiwire});return}if(s===247){this.emit(o.MIDI_RAW,{status:s,data:[e,E],channel:i,timestamp:t.midiwire});return}if(_===176){const r=`${i}:${e}`;this.state.controlChange.set(r,E),this.emit(o.CH_CC_RECV,{cc:e,value:E,channel:i});return}if(_===192){this.state.programChange.set(i.toString(),e),this.emit(o.CH_PC_RECV,{program:e,channel:i});return}if(_===224){const r=e+(E<<7);this.state.pitchBend.set(i.toString(),r),this.emit(o.CH_PITCH_BEND_RECV,{value:r,channel:i});return}if(_===208){this.state.monoPressure.set(i.toString(),e),this.emit(o.CH_MONO_PRESS_RECV,{pressure:e,channel:i});return}if(_===160){const r=`${i}:${e}`;this.state.polyPressure.set(r,E),this.emit(o.CH_POLY_PRESS_RECV,{note:e,pressure:E,channel:i});return}if(_===144&&E>0){this.emit(o.CH_NOTE_ON_RECV,{note:e,velocity:E,channel:i});return}if(_===128||_===144&&E===0){this.emit(o.CH_NOTE_OFF_RECV,{note:e,channel:i});return}this.emit(o.MIDI_RAW,{status:s,data:[e,E],channel:i,timestamp:t.midiwire})}_getPatch(t="Unnamed Patch"){const s={name:t,device:this._getCurrentOutput()?.name||null,timestamp:new Date().toISOString(),version:"1.0",channels:{},settings:{}};for(const[e,E]of this.state.controlChange.entries()){const[_,i]=e.split(":").map(Number);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].ccs[i]=E}for(const[e,E]of this.state.programChange.entries()){const _=parseInt(e,10);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].program=E}for(const[e,E]of this.state.pitchBend.entries()){const _=parseInt(e,10);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].pitchBend=E}for(const[e,E]of this.state.monoPressure.entries()){const _=parseInt(e,10);s.channels[_]||(s.channels[_]={ccs:{},notes:{}}),s.channels[_].monoPressure=E}for(const[e,E]of this.state.polyPressure.entries()){const[_,i]=e.split(":").map(Number),r=parseInt(_,10);s.channels[r]||(s.channels[r]={ccs:{},notes:{}}),s.channels[r].polyPressure||(s.channels[r].polyPressure={}),s.channels[r].polyPressure[i]=E}for(const[e,E]of this.bindings.entries()){const{config:_}=E;if(_.cc){const i=`cc${_.cc}`;s.settings[i]={min:_.min,max:_.max,invert:_.invert||!1,is14Bit:_.is14Bit||!1,label:e.getAttribute?.("data-midi-label")||null,elementId:e.id||null}}}return s}async _setPatch(t){if(!t||!t.channels)throw new R("Invalid patch format","patch");const s=t.version||"1.0";s==="1.0"?await this._applyPatchV1(t):(console.warn(`Unknown patch version: ${s}. Attempting to apply as v1.0`),await this._applyPatchV1(t)),this.emit(o.PATCH_LOADED,{patch:t})}async _applyPatchV1(t){for(const[s,e]of Object.entries(t.channels)){const E=parseInt(s,10);if(e.ccs)for(const[_,i]of Object.entries(e.ccs)){const r=parseInt(_,10);this._sendCC(r,i,E)}if(e.program!==void 0&&this._sendPC(e.program,E),e.pitchBend!==void 0&&this._sendPitchBend(e.pitchBend,E),e.monoPressure!==void 0&&this._sendMonoPressure(e.monoPressure,E),e.polyPressure)for(const[_,i]of Object.entries(e.polyPressure)){const r=parseInt(_,10);this._sendPolyPressure(r,i,E)}if(e.notes)for(const[_,i]of Object.entries(e.notes)){const r=parseInt(_,10);i>0?this._sendNoteOn(r,i,E):this._sendNoteOff(r,E)}}if(t.settings)for(const[s,e]of Object.entries(t.settings))for(const[E,_]of this.bindings.entries())_.config.cc?.toString()===s.replace("cc","")&&(E.min!==void 0&&e.min!==void 0&&(E.min=String(e.min)),E.max!==void 0&&e.max!==void 0&&(E.max=String(e.max)));for(const[s,e]of this.bindings.entries()){const{config:E}=e;if(E.cc!==void 0){const _=E.channel||this.options.inputChannel,i=t.channels[_];if(i?.ccs){const r=i.ccs[E.cc];if(r!==void 0){const h=E.min!==void 0?E.min:parseFloat(s.getAttribute?.("min"))||0,N=E.max!==void 0?E.max:parseFloat(s.getAttribute?.("max"))||127,P=E.invert||!1;let a;P?a=N-r/127*(N-h):a=h+r/127*(N-h),E.onInput&&typeof E.onInput=="function"?E.onInput(a):(s.value=a,s.dispatchEvent(new Event("input",{bubbles:!0})))}}}}}_savePatch(t,s=null){const e=s||this._getPatch(t),E=`midiwire_patch_${t}`;try{return localStorage.setItem(E,JSON.stringify(e)),this.emit(o.PATCH_SAVED,{name:t,patch:e}),E}catch(_){throw console.error("Failed to save patch:",_),_}}_loadPatch(t){const s=`midiwire_patch_${t}`;try{const e=localStorage.getItem(s);if(!e)return null;const E=JSON.parse(e);return this.emit(o.PATCH_LOADED,{name:t,patch:E}),E}catch(e){return console.error("Failed to load patch:",e),null}}_deletePatch(t){const s=`midiwire_patch_${t}`;try{return localStorage.removeItem(s),this.emit(o.PATCH_DELETED,{name:t}),!0}catch(e){return console.error("Failed to delete patch:",e),!1}}_listPatches(){const t=[];try{for(let s=0;s<localStorage.length;s++){const e=localStorage.key(s);if(e?.startsWith("midiwire_patch_")){const E=e.replace("midiwire_patch_",""),_=this._loadPatch(E);_&&t.push({name:E,patch:_})}}}catch(s){console.error("Failed to list patches:",s)}return t.sort((s,e)=>s.name.localeCompare(e.name))}}class ${constructor(t={}){this.midi=t.midiController||null,this.onStatusUpdate=t.onStatusUpdate||(()=>{}),this.onConnectionUpdate=t.onConnectionUpdate||(()=>{}),this.channel=t.channel||1,this.currentOutput=null,this.currentInput=null,this.isConnecting=!1}async setupSelectors(t={},s={}){if(!this.midi)throw new Error("MIDI controller not initialized. Pass midiController in constructor options.");const{output:e,input:E,channel:_}=t,i=this._resolveSelector(e),r=this._resolveSelector(E),h=this._resolveSelector(_);if(this._setupDeviceChangeListeners({output:i,input:r},s.onDeviceListChange),i){await this._populateOutputDeviceList(i);const N=s.onConnect?async(a,A)=>s.onConnect({midi:a,device:A,type:"output"}):void 0,P=s.onDisconnect?async a=>s.onDisconnect({midi:a,type:"output"}):void 0;this._connectOutputDeviceSelection(i,N,P)}if(r){await this._populateInputDeviceList(r);const N=s.onConnect?async(a,A)=>s.onConnect({midi:a,device:A,type:"input"}):void 0,P=s.onDisconnect?async a=>s.onDisconnect({midi:a,type:"input"}):void 0;this._connectInputDeviceSelection(r,N,P)}return h&&this._connectChannelSelection(h,"output"),this.midi}updateStatus(t,s=""){this.onStatusUpdate(t,s)}updateConnectionStatus(){this.onConnectionUpdate(this.currentOutput,this.currentInput,this.midi)}_setupDeviceChangeListeners(t={},s){!this.midi||this._listenersInitialized||(this._listenersInitialized=!0,this.midi.on(o.DEV_OUT_CONNECTED,async e=>{this.updateStatus(`Output device connected: ${e?.name||"Unknown"}`,"connected"),t.output&&await this._populateOutputDeviceList(t.output),s&&s()}),this.midi.on(o.DEV_OUT_DISCONNECTED,async e=>{this.updateStatus(`Output device disconnected: ${e?.name||"Unknown"}`,"error"),this.currentOutput&&e?.name===this.currentOutput.name&&(this.currentOutput=null,this.updateConnectionStatus(),t.output&&(t.output.value="")),t.output&&await this._populateOutputDeviceList(t.output),s&&s()}),this.midi.on(o.DEV_IN_CONNECTED,async e=>{this.updateStatus(`Input device connected: ${e?.name||"Unknown"}`,"connected"),t.input&&await this._populateInputDeviceList(t.input),s&&s()}),this.midi.on(o.DEV_IN_DISCONNECTED,async e=>{this.updateStatus(`Input device disconnected: ${e?.name||"Unknown"}`,"error"),t.input&&(t.input.value="",await this._populateInputDeviceList(t.input)),s&&s()}))}_resolveSelector(t){if(typeof t=="string"){const s=document.querySelector(t);return s||console.warn(`MIDIDeviceManager: Selector "${t}" not found`),s}return t||null}_getOutputDevices(){return this.midi?this.midi.device.getOutputs():[]}_getInputDevices(){return this.midi?this.midi.device.getInputs():[]}_connectOutputDeviceSelection(t,s,e){!t||!this.midi||t.addEventListener("change",async E=>{if(this.isConnecting)return;this.isConnecting=!0;const _=E.target.value;if(!_){this.currentOutput&&this.midi&&(await this.midi.device.disconnectOutput(),this.currentOutput=null,this.updateStatus("Output device disconnected",""),this.updateConnectionStatus()),this.isConnecting=!1,e&&await e(this.midi);return}try{if(await this.midi.device.connectOutput(parseInt(_,10)),this.currentOutput=this.midi.device.getCurrentOutput(),this.currentOutput){const r=this.midi.device.getOutputs().findIndex(h=>h.id===this.currentOutput.id);r!==-1&&(t.value=r.toString())}this.updateConnectionStatus(),s&&await s(this.midi,this.currentOutput)}catch(i){this.updateStatus(`Output connection failed: ${i.message}`,"error")}finally{this.isConnecting=!1}})}_connectInputDeviceSelection(t,s,e){!t||!this.midi||t.addEventListener("change",async E=>{const _=E.target.value;if(!_){this.midi&&(await this.midi.device.disconnectInput(),this.updateStatus("Input device disconnected",""),this.updateConnectionStatus()),e&&await e(this.midi);return}if(!this.isConnecting){this.isConnecting=!0;try{await this.midi.device.connectInput(parseInt(_,10));const i=this.midi.device.getCurrentInput();this.updateConnectionStatus(),s&&await s(this.midi,i)}catch(i){this.updateStatus(`Input connection failed: ${i.message}`,"error")}finally{this.isConnecting=!1}}})}_populateDeviceList(t,s,e,E,_){if(s.length>0){if(t.innerHTML='<option value="">Select a device</option>'+s.map((i,r)=>`<option value="${r}">${i.name}</option>`).join(""),e){const i=s.findIndex(r=>r.name===e.name);i!==-1?t.value=i.toString():(t.value="",_&&(this.currentOutput=null,this.updateConnectionStatus()))}else t.value="";t.disabled=!1,_&&!this.currentOutput&&this.updateStatus("Select a device")}else t.innerHTML='<option value="">No devices connected</option>',t.disabled=!0,_&&this.updateStatus("No devices connected","error");E&&E()}async _populateOutputDeviceList(t,s){if(!t||!this.midi)return;const e=this._getOutputDevices();this._populateDeviceList(t,e,this.currentOutput,s,!0)}async _populateInputDeviceList(t,s){if(!t||!this.midi)return;const e=this._getInputDevices(),E=this.midi.device.getCurrentInput();this._populateDeviceList(t,e,E,s,!1)}_connectChannelSelection(t,s){if(!t||!this.midi)return;const e=s==="input"?"inputChannel":"outputChannel";t.addEventListener("change",E=>{this.midi&&(this.midi.options[e]=parseInt(E.target.value,10),this.updateConnectionStatus())})}}class n{static PACKED_SIZE=128;static PACKED_OP_SIZE=17;static NUM_OPERATORS=6;static PACKED_OP_EG_RATE_1=0;static PACKED_OP_EG_RATE_2=1;static PACKED_OP_EG_RATE_3=2;static PACKED_OP_EG_RATE_4=3;static PACKED_OP_EG_LEVEL_1=4;static PACKED_OP_EG_LEVEL_2=5;static PACKED_OP_EG_LEVEL_3=6;static PACKED_OP_EG_LEVEL_4=7;static PACKED_OP_BREAK_POINT=8;static PACKED_OP_L_SCALE_DEPTH=9;static PACKED_OP_R_SCALE_DEPTH=10;static PACKED_OP_CURVES=11;static PACKED_OP_RATE_SCALING=12;static PACKED_OP_MOD_SENS=13;static PACKED_OP_OUTPUT_LEVEL=14;static PACKED_OP_MODE_FREQ=15;static PACKED_OP_DETUNE_FINE=16;static PACKED_PITCH_EG_RATE_1=102;static PACKED_PITCH_EG_RATE_2=103;static PACKED_PITCH_EG_RATE_3=104;static PACKED_PITCH_EG_RATE_4=105;static PACKED_PITCH_EG_LEVEL_1=106;static PACKED_PITCH_EG_LEVEL_2=107;static PACKED_PITCH_EG_LEVEL_3=108;static PACKED_PITCH_EG_LEVEL_4=109;static OFFSET_ALGORITHM=110;static OFFSET_FEEDBACK=111;static OFFSET_LFO_SPEED=112;static OFFSET_LFO_DELAY=113;static OFFSET_LFO_PM_DEPTH=114;static OFFSET_LFO_AM_DEPTH=115;static OFFSET_LFO_SYNC_WAVE=116;static OFFSET_TRANSPOSE=117;static OFFSET_AMP_MOD_SENS=118;static OFFSET_EG_BIAS_SENS=119;static PACKED_NAME_START=118;static NAME_LENGTH=10;static UNPACKED_SIZE=169;static UNPACKED_OP_SIZE=23;static UNPACKED_OP_EG_RATE_1=0;static UNPACKED_OP_EG_RATE_2=1;static UNPACKED_OP_EG_RATE_3=2;static UNPACKED_OP_EG_RATE_4=3;static UNPACKED_OP_EG_LEVEL_1=4;static UNPACKED_OP_EG_LEVEL_2=5;static UNPACKED_OP_EG_LEVEL_3=6;static UNPACKED_OP_EG_LEVEL_4=7;static UNPACKED_OP_BREAK_POINT=8;static UNPACKED_OP_L_SCALE_DEPTH=9;static UNPACKED_OP_R_SCALE_DEPTH=10;static UNPACKED_OP_L_CURVE=11;static UNPACKED_OP_R_CURVE=12;static UNPACKED_OP_RATE_SCALING=13;static UNPACKED_OP_DETUNE=14;static UNPACKED_OP_AMP_MOD_SENS=15;static UNPACKED_OP_OUTPUT_LEVEL=16;static UNPACKED_OP_MODE=17;static UNPACKED_OP_KEY_VEL_SENS=18;static UNPACKED_OP_FREQ_COARSE=19;static UNPACKED_OP_OSC_DETUNE=20;static UNPACKED_OP_FREQ_FINE=21;static UNPACKED_PITCH_EG_RATE_1=138;static UNPACKED_PITCH_EG_RATE_2=139;static UNPACKED_PITCH_EG_RATE_3=140;static UNPACKED_PITCH_EG_RATE_4=141;static UNPACKED_PITCH_EG_LEVEL_1=142;static UNPACKED_PITCH_EG_LEVEL_2=143;static UNPACKED_PITCH_EG_LEVEL_3=144;static UNPACKED_PITCH_EG_LEVEL_4=145;static UNPACKED_ALGORITHM=146;static UNPACKED_FEEDBACK=147;static UNPACKED_OSC_SYNC=148;static UNPACKED_LFO_SPEED=149;static UNPACKED_LFO_DELAY=150;static UNPACKED_LFO_PM_DEPTH=151;static UNPACKED_LFO_AM_DEPTH=152;static UNPACKED_LFO_KEY_SYNC=153;static UNPACKED_LFO_WAVE=154;static UNPACKED_LFO_PM_SENS=155;static UNPACKED_AMP_MOD_SENS=156;static UNPACKED_TRANSPOSE=157;static UNPACKED_EG_BIAS_SENS=158;static UNPACKED_NAME_START=159;static VCED_SIZE=163;static VCED_HEADER_SIZE=6;static VCED_DATA_SIZE=155;static VCED_SYSEX_START=240;static VCED_YAMAHA_ID=67;static VCED_SUB_STATUS=0;static VCED_FORMAT_SINGLE=0;static VCED_BYTE_COUNT_MSB=1;static VCED_BYTE_COUNT_LSB=27;static VCED_SYSEX_END=247;static MASK_7BIT=127;static MASK_2BIT=3;static MASK_3BIT=7;static MASK_4BIT=15;static MASK_5BIT=31;static MASK_1BIT=1;static TRANSPOSE_CENTER=24;static CHAR_YEN=92;static CHAR_ARROW_RIGHT=126;static CHAR_ARROW_LEFT=127;static CHAR_REPLACEMENT_Y=89;static CHAR_REPLACEMENT_GT=62;static CHAR_REPLACEMENT_LT=60;static CHAR_SPACE=32;static CHAR_MIN_PRINTABLE=32;static CHAR_MAX_PRINTABLE=126;static DEFAULT_EG_RATE=99;static DEFAULT_EG_LEVEL_MAX=99;static DEFAULT_EG_LEVEL_MIN=0;static DEFAULT_BREAK_POINT=0;static DEFAULT_OUTPUT_LEVEL=99;static DEFAULT_PITCH_EG_LEVEL=50;static DEFAULT_LFO_SPEED=35;static DEFAULT_LFO_PM_SENS=3;static DEFAULT_DETUNE=7;static DEFAULT_FREQ_COARSE=1;static DEFAULT_ALGORITHM=0;static DEFAULT_FEEDBACK=0;static DEFAULT_OSC_SYNC=1;static DEFAULT_LFO_KEY_SYNC=1;static MIDI_OCTAVE_OFFSET=-2;static MIDI_BREAK_POINT_OFFSET=21;constructor(t,s=0){if(t.length!==n.PACKED_SIZE)throw new d(`Invalid voice data length: expected ${n.PACKED_SIZE} bytes, got ${t.length}`,"length",t.length);this.index=s,this.data=new Uint8Array(t),this.name=this._extractName(),this._unpackedCache=null}_extractName(){const t=this.data.subarray(n.PACKED_NAME_START,n.PACKED_NAME_START+n.NAME_LENGTH);return Array.from(t).map(e=>{let E=e&n.MASK_7BIT;return E===n.CHAR_YEN&&(E=n.CHAR_REPLACEMENT_Y),E===n.CHAR_ARROW_RIGHT&&(E=n.CHAR_REPLACEMENT_GT),E===n.CHAR_ARROW_LEFT&&(E=n.CHAR_REPLACEMENT_LT),(E<n.CHAR_MIN_PRINTABLE||E>n.CHAR_MAX_PRINTABLE)&&(E=n.CHAR_SPACE),String.fromCharCode(E)}).join("").trim()}getParameter(t){if(t<0||t>=n.PACKED_SIZE)throw new d(`Parameter offset out of range: ${t} (must be 0-${n.PACKED_SIZE-1})`,"offset",t);return this.data[t]&n.MASK_7BIT}getUnpackedParameter(t){if(t<0||t>=n.UNPACKED_SIZE)throw new d(`Unpacked parameter offset out of range: ${t} (must be 0-${n.UNPACKED_SIZE-1})`,"offset",t);return this._unpackedCache||(this._unpackedCache=this.unpack()),this._unpackedCache[t]&n.MASK_7BIT}setParameter(t,s){if(t<0||t>=n.PACKED_SIZE)throw new d(`Parameter offset out of range: ${t} (must be 0-${n.PACKED_SIZE-1})`,"offset",t);this.data[t]=s&n.MASK_7BIT,this._unpackedCache=null,t>=n.PACKED_NAME_START&&t<n.PACKED_NAME_START+n.NAME_LENGTH&&(this.name=this._extractName())}unpack(){const t=this.data,s=new Uint8Array(n.UNPACKED_SIZE);return this._unpackOperators(t,s),this._unpackPitchEG(t,s),this._unpackGlobalParams(t,s),this._unpackName(t,s),s}_unpackOperators(t,s){for(let e=0;e<n.NUM_OPERATORS;e++){const E=(n.NUM_OPERATORS-1-e)*n.PACKED_OP_SIZE,_=e*n.UNPACKED_OP_SIZE;this._unpackOperator(t,s,E,_)}}_unpackOperator(t,s,e,E){this._unpackOperatorEG(t,s,e,E),this._unpackOperatorScaling(t,s,e,E),this._unpackOperatorPackedParams(t,s,e,E),this._unpackOperatorFrequency(t,s,e,E)}_unpackOperatorEG(t,s,e,E){s[E+n.UNPACKED_OP_EG_RATE_1]=t[e+n.PACKED_OP_EG_RATE_1]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_RATE_2]=t[e+n.PACKED_OP_EG_RATE_2]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_RATE_3]=t[e+n.PACKED_OP_EG_RATE_3]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_RATE_4]=t[e+n.PACKED_OP_EG_RATE_4]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_1]=t[e+n.PACKED_OP_EG_LEVEL_1]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_2]=t[e+n.PACKED_OP_EG_LEVEL_2]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_3]=t[e+n.PACKED_OP_EG_LEVEL_3]&n.MASK_7BIT,s[E+n.UNPACKED_OP_EG_LEVEL_4]=t[e+n.PACKED_OP_EG_LEVEL_4]&n.MASK_7BIT}_unpackOperatorScaling(t,s,e,E){s[E+n.UNPACKED_OP_BREAK_POINT]=t[e+n.PACKED_OP_BREAK_POINT]&n.MASK_7BIT,s[E+n.UNPACKED_OP_L_SCALE_DEPTH]=t[e+n.PACKED_OP_L_SCALE_DEPTH]&n.MASK_7BIT,s[E+n.UNPACKED_OP_R_SCALE_DEPTH]=t[e+n.PACKED_OP_R_SCALE_DEPTH]&n.MASK_7BIT}_unpackOperatorPackedParams(t,s,e,E){const _=t[e+n.PACKED_OP_CURVES]&n.MASK_7BIT;s[E+n.UNPACKED_OP_L_CURVE]=_&n.MASK_2BIT,s[E+n.UNPACKED_OP_R_CURVE]=_>>2&n.MASK_2BIT;const i=t[e+n.PACKED_OP_RATE_SCALING]&n.MASK_7BIT;s[E+n.UNPACKED_OP_RATE_SCALING]=i&n.MASK_3BIT,s[E+n.UNPACKED_OP_DETUNE]=i>>3&n.MASK_4BIT;const r=t[e+n.PACKED_OP_MOD_SENS]&n.MASK_7BIT;s[E+n.UNPACKED_OP_AMP_MOD_SENS]=r&n.MASK_2BIT,s[E+n.UNPACKED_OP_KEY_VEL_SENS]=r>>2&n.MASK_3BIT,s[E+n.UNPACKED_OP_OUTPUT_LEVEL]=t[e+n.PACKED_OP_OUTPUT_LEVEL]&n.MASK_7BIT}_unpackOperatorFrequency(t,s,e,E){const _=t[e+n.PACKED_OP_MODE_FREQ]&n.MASK_7BIT;s[E+n.UNPACKED_OP_MODE]=_&n.MASK_1BIT,s[E+n.UNPACKED_OP_FREQ_COARSE]=_>>1&n.MASK_5BIT;const i=t[e+n.PACKED_OP_DETUNE_FINE]&n.MASK_7BIT;s[E+n.UNPACKED_OP_OSC_DETUNE]=i&n.MASK_3BIT,s[E+n.UNPACKED_OP_FREQ_FINE]=i>>3&n.MASK_4BIT}_unpackPitchEG(t,s){s[n.UNPACKED_PITCH_EG_RATE_1]=t[n.PACKED_PITCH_EG_RATE_1]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_RATE_2]=t[n.PACKED_PITCH_EG_RATE_2]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_RATE_3]=t[n.PACKED_PITCH_EG_RATE_3]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_RATE_4]=t[n.PACKED_PITCH_EG_RATE_4]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_1]=t[n.PACKED_PITCH_EG_LEVEL_1]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_2]=t[n.PACKED_PITCH_EG_LEVEL_2]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_3]=t[n.PACKED_PITCH_EG_LEVEL_3]&n.MASK_7BIT,s[n.UNPACKED_PITCH_EG_LEVEL_4]=t[n.PACKED_PITCH_EG_LEVEL_4]&n.MASK_7BIT}_unpackGlobalParams(t,s){s[n.UNPACKED_ALGORITHM]=t[n.OFFSET_ALGORITHM]&n.MASK_5BIT;const e=t[n.OFFSET_FEEDBACK]&n.MASK_7BIT;s[n.UNPACKED_FEEDBACK]=e&n.MASK_3BIT,s[n.UNPACKED_OSC_SYNC]=e>>3&n.MASK_1BIT,s[n.UNPACKED_LFO_SPEED]=t[n.OFFSET_LFO_SPEED]&n.MASK_7BIT,s[n.UNPACKED_LFO_DELAY]=t[n.OFFSET_LFO_DELAY]&n.MASK_7BIT,s[n.UNPACKED_LFO_PM_DEPTH]=t[n.OFFSET_LFO_PM_DEPTH]&n.MASK_7BIT,s[n.UNPACKED_LFO_AM_DEPTH]=t[n.OFFSET_LFO_AM_DEPTH]&n.MASK_7BIT;const E=t[n.OFFSET_LFO_SYNC_WAVE]&n.MASK_7BIT;s[n.UNPACKED_LFO_KEY_SYNC]=E&n.MASK_1BIT,s[n.UNPACKED_LFO_WAVE]=E>>1&n.MASK_3BIT,s[n.UNPACKED_LFO_PM_SENS]=E>>4&n.MASK_3BIT,s[n.UNPACKED_AMP_MOD_SENS]=t[n.OFFSET_AMP_MOD_SENS]&n.MASK_7BIT,s[n.UNPACKED_TRANSPOSE]=t[n.OFFSET_TRANSPOSE]&n.MASK_7BIT,s[n.UNPACKED_EG_BIAS_SENS]=t[n.OFFSET_EG_BIAS_SENS]&n.MASK_7BIT}_unpackName(t,s){for(let e=0;e<n.NAME_LENGTH;e++)s[n.UNPACKED_NAME_START+e]=t[n.PACKED_NAME_START+e]&n.MASK_7BIT}static pack(t){if(t.length!==n.UNPACKED_SIZE)throw new d(`Invalid unpacked data length: expected ${n.UNPACKED_SIZE} bytes, got ${t.length}`,"length",t.length);const s=new Uint8Array(n.PACKED_SIZE);return n._packOperators(t,s),n._packPitchEG(t,s),n._packGlobalParams(t,s),n._packName(t,s),s}static _packOperators(t,s){for(let e=0;e<n.NUM_OPERATORS;e++){const E=e*n.UNPACKED_OP_SIZE,_=(n.NUM_OPERATORS-1-e)*n.PACKED_OP_SIZE;n._packOperator(t,s,E,_)}}static _packOperator(t,s,e,E){n._packOperatorEG(t,s,e,E),n._packOperatorScaling(t,s,e,E),n._packOperatorPackedParams(t,s,e,E),n._packOperatorFrequency(t,s,e,E)}static _packOperatorEG(t,s,e,E){s[E+n.PACKED_OP_EG_RATE_1]=t[e+n.UNPACKED_OP_EG_RATE_1],s[E+n.PACKED_OP_EG_RATE_2]=t[e+n.UNPACKED_OP_EG_RATE_2],s[E+n.PACKED_OP_EG_RATE_3]=t[e+n.UNPACKED_OP_EG_RATE_3],s[E+n.PACKED_OP_EG_RATE_4]=t[e+n.UNPACKED_OP_EG_RATE_4],s[E+n.PACKED_OP_EG_LEVEL_1]=t[e+n.UNPACKED_OP_EG_LEVEL_1],s[E+n.PACKED_OP_EG_LEVEL_2]=t[e+n.UNPACKED_OP_EG_LEVEL_2],s[E+n.PACKED_OP_EG_LEVEL_3]=t[e+n.UNPACKED_OP_EG_LEVEL_3],s[E+n.PACKED_OP_EG_LEVEL_4]=t[e+n.UNPACKED_OP_EG_LEVEL_4]}static _packOperatorScaling(t,s,e,E){s[E+n.PACKED_OP_BREAK_POINT]=t[e+n.UNPACKED_OP_BREAK_POINT],s[E+n.PACKED_OP_L_SCALE_DEPTH]=t[e+n.UNPACKED_OP_L_SCALE_DEPTH],s[E+n.PACKED_OP_R_SCALE_DEPTH]=t[e+n.UNPACKED_OP_R_SCALE_DEPTH]}static _packOperatorPackedParams(t,s,e,E){const _=t[e+n.UNPACKED_OP_L_CURVE]&n.MASK_2BIT,i=t[e+n.UNPACKED_OP_R_CURVE]&n.MASK_2BIT;s[E+n.PACKED_OP_CURVES]=_|i<<2;const r=t[e+n.UNPACKED_OP_RATE_SCALING]&n.MASK_3BIT,h=t[e+n.UNPACKED_OP_DETUNE]&n.MASK_4BIT;s[E+n.PACKED_OP_RATE_SCALING]=r|h<<3;const N=t[e+n.UNPACKED_OP_AMP_MOD_SENS]&n.MASK_2BIT,P=t[e+n.UNPACKED_OP_KEY_VEL_SENS]&n.MASK_3BIT;s[E+n.PACKED_OP_MOD_SENS]=N|P<<2,s[E+n.PACKED_OP_OUTPUT_LEVEL]=t[e+n.UNPACKED_OP_OUTPUT_LEVEL]}static _packOperatorFrequency(t,s,e,E){const _=t[e+n.UNPACKED_OP_MODE]&n.MASK_1BIT,i=t[e+n.UNPACKED_OP_FREQ_COARSE]&n.MASK_5BIT;s[E+n.PACKED_OP_MODE_FREQ]=_|i<<1;const r=t[e+n.UNPACKED_OP_OSC_DETUNE]&n.MASK_3BIT,h=t[e+n.UNPACKED_OP_FREQ_FINE]&n.MASK_4BIT;s[E+n.PACKED_OP_DETUNE_FINE]=r|h<<3}static _packPitchEG(t,s){s[n.PACKED_PITCH_EG_RATE_1]=t[n.UNPACKED_PITCH_EG_RATE_1],s[n.PACKED_PITCH_EG_RATE_2]=t[n.UNPACKED_PITCH_EG_RATE_2],s[n.PACKED_PITCH_EG_RATE_3]=t[n.UNPACKED_PITCH_EG_RATE_3],s[n.PACKED_PITCH_EG_RATE_4]=t[n.UNPACKED_PITCH_EG_RATE_4],s[n.PACKED_PITCH_EG_LEVEL_1]=t[n.UNPACKED_PITCH_EG_LEVEL_1],s[n.PACKED_PITCH_EG_LEVEL_2]=t[n.UNPACKED_PITCH_EG_LEVEL_2],s[n.PACKED_PITCH_EG_LEVEL_3]=t[n.UNPACKED_PITCH_EG_LEVEL_3],s[n.PACKED_PITCH_EG_LEVEL_4]=t[n.UNPACKED_PITCH_EG_LEVEL_4]}static _packGlobalParams(t,s){s[n.OFFSET_ALGORITHM]=t[n.UNPACKED_ALGORITHM];const e=t[n.UNPACKED_FEEDBACK]&n.MASK_3BIT,E=t[n.UNPACKED_OSC_SYNC]&n.MASK_1BIT;s[n.OFFSET_FEEDBACK]=e|E<<3,s[n.OFFSET_LFO_SPEED]=t[n.UNPACKED_LFO_SPEED],s[n.OFFSET_LFO_DELAY]=t[n.UNPACKED_LFO_DELAY],s[n.OFFSET_LFO_PM_DEPTH]=t[n.UNPACKED_LFO_PM_DEPTH],s[n.OFFSET_LFO_AM_DEPTH]=t[n.UNPACKED_LFO_AM_DEPTH];const _=t[n.UNPACKED_LFO_KEY_SYNC]&n.MASK_1BIT,i=t[n.UNPACKED_LFO_WAVE]&n.MASK_3BIT,r=t[n.UNPACKED_LFO_PM_SENS]&n.MASK_3BIT;s[n.OFFSET_LFO_SYNC_WAVE]=_|i<<1|r<<4,s[n.OFFSET_AMP_MOD_SENS]=t[n.UNPACKED_AMP_MOD_SENS],s[n.OFFSET_TRANSPOSE]=t[n.UNPACKED_TRANSPOSE],s[n.OFFSET_EG_BIAS_SENS]=t[n.UNPACKED_EG_BIAS_SENS]}static _packName(t,s){for(let e=0;e<n.NAME_LENGTH;e++)s[n.PACKED_NAME_START+e]=t[n.UNPACKED_NAME_START+e]}static createDefault(t=0){const s=new Uint8Array(n.UNPACKED_SIZE);for(let _=0;_<n.NUM_OPERATORS;_++){const i=_*n.UNPACKED_OP_SIZE;s[i+n.UNPACKED_OP_EG_RATE_1]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_RATE_2]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_RATE_3]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_RATE_4]=n.DEFAULT_EG_RATE,s[i+n.UNPACKED_OP_EG_LEVEL_1]=n.DEFAULT_EG_LEVEL_MAX,s[i+n.UNPACKED_OP_EG_LEVEL_2]=n.DEFAULT_EG_LEVEL_MAX,s[i+n.UNPACKED_OP_EG_LEVEL_3]=n.DEFAULT_EG_LEVEL_MAX,s[i+n.UNPACKED_OP_EG_LEVEL_4]=n.DEFAULT_EG_LEVEL_MIN,s[i+n.UNPACKED_OP_BREAK_POINT]=n.DEFAULT_BREAK_POINT,s[i+n.UNPACKED_OP_L_SCALE_DEPTH]=0,s[i+n.UNPACKED_OP_R_SCALE_DEPTH]=0,s[i+n.UNPACKED_OP_L_CURVE]=0,s[i+n.UNPACKED_OP_R_CURVE]=0,s[i+n.UNPACKED_OP_RATE_SCALING]=0,s[i+n.UNPACKED_OP_DETUNE]=n.DEFAULT_DETUNE,s[i+n.UNPACKED_OP_AMP_MOD_SENS]=0,s[i+n.UNPACKED_OP_KEY_VEL_SENS]=0,s[i+n.UNPACKED_OP_OUTPUT_LEVEL]=n.DEFAULT_OUTPUT_LEVEL,s[i+n.UNPACKED_OP_MODE]=0,s[i+n.UNPACKED_OP_FREQ_COARSE]=n.DEFAULT_FREQ_COARSE,s[i+n.UNPACKED_OP_OSC_DETUNE]=0,s[i+n.UNPACKED_OP_FREQ_FINE]=0}s[n.UNPACKED_PITCH_EG_RATE_1]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_RATE_2]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_RATE_3]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_RATE_4]=n.DEFAULT_EG_RATE,s[n.UNPACKED_PITCH_EG_LEVEL_1]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_PITCH_EG_LEVEL_2]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_PITCH_EG_LEVEL_3]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_PITCH_EG_LEVEL_4]=n.DEFAULT_PITCH_EG_LEVEL,s[n.UNPACKED_ALGORITHM]=n.DEFAULT_ALGORITHM,s[n.UNPACKED_FEEDBACK]=n.DEFAULT_FEEDBACK,s[n.UNPACKED_OSC_SYNC]=n.DEFAULT_OSC_SYNC,s[n.UNPACKED_LFO_SPEED]=n.DEFAULT_LFO_SPEED,s[n.UNPACKED_LFO_DELAY]=0,s[n.UNPACKED_LFO_PM_DEPTH]=0,s[n.UNPACKED_LFO_AM_DEPTH]=0,s[n.UNPACKED_LFO_KEY_SYNC]=n.DEFAULT_LFO_KEY_SYNC,s[n.UNPACKED_LFO_WAVE]=0,s[n.UNPACKED_LFO_PM_SENS]=n.DEFAULT_LFO_PM_SENS,s[n.UNPACKED_AMP_MOD_SENS]=0,s[n.UNPACKED_TRANSPOSE]=n.TRANSPOSE_CENTER,s[n.UNPACKED_EG_BIAS_SENS]=0;const e="Init Voice";for(let _=0;_<n.NAME_LENGTH;_++)s[n.UNPACKED_NAME_START+_]=_<e.length?e.charCodeAt(_):n.CHAR_SPACE;const E=n.pack(s);return new n(E,t)}static fromUnpacked(t,s=0){const e=n.pack(t);return new n(e,s)}static async fromFile(t){return new Promise((s,e)=>{const E=new FileReader;E.onload=_=>{try{const i=new Uint8Array(_.target.result);if(i[0]!==n.VCED_SYSEX_START||i[1]!==n.VCED_YAMAHA_ID||i[2]!==n.VCED_SUB_STATUS||i[3]!==n.VCED_FORMAT_SINGLE||i[4]!==n.VCED_BYTE_COUNT_MSB||i[5]!==n.VCED_BYTE_COUNT_LSB)throw new M("Invalid VCED header","header",0);const r=i.subarray(n.VCED_HEADER_SIZE,n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE),h=i[n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE],N=u._calculateChecksum(r,n.VCED_DATA_SIZE);h!==N&&console.warn(`DX7 VCED checksum mismatch (expected ${N.toString(16)}, got ${h.toString(16)}). This is common with vintage SysEx files.`);const P=new Uint8Array(n.UNPACKED_SIZE);let a=0;for(let S=0;S<n.NUM_OPERATORS;S++){const O=(n.NUM_OPERATORS-1-S)*n.UNPACKED_OP_SIZE;P[O+n.UNPACKED_OP_EG_RATE_1]=r[a++],P[O+n.UNPACKED_OP_EG_RATE_2]=r[a++],P[O+n.UNPACKED_OP_EG_RATE_3]=r[a++],P[O+n.UNPACKED_OP_EG_RATE_4]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_1]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_2]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_3]=r[a++],P[O+n.UNPACKED_OP_EG_LEVEL_4]=r[a++],P[O+n.UNPACKED_OP_BREAK_POINT]=r[a++],P[O+n.UNPACKED_OP_L_SCALE_DEPTH]=r[a++],P[O+n.UNPACKED_OP_R_SCALE_DEPTH]=r[a++],P[O+n.UNPACKED_OP_L_CURVE]=r[a++],P[O+n.UNPACKED_OP_R_CURVE]=r[a++],P[O+n.UNPACKED_OP_RATE_SCALING]=r[a++],P[O+n.UNPACKED_OP_DETUNE]=r[a++];const T=r[a++];P[O+n.UNPACKED_OP_AMP_MOD_SENS]=T&n.MASK_2BIT,P[O+n.UNPACKED_OP_KEY_VEL_SENS]=T>>2&n.MASK_3BIT,P[O+n.UNPACKED_OP_OUTPUT_LEVEL]=r[a++],P[O+n.UNPACKED_OP_MODE]=r[a++],P[O+n.UNPACKED_OP_FREQ_COARSE]=r[a++],P[O+n.UNPACKED_OP_FREQ_FINE]=r[a++],P[O+n.UNPACKED_OP_OSC_DETUNE]=r[a++]}P[n.UNPACKED_PITCH_EG_RATE_1]=r[a++],P[n.UNPACKED_PITCH_EG_RATE_2]=r[a++],P[n.UNPACKED_PITCH_EG_RATE_3]=r[a++],P[n.UNPACKED_PITCH_EG_RATE_4]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_1]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_2]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_3]=r[a++],P[n.UNPACKED_PITCH_EG_LEVEL_4]=r[a++],P[n.UNPACKED_ALGORITHM]=r[a++],P[n.UNPACKED_FEEDBACK]=r[a++],P[n.UNPACKED_OSC_SYNC]=r[a++],P[n.UNPACKED_LFO_SPEED]=r[a++],P[n.UNPACKED_LFO_DELAY]=r[a++],P[n.UNPACKED_LFO_PM_DEPTH]=r[a++],P[n.UNPACKED_LFO_AM_DEPTH]=r[a++],P[n.UNPACKED_LFO_KEY_SYNC]=r[a++],P[n.UNPACKED_LFO_WAVE]=r[a++],P[n.UNPACKED_LFO_PM_SENS]=r[a++],P[n.UNPACKED_TRANSPOSE]=r[a++];for(let S=0;S<n.NAME_LENGTH;S++)P[n.UNPACKED_NAME_START+S]=r[a++];const A=n.pack(P);s(new n(A,0))}catch(i){e(i)}},E.onerror=()=>e(new Error("Failed to read file")),E.readAsArrayBuffer(t)})}static fromSysEx(t,s=0){const e=t instanceof Uint8Array?t:new Uint8Array(t);let E;if(e[0]===n.VCED_SYSEX_START){if(e[0]!==n.VCED_SYSEX_START||e[1]!==n.VCED_YAMAHA_ID||e[2]!==n.VCED_SUB_STATUS||e[3]!==n.VCED_FORMAT_SINGLE||e[4]!==n.VCED_BYTE_COUNT_MSB||e[5]!==n.VCED_BYTE_COUNT_LSB)throw new M("Invalid VCED header","header",0);E=e.subarray(n.VCED_HEADER_SIZE,n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE)}else if(e.length===n.PACKED_SIZE)E=e;else throw new d(`Invalid data length: expected ${n.PACKED_SIZE} or ${n.VCED_SIZE} bytes, got ${e.length}`,"length",e.length);if(E.length!==n.VCED_DATA_SIZE&&E.length!==n.PACKED_SIZE)throw new d(`Invalid voice data length: expected ${n.VCED_DATA_SIZE} or ${n.PACKED_SIZE} bytes, got ${E.length}`,"length",E.length);if(E.length===n.VCED_DATA_SIZE){const _=new Uint8Array(n.UNPACKED_SIZE);let i=0;for(let h=0;h<n.NUM_OPERATORS;h++){const N=(n.NUM_OPERATORS-1-h)*n.UNPACKED_OP_SIZE;_[N+n.UNPACKED_OP_EG_RATE_1]=E[i++],_[N+n.UNPACKED_OP_EG_RATE_2]=E[i++],_[N+n.UNPACKED_OP_EG_RATE_3]=E[i++],_[N+n.UNPACKED_OP_EG_RATE_4]=E[i++],_[N+n.UNPACKED_OP_EG_LEVEL_1]=E[i++],_[N+n.UNPACKED_OP_EG_LEVEL_2]=E[i++],_[N+n.UNPACKED_OP_EG_LEVEL_3]=E[i++],_[N+n.UNPACKED_OP_EG_LEVEL_4]=E[i++],_[N+n.UNPACKED_OP_BREAK_POINT]=E[i++],_[N+n.UNPACKED_OP_L_SCALE_DEPTH]=E[i++],_[N+n.UNPACKED_OP_R_SCALE_DEPTH]=E[i++],_[N+n.UNPACKED_OP_L_CURVE]=E[i++],_[N+n.UNPACKED_OP_R_CURVE]=E[i++],_[N+n.UNPACKED_OP_RATE_SCALING]=E[i++],_[N+n.UNPACKED_OP_DETUNE]=E[i++];const P=E[i++];_[N+n.UNPACKED_OP_AMP_MOD_SENS]=P&n.MASK_2BIT,_[N+n.UNPACKED_OP_KEY_VEL_SENS]=P>>2&n.MASK_3BIT,_[N+n.UNPACKED_OP_OUTPUT_LEVEL]=E[i++],_[N+n.UNPACKED_OP_MODE]=E[i++],_[N+n.UNPACKED_OP_FREQ_COARSE]=E[i++],_[N+n.UNPACKED_OP_FREQ_FINE]=E[i++],_[N+n.UNPACKED_OP_OSC_DETUNE]=E[i++]}_[n.UNPACKED_PITCH_EG_RATE_1]=E[i++],_[n.UNPACKED_PITCH_EG_RATE_2]=E[i++],_[n.UNPACKED_PITCH_EG_RATE_3]=E[i++],_[n.UNPACKED_PITCH_EG_RATE_4]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_1]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_2]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_3]=E[i++],_[n.UNPACKED_PITCH_EG_LEVEL_4]=E[i++],_[n.UNPACKED_ALGORITHM]=E[i++],_[n.UNPACKED_FEEDBACK]=E[i++],_[n.UNPACKED_OSC_SYNC]=E[i++],_[n.UNPACKED_LFO_SPEED]=E[i++],_[n.UNPACKED_LFO_DELAY]=E[i++],_[n.UNPACKED_LFO_PM_DEPTH]=E[i++],_[n.UNPACKED_LFO_AM_DEPTH]=E[i++],_[n.UNPACKED_LFO_KEY_SYNC]=E[i++],_[n.UNPACKED_LFO_WAVE]=E[i++],_[n.UNPACKED_LFO_PM_SENS]=E[i++],_[n.UNPACKED_TRANSPOSE]=E[i++];for(let h=0;h<n.NAME_LENGTH;h++)_[n.UNPACKED_NAME_START+h]=E[i++];const r=n.pack(_);return new n(r,s)}return new n(E,s)}static fromJSON(t,s=0){if(!t||typeof t!="object")throw new d("Invalid JSON: expected object","json",t);const e=new Uint8Array(n.UNPACKED_SIZE),E=(a,A,S,O=0,T=127)=>{if(A==null)throw new d(`Missing required parameter: ${S}`,S,A);const I=Number(A);if(Number.isNaN(I))throw new d(`Invalid parameter value for ${S}: ${A}`,S,A);if(I<O||I>T)throw new d(`Parameter ${S} out of range: ${I} (must be ${O}-${T})`,S,I);e[a]=Math.floor(I)},_=a=>{const A={"-LN":0,"-EX":1,"+EX":2,"+LN":3};return A[a]!==void 0?A[a]:0},i=a=>{const A={TRIANGLE:0,"SAW DOWN":1,"SAW UP":2,SQUARE:3,SINE:4,"SAMPLE & HOLD":5};return A[a]!==void 0?A[a]:0},r=a=>{if(!a||typeof a!="string")return 60;const A=a.trim().match(/^([A-G]#?)(-?\d+)$/);if(!A)return 60;const[,S,O]=A,T=parseInt(O,10),f={C:0,"C#":1,D:2,"D#":3,E:4,F:5,"F#":6,G:7,"G#":8,A:9,"A#":10,B:11}[S.toUpperCase()];return f===void 0?60:(T-n.MIDI_OCTAVE_OFFSET)*12+f};if(!Array.isArray(t.operators))throw new d("Invalid operators array: expected array","operators",t.operators);for(let a=0;a<t.operators.length;a++){const A=t.operators[a];if(!A||typeof A!="object")throw new d(`Invalid operator data at index ${a}`,`operators[${a}]`,A);if(!A.eg||!Array.isArray(A.eg.rates)||A.eg.rates.length!==4)throw new d(`Invalid EG rates for operator ${a}`,`operators[${a}].eg.rates`,A.eg?.rates);if(!A.eg||!Array.isArray(A.eg.levels)||A.eg.levels.length!==4)throw new d(`Invalid EG levels for operator ${a}`,`operators[${a}].eg.levels`,A.eg?.levels)}if(t.operators.length!==n.NUM_OPERATORS)throw new d(`Invalid operators array: expected ${n.NUM_OPERATORS} operators`,"operators",t.operators);for(let a=0;a<n.NUM_OPERATORS;a++){const A=t.operators[a],S=a*n.UNPACKED_OP_SIZE;if(!A.eg||!Array.isArray(A.eg.rates)||A.eg.rates.length!==4)throw new d(`Invalid EG rates for operator ${a}`,`operators[${a}].eg.rates`,A.eg?.rates);if(E(S+n.UNPACKED_OP_EG_RATE_1,A.eg.rates[0],`operators[${a}].eg.rates[0]`,0,99),E(S+n.UNPACKED_OP_EG_RATE_2,A.eg.rates[1],`operators[${a}].eg.rates[1]`,0,99),E(S+n.UNPACKED_OP_EG_RATE_3,A.eg.rates[2],`operators[${a}].eg.rates[2]`,0,99),E(S+n.UNPACKED_OP_EG_RATE_4,A.eg.rates[3],`operators[${a}].eg.rates[3]`,0,99),!A.eg||!Array.isArray(A.eg.levels)||A.eg.levels.length!==4)throw new d(`Invalid EG levels for operator ${a}`,`operators[${a}].eg.levels`,A.eg?.levels);E(S+n.UNPACKED_OP_EG_LEVEL_1,A.eg.levels[0],`operators[${a}].eg.levels[0]`,0,99),E(S+n.UNPACKED_OP_EG_LEVEL_2,A.eg.levels[1],`operators[${a}].eg.levels[1]`,0,99),E(S+n.UNPACKED_OP_EG_LEVEL_3,A.eg.levels[2],`operators[${a}].eg.levels[2]`,0,99),E(S+n.UNPACKED_OP_EG_LEVEL_4,A.eg.levels[3],`operators[${a}].eg.levels[3]`,0,99);const O=r(A.key?.breakPoint)-n.MIDI_BREAK_POINT_OFFSET;E(S+n.UNPACKED_OP_BREAK_POINT,O,`operators[${a}].key.breakPoint`,0,127),E(S+n.UNPACKED_OP_L_SCALE_DEPTH,A.scale?.left?.depth||0,`operators[${a}].scale.left.depth`,0,99),E(S+n.UNPACKED_OP_R_SCALE_DEPTH,A.scale?.right?.depth||0,`operators[${a}].scale.right.depth`,0,99),e[S+n.UNPACKED_OP_L_CURVE]=_(A.scale?.left?.curve||"-LN"),e[S+n.UNPACKED_OP_R_CURVE]=_(A.scale?.right?.curve||"-LN"),E(S+n.UNPACKED_OP_RATE_SCALING,A.key?.scaling||0,`operators[${a}].key.scaling`,0,7);const T=Number(A.osc?.detune)||0;E(S+n.UNPACKED_OP_DETUNE,T+7,`operators[${a}].osc.detune`,0,14),E(S+n.UNPACKED_OP_AMP_MOD_SENS,A.output?.ampModSens||0,`operators[${a}].output.ampModSens`,0,3),E(S+n.UNPACKED_OP_OUTPUT_LEVEL,A.output?.level||0,`operators[${a}].output.level`,0,99);const I=A.osc?.freq?.mode?.toUpperCase()==="FIXED"?1:0,f=Number(A.osc?.freq?.coarse)||0,K=Number(A.osc?.freq?.fine)||0;e[S+n.UNPACKED_OP_MODE]=I,E(S+n.UNPACKED_OP_FREQ_COARSE,f,`operators[${a}].osc.freq.coarse`,0,31),E(S+n.UNPACKED_OP_FREQ_FINE,K,`operators[${a}].osc.freq.fine`,0,15),E(S+n.UNPACKED_OP_KEY_VEL_SENS,A.key?.velocity||0,`operators[${a}].key.velocity`,0,7)}if(!t.pitchEG||!Array.isArray(t.pitchEG.rates)||t.pitchEG.rates.length!==4)throw new d("Invalid pitch EG rates","pitchEG.rates",t.pitchEG?.rates);if(!t.pitchEG||!Array.isArray(t.pitchEG.levels)||t.pitchEG.levels.length!==4)throw new d("Invalid pitch EG levels","pitchEG.levels",t.pitchEG?.levels);if(E(n.UNPACKED_PITCH_EG_RATE_1,t.pitchEG.rates[0],"pitchEG.rates[0]",0,99),E(n.UNPACKED_PITCH_EG_RATE_2,t.pitchEG.rates[1],"pitchEG.rates[1]",0,99),E(n.UNPACKED_PITCH_EG_RATE_3,t.pitchEG.rates[2],"pitchEG.rates[2]",0,99),E(n.UNPACKED_PITCH_EG_RATE_4,t.pitchEG.rates[3],"pitchEG.rates[3]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_1,t.pitchEG.levels[0],"pitchEG.levels[0]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_2,t.pitchEG.levels[1],"pitchEG.levels[1]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_3,t.pitchEG.levels[2],"pitchEG.levels[2]",0,99),E(n.UNPACKED_PITCH_EG_LEVEL_4,t.pitchEG.levels[3],"pitchEG.levels[3]",0,99),!t.lfo||typeof t.lfo!="object")throw new d("Invalid LFO data","lfo",t.lfo);if(E(n.UNPACKED_LFO_SPEED,t.lfo.speed,"lfo.speed",0,99),E(n.UNPACKED_LFO_DELAY,t.lfo.delay,"lfo.delay",0,99),E(n.UNPACKED_LFO_PM_DEPTH,t.lfo.pmDepth,"lfo.pmDepth",0,99),E(n.UNPACKED_LFO_AM_DEPTH,t.lfo.amDepth,"lfo.amDepth",0,99),e[n.UNPACKED_LFO_KEY_SYNC]=t.lfo.keySync?1:0,e[n.UNPACKED_LFO_WAVE]=i(t.lfo.wave),!t.global||typeof t.global!="object")throw new d("Invalid global data","global",t.global);const h=Number(t.global.algorithm)||1;E(n.UNPACKED_ALGORITHM,h-1,"global.algorithm",0,31),E(n.UNPACKED_FEEDBACK,t.global.feedback,"global.feedback",0,7),e[n.UNPACKED_OSC_SYNC]=t.global.oscKeySync?1:0,E(n.UNPACKED_LFO_PM_SENS,t.global.pitchModSens,"global.pitchModSens",0,7);const N=Number(t.global.transpose)||0;E(n.UNPACKED_TRANSPOSE,N+n.TRANSPOSE_CENTER,"global.transpose",0,127),E(n.UNPACKED_AMP_MOD_SENS,t.global.ampModSens||0,"global.ampModSens",0,3),E(n.UNPACKED_EG_BIAS_SENS,t.global.egBiasSens||0,"global.egBiasSens",0,7);const P=t.name||"";for(let a=0;a<n.NAME_LENGTH;a++)e[n.UNPACKED_NAME_START+a]=a<P.length?P.charCodeAt(a):n.CHAR_SPACE;return n.fromUnpacked(e,s)}toSysEx(){const t=this.unpack(),s=new Uint8Array(n.VCED_SIZE);let e=0;s[e++]=n.VCED_SYSEX_START,s[e++]=n.VCED_YAMAHA_ID,s[e++]=n.VCED_SUB_STATUS,s[e++]=n.VCED_FORMAT_SINGLE,s[e++]=n.VCED_BYTE_COUNT_MSB,s[e++]=n.VCED_BYTE_COUNT_LSB;for(let _=n.NUM_OPERATORS-1;_>=0;_--){const i=_*n.UNPACKED_OP_SIZE;s[e++]=t[i+n.UNPACKED_OP_EG_RATE_1],s[e++]=t[i+n.UNPACKED_OP_EG_RATE_2],s[e++]=t[i+n.UNPACKED_OP_EG_RATE_3],s[e++]=t[i+n.UNPACKED_OP_EG_RATE_4],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_1],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_2],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_3],s[e++]=t[i+n.UNPACKED_OP_EG_LEVEL_4],s[e++]=t[i+n.UNPACKED_OP_BREAK_POINT],s[e++]=t[i+n.UNPACKED_OP_L_SCALE_DEPTH],s[e++]=t[i+n.UNPACKED_OP_R_SCALE_DEPTH],s[e++]=t[i+n.UNPACKED_OP_L_CURVE],s[e++]=t[i+n.UNPACKED_OP_R_CURVE],s[e++]=t[i+n.UNPACKED_OP_RATE_SCALING],s[e++]=t[i+n.UNPACKED_OP_DETUNE];const r=t[i+n.UNPACKED_OP_AMP_MOD_SENS]&n.MASK_2BIT,h=t[i+n.UNPACKED_OP_KEY_VEL_SENS]&n.MASK_3BIT;s[e++]=r|h<<2,s[e++]=t[i+n.UNPACKED_OP_OUTPUT_LEVEL],s[e++]=t[i+n.UNPACKED_OP_MODE],s[e++]=t[i+n.UNPACKED_OP_FREQ_COARSE],s[e++]=t[i+n.UNPACKED_OP_OSC_DETUNE],s[e++]=t[i+n.UNPACKED_OP_FREQ_FINE]}s[e++]=t[n.UNPACKED_PITCH_EG_RATE_1],s[e++]=t[n.UNPACKED_PITCH_EG_RATE_2],s[e++]=t[n.UNPACKED_PITCH_EG_RATE_3],s[e++]=t[n.UNPACKED_PITCH_EG_RATE_4],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_1],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_2],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_3],s[e++]=t[n.UNPACKED_PITCH_EG_LEVEL_4],s[e++]=t[n.UNPACKED_ALGORITHM],s[e++]=t[n.UNPACKED_FEEDBACK],s[e++]=t[n.UNPACKED_OSC_SYNC],s[e++]=t[n.UNPACKED_LFO_SPEED],s[e++]=t[n.UNPACKED_LFO_DELAY],s[e++]=t[n.UNPACKED_LFO_PM_DEPTH],s[e++]=t[n.UNPACKED_LFO_AM_DEPTH],s[e++]=t[n.UNPACKED_LFO_KEY_SYNC],s[e++]=t[n.UNPACKED_LFO_WAVE],s[e++]=t[n.UNPACKED_LFO_PM_SENS],s[e++]=t[n.UNPACKED_TRANSPOSE];for(let _=0;_<n.NAME_LENGTH;_++)s[e++]=t[n.UNPACKED_NAME_START+_];const E=s.subarray(n.VCED_HEADER_SIZE,n.VCED_HEADER_SIZE+n.VCED_DATA_SIZE);return s[e++]=u._calculateChecksum(E,n.VCED_DATA_SIZE),s[e++]=n.VCED_SYSEX_END,s}toJSON(){const t=this.unpack(),s=[],e=i=>["-LN","-EX","+EX","+LN"][i]||"UNKNOWN",E=i=>["TRIANGLE","SAW DOWN","SAW UP","SQUARE","SINE","SAMPLE & HOLD"][i]||"UNKNOWN",_=i=>{const r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],h=Math.floor(i/12)+n.MIDI_OCTAVE_OFFSET;return`${r[i%12]}${h}`};for(let i=0;i<n.NUM_OPERATORS;i++){const r=i*n.UNPACKED_OP_SIZE,h=t[r+n.UNPACKED_OP_MODE]===0?"RATIO":"FIXED";s.push({id:i+1,osc:{detune:t[r+n.UNPACKED_OP_OSC_DETUNE],freq:{coarse:t[r+n.UNPACKED_OP_FREQ_COARSE],fine:t[r+n.UNPACKED_OP_FREQ_FINE],mode:h}},eg:{rates:[t[r+n.UNPACKED_OP_EG_RATE_1],t[r+n.UNPACKED_OP_EG_RATE_2],t[r+n.UNPACKED_OP_EG_RATE_3],t[r+n.UNPACKED_OP_EG_RATE_4]],levels:[t[r+n.UNPACKED_OP_EG_LEVEL_1],t[r+n.UNPACKED_OP_EG_LEVEL_2],t[r+n.UNPACKED_OP_EG_LEVEL_3],t[r+n.UNPACKED_OP_EG_LEVEL_4]]},key:{velocity:t[r+n.UNPACKED_OP_KEY_VEL_SENS],scaling:t[r+n.UNPACKED_OP_RATE_SCALING],breakPoint:_(t[r+n.UNPACKED_OP_BREAK_POINT]+n.MIDI_BREAK_POINT_OFFSET)},output:{level:t[r+n.UNPACKED_OP_OUTPUT_LEVEL],ampModSens:t[r+n.UNPACKED_OP_AMP_MOD_SENS]},scale:{left:{depth:t[r+n.UNPACKED_OP_L_SCALE_DEPTH],curve:e(t[r+n.UNPACKED_OP_L_CURVE])},right:{depth:t[r+n.UNPACKED_OP_R_SCALE_DEPTH],curve:e(t[r+n.UNPACKED_OP_R_CURVE])}}})}return{name:this.name||"(Empty)",operators:s,pitchEG:{rates:[t[n.UNPACKED_PITCH_EG_RATE_1],t[n.UNPACKED_PITCH_EG_RATE_2],t[n.UNPACKED_PITCH_EG_RATE_3],t[n.UNPACKED_PITCH_EG_RATE_4]],levels:[t[n.UNPACKED_PITCH_EG_LEVEL_1],t[n.UNPACKED_PITCH_EG_LEVEL_2],t[n.UNPACKED_PITCH_EG_LEVEL_3],t[n.UNPACKED_PITCH_EG_LEVEL_4]]},lfo:{speed:t[n.UNPACKED_LFO_SPEED],delay:t[n.UNPACKED_LFO_DELAY],pmDepth:t[n.UNPACKED_LFO_PM_DEPTH],amDepth:t[n.UNPACKED_LFO_AM_DEPTH],keySync:t[n.UNPACKED_LFO_KEY_SYNC]===1,wave:E(t[n.UNPACKED_LFO_WAVE])},global:{algorithm:t[n.UNPACKED_ALGORITHM]+1,feedback:t[n.UNPACKED_FEEDBACK],oscKeySync:t[n.UNPACKED_OSC_SYNC]===1,pitchModSens:t[n.UNPACKED_LFO_PM_SENS],transpose:t[n.UNPACKED_TRANSPOSE]-n.TRANSPOSE_CENTER}}}}class u{static SYSEX_START=240;static SYSEX_END=247;static SYSEX_YAMAHA_ID=67;static SYSEX_SUB_STATUS=0;static SYSEX_FORMAT_32_VOICES=9;static SYSEX_BYTE_COUNT_MSB=32;static SYSEX_BYTE_COUNT_LSB=0;static SYSEX_HEADER=[u.SYSEX_START,u.SYSEX_YAMAHA_ID,u.SYSEX_SUB_STATUS,u.SYSEX_FORMAT_32_VOICES,u.SYSEX_BYTE_COUNT_MSB,u.SYSEX_BYTE_COUNT_LSB];static SYSEX_HEADER_SIZE=6;static VOICE_DATA_SIZE=4096;static SYSEX_SIZE=4104;static VOICE_SIZE=128;static NUM_VOICES=32;static CHECKSUM_MODULO=128;static MASK_7BIT=127;constructor(t,s=""){if(this.voices=new Array(u.NUM_VOICES),this.name=s,t)this._load(t);else for(let e=0;e<u.NUM_VOICES;e++)this.voices[e]=n.createDefault(e)}static _calculateChecksum(t,s){let e=0;for(let E=0;E<s;E++)e+=t[E];return u.CHECKSUM_MODULO-e%u.CHECKSUM_MODULO&u.MASK_7BIT}_load(t){const s=t instanceof Uint8Array?t:new Uint8Array(t);let e,E=0;if(s[0]===u.SYSEX_START){const i=s.subarray(0,u.SYSEX_HEADER_SIZE),r=u.SYSEX_HEADER;for(let h=0;h<u.SYSEX_HEADER_SIZE;h++)if(i[h]!==r[h])throw new M(`Invalid SysEx header at position ${h}: expected ${r[h].toString(16)}, got ${i[h].toString(16)}`,"header",h);e=s.subarray(u.SYSEX_HEADER_SIZE,u.SYSEX_HEADER_SIZE+u.VOICE_DATA_SIZE),E=u.SYSEX_HEADER_SIZE}else if(s.length===u.VOICE_DATA_SIZE)e=s;else throw new d(`Invalid data length: expected ${u.VOICE_DATA_SIZE} or ${u.SYSEX_SIZE} bytes, got ${s.length}`,"length",s.length);if(e.length!==u.VOICE_DATA_SIZE)throw new d(`Invalid voice data length: expected ${u.VOICE_DATA_SIZE} bytes, got ${e.length}`,"length",e.length);const _=u.SYSEX_HEADER_SIZE+u.VOICE_DATA_SIZE;if(E>0&&s.length>=_+1){const i=s[_],r=u._calculateChecksum(e,u.VOICE_DATA_SIZE);i!==r&&console.warn(`DX7 checksum mismatch (expected ${r.toString(16)}, got ${i.toString(16)}). This is common with vintage SysEx files and the data is likely still valid.`)}this.voices=new Array(u.NUM_VOICES);for(let i=0;i<u.NUM_VOICES;i++){const r=i*u.VOICE_SIZE,h=e.subarray(r,r+u.VOICE_SIZE);this.voices[i]=new n(h,i)}}replaceVoice(t,s){if(t<0||t>=u.NUM_VOICES)throw new d(`Invalid voice index: ${t}`,"index",t);const e=new Uint8Array(s.data);this.voices[t]=new n(e,t)}addVoice(t){for(let s=0;s<this.voices.length;s++){const e=this.voices[s];if(e.name===""||e.name==="Init Voice")return this.replaceVoice(s,t),s}return-1}getVoices(){return this.voices}getVoice(t){return t<0||t>=this.voices.length?null:this.voices[t]}getVoiceNames(){return this.voices.map(t=>t.name)}findVoiceByName(t){const s=t.toLowerCase();return this.voices.find(e=>e.name.toLowerCase().includes(s))||null}static async fromFile(t){return new Promise((s,e)=>{const E=new FileReader;E.onload=async _=>{try{const i=t.name||"",r=new Uint8Array(_.target.result);if(r[0]===u.SYSEX_START&&r[3]===n.VCED_FORMAT_SINGLE)e(new M("This is a single voice file. Use DX7Voice.fromFile() instead.","format",3));else{const h=i.replace(/\.[^/.]+$/,""),N=new u(_.target.result,h);s(N)}}catch(i){e(i)}},E.onerror=()=>e(new Error("Failed to read file")),E.readAsArrayBuffer(t)})}static fromSysEx(t,s=""){return new u(t,s)}static fromJSON(t){if(!t||typeof t!="object")throw new d("Invalid JSON: expected object","json",t);const s=new u;if(s.name=t.name||"",!Array.isArray(t.voices))throw new d("Invalid voices array","voices",t.voices);t.voices.length!==u.NUM_VOICES&&console.warn(`Bank JSON has ${t.voices.length} voices, expected ${u.NUM_VOICES}. Missing voices will be filled with defaults.`);const e=Math.min(t.voices.length,u.NUM_VOICES);for(let E=0;E<e;E++){const _=t.voices[E];if(!_||typeof _!="object"){console.warn(`Invalid voice data at index ${E}, using default voice`);continue}try{const{index:i,...r}=_,h=n.fromJSON(r,E);s.replaceVoice(E,h)}catch(i){console.warn(`Failed to load voice at index ${E}: ${i.message}, using default voice`)}}return s}toSysEx(){const t=new Uint8Array(u.SYSEX_SIZE);let s=0;u.SYSEX_HEADER.forEach(E=>{t[s++]=E});for(const E of this.voices)for(let _=0;_<u.VOICE_SIZE;_++)t[s++]=E.data[_];const e=t.subarray(u.SYSEX_HEADER_SIZE,u.SYSEX_HEADER_SIZE+u.VOICE_DATA_SIZE);return t[s++]=u._calculateChecksum(e,u.VOICE_DATA_SIZE),t[s++]=u.SYSEX_END,t}toJSON(){const t=this.voices.map((s,e)=>{const E=s.toJSON();return{index:e+1,...E}});return{version:"1.0",name:this.name||"",voices:t}}}function tt(C){return C[0]!==240||C[C.length-1]!==247?null:{manufacturerId:C[1],payload:C.slice(2,-1),raw:C}}function nt(C,t){return[240,C,...t,247]}function st(C){return C.length>=2&&C[0]===240&&C[C.length-1]===247}function et(C){const t=[];for(let s=0;s<C.length;s+=7){const e=C.slice(s,s+7);let E=0;const _=[];for(let i=0;i<e.length;i++){const r=e[i];r&128&&(E|=1<<i),_.push(r&127)}t.push(E,..._)}return t}function Et(C){const t=[];for(let s=0;s<C.length;s+=8){const e=C[s],E=Math.min(7,C.length-s-1);for(let _=0;_<E;_++){let i=C[s+1+_];e&1<<_&&(i|=128),t.push(i)}}return t}function it(C){return Number.isInteger(C)&&C>=1&&C<=16}function _t(C){return Number.isInteger(C)&&C>=0&&C<=127}function rt(C){return Number.isInteger(C)&&C>=0&&C<=31}function at(C){return Number.isInteger(C)&&C>=0&&C<=127}function Ct(C){return Number.isInteger(C)&&C>=0&&C<=127}function At(C){return Number.isInteger(C)&&C>=0&&C<=127}function ot(C){return Number.isInteger(C)&&C>=0&&C<=127}function Pt(C){return Number.isInteger(C)&&C>=0&&C<=16383}function ut(C,t){return Number.isInteger(C)&&C>=0&&C<=127&&Number.isInteger(t)&&t>=0&&t<=127}async function lt(C={}){const{onStatusUpdate:t,onConnectionUpdate:s,inputChannel:e=1,outputChannel:E=1,output:_,sysex:i,onReady:r,onError:h,selector:N,watchDOM:P,...a}=C,S=await Z({autoConnect:!1,sysex:i,inputChannel:e,outputChannel:E,selector:N||"[data-midi-cc]",watchDOM:P,onError:h,...a}),O=new $({midiController:S,onStatusUpdate:t||(()=>{}),onConnectionUpdate:s||(()=>{}),channel:E});if(_)try{await S.device.connectOutput(_),O.currentOutput=S.device.getCurrentOutput(),O.updateConnectionStatus()}catch(T){h?h(T):console.error("Failed to connect to MIDI device:",T.message)}return r&&r(S,O),O}async function Z(C={}){const t=new x(C);await t.init();const s=C.selector||"[data-midi-cc]";{const e=new p(t,s);e.bindAll(),C.watchDOM&&e.enableAutoBinding(),t._binder=e}return t}l.CONN=U,l.CONNECTION_EVENTS=U,l.CONTROLLER_EVENTS=o,l.CTRL=o,l.DX7Bank=u,l.DX7Error=F,l.DX7ParseError=M,l.DX7ValidationError=d,l.DX7Voice=n,l.DataAttributeBinder=p,l.EventEmitter=b,l.MIDIAccessError=g,l.MIDIConnection=Y,l.MIDIConnectionError=G,l.MIDIController=x,l.MIDIDeviceError=L,l.MIDIDeviceManager=$,l.MIDIError=m,l.MIDIValidationError=R,l.clamp=c,l.createMIDIController=Z,l.createMIDIDeviceManager=lt,l.createSysEx=nt,l.decode14BitValue=w,l.decode7Bit=Et,l.denormalize14BitValue=X,l.denormalizeValue=W,l.encode14BitValue=v,l.encode7Bit=et,l.frequencyToNote=j,l.getCCName=V,l.isSysEx=st,l.isValid14BitCC=rt,l.isValidCC=_t,l.isValidChannel=it,l.isValidMIDIValue=at,l.isValidNote=Ct,l.isValidPitchBend=Pt,l.isValidPitchBendBytes=ut,l.isValidProgramChange=ot,l.isValidVelocity=At,l.normalize14BitValue=B,l.normalizeValue=H,l.noteNameToNumber=Q,l.noteNumberToName=J,l.noteToFrequency=k,l.parseSysEx=tt,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
@@ -209,6 +209,8 @@ export class DX7Voice {
209
209
  static DEFAULT_FREQ_COARSE: number;
210
210
  static DEFAULT_ALGORITHM: number;
211
211
  static DEFAULT_FEEDBACK: number;
212
+ static DEFAULT_OSC_SYNC: number;
213
+ static DEFAULT_LFO_KEY_SYNC: number;
212
214
  static MIDI_OCTAVE_OFFSET: number;
213
215
  static MIDI_BREAK_POINT_OFFSET: number;
214
216
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"DX7Voice.d.ts","sourceRoot":"","sources":["../../../src/utils/dx7/DX7Voice.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH;IAGE,2BAAwB;IACxB,8BAA0B;IAC1B,6BAAwB;IAGxB,mCAA8B;IAC9B,mCAA8B;IAC9B,mCAA8B;IAC9B,mCAA8B;IAC9B,oCAA+B;IAC/B,oCAA+B;IAC/B,oCAA+B;IAC/B,oCAA+B;IAC/B,qCAAgC;IAChC,uCAAkC;IAClC,uCAAmC;IACnC,gCAA4B;IAC5B,sCAAkC;IAClC,kCAA8B;IAC9B,sCAAkC;IAClC,mCAA+B;IAC/B,qCAAiC;IAGjC,sCAAmC;IACnC,sCAAmC;IACnC,sCAAmC;IACnC,sCAAmC;IACnC,uCAAoC;IACpC,uCAAoC;IACpC,uCAAoC;IACpC,uCAAoC;IACpC,gCAA6B;IAC7B,+BAA4B;IAC5B,gCAA6B;IAC7B,gCAA6B;IAC7B,mCAAgC;IAChC,mCAAgC;IAChC,oCAAiC;IACjC,gCAA6B;IAC7B,mCAAgC;IAChC,mCAAgC;IAOhC,iCAA8B;IAC9B,2BAAuB;IAGvB,6BAA0B;IAC1B,gCAA4B;IAG5B,qCAAgC;IAChC,qCAAgC;IAChC,qCAAgC;IAChC,qCAAgC;IAChC,sCAAiC;IACjC,sCAAiC;IACjC,sCAAiC;IACjC,sCAAiC;IACjC,uCAAkC;IAClC,yCAAoC;IACpC,yCAAqC;IACrC,mCAA+B;IAC/B,mCAA+B;IAC/B,wCAAoC;IACpC,kCAA8B;IAC9B,wCAAoC;IACpC,wCAAoC;IACpC,gCAA4B;IAC5B,wCAAoC;IACpC,uCAAmC;IACnC,sCAAkC;IAClC,qCAAiC;IAGjC,wCAAqC;IACrC,wCAAqC;IACrC,wCAAqC;IACrC,wCAAqC;IACrC,yCAAsC;IACtC,yCAAsC;IACtC,yCAAsC;IACtC,yCAAsC;IAGtC,kCAA+B;IAC/B,iCAA8B;IAC9B,iCAA8B;IAC9B,kCAA+B;IAC/B,kCAA+B;IAC/B,qCAAkC;IAClC,qCAAkC;IAClC,qCAAkC;IAClC,iCAA8B;IAC9B,oCAAiC;IACjC,qCAAkC;IAClC,kCAA+B;IAC/B,qCAAkC;IAClC,mCAAgC;IAGhC,yBAAsB;IACtB,gCAA2B;IAC3B,8BAA2B;IAG3B,gCAA8B;IAC9B,8BAA4B;IAC5B,+BAA6B;IAC7B,kCAAgC;IAChC,mCAAiC;IACjC,mCAAiC;IACjC,8BAA4B;IAG5B,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IAGvB,gCAA4B;IAG5B,wBAAoB;IACpB,gCAA6B;IAC7B,+BAA4B;IAC5B,kCAA8B;IAC9B,mCAA+B;IAC/B,mCAA+B;IAC/B,0BAAsB;IACtB,kCAA8B;IAC9B,kCAA+B;IAG/B,+BAA2B;IAC3B,oCAAgC;IAChC,oCAA+B;IAC/B,mCAA8B;IAC9B,oCAAgC;IAChC,sCAAkC;IAClC,iCAA6B;IAC7B,mCAA8B;IAC9B,8BAAyB;IACzB,mCAA8B;IAC9B,iCAA4B;IAC5B,gCAA2B;IAG3B,kCAA8B;IAC9B,uCAAmC;IA8QnC;;;;OAIG;IACH,sBAHW,KAAK,CAAC,MAAM,CAAC,GAAC,UAAU,GACtB,UAAU,CAmBtB;IAED;;;OAGG;IACH,8BAQC;IAED;;;OAGG;IACH,6BAKC;IAED;;;OAGG;IACH,+BAYC;IAED;;;OAGG;IACH,oCAIC;IAED;;;OAGG;IACH,yCAkBC;IAED;;;OAGG;IACH,sCAUC;IAED;;;OAGG;IACH,4BAUC;IAED;;;OAGG;IACH,iCAsBC;IAED;;;OAGG;IACH,yBAIC;IAED;;;;OAIG;IACH,6BAHW,MAAM,GACJ,QAAQ,CA2EpB;IAED;;;;;OAKG;IACH,8BAJW,KAAK,CAAC,MAAM,CAAC,GAAC,UAAU,UACxB,MAAM,GACJ,QAAQ,CAKpB;IAED;;;;;;OAMG;IACH,sBALW,IAAI,GAAC,IAAI,GACP,OAAO,CAAC,QAAQ,CAAC,CAiH7B;IAED;;;;;;;OAOG;IACH,uBANW,KAAK,CAAC,MAAM,CAAC,GAAC,WAAW,GAAC,UAAU,UACpC,MAAM,GACJ,QAAQ,CAwHpB;IAED;;;;;;OAMG;IACH,sBALW,YAAY,UACZ,MAAM,GACJ,QAAQ,CA8QpB;IAxhCD;;;;;OAKG;IACH,kBAJW,KAAK,CAAC,MAAM,CAAC,GAAC,UAAU,UACxB,MAAM,EAgBhB;IAJC,cAAkB;IAClB,8BAAgC;IAChC,aAA+B;IAC/B,4CAA0B;IAG5B;;;OAGG;IACH,qBAYC;IAED;;;;;OAKG;IACH,qBAJW,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;OAKG;IACH,6BAJW,MAAM,GACJ,MAAM,CAiBlB;IAED;;;;OAIG;IACH,qBAHW,MAAM,SACN,MAAM,QAkBhB;IAED;;;;OAIG;IACH,UAFa,UAAU,CAYtB;IAED;;;OAGG;IACH,yBAQC;IAED;;;OAGG;IACH,wBAKC;IAED;;;OAGG;IACH,0BAYC;IAED;;;OAGG;IACH,+BAMC;IAED;;;OAGG;IACH,oCAmBC;IAED;;;OAGG;IACH,iCAUC;IAED;;;OAGG;IACH,uBAUC;IAED;;;OAGG;IACH,4BAsBC;IAED;;;OAGG;IACH,oBAIC;IAgxBD;;;;;OAKG;IACH,WAFa,UAAU,CAsFtB;IAED;;;OAGG;IACH,UAFa,MAAM,CA4GlB;CACF"}
1
+ {"version":3,"file":"DX7Voice.d.ts","sourceRoot":"","sources":["../../../src/utils/dx7/DX7Voice.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;GAUG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH;IAGE,2BAAwB;IACxB,8BAA0B;IAC1B,6BAAwB;IAGxB,mCAA8B;IAC9B,mCAA8B;IAC9B,mCAA8B;IAC9B,mCAA8B;IAC9B,oCAA+B;IAC/B,oCAA+B;IAC/B,oCAA+B;IAC/B,oCAA+B;IAC/B,qCAAgC;IAChC,uCAAkC;IAClC,uCAAmC;IACnC,gCAA4B;IAC5B,sCAAkC;IAClC,kCAA8B;IAC9B,sCAAkC;IAClC,mCAA+B;IAC/B,qCAAiC;IAGjC,sCAAmC;IACnC,sCAAmC;IACnC,sCAAmC;IACnC,sCAAmC;IACnC,uCAAoC;IACpC,uCAAoC;IACpC,uCAAoC;IACpC,uCAAoC;IACpC,gCAA6B;IAC7B,+BAA4B;IAC5B,gCAA6B;IAC7B,gCAA6B;IAC7B,mCAAgC;IAChC,mCAAgC;IAChC,oCAAiC;IACjC,gCAA6B;IAC7B,mCAAgC;IAChC,mCAAgC;IAOhC,iCAA8B;IAC9B,2BAAuB;IAGvB,6BAA0B;IAC1B,gCAA4B;IAG5B,qCAAgC;IAChC,qCAAgC;IAChC,qCAAgC;IAChC,qCAAgC;IAChC,sCAAiC;IACjC,sCAAiC;IACjC,sCAAiC;IACjC,sCAAiC;IACjC,uCAAkC;IAClC,yCAAoC;IACpC,yCAAqC;IACrC,mCAA+B;IAC/B,mCAA+B;IAC/B,wCAAoC;IACpC,kCAA8B;IAC9B,wCAAoC;IACpC,wCAAoC;IACpC,gCAA4B;IAC5B,wCAAoC;IACpC,uCAAmC;IACnC,sCAAkC;IAClC,qCAAiC;IAGjC,wCAAqC;IACrC,wCAAqC;IACrC,wCAAqC;IACrC,wCAAqC;IACrC,yCAAsC;IACtC,yCAAsC;IACtC,yCAAsC;IACtC,yCAAsC;IAGtC,kCAA+B;IAC/B,iCAA8B;IAC9B,iCAA8B;IAC9B,kCAA+B;IAC/B,kCAA+B;IAC/B,qCAAkC;IAClC,qCAAkC;IAClC,qCAAkC;IAClC,iCAA8B;IAC9B,oCAAiC;IACjC,qCAAkC;IAClC,kCAA+B;IAC/B,qCAAkC;IAClC,mCAAgC;IAGhC,yBAAsB;IACtB,gCAA2B;IAC3B,8BAA2B;IAG3B,gCAA8B;IAC9B,8BAA4B;IAC5B,+BAA6B;IAC7B,kCAAgC;IAChC,mCAAiC;IACjC,mCAAiC;IACjC,8BAA4B;IAG5B,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IACvB,yBAAuB;IAGvB,gCAA4B;IAG5B,wBAAoB;IACpB,gCAA6B;IAC7B,+BAA4B;IAC5B,kCAA8B;IAC9B,mCAA+B;IAC/B,mCAA+B;IAC/B,0BAAsB;IACtB,kCAA8B;IAC9B,kCAA+B;IAG/B,+BAA2B;IAC3B,oCAAgC;IAChC,oCAA+B;IAC/B,mCAA8B;IAC9B,oCAAgC;IAChC,sCAAkC;IAClC,iCAA6B;IAC7B,mCAA8B;IAC9B,8BAAyB;IACzB,mCAA8B;IAC9B,iCAA4B;IAC5B,gCAA2B;IAC3B,gCAA2B;IAC3B,oCAA+B;IAG/B,kCAA8B;IAC9B,uCAAmC;IA8QnC;;;;OAIG;IACH,sBAHW,KAAK,CAAC,MAAM,CAAC,GAAC,UAAU,GACtB,UAAU,CAmBtB;IAED;;;OAGG;IACH,8BAQC;IAED;;;OAGG;IACH,6BAKC;IAED;;;OAGG;IACH,+BAYC;IAED;;;OAGG;IACH,oCAIC;IAED;;;OAGG;IACH,yCAkBC;IAED;;;OAGG;IACH,sCAUC;IAED;;;OAGG;IACH,4BAUC;IAED;;;OAGG;IACH,iCAsBC;IAED;;;OAGG;IACH,yBAIC;IAED;;;;OAIG;IACH,6BAHW,MAAM,GACJ,QAAQ,CA2EpB;IAED;;;;;OAKG;IACH,8BAJW,KAAK,CAAC,MAAM,CAAC,GAAC,UAAU,UACxB,MAAM,GACJ,QAAQ,CAKpB;IAED;;;;;;OAMG;IACH,sBALW,IAAI,GAAC,IAAI,GACP,OAAO,CAAC,QAAQ,CAAC,CAiH7B;IAED;;;;;;;OAOG;IACH,uBANW,KAAK,CAAC,MAAM,CAAC,GAAC,WAAW,GAAC,UAAU,UACpC,MAAM,GACJ,QAAQ,CAwHpB;IAED;;;;;;OAMG;IACH,sBALW,YAAY,UACZ,MAAM,GACJ,QAAQ,CA8QpB;IAxhCD;;;;;OAKG;IACH,kBAJW,KAAK,CAAC,MAAM,CAAC,GAAC,UAAU,UACxB,MAAM,EAgBhB;IAJC,cAAkB;IAClB,8BAAgC;IAChC,aAA+B;IAC/B,4CAA0B;IAG5B;;;OAGG;IACH,qBAYC;IAED;;;;;OAKG;IACH,qBAJW,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;OAKG;IACH,6BAJW,MAAM,GACJ,MAAM,CAiBlB;IAED;;;;OAIG;IACH,qBAHW,MAAM,SACN,MAAM,QAkBhB;IAED;;;;OAIG;IACH,UAFa,UAAU,CAYtB;IAED;;;OAGG;IACH,yBAQC;IAED;;;OAGG;IACH,wBAKC;IAED;;;OAGG;IACH,0BAYC;IAED;;;OAGG;IACH,+BAMC;IAED;;;OAGG;IACH,oCAmBC;IAED;;;OAGG;IACH,iCAUC;IAED;;;OAGG;IACH,uBAUC;IAED;;;OAGG;IACH,4BAsBC;IAED;;;OAGG;IACH,oBAIC;IAgxBD;;;;;OAKG;IACH,WAFa,UAAU,CAsFtB;IAED;;;OAGG;IACH,UAFa,MAAM,CA4GlB;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midiwire",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "Declarative JavaScript library for browser-based MIDI control",
5
5
  "type": "module",
6
6
  "main": "./dist/midiwire.umd.js",
@@ -269,6 +269,8 @@ export class DX7Voice {
269
269
  static DEFAULT_FREQ_COARSE = 1
270
270
  static DEFAULT_ALGORITHM = 0
271
271
  static DEFAULT_FEEDBACK = 0
272
+ static DEFAULT_OSC_SYNC = 1
273
+ static DEFAULT_LFO_KEY_SYNC = 1
272
274
 
273
275
  // MIDI notes
274
276
  static MIDI_OCTAVE_OFFSET = -2 // For displaying MIDI notes (MIDI 0 = C-2)
@@ -772,12 +774,12 @@ export class DX7Voice {
772
774
  // Global params
773
775
  unpacked[DX7Voice.UNPACKED_ALGORITHM] = DX7Voice.DEFAULT_ALGORITHM
774
776
  unpacked[DX7Voice.UNPACKED_FEEDBACK] = DX7Voice.DEFAULT_FEEDBACK
775
- unpacked[DX7Voice.UNPACKED_OSC_SYNC] = 0
777
+ unpacked[DX7Voice.UNPACKED_OSC_SYNC] = DX7Voice.DEFAULT_OSC_SYNC
776
778
  unpacked[DX7Voice.UNPACKED_LFO_SPEED] = DX7Voice.DEFAULT_LFO_SPEED
777
779
  unpacked[DX7Voice.UNPACKED_LFO_DELAY] = 0
778
780
  unpacked[DX7Voice.UNPACKED_LFO_PM_DEPTH] = 0
779
781
  unpacked[DX7Voice.UNPACKED_LFO_AM_DEPTH] = 0
780
- unpacked[DX7Voice.UNPACKED_LFO_KEY_SYNC] = 0
782
+ unpacked[DX7Voice.UNPACKED_LFO_KEY_SYNC] = DX7Voice.DEFAULT_LFO_KEY_SYNC
781
783
  unpacked[DX7Voice.UNPACKED_LFO_WAVE] = 0
782
784
  unpacked[DX7Voice.UNPACKED_LFO_PM_SENS] = DX7Voice.DEFAULT_LFO_PM_SENS
783
785
  unpacked[DX7Voice.UNPACKED_AMP_MOD_SENS] = 0