arirusso / unimidi

Realtime MIDI IO for Ruby
Other
255 stars 28 forks source link

How to access UniMIDI::Output's @buffer to see if a note is still playing? #17

Closed christiangenco closed 12 years ago

christiangenco commented 12 years ago

I have an imperfect method of sending notes to be played to UniMIDI (javascript/ajax) and sometimes the signal to stop playing the note isn't sent, so the note keeps going on indefinitely.

I need a way to view which notes are currently playing, but can't find it in the documentation or demos. When I inspect my Output object, however, I see this:

=> #<UniMIDI::CoreMIDIAdapter::Output:0x007fceb217b5f0
 @device=
  #<CoreMIDI::Destination:0x007fceb21815e0
   @client=#<FFI::Pointer address=0x00000005eeb01c>,
   @enabled=true,
   @entity=
    #<CoreMIDI::Entity:0x007fceb2183930
     @endpoints=
      {:source=>
        [#<CoreMIDI::Source:0x007fceb2183278
          @buffer=
           [{:data=>[144, 36, 100], :timestamp=>19540.279150009155},
            {:data=>[144, 40, 100], :timestamp=>48366.633892059326}],
            ...

That @buffer array is exactly what I need (it's currently showing two notes, 36 and 40, that haven't been stopped), but after several minutes pouring through the docs and poking each of Output's public methods, I can't seem to get at it. Is there a correct way to do this?

arirusso commented 12 years ago

@christiangenco

[corrected]

arirusso commented 12 years ago

@christiangenco

(disregard my last message)

I'll need to know a little more about your setup. What exactly are you doing with the output?

You may need to instantiate an input eg.

@i = UniMIDI::Input.first

Then you can inspect the buffer directly on that object

@i.buffer
=> [144, 36, 100]
christiangenco commented 12 years ago

Ahh hah! That fixes my problem - thanks :D

Is there a good reason why UniMIDI::Output can't have a buffer method as well?

arirusso commented 12 years ago

@christiangenco Great, glad to help.

The output itself doesn't have a buffer. The fact that you can see the input buffer associated with the output buffer (as in the example you posted) is a peculiarity of how OSX CoreMIDI organizes MIDI ins and outs.

I'm more than happy to consider anything if you have a compelling argument

but (to my knowledge) Linux and Windows wouldn't natively accomodate that functionality, and Unimidi is cross-platform...so it could be impossible or a ton of trouble to implement, for what I would currently consider not a lot of gain

christiangenco commented 12 years ago

Reason enough for me!

Thanks for your work on this gem - it's absolutely perfect for turning things into MIDI keyboards via MaKey MaKey.