| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="x-ua-compatible" content="ie=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <link rel="icon" href="favicon.ico" type="image/x-icon"/> |
| <link rel="stylesheet" href="examples-styles.css"/> |
|
|
| <title>Karaoke Synth</title> |
|
|
| <style> |
| main { |
| max-width: 770px; |
| margin: 0 auto; |
| } |
| .buttons { |
| text-align: center; |
| } |
| </style> |
|
|
| <script src="../dist/abcjs-basic.js" type="text/javascript"></script> |
| <script type="text/javascript"> |
| var abc = |
| 'T:Cindy\n' + |
| 'M:4/4\n' + |
| 'K:G\n' + |
| '%%score (harmony melody)\n' + |
| 'L:1/4\n' + |
| '[V: harmony]' + |
| 'g||"G"gggg|dB2g|gggd|g3g|\n' + |
| '"G"gggd|dcB2|dccA|Bzz2|\n' + |
| '"C"G2cc|ccd/c/B|"G"G4-|Gzz2|\n' + |
| '"C"G2cc|cc2c|"D7"dddc|"G"B2z2|]\n' + |
| '[V: melody]' + |
| 'd||"G"eddB|AG2d|eddB|d3d|\n' + |
| '"G"eddB|BAG2|"D7"BGGE|"G"GzB/A/G|\n' + |
| '"C"E2GG|AGB/A/G|"G"D4-|DzB/A/G|\n' + |
| '"C"E2GG|AG2A|"D7"BBBA|"G"G2z2|]\n'; |
| |
| function load() { |
| |
| var visualObj = ABCJS.renderAbc("paper", abc, { |
| responsive: "resize" })[0]; |
| |
| |
| var midiBuffer; |
| |
| var startChordsButton = document.querySelector(".play-chords"); |
| var startMelodiesButton = document.querySelector(".play-melodies"); |
| var startHarmonyButton = document.querySelector(".play-harmony"); |
| var startMelodyButton = document.querySelector(".play-melody"); |
| var startAllButton = document.querySelector(".play-all"); |
| var stopAudioButton = document.querySelector(".stop-audio"); |
| |
| startChordsButton.addEventListener("click", function() { |
| var options = {voicesOff: true}; |
| play(options); |
| }); |
| |
| startMelodiesButton.addEventListener("click", function() { |
| var options = {chordsOff: true}; |
| play(options); |
| }); |
| |
| startHarmonyButton.addEventListener("click", function() { |
| var options = {chordsOff: true, voicesOff: [1]}; |
| play(options); |
| }); |
| |
| startMelodyButton.addEventListener("click", function() { |
| var options = {chordsOff: true, voicesOff: [0]}; |
| play(options); |
| }); |
| |
| startAllButton.addEventListener("click", function() { |
| var options = {}; |
| play(options); |
| }); |
| |
| function play(options) { |
| startChordsButton.setAttribute("style", "display:none;"); |
| startMelodiesButton.setAttribute("style", "display:none;"); |
| startHarmonyButton.setAttribute("style", "display:none;"); |
| startMelodyButton.setAttribute("style", "display:none;"); |
| startAllButton.setAttribute("style", "display:none;"); |
| if (ABCJS.synth.supportsAudio()) { |
| stopAudioButton.setAttribute("style", ""); |
| |
| |
| |
| |
| |
| window.AudioContext = window.AudioContext || |
| window.webkitAudioContext || |
| navigator.mozAudioContext || |
| navigator.msAudioContext; |
| var audioContext = new window.AudioContext(); |
| audioContext.resume().then(function () { |
| |
| |
| |
| midiBuffer = new ABCJS.synth.CreateSynth(); |
| |
| |
| return midiBuffer.init({ |
| visualObj: visualObj, |
| audioContext: audioContext, |
| millisecondsPerMeasure: visualObj.millisecondsPerMeasure(), |
| options: options |
| |
| }).then(function (response) { |
| |
| |
| return midiBuffer.prime(); |
| }).then(function () { |
| |
| midiBuffer.start(); |
| return Promise.resolve(); |
| }).catch(function (error) { |
| if (error.status === "NotSupported") { |
| stopAudioButton.setAttribute("style", "display:none;"); |
| var audioError = document.querySelector(".audio-error"); |
| audioError.setAttribute("style", ""); |
| } else |
| console.warn("synth error", error); |
| }); |
| }); |
| } else { |
| var audioError = document.querySelector(".audio-error"); |
| audioError.setAttribute("style", ""); |
| } |
| } |
| |
| stopAudioButton.addEventListener("click", function() { |
| startChordsButton.setAttribute("style", ""); |
| startMelodiesButton.setAttribute("style", ""); |
| startHarmonyButton.setAttribute("style", ""); |
| startMelodyButton.setAttribute("style", ""); |
| startAllButton.setAttribute("style", ""); |
| stopAudioButton.setAttribute("style", "display:none;"); |
| if (midiBuffer) |
| midiBuffer.stop(); |
| }); |
| } |
| </script> |
| </head> |
| <body onload="load()"> |
| <header> |
| <img src="https://paulrosen.github.io/abcjs/img/abcjs_comp_extended_08.svg" alt="abcjs logo"> |
| <h1>abcjs karaoke synth</h1> |
| </header> |
| <div class="container"> |
| <main> |
| <div id="paper"></div> |
| <div class="buttons"> |
| <button class="play-chords">Play Chords</button> |
| <button class="play-melodies">Play Melodies</button> |
| <button class="play-harmony">Play Harmony</button> |
| <button class="play-melody">Play Melody</button> |
| <button class="play-all">Play All</button> |
| <button class="stop-audio" style="display:none;">Stop Audio</button> |
| </div> |
| <div class='audio-error' style="display:none;">Audio is not supported in this browser.</div> |
| </main> |
| </div> |
| </body> |
| </html> |
|
|