Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
momentollogy committed Apr 8, 2023
1 parent 37ffef1 commit 4320bb7
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,31 +369,35 @@ <h1>Arduino Piano Buzzer Song Creator V1 <br> <small>by momentollogy</small><br>


// FUNCTION DISPLAYRECORDING
function displayRecording() {
let output = "";
let songArray = "";

const songTitle = document.getElementById("song-title").value;
const notesCount = recordedNotes.length;
async function playRecordedNotes(recordedNotes) {
const timeBetweenNotesMs = 50;

output += `${songTitle}[${notesCount}][2] =\n{\n`;
for (const note of recordedNotes) {
console.log('Playing note:', note); // Debug: log the current note

recordedNotes.forEach((note, index) => {
if (note.rest) {
output += ` {0, ${mapDurationToNoteLength(note.duration, true)}},\n`;
await new Promise(resolve => setTimeout(resolve, note.duration + timeBetweenNotesMs));
} else {
output += ` {${noteNames[note.frequency]}, ${mapDurationToNoteLength(note.duration)}},\n`;
}
});
const keyElement = document.querySelector(`.key[data-note="${getKeyCodeForFrequency(note.frequency)}"]`);

output += "};";
songArray = output;
if (!keyElement) {
console.error('Could not find key element for note:', note);
continue;
}

const recordingElement = document.getElementById("recording");
recordingElement.innerHTML = `<button id="copy-song">Copy Song</button><pre>${output}</pre>`;

const copySongButton = document.getElementById("copy-song");
copySongButton.addEventListener("click", () => copySongToClipboard(output));
const oscillator = playNote(note.frequency, keyElement);

// Stop the oscillator after the note duration
setTimeout(() => {
console.log('Stopping note:', note); // Debug: log the note being stopped
oscillator.stop();
keyElement.classList.remove("pressed");
}, note.duration);

// Wait for the note duration plus the time delay before proceeding to the next note
await new Promise(resolve => setTimeout(resolve, note.duration + timeBetweenNotesMs));
}
}
}


Expand Down

0 comments on commit 4320bb7

Please sign in to comment.