arirusso/unimidi — Issue #7: jruby192 vs ruby193p0 input errors and latency
Author: sdj
Created: 2012-02-27 02:48:40+00:00
State: open

A loop dumping received MIDI data on JRuby 1.9.2 is returning strange data for the bottom of my controller sliders and knobs (i.e.: if I turn the knobs or pull the sliders towards zero). (Both jruby and ruby where installed via brew.):

```
$ ./input_jruby192.rb
java
1.9.2
2012-01-30

Select a MIDI input...
0) Fast Track Ultra
1) Akai APC40
5) Real Time Sequencer
> 1
send some MIDI to your input now...
[{:data=>[176, 14, 33], :timestamp=>15042.999982833862}]
[{:data=>[176, 14, 32], :timestamp=>15138.999938964844}]
[{:data=>[176, 14, 31], :timestamp=>16249.000072479248}]
[{:data=>[176, 14, 30], :timestamp=>16311.000108718872}]
[{:data=>[176, 14, 29], :timestamp=>16497.999906539917}]
[{:data=>[176, 14, 28], :timestamp=>16584.00011062622}]
[{:data=>[176, 14, 27], :timestamp=>16696.00009918213}]
[{:data=>[176, 14, 26], :timestamp=>16854.000091552734}]
[{:data=>[176, 14, 25], :timestamp=>17042.999982833862}]
[{:data=>[176, 14, 24], :timestamp=>17094.000101089478}]
[{:data=>[176, 14, 23], :timestamp=>17194.000005722046}]
[{:data=>[176, 14, 22], :timestamp=>17332.99994468689}]
[{:data=>[176, 14, 21], :timestamp=>17473.000049591064}]
[{:data=>[176, 14, 20], :timestamp=>17614.00008201599}]
[{:data=>[176, 14, 19], :timestamp=>17703.999996185303}]
[{:data=>[176, 14, 18], :timestamp=>17785.00008583069}]
[{:data=>[176, 14, 17], :timestamp=>17884.000062942505}]
[{:data=>[176, 14, 16], :timestamp=>17983.999967575073}]
[{:data=>[0, 235, 240], :timestamp=>18134.000062942505}]
[{:data=>[0, 235, 224], :timestamp=>18394.00005340576}]
[{:data=>[0, 235, 208], :timestamp=>18575.000047683716}]
[{:data=>[0, 235, 192], :timestamp=>18834.00011062622}]
[{:data=>[0, 235, 176], :timestamp=>19184.00001525879}]
[{:data=>[0, 235, 160], :timestamp=>19283.999919891357}]
[{:data=>[0, 235, 144], :timestamp=>19533.999919891357}]
[{:data=>[0, 235, 128], :timestamp=>19927.000045776367}]
[{:data=>[0, 235, 96], :timestamp=>20043.999910354614}]
[{:data=>[0, 235, 80], :timestamp=>20184.99994277954}]
[{:data=>[0, 235, 64], :timestamp=>20394.999980926514}]
[{:data=>[0, 235, 48], :timestamp=>20555.000066757202}]
[{:data=>[0, 235, 32], :timestamp=>20694.000005722046}]
[{:data=>[0, 235, 16], :timestamp=>21114.00008201599}]
[{:data=>[0, 235], :timestamp=>21483.999967575073}]
^C
$
```

