-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2cf985
commit fb6614d
Showing
2 changed files
with
24 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | ||
<link rel="stylesheet" href="./svg/style.css"> | ||
<title>Piano Web</title> | ||
</head> | ||
<body> | ||
<div id="container"></div> | ||
<button id="startButton" style="width:100%">Start</button> | ||
|
||
<script type="module"> | ||
import PianoSvg from './svg/PianoSvg.mjs'; | ||
import PianoSynth from './synth/PianoSynth.mjs'; | ||
|
||
const startButton = document.getElementById("startButton"); | ||
const options = { firstPitch: 47, lastPitch: 72 }; | ||
|
||
const svg = new PianoSvg(options); | ||
document.getElementById('container').appendChild(svg.element); | ||
let svg; | ||
let synth; | ||
|
||
let synth = null; | ||
function getSynth() { | ||
// Browsers require on-screen interaction before producing sound. | ||
if (!synth) synth = new PianoSynth(options); | ||
return synth; | ||
} | ||
function start() { | ||
synth = new PianoSynth(options); | ||
svg = new PianoSvg(options); | ||
|
||
svg.onKeyPress = key => { | ||
key.addHighlight(); | ||
getSynth().press(key.data.pitch); | ||
}; | ||
svg.onKeyPress = key => { | ||
key.addHighlight(); | ||
synth.press(key.data.pitch); | ||
}; | ||
|
||
svg.onKeyRelease = key => { | ||
key.clearHighlight(); | ||
getSynth().release(key.data.pitch); | ||
}; | ||
svg.onKeyRelease = key => { | ||
key.clearHighlight(); | ||
synth.release(key.data.pitch); | ||
}; | ||
|
||
document.body.removeChild(startButton); | ||
document.getElementById('container').appendChild(svg.element); | ||
} | ||
|
||
startButton.onclick = () => start(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters