Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Ability to enable/disable keyboard events for individual keys #5

Closed
NinjaNas opened this issue Sep 11, 2023 · 6 comments

Comments

@NinjaNas
Copy link

I understand you can disable touch and pointer events using the code below.

piano.getKey('60').setStyle({ "pointer-events": "none" })

But I wish to enable and disable individual keyboard events from JZZ.input.ASCII as well. For example like so:

piano.getKey('60').asciiActive(false)
// do something
piano.getKey('60').asciiActive(true)

It would be useful to disable certain keys to showcase different scales and allow the user to only play those notes using their keyboard.

@jazz-soft
Copy link
Owner

This feature already exists. You can disable/enable individual keys.
I guess I should update the docs, but you can find these calls by looking at the code.

@NinjaNas
Copy link
Author

NinjaNas commented Sep 13, 2023

I see now that disable() and enable() exist and have tried them and they work for pointer-events. However, it seems like the keydown and keyup functions are missing a check to see that the keys are active, thus not preventing keydown and keyup events.

@jazz-soft
Copy link
Owner

Keydown and keyup events are handled by JZZ.input.ASCII class, those are also easy to disable.

@NinjaNas
Copy link
Author

Would you recommend doing something like this? Or what else could I do?

const ascii = JZZ.input.ASCII({
    at: "piano",
    Z: '60',
    S: '61',
    X: '62',
    D: '63',
    C: '64',
    V: '65',
    G: '66',
    B: '67',
    H: '68',
    N: '69',
    J: '70',
    M: '71'
  })

ascii.connect(piano)

// do something

ascii.disconnect(piano)

ascii = JZZ.input.ASCII({
      at: "piano",
      Z: '60',
      null: '61',
      X: '62',
      null: '63',
      C: '64',
      V: '65',
      null: '66',
      B: '67',
      null: '68',
      N: '69',
      null: '70',
      M: '71'
    })

ascii.connect(piano)

@jazz-soft
Copy link
Owner

Yes, that would work. Just remove the 'null: ...' from your code, e.g.:

ascii = JZZ.input.ASCII({
      at: "piano",
      Z: '60',
      X: '62',
      C: '64',
      V: '65',
      B: '67',
      N: '69',
      M: '71'
})

Alternatively, you can insert a JZZ.Widget between the ASCII and piano and use more complicated logic control the MIDI traffic.

@NinjaNas
Copy link
Author

Got it! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants