play()

in Output/GPT4_Turbo/JS/extracted_code/translation/VanillaToAngular_high_low/piano.component.ts [34:48]


  play(event: any) {
    const isKeyboard = event instanceof KeyboardEvent;
    const key = isKeyboard ? event.key.toUpperCase() : null;
    const note = isKeyboard ? key : event.target.dataset.note;
    if (!note || this.played.includes(note)) return;

    const pianoEl = isKeyboard ? document.querySelector(`.piano-key[data-letter=${key}]`) : event.target;
    if (!pianoEl) return;

    pianoEl.classList.add('piano-key-active');
    const sound = this.soundMapper[note];
    sound.currentTime = 0;
    sound.play();
    this.played.push(note);
  }