SlideShare a Scribd company logo
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.pdf
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 
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
EricvtJFraserr
 

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

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 

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);