Skip to content

Instantly share code, notes, and snippets.

@Jack5079
Last active May 21, 2021 20:03
Show Gist options
  • Select an option

  • Save Jack5079/3df00dcca6922444ade43bfbd39d1d69 to your computer and use it in GitHub Desktop.

Select an option

Save Jack5079/3df00dcca6922444ade43bfbd39d1d69 to your computer and use it in GitHub Desktop.
Shared Piano destroyer
const notes = [...document.querySelector('piano-keyboard').shadowRoot.querySelectorAll('piano-keyboard-octave')].map(oct=>oct.shadowRoot.querySelectorAll('piano-keyboard-note')).map((a)=>Array.from(a)).flat()
async function trollar () {
for (const note of notes.filter((_,e)=>e%2==0)) {
note.clicked = true
}
await new Promise(r=>setTimeout(r,5))
for (const note of notes.filter((_,e)=>e%2==0)) {
note.clicked = false
note.release()
}
for (const note of notes.filter((_,e)=>e%2!=0)) {
note.clicked = true
}
await new Promise(r=>setTimeout(r,5))
for (const note of notes.filter((_,e)=>e%2!=0)) {
note.clicked = false
note.release()
}
trollar()
}
trollar()
const selector = document.querySelector('piano-instrument-selector')
const notes = [...document.querySelector('piano-keyboard').shadowRoot.querySelectorAll('piano-keyboard-octave')].map(oct=>oct.shadowRoot.querySelectorAll('piano-keyboard-note')).map((a)=>Array.from(a)).flat()
async function trollar () {
for (const note of notes) {
note.clicked = true
await new Promise(r=>setTimeout(r,5))
}
for (const note of notes) {
note.clicked = false
note.release()
}
for (const note of notes.reverse()) {
note.clicked = true
await new Promise(r=>setTimeout(r,5))
}
for (const note of notes.reverse()) {
note.clicked = false
note.release()
}
trollar()
}
trollar()
// Test it: https://musiclab.chromeexperiments.com/Shared-Piano/#a
const notes = [...document.querySelector('piano-keyboard').shadowRoot.querySelectorAll('piano-keyboard-octave')].map(oct=>oct.shadowRoot.querySelectorAll('piano-keyboard-note')).map((a)=>Array.from(a)).flat()
setInterval(()=>{
notes.forEach(note=>(note.clicked=true))
setTimeout(()=>notes.forEach(note=>{note.clicked=false;note.release()}), 10)
}, 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment