SlideShare a Scribd company logo
1 of 7
Download to read offline
Things wrong with my code:
1. The notes do not play when i press down the key on keyboard or the mouse.
2. The premade songs in the backend do not show up or play in the dropdown
3. The recordings do not go to the file when you save them.
// Wait for the DOM to finish loading
document.addEventListener("DOMContentLoaded", () => {
// Create a new synthesizer object from Tone.js
const synth = new Tone.Synth().toDestination();
// Define the mappings between keyboard keys and notes
const keyNoteMappings = {
"a": "C4", "w": "C#4", "s": "D4", "e": "D#4", "d": "E4",
"f": "F4", "t": "F#4", "g": "G4", "y": "G#4", "h": "A4",
"u": "Bb4", "j": "B4", "k": "C5", "o": "C#5", "l": "D5",
"p": "D#5", ";": "E5"
};
// Add event listeners to each keyboard key
const keys = document.querySelectorAll(".keyboard button");
keys.forEach(key => {
// When the key is pressed, play the corresponding note
key.addEventListener("mousedown", () => {
const note = keyNoteMappings[key.textContent.trim().toLowerCase()];
synth.triggerAttack(note);
});
// When the key is released, stop playing the note
key.addEventListener("mouseup", () => {
const note = keyNoteMappings[key.textContent.trim().toLowerCase()];
synth.triggerRelease(note);
});
});
// Get a reference to the tune dropdown, tune button, and recording buttons
const tuneDropdown = document.querySelector("#tune-dropdown");
const tuneButton = document.querySelector("#tunebtn");
const recordButton = document.querySelector("#recordbtn");
const stopButton = document.querySelector("#stopbtn");
const saveButton = document.querySelector("#savebtn");
const tuneNameInput = document.querySelector("#tuneNameInput");
// Load the list of available tunes from the server and populate the dropdown
axios.get("http://localhost:3000/api/v1/tunes/").then(response => {
const tunes = response.data;
tunes.forEach(tune => {
const option = document.createElement("option");
option.value = tune.name;
option.textContent = tune.name;
tuneDropdown.appendChild(option);
});
}).catch(error => {
console.error("Failed to load tunes:", error);
});
// Add a click event listener to the tune button
tuneButton.addEventListener("click", () => {
const selectedTune = tuneDropdown.value;
if (!selectedTune) {
alert("Please select a tune first.");
return;
}
axios.get("http://localhost:3000/api/v1/tunes/${selectedTune}").then(response => {
const tune = response.data;
// Play each note in the tune with a slight delay between them
tune.notes.forEach((note, index) => {
setTimeout(() => {
synth.triggerAttackRelease(note.note, note.duration);
}, index * note.duration);
});
}).catch(error => {
console.error(`Failed to load tune "${selectedTune}":`, error);
});
});
// Define variables for recording a new tune
let recordedNotes = [];
let recordingStartTime = null;
// Define a function for starting a new recording
function startRecording() {
recordedNotes = [];
recordingStartTime = Date.now();
recordButton.disabled = true;
stopButton.disabled = false;
}
// Define a function for stopping a recording
function stopRecording() {
recordButton.disabled = false;
stopButton.disabled = true;
}
// Define a function for saving a recorded tune
function saveRecording() {
const tuneName = tuneNameInput.value;
if (!tuneName) {
alert("Please enter a name for the tune.");
return;
}
const tune = {
name: tuneName,
notes: recordedNotes
};
axios.post("http://localhost:3000/api/v1/tunes/", tune).then(response => {
const option = document.createElement("option");
option.value = tune.name;
option.textContent = tune.name;
tuneDropdown.appendChild(option);
tuneDropdown.value = tune.name;
tuneNameInput.value = "";
alert("Tune saved successfully!");
}).catch(error => {
console.error("Failed to save tune:", error);
});
}
// Add a click event listener to the record button
recordButton.addEventListener("click", () => {
startRecording();
}
);
// Add a click event listener to the stop button
stopButton.addEventListener("click", () => {
stopRecording();
}
);
// Add a click event listener to the save button
saveButton.addEventListener("click", () => {
saveRecording();
}
);
// Add event listeners to each keyboard key
keys.forEach(key => {
// When the key is pressed, play the corresponding note
key.addEventListener("mousedown", () => {
const note = keyNoteMappings[key.textContent.trim().toLowerCase()];
synth.triggerAttack(note);
if (recordingStartTime) {
const noteStartTime = Date.now() - recordingStartTime;
recordedNotes.push({
note: note,
startTime: noteStartTime
});
}
});
// When the key is released, stop playing the note
key.addEventListener("mouseup", () => {
const note = keyNoteMappings[key.textContent.trim().toLowerCase()];
synth.triggerRelease(note);
});
});
});
/html>

