Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new selectors (with open), coremidi api changes, version

  • Loading branch information...
commit 00d1e91f4d299e2389730f1c0cdc7a2ea6d9eadc 1 parent c39cc3f
@arirusso authored
View
5 Rakefile
@@ -1,5 +1,6 @@
-dir = File.dirname(File.expand_path(__FILE__))
-$LOAD_PATH.unshift dir
+$:.unshift File.join( File.dirname( __FILE__ ))
+$:.unshift File.join( File.dirname( __FILE__ ), 'lib')
+
require 'rake'
require 'rake/testtask'
View
2  examples/output.rb
@@ -14,7 +14,7 @@
# UniMIDI::Device.all.to_s will list your midi devices
# or amidi -l from the command line
-UniMIDI::Output.first.open do |output|
+UniMIDI::Output.first do |output|
(0..((octaves-1)*12)).step(12) do |oct|
View
2  lib/unimidi.rb
@@ -6,7 +6,7 @@
module UniMIDI
- VERSION = "0.2.2"
+ VERSION = "0.2.3"
end
View
2  lib/unimidi/adapter/alsa-rawmidi.rb
@@ -9,10 +9,12 @@ module AlsaRawMIDIAdapter
class Input < CongruousApiInput
defer_to AlsaRawMIDI::Input
+ device_class AlsaRawMIDI::Device
end
class Output < CongruousApiOutput
defer_to AlsaRawMIDI::Output
+ device_class AlsaRawMIDI::Device
end
class Device < CongruousApiDevice
View
15 lib/unimidi/adapter/ffi-coremidi.rb
@@ -8,17 +8,28 @@ module UniMIDI
module CoreMIDIAdapter
class Input < CongruousApiInput
- defer_to CoreMIDI::Input
+ defer_to CoreMIDI::Source
+ device_class CoreMIDI::Endpoint
end
class Output < CongruousApiOutput
- defer_to CoreMIDI::Output
+ defer_to CoreMIDI::Destination
+ device_class CoreMIDI::Endpoint
end
class Device < CongruousApiDevice
defer_to CoreMIDI::Endpoint
input_class Input
output_class Output
+
+ def self.populate
+ klass = @deference[self].respond_to?(:all_by_type) ? @deference[self] : @device_class
+ @devices = {
+ :input => klass.all_by_type[:source].map { |d| @input_class.new(d) },
+ :output => klass.all_by_type[:destination].map { |d| @output_class.new(d) }
+ }
+ end
+
end
end
View
2  lib/unimidi/adapter/midi-jruby.rb
@@ -9,10 +9,12 @@ module MIDIJRubyAdapter
class Input < CongruousApiInput
defer_to MIDIJRuby::Input
+ device_class MIDIJRuby::Device
end
class Output < CongruousApiOutput
defer_to MIDIJRuby::Output
+ device_class MIDIJRuby::Device
end
class Device < CongruousApiDevice
View
2  lib/unimidi/adapter/midi-winmm.rb
@@ -9,10 +9,12 @@ module MIDIWinMMAdapter
class Input < CongruousApiInput
defer_to MIDIWinMM::Input
+ device_class MIDIWinMM::Device
end
class Output < CongruousApiOutput
defer_to MIDIWinMM::Output
+ device_class MIDIWinMM::Device
end
class Device < CongruousApiDevice
View
57 lib/unimidi/congruous_api_adapter.rb
@@ -13,6 +13,10 @@ def initialize(device_obj)
@name = @device.name
@type = @device.type
end
+
+ def enabled?
+ @device.enabled
+ end
# enable the device for use, can be passed a block to which the device will be passed back
def open(*a, &block)
@@ -47,13 +51,13 @@ def self.included(base)
module ClassMethods
# returns the first device for this class
- def first(*a, &block)
- use(@deference[self].first(*a), &block)
+ def first(&block)
+ use_device(all.first, &block)
end
# returns the last device for this class
- def last(*a, &block)
- use(@deference[self].last(*a), &block)
+ def last(&block)
+ use_device(all.last, &block)
end
# returns all devices in an array
@@ -62,25 +66,29 @@ def all
end
# returns the device at <em>index</em>
- def [](index, &block)
- d = all[index]
- d.open(&block) unless block.nil?
- d
+ def use(index, &block)
+ use_device(all[index], &block)
+ end
+
+ def [](index)
+ all[index]
end
# returns all devices as a hash as such
# { :input => [input devices], :output => [output devices] }
def all_by_type
- {
- :input => @deference[self].all_by_type[:input].map { |d| @input_class.new(d) },
- :output => @deference[self].all_by_type[:output].map { |d| @output_class.new(d) }
- }
+ ensure_initialized
+ @devices
end
def defer_to(klass)
@deference ||= {}
@deference[self] = klass
end
+
+ def device_class(klass)
+ @device_class = klass
+ end
def input_class(klass)
@input_class = klass
@@ -90,13 +98,24 @@ def output_class(klass)
@output_class = klass
end
+ def populate
+ klass = @deference[self].respond_to?(:all_by_type) ? @deference[self] : @device_class
+ @devices = {
+ :input => klass.all_by_type[:input].map { |d| @input_class.new(d) },
+ :output => klass.all_by_type[:output].map { |d| @output_class.new(d) }
+ }
+ end
+ alias_method :refresh, :populate
+
private
- def use(dev, &block)
- raise 'Device not found' if dev.nil?
- d = new(dev)
- d.open(&block) unless block.nil?
- d
+ def ensure_initialized
+ populate if @devices.nil?
+ end
+
+ def use_device(device, &block)
+ device.open(&block) unless block.nil?
+ device
end
end
@@ -184,7 +203,7 @@ def gets_buffer_data(*a)
# returns all inputs
def self.all
- @deference[self].all.map { |d| new(d) }
+ UniMIDI::Device.all_by_type[:input]
end
end
@@ -232,7 +251,7 @@ def puts_bytes(*a)
# returns all outputs
def self.all
- @deference[self].all.map { |d| new(d) }
+ UniMIDI::Device.all_by_type[:output]
end
end
View
21 test/helper.rb
@@ -29,16 +29,19 @@ def self.select_devices
end
end
- def platform_test(adapter, mod)
+ def platform_test(adapter, mod, device_class = nil, input_class = nil, output_class = nil)
+ device_class ||= mod::Device
+ input_class ||= mod::Input
+ output_class ||= mod::Output
assert_equal(adapter, UniMIDI::Platform.instance.interface)
- assert_not_same(mod::Input, UniMIDI::Input)
- assert_not_same(mod::Output, UniMIDI::Output)
- assert_not_same(mod::Device, UniMIDI::Device)
- assert_equal(mod::Input.first.name, UniMIDI::Input.first.name)
- assert_equal(mod::Input.first.id, UniMIDI::Input.first.id)
- assert_not_same(mod::Output.first, UniMIDI::Output.first)
- assert_equal(mod::Output.first.name, UniMIDI::Output.first.name)
- assert_equal(mod::Output.first.id, UniMIDI::Output.first.id)
+ assert_not_same(input_class, UniMIDI::Input)
+ assert_not_same(output_class, UniMIDI::Output)
+ assert_not_same(device_class, UniMIDI::Device)
+ assert_equal(input_class.first.name, UniMIDI::Input.first.name)
+ assert_equal(input_class.first.id, UniMIDI::Input.first.id)
+ assert_not_same(output_class.first, UniMIDI::Output.first)
+ assert_equal(output_class.first.name, UniMIDI::Output.first.name)
+ assert_equal(output_class.first.id, UniMIDI::Output.first.id)
end
def bytestrs_to_ints(arr)
View
2  test/test_input_buffer.rb
@@ -15,6 +15,8 @@ def test_input_buffer
$test_device[:output].open do |output|
$test_device[:input].open do |input|
+
+ input.buffer.clear
messages.each do |msg|
View
8 test/test_io.rb
@@ -16,7 +16,9 @@ def test_full_io
pointer = 0
$test_device[:output].open do |output|
$test_device[:input].open do |input|
-
+
+ input.buffer.clear
+
messages.each do |msg|
$>.puts "sending: " + msg.inspect
@@ -87,7 +89,9 @@ def test_full_io_objects
pointer = 0
$test_device[:output].open do |output|
$test_device[:input].open do |input|
-
+
+ #input.buffer.clear
+
messages.each do |msg|
$>.puts "sending: " + msg.inspect
View
2  test/test_platform.rb
@@ -21,7 +21,7 @@ def test_linux
def test_osx
if RUBY_PLATFORM.include?("darwin")
- platform_test(CoreMIDIAdapter, CoreMIDI)
+ platform_test(CoreMIDIAdapter, CoreMIDI, CoreMIDI::Endpoint, CoreMIDI::Source, CoreMIDI::Destination)
end
end
View
56 test/test_selectors.rb
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+
+require 'helper'
+
+class SelectorTest < Test::Unit::TestCase
+
+ include UniMIDI
+ include TestHelper
+
+ def test_first
+ i = Input.first
+ assert_equal(Input.all.first, i)
+ end
+
+ def test_last
+ i = Input.last
+ assert_equal(Input.all.last, i)
+ end
+
+ def test_first_with_block
+ sleep(1)
+ i = Input.first do |i|
+ assert_equal(true, i.enabled?)
+ end
+ assert_equal(Input.all.first, i)
+ end
+
+ def test_last_with_block
+ sleep(1)
+ i = Input.last do |i|
+ assert_equal(true, i.enabled?)
+ end
+ assert_equal(Input.all.last, i)
+ end
+
+ def test_brackets
+ i = Input[0]
+ assert_equal(Input.first, i)
+ assert_equal(Input.all.first, i)
+ end
+
+ def test_use_with_block
+ sleep(1)
+ i = Input.use(0) do |i|
+ assert_equal(true, i.enabled?)
+ end
+ assert_equal(Input.first, i)
+ assert_equal(Input.all.first, i)
+ end
+
+ def test_all
+ i = Input.all
+ assert_equal(Device.all_by_type[:input], Input.all)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.