Coder Social home page Coder Social logo

midi-jruby's Introduction

midi-jruby

Realtime MIDI IO with JRuby using the javax.sound.midi API.

In the interest of allowing people on other platforms to utilize your code, you should consider using unimidi. Unimidi is a platform independent wrapper that implements midi-jruby and has a similar API.

Features

  • Simplified API
  • Input and output on multiple devices concurrently
  • Generalized handling of different MIDI Message types (including SysEx)
  • Timestamped input events

Install

If you're using Bundler, add this line to your application's Gemfile:

gem "midi-jruby"

Otherwise

gem install midi-jruby

Examples

Issues

There is an issue that causes javax.sound.midi not to be able to send SysEx messages in some versions of OSX.

Documentation

License

Apache 2.0, See the file LICENSE

Copyright (c) 2011-2022 Ari Russo

midi-jruby's People

Contributors

arirusso avatar jasongrlicky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

midi-jruby's Issues

RangeError: too big for byte: 240

Hey ari. How's life? Finally made the shift to jruby. Are the tests in midi-jruby known to pass?

jruby -v

jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]

uname -a

Darwin Michaels-MacBook-Air.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64

Running tests:

sending: [240, 65, 16, 66, 18, 64, 0, 127, 0, 65, 247]
Esending: [240, 65, 16, 66, 18, 64, 0, 127, 0, 65, 247]
Esending: "F04110421240007F0041F7"
E

Finished tests in 6.061000s, 0.4950 tests/s, 0.0000 assertions/s.

  1. Error:
    test_input_buffer(InputBufferTest):
    RangeError: too big for byte: 240
    org/jruby/java/addons/KernelJavaAddons.java:68:in to_java' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:34:inputs_bytes'
    /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:45:in puts' /Users/mgarriss/develop/midi-jruby/test/test_input_buffer.rb:23:intest_input_buffer'
    org/jruby/RubyArray.java:1611:in each' /Users/mgarriss/develop/midi-jruby/test/test_input_buffer.rb:19:intest_input_buffer'
    org/jruby/RubyProc.java:257:in call' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/input.rb:105:inenable'
    /Users/mgarriss/develop/midi-jruby/test/test_input_buffer.rb:17:in test_input_buffer' org/jruby/RubyProc.java:257:incall'
    /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:58:in enable' /Users/mgarriss/develop/midi-jruby/test/test_input_buffer.rb:16:intest_input_buffer'
    org/jruby/RubyBasicObject.java:1786:in `send'

  2. Error:
    test_full_io(IoTest):
    RangeError: too big for byte: 240
    org/jruby/java/addons/KernelJavaAddons.java:68:in to_java' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:34:inputs_bytes'
    /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:45:in puts' /Users/mgarriss/develop/midi-jruby/test/test_io.rb:25:intest_full_io'
    org/jruby/RubyArray.java:1611:in each' /Users/mgarriss/develop/midi-jruby/test/test_io.rb:21:intest_full_io'
    org/jruby/RubyProc.java:257:in call' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/input.rb:105:inenable'
    /Users/mgarriss/develop/midi-jruby/test/test_io.rb:19:in test_full_io' org/jruby/RubyProc.java:257:incall'
    /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:58:in enable' /Users/mgarriss/develop/midi-jruby/test/test_io.rb:18:intest_full_io'
    org/jruby/RubyBasicObject.java:1786:in `send'

  3. Error:
    test_full_io_bytestr(IoTest):
    RangeError: too big for byte: 240
    org/jruby/java/addons/KernelJavaAddons.java:68:in to_java' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:34:inputs_bytes'
    /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:25:in puts_s' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:47:inputs'
    /Users/mgarriss/develop/midi-jruby/test/test_io.rb:62:in test_full_io_bytestr' org/jruby/RubyArray.java:1611:ineach'
    /Users/mgarriss/develop/midi-jruby/test/test_io.rb:58:in test_full_io_bytestr' org/jruby/RubyProc.java:257:incall'
    /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/input.rb:105:in enable' /Users/mgarriss/develop/midi-jruby/test/test_io.rb:56:intest_full_io_bytestr'
    org/jruby/RubyProc.java:257:in call' /Users/mgarriss/develop/midi-jruby/test/../lib/midi-jruby/output.rb:58:inenable'
    /Users/mgarriss/develop/midi-jruby/test/test_io.rb:55:in test_full_io_bytestr' org/jruby/RubyBasicObject.java:1786:insend'

3 tests, 0 assertions, 0 failures, 3 errors, 0 skips
rake aborted!
Command failed with status (3): [/usr/local/jruby/bin/jruby -I"lib:test" -I...]

Tasks: TOP => test
(See full trace by running task with --trace)

Cannot receive a data byte 2 with a value of 0

Hello Ari. Thank you for making 'midi-jruby' and 'unimidi', great libraries.
I found an issue of 'midi-jruby'.

When receiving bytes [176, 14, 0], 'examples/input.rb' prints the following:

[{:data=>[176, 14], :timestamp=>1569.000005722046}]

I think 'midi-jruby' cannot receive a data byte 2 with a value of 0.

I think this is a problem of https://github.com/risgk/midi-jruby/blob/master/lib/midi-jruby/input.rb#L34 or https://github.com/risgk/midi-jruby/blob/master/lib/midi-jruby/input.rb#L45 .
The method unpack ignores the length of the message.

The following code is my workaround (monky patch) of this issue (unpack is not used):

module MIDIJRuby
  class Input
    class InputReceiver
      def send(msg, timestamp = -1)
        if msg.respond_to?(:get_packed_msg)
          m = msg.get_packed_msg
          @buf << [m & 0xFF, (m & 0xFF00) >> 8, (m & 0xFF0000) >> 16].take(msg.get_length) # modified
        else
          str = String.from_java_bytes(msg.get_data)
          arr = str.unpack("C" * str.length)
          arr.insert(0, msg.get_status)
          @buf << arr
        end
      end
    end
  end
end

I am sorry that my English is horrible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.