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

Input example pegs CPU #20

Closed
trogdoro opened this issue Aug 28, 2012 · 3 comments
Closed

Input example pegs CPU #20

trogdoro opened this issue Aug 28, 2012 · 3 comments

Comments

@trogdoro
Copy link

Is it normal for the CPU to go to 99% when input.gets is waiting? That's happening for me on OSX Lion with ruby 1.9.3.

It happens when running the input example code: https://github.com/arirusso/unimidi/blob/master/examples/input.rb

Also, it seems like it misses some events, and gets them on a slight delay.

@zensible
Copy link

I had the same issue when using a combination of midi controllers (Yamaha P120 and Behringer FCB1010). I was able to fix it by making a small change to the ffi-coremidi gem:

/your.gems.folder/ffi-coremidi-0.2.0/lib/coremidi/source.rb#gets

    def gets
      until queued_messages?
        sleep(0.0001)  # <-- patch to prevent 100% CPU issue with some midi controllers
      end
      msgs = queued_messages
      @pointer = @buffer.length
      msgs
    end

The issue was that 'queued_messages?' was always returning false, this slight delay seems to fix the problem without introducing any latency.

@arirusso
Copy link
Owner

arirusso commented Jun 1, 2014

You can certainly submit a patch to ffi-coremidi ! If not I'll try and get around to it soon

Thanks

@arirusso
Copy link
Owner

Wound up adding the patch here: arirusso/ffi-coremidi@05200fb#diff-d41d8cd98f00b204e9800998ecf8427e

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

3 participants