Warning message while sending midi

I am using the code below to play around with scamp and reaper.
Using Tobias Erichsen’s loopmidi I set up a virtual midi channel between the scamp code and the reaper daw. It works as expected except I get a continuous stream of warnings as shown below:


from scamp import *

from collections import namedtuple

s = Session()

s.print_available_midi_output_devices()

s.print_available_midi_input_devices()

piano = s.new_midi_part("piano", midi_output_device=3, num_channels=15)

# dictionary mapping keys that are down to the NoteHandles used to manipulate them.

notes_started = {}

def midi_callback(midi_message):

    code, pitch, volume = midi_message

    if volume > 0 and 144 <= code <= 159:

        notes_started[pitch] = piano.start_note(pitch + 7, volume/127)

    elif (volume == 0 and 144 <= code <= 159 or 128 <= code <= 143) and pitch in notes_started:

        notes_started[pitch].end()

s.register_midi_listener(3, midi_callback)

s.wait_forever()

WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!
WARNING:root:Tried to end a note that was never started!

Any idea why I am seeing this message?

I think you may need to add del notes_started[pitch] after notes_started[pitch].end()? Let me know if that works.

Thank you Marc,

That solved the problem!

1 Like

Awesome. I’ll change the warning message to “Tried to end a note that was never started (or already ended)!”, since the problem in your case was that you were ending a note that you had already ended.

Thanks Marc,

The code was taken from your 25_MIDI_in_out.py example in Tutorials so you may want to add that missing line to that example.

1 Like