For comparison, ruby 1.9.3p0 running simultaneously (same behaviour if only running one or the other) -- this version also throw exception on ^C that JRuby version does not, and is quite chunky outputting received data compared to the JRuby version (I'm not sure how to measure that to prove it -- unless the number of elements in the dumped arrays is indicative?):

```
$ ./input_ruby193.rb
x86_64-darwin11.3.0
1.9.3
2011-10-30

Select a MIDI input...
0) M-Audio Fast Track Ultra
2) Akai Akai APC40
> 2
send some MIDI to your input now...
[{:data=>[176, 14, 33], :timestamp=>6656.177759170532},
{:data=>[176, 14, 32], :timestamp=>6656.36682510376}]
[{:data=>[176, 14, 31], :timestamp=>7866.124629974365},
{:data=>[176, 14, 30], :timestamp=>7866.4116859436035}]
[{:data=>[176, 14, 29], :timestamp=>8123.588800430298},
{:data=>[176, 14, 28], :timestamp=>8123.771905899048}]
[{:data=>[176, 14, 27], :timestamp=>8411.648750305176},
{:data=>[176, 14, 26], :timestamp=>8411.79871559143}]
[{:data=>[176, 14, 25], :timestamp=>8661.818742752075}]
[{:data=>[176, 14, 24], :timestamp=>8662.103652954102}]
[{:data=>[176, 14, 23], :timestamp=>8912.774801254272}]
[{:data=>[176, 14, 22], :timestamp=>8913.033962249756}]
[{:data=>[176, 14, 21], :timestamp=>9193.013668060303},
{:data=>[176, 14, 20], :timestamp=>9193.187713623047}]
[{:data=>[176, 14, 19], :timestamp=>9430.135726928711},
{:data=>[176, 14, 18], :timestamp=>9430.555820465088},
{:data=>[176, 14, 17], :timestamp=>9430.671691894531}]
[{:data=>[176, 14, 16], :timestamp=>9703.298807144165},
{:data=>[176, 14, 15], :timestamp=>9703.441858291626}]
[{:data=>[176, 14, 14], :timestamp=>10037.22882270813}]
[{:data=>[176, 14, 13], :timestamp=>10309.62586402893}]
[{:data=>[176, 14, 12], :timestamp=>10553.469896316528}]
[{:data=>[176, 14, 11], :timestamp=>10802.077770233154},
{:data=>[176, 14, 10], :timestamp=>10802.196979522705}]
[{:data=>[176, 14, 9], :timestamp=>11152.296781539917}]
[{:data=>[176, 14, 8], :timestamp=>11542.020797729492}]
[{:data=>[176, 14, 6], :timestamp=>11765.419721603394},
{:data=>[176, 14, 5], :timestamp=>11765.552759170532}]
[{:data=>[176, 14, 4], :timestamp=>12013.13066482544}]
[{:data=>[176, 14, 3], :timestamp=>12273.216009140015},
{:data=>[176, 14, 2], :timestamp=>12273.362874984741}]
[{:data=>[176, 14, 1], :timestamp=>12821.009874343872}]
[{:data=>[176, 14, 0], :timestamp=>13143.155813217163}]
^C/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/ffi-coremidi-0.1.4/lib/coremidi/source.rb:120:in `queued_messages?': Interrupt
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/ffi-coremidi-0.1.4/lib/coremidi/source.rb:26:in `gets'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/unimidi-0.3.2/lib/unimidi/congruous_api_adapter.rb:186:in `gets'
from /Users/sdj/Code/midi/midi.rb:39:in `block (2 levels) in poll_input'
from /Users/sdj/Code/midi/midi.rb:38:in `loop'
from /Users/sdj/Code/midi/midi.rb:38:in `block in poll_input'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/unimidi-0.3.2/lib/unimidi/congruous_api_adapter.rb:26:in `open'
from /Users/sdj/Code/midi/midi.rb:34:in `poll_input'
from /Users/sdj/Code/midi/input.rb:8:in `'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from ./input_ruby193.rb:3:in `

'
$
```

input.rb:

```ruby
require 'unimidi'
require 'pp'

def poll_input(input)
input.open do |i|

$stdout.puts "send some MIDI to your input now..."

loop do
m = i.gets
yield(m)
end

end
end

puts RUBY_PLATFORM, RUBY_VERSION, RUBY_RELEASE_DATE

input = UniMIDI::Input.gets

poll_input(input) do |m|
pp m
end
```

input_jruby192.rb:

```ruby
#!/usr/bin/env jruby --1.9
# $ jruby --1.9 -v
# jruby 1.6.6 (ruby-1.9.2-p312) (2012-01-30 5673572) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
require './input.rb'
```

input_ruby193.rb:

```ruby
#!/usr/bin/env ruby
# $ ruby -v
# ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
require './input.rb'
```

This is on Lion 10.7.3 on a late 2010 Mac Book Air.

Any ideas? Am I missing something?

Let me know if you need any more info. Thanks!