superquadratic / rtmidi-python

Python wrapper for RtMidi
MIT License
56 stars 2 forks source link

Queue problem #7

Closed benjamind2008 closed 12 years ago

benjamind2008 commented 12 years ago

I am running this code (sorry if the code seems a little messy, it's better than the older code I had, I fixed up some stuff):

Each time I run it, the queue does not appear to flush when the port is closed, and periodically I would want to clear the queue so that it does not run out of queue space ;)

Each time I run the program, the old messages seem to re-iterate and the new messages that I generate via an external program are just added to the queue (which is good), but the old messages don't seem to get flushed out of the queue as I would expect them to when I close the port, but I don't know how to flush the queue as there appears to be no function to do that. But I'm not sure why it isn't clearing the queue when I close the port, is this something I am doing wrong, or if there is something I am missing?

import rtmidi_python as rtmidi
import sched, time, unittest
import math

prog_condition = True
old_time_count = 0 # main initial time counter
time_count = 0 # main time counter

message = 0

midi_port_count = 0 #define the port count integer

midi_in = None
midi_in = rtmidi.MidiIn()
for port_name in midi_in.ports:
    print port_name, midi_port_count
    midi_port_count = midi_port_count + 1

time.sleep(0.5)

old_time_count = time.time()

stored_time = time.time() #we set the stored time to the current time

print ("opening MIDI port")
midi_in.open_port(2) # we just use (2) for now
stored_time = time.time()

while (prog_condition == True):
    time_count = time.time() - old_time_count
    current_time = time.time()    
    message, delta_time = midi_in.get_message()
    if (time_count > 10):
        prog_condition = False
        print ("program stops after 10 seconds")
        midi_in.close_port() # close the port
        midi_in = None
        midi_out = None        
        exit
    if message:
        print message, delta_time
        current_time = time.time()
superquadratic commented 12 years ago

Unfortunately I cannot reproduce your issue. I ran the code and it runs for 10 seconds, printing every MIDI message received from my MIDI controller. Running it again, it only prints new messages.

Actually, since the same messages show up in different runs of the program for you, I can hardly imagine this being an issue with RtMidi or the Python module. What OS are you using and what kind of MIDI port is number 2 on your system? Also, have you double-checked the output of the program that generates the messages, e.g. by recording them in a sequencer?

benjamind2008 commented 12 years ago

Thanks Guido. I think it could be the LoopBe30 midi loopback system I'm using. Port number 2 was "Internal MIDI channel 1" on my system, and I connected my output program to that MIDI port to test how it received messages. I use the LoopBe30, but I might uninstall it and use MidiYoke instead and see if I have the same issue. As you say it could also be the program I'm using to output. I use Synfire Pro which is a music prototyping program.

regards Ben

On 5/10/12, Guido Lorenz reply@reply.github.com wrote:

Unfortunately I cannot reproduce your issue. I ran the code and it runs for 10 seconds, printing every MIDI message received from my MIDI controller. Running it again, it only prints new messages.

Actually, since the same messages show up in different runs of the program for you, I can hardly imagine this being an issue with RtMidi or the Python module. What OS are you using and what kind of MIDI port is number 2 on your system? Also, have you double-checked the output of the program that generates the messages, e.g. by recording them in a sequencer?


Reply to this email directly or view it on GitHub: https://github.com/superquadratic/rtmidi-python/issues/7#issuecomment-5604713