import { sendMidiMessage } from "./midi.js";
import { Conductor } from "./conductor.js";
import { DataStream } from "./socket.js";
import { playSound } from "./audio";
import { Renderer } from "./render.js";

document.addEventListener("DOMContentLoaded", async () => {
  sendMidiMessage();

  const conductor = new Conductor();
  await conductor.init();
  const dataStream = new DataStream();
  const instruments = await conductor.instruments;
  console.log(instruments);

  const renderer = new Renderer();

  dataStream.addEventListener("strike", () => {
    const keys = Object.keys(instruments);
    const randomIndex = Math.floor(Math.random() * keys.length);
    const selectedInstrument = instruments[keys[randomIndex]];

    renderer.placeIcon(selectedInstrument);
    playSound(selectedInstrument);
  });

  dataStream.init();

  // let currStaveNumber = 1;

  conductor.showMainContent();

  //  let strikeNumber = 0;

  //  setupWebSocketListeners(); // Setup the WebSocket listeners
  //  resetTimeout(); // Start the timeout timer
});