More Related Content

More from EricvtJFraserr

Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfTopic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfEricvtJFraserr
 
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfTotal tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfEricvtJFraserr
 
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
Topographic Maps  10-  What is the scale of a map-  Give some examples.pdfTopographic Maps  10-  What is the scale of a map-  Give some examples.pdf
Topographic Maps 10- What is the scale of a map- Give some examples.pdfEricvtJFraserr
 
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfToast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfEricvtJFraserr
 
To do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfTo do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfEricvtJFraserr
 
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfTo determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfEricvtJFraserr
 
To clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfTo clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfEricvtJFraserr
 
To avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfTo avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfEricvtJFraserr
 
Three Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfThree Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfEricvtJFraserr
 
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfThis year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfEricvtJFraserr
 
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfThis Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfEricvtJFraserr
 
This map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfThis map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfEricvtJFraserr
 
This medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfThis medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfEricvtJFraserr
 
This map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfThis map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfEricvtJFraserr
 
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfThis map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfEricvtJFraserr
 
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdfThis is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdfEricvtJFraserr
 
This chemical provides the body with energy a- Electro-energizing fusi.pdf
This chemical provides the body with energy a- Electro-energizing fusi.pdfThis chemical provides the body with energy a- Electro-energizing fusi.pdf
This chemical provides the body with energy a- Electro-energizing fusi.pdfEricvtJFraserr
 
This is computer network class Select the statement that is correct- D.pdf
This is computer network class Select the statement that is correct- D.pdfThis is computer network class Select the statement that is correct- D.pdf
This is computer network class Select the statement that is correct- D.pdfEricvtJFraserr
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
These structures are formed in similar ways during embryonic developme.pdf
These structures are formed in similar ways during embryonic developme.pdfThese structures are formed in similar ways during embryonic developme.pdf
These structures are formed in similar ways during embryonic developme.pdfEricvtJFraserr
 

More from EricvtJFraserr (20)

Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfTopic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
 
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfTotal tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
 
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
Topographic Maps  10-  What is the scale of a map-  Give some examples.pdfTopographic Maps  10-  What is the scale of a map-  Give some examples.pdf
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
 
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfToast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
 
To do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfTo do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdf
 
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfTo determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
 
To clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfTo clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdf
 
To avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfTo avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdf
 
Three Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfThree Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdf
 
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfThis year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
 
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfThis Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
 
This map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfThis map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdf
 
This medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfThis medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdf
 
This map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfThis map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdf
 
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfThis map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
 
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdfThis is my code-  #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf
 
This chemical provides the body with energy a- Electro-energizing fusi.pdf
This chemical provides the body with energy a- Electro-energizing fusi.pdfThis chemical provides the body with energy a- Electro-energizing fusi.pdf
This chemical provides the body with energy a- Electro-energizing fusi.pdf
 
This is computer network class Select the statement that is correct- D.pdf
This is computer network class Select the statement that is correct- D.pdfThis is computer network class Select the statement that is correct- D.pdf
This is computer network class Select the statement that is correct- D.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
These structures are formed in similar ways during embryonic developme.pdf
These structures are formed in similar ways during embryonic developme.pdfThese structures are formed in similar ways during embryonic developme.pdf
These structures are formed in similar ways during embryonic developme.pdf
 

Recently uploaded

How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 

Recently uploaded (20)

How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 

