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

Midi recording doesn't work #523

Open
taherromdhane opened this issue Nov 12, 2024 · 4 comments
Open

Midi recording doesn't work #523

taherromdhane opened this issue Nov 12, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@taherromdhane
Copy link

taherromdhane commented Nov 12, 2024

When I try to record midi, the application seemingly crashes and restarts. From what I understood, there's an issue with the midi input logic in the code, I played around with midi settings but it works 1 out of 5 times on a good day.

Installation Method
Project image, latest version (v1.5.1 - Hotfix)

Error Messages
I have this in the logs, I'm actively investigating so will update with more findings

[2024-11-11 17:20:06] Starting webinterface
[2024-11-11 17:20:06] Running disable_ap.sh
[2024-11-11 17:21:31] 'NoneType' object has no attribute 'send'
[2024-11-11 17:21:39] Unhandled Exception: TypeError - list indices must be integers or slices, not str
[2024-11-11 17:21:48] Inport loaded and set to Digital Piano:Digital Piano MIDI 1 20:0
[2024-11-11 17:21:48] Can't load input port: RtMidiOut Client:RtMidi output 130:0
[2024-11-11 17:21:48] hostapd package is installed
[2024-11-11 17:21:50] Starting webinterface
[2024-11-11 17:21:50] Running disable_ap.sh
[2024-11-11 17:23:03] Unhandled Exception: TypeError - 'NoneType' object is not subscriptable
[2024-11-11 17:23:11] Inport loaded and set to Digital Piano:Digital Piano MIDI 1 20:0
[2024-11-11 17:23:11] Can't load input port: RtMidiOut Client:RtMidi output 130:0
[2024-11-11 17:23:12] hostapd package is installed
[2024-11-11 17:23:14] Starting webinterface
[2024-11-11 17:23:14] Running disable_ap.sh
[2024-11-11 17:26:44] Can't load input port: Digital Piano:Digital Piano MIDI 1 20:0
[2024-11-11 17:26:44] Can't load input port: RtMidiOut Client:RtMidi output 130:0
[2024-11-11 17:26:45] hostapd package is installed
[2024-11-11 17:26:48] Starting webinterface
[2024-11-11 17:26:48] Running disable_ap.sh
[2024-11-12 08:40:12] Error while getting ports 'NoneType' object has no attribute 'poll'

Environment

  • Python version: 3.9.2
  • No LCD screen, I'm using only the web interface
@taherromdhane taherromdhane added the bug Something isn't working label Nov 12, 2024
@taherromdhane
Copy link
Author

taherromdhane commented Nov 12, 2024

When debugging here's the stack trace of the error:

Exception has occurred: TypeError       (note: full exception trace is shown but execution is paused at: <module>)
'NoneType' object is not subscriptable
  File "D:\Work\Projects\piano led\Piano-LED-Visualizer\lib\savemidi.py", line 50, in add_control_change
    self.messages_to_save["main"].append(["control_change", time_value, status, channel, control, value])
  File "D:\Work\Projects\piano led\Piano-LED-Visualizer\visualizer.py", line 495, in <module> (Current frame)
    saving.add_control_change("control_change", 0, control, value, midiports.last_activity)
TypeError: 'NoneType' object is not subscriptable

@taherromdhane
Copy link
Author

taherromdhane commented Nov 12, 2024

Update:

When investigating more I found that it might be a race condition, since the call to

    def add_control_change(self, status, channel, control, value, time_value):
        self.messages_to_save["main"].append(["control_change", time_value, status, channel, control, value])

in main thread was made before the initialization of messages_to_save in the midi controller thread (I assume ?)

def start_recording(self):
        self.is_recording = True
        self.menu.render_message("Recording started", "", 500)
        self.messages_to_save = dict()
        self.messages_to_save["main"] = []
        self.restart_time()
        self.first_note_time = 0

my theory is that the call to MenuLCD.render_message is delaying the midi controlling thread right after we set is_recording to true, thus when the main thread tries to save midi by calling add_control_change the exception is thrown.

@jka-kan
Copy link

jka-kan commented Nov 18, 2024

Does changing the order in start_recording help? Initialize self.messages_to_save before setting self.is_recording = True?
I also noticed that in line 73 self.messages_to_save is initialized as a list. Is this intentional or should it be a dict with key "main" always available in case of something wants to write to it even though it is not expected?

@taherromdhane
Copy link
Author

@jka-kan changing the order fixed the problem for me, I might open a pull request for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants