question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onRelease not working

See original GitHub issue

I am working on a synthesyzer, and my current objective is to get keyboard inputs and turn them into MIDI outputs. Here is the code I’m using: `#Import libraries import time import rtmidi import keyboard #Define midi commands midiout = rtmidi.MidiOut() available_ports = midiout.get_ports() #Callback when key is released def onRelease(self):
global offNote #Define the command to turn off a note, then turn it off. for i in range(len(keys)): note_off = [0x80, i+30, 0] midiout.send_message(note_off)

#Callback when key is pressed def onPress(self): global onNote #Define the command to turn on a note, then turn it on. for i in range(len(keys)): if keyboard.is_pressed(keys[i]) == True: global onNote onNote = i print(keys[i]) note_on = [0x90, onNote+30, 112] midiout.send_message(note_on)

#List of the 61 keys to listen for keys = [41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 43, 58, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 28, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 29, 125, 56, 57, 100, 126, 127, 97]

#Check for midi ports if available_ports: midiout.open_port(0) else: midiout.open_virtual_port(“My virtual output”) #Stop all notes when program is started for i in range(len(keys)): note_off = [0x80, i+30, 0] midiout.send_message(note_off)

try: while True: #Continue a loop sensing for any key being pressed or released and running the respective callback keyboard.on_press(onPress) keyboard.on_release(onRelease)

except: #Stop all notes when program is stopped for i in range(len(keys)): note_off = [0x80, i+30, 0] midiout.send_message(note_off)` With this code, I can start a note, but the note doesn’t stop when the key is released. What should I do?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bopprehcommented, Aug 18, 2021

Fixing this properly requires a rewrite of the (small) core that handles hotkeys, something that I’m currently working on. Stay tuned!

0reactions
johmarjaccommented, Aug 18, 2021

Glad I could help, Cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Jcrop "onRelease" not working?
onRelease means you cancel your selection, not to stop dragging your crop indicator. Share. Share a link to this answer.
Read more >
OnRelease not working
I'm having some issues getting the OnRelease function to work. For the sake of troubleshooting, I just have it printing a message when ......
Read more >
Github Action trigger on release not working if ...
I've been working on some workflows that automatically build & release my application using Github Actions. i have 2 workflows:.
Read more >
Solved: .onRelease button not playing video
Solved: I created an video Flash ad with ActionScript 3.0 and was then told by the publisher I could only use ActionScript 2.0....
Read more >
OnClicked, OnReleased not firing yet On Begin and End ...
I have a primitive cube that I converted to a static mesh. I got OnBeginOverlap and OnEndOverlap functionality(changing material) working ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found