Things wrong with my code- 1- The notes do not play when i press down.pdf

  • 1. Things wrong with my code: 1. The notes do not play when i press down the key on keyboard or the mouse. 2. The premade songs in the backend do not show up or play in the dropdown 3. The recordings do not go to the file when you save them. // Wait for the DOM to finish loading document.addEventListener("DOMContentLoaded", () => { // Create a new synthesizer object from Tone.js const synth = new Tone.Synth().toDestination(); // Define the mappings between keyboard keys and notes const keyNoteMappings = { "a": "C4", "w": "C#4", "s": "D4", "e": "D#4", "d": "E4", "f": "F4", "t": "F#4", "g": "G4", "y": "G#4", "h": "A4", "u": "Bb4", "j": "B4", "k": "C5", "o": "C#5", "l": "D5", "p": "D#5", ";": "E5" }; // Add event listeners to each keyboard key const keys = document.querySelectorAll(".keyboard button"); keys.forEach(key => { // When the key is pressed, play the corresponding note key.addEventListener("mousedown", () => { const note = keyNoteMappings[key.textContent.trim().toLowerCase()]; synth.triggerAttack(note); });
  • 2. // When the key is released, stop playing the note key.addEventListener("mouseup", () => { const note = keyNoteMappings[key.textContent.trim().toLowerCase()]; synth.triggerRelease(note); }); }); // Get a reference to the tune dropdown, tune button, and recording buttons const tuneDropdown = document.querySelector("#tune-dropdown"); const tuneButton = document.querySelector("#tunebtn"); const recordButton = document.querySelector("#recordbtn"); const stopButton = document.querySelector("#stopbtn"); const saveButton = document.querySelector("#savebtn"); const tuneNameInput = document.querySelector("#tuneNameInput"); // Load the list of available tunes from the server and populate the dropdown axios.get("http://localhost:3000/api/v1/tunes/").then(response => { const tunes = response.data; tunes.forEach(tune => { const option = document.createElement("option"); option.value = tune.name; option.textContent = tune.name; tuneDropdown.appendChild(option); }); }).catch(error => {
  • 3. console.error("Failed to load tunes:", error); }); // Add a click event listener to the tune button tuneButton.addEventListener("click", () => { const selectedTune = tuneDropdown.value; if (!selectedTune) { alert("Please select a tune first."); return; } axios.get("http://localhost:3000/api/v1/tunes/${selectedTune}").then(response => { const tune = response.data; // Play each note in the tune with a slight delay between them tune.notes.forEach((note, index) => { setTimeout(() => { synth.triggerAttackRelease(note.note, note.duration); }, index * note.duration); }); }).catch(error => { console.error(`Failed to load tune "${selectedTune}":`, error); }); }); // Define variables for recording a new tune let recordedNotes = [];
  • 4. let recordingStartTime = null; // Define a function for starting a new recording function startRecording() { recordedNotes = []; recordingStartTime = Date.now(); recordButton.disabled = true; stopButton.disabled = false; } // Define a function for stopping a recording function stopRecording() { recordButton.disabled = false; stopButton.disabled = true; } // Define a function for saving a recorded tune function saveRecording() { const tuneName = tuneNameInput.value; if (!tuneName) { alert("Please enter a name for the tune."); return; } const tune = { name: tuneName, notes: recordedNotes
  • 5. }; axios.post("http://localhost:3000/api/v1/tunes/", tune).then(response => { const option = document.createElement("option"); option.value = tune.name; option.textContent = tune.name; tuneDropdown.appendChild(option); tuneDropdown.value = tune.name; tuneNameInput.value = ""; alert("Tune saved successfully!"); }).catch(error => { console.error("Failed to save tune:", error); }); } // Add a click event listener to the record button recordButton.addEventListener("click", () => { startRecording(); } ); // Add a click event listener to the stop button stopButton.addEventListener("click", () => { stopRecording(); } );
  • 6. // Add a click event listener to the save button saveButton.addEventListener("click", () => { saveRecording(); } ); // Add event listeners to each keyboard key keys.forEach(key => { // When the key is pressed, play the corresponding note key.addEventListener("mousedown", () => { const note = keyNoteMappings[key.textContent.trim().toLowerCase()]; synth.triggerAttack(note); if (recordingStartTime) { const noteStartTime = Date.now() - recordingStartTime; recordedNotes.push({ note: note, startTime: noteStartTime }); } }); // When the key is released, stop playing the note key.addEventListener("mouseup", () => { const note = keyNoteMappings[key.textContent.trim().toLowerCase()]; synth.triggerRelease(note);