Barnard-PL-Labs / SequencerLiveCoding

Live Coding for the Novation Circuit
19 stars 5 forks source link

space bar initiates start/stop of beat #26

Open justinkim668 opened 2 years ago

santolucito commented 2 years ago

any updates @justinkim668 ?

justinkim668 commented 2 years ago

I already added an an addEventListener function in the init.js file to track the spacebar, but for some reason it's still not working @santolucito. I am trying to figure out why this is not working.

playButton.addEventListener('keyup', event => { if (event.key === ' ' && event.target === document.body) { event.preventDefault(); recordedAudio.play() console.log('Space pressed') } });

justinkim668 commented 2 years ago

changed playButton.addEventListener to document.addEventListener. The issue here is that it tracks spacebar pressing across the entire webpage, which creates issues when the spacebar is being used in other parts of the interface (i.e. we do not want the beat to play every time the spacebar is used to type code in the live coding interface). Hence we need to figure out a way to filter out non-relevant instances of the spacebar.

santolucito commented 2 years ago

@justinkim668 did you ever finish this?

santolucito commented 2 years ago

if not, you probably want the .hasFocus() function from codeMirror (https://codemirror.net/doc/manual.html) to tell you if the user's cursor is in the code window. if so, do not start or stop the music on a spacebar press.