unimidi 0.2.3-java → 0.3.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/unimidi.rb +5 -3
- data/lib/unimidi/congruous_api_adapter.rb +44 -5
- data/test/helper.rb +2 -14
- data/test/test_congruous_api_adapter.rb +20 -0
- data/test/test_selectors.rb +8 -0
- metadata +5 -4
data/lib/unimidi.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
module UniMIDI
|
8
8
|
|
9
|
-
VERSION = "0.
|
9
|
+
VERSION = "0.3.0"
|
10
10
|
|
11
11
|
end
|
12
12
|
|
@@ -22,8 +22,10 @@ module UniMIDI
|
|
22
22
|
|
23
23
|
def self.command(command, options = {})
|
24
24
|
if [:l, :list, :list_devices].include?(command)
|
25
|
-
|
26
|
-
|
25
|
+
puts "input:"
|
26
|
+
Input.list
|
27
|
+
puts "output:"
|
28
|
+
Output.list
|
27
29
|
else
|
28
30
|
raise "Command #{command.to_s} not found"
|
29
31
|
end
|
@@ -11,7 +11,7 @@ module UniMIDI
|
|
11
11
|
@device = device_obj
|
12
12
|
@id = @device.id
|
13
13
|
@name = @device.name
|
14
|
-
|
14
|
+
populate_type
|
15
15
|
end
|
16
16
|
|
17
17
|
def enabled?
|
@@ -20,7 +20,7 @@ module UniMIDI
|
|
20
20
|
|
21
21
|
# enable the device for use, can be passed a block to which the device will be passed back
|
22
22
|
def open(*a, &block)
|
23
|
-
@device.open(*a)
|
23
|
+
@device.open(*a) unless enabled?
|
24
24
|
unless block.nil?
|
25
25
|
begin
|
26
26
|
yield(self)
|
@@ -33,7 +33,7 @@ module UniMIDI
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def pretty_name
|
36
|
-
"#{id}
|
36
|
+
"#{id}) #{name}"
|
37
37
|
end
|
38
38
|
|
39
39
|
# close the device
|
@@ -50,6 +50,29 @@ module UniMIDI
|
|
50
50
|
|
51
51
|
module ClassMethods
|
52
52
|
|
53
|
+
def list
|
54
|
+
all.each { |device| puts(device.pretty_name) }
|
55
|
+
end
|
56
|
+
|
57
|
+
# streamlined console prompt that asks the user to select a device
|
58
|
+
def gets
|
59
|
+
device = nil
|
60
|
+
class_name = self.name.split("::").last.downcase
|
61
|
+
grammer = %w{o i}.include?(class_name[0]) ? "n" : ""
|
62
|
+
puts ""
|
63
|
+
puts "Select a#{grammer} #{class_name}..."
|
64
|
+
while device.nil?
|
65
|
+
list
|
66
|
+
print "> "
|
67
|
+
selection = $stdin.gets.chomp
|
68
|
+
if selection != ""
|
69
|
+
selection = Integer(selection) rescue nil
|
70
|
+
device = all.find { |d| d.id == selection }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
device
|
74
|
+
end
|
75
|
+
|
53
76
|
# returns the first device for this class
|
54
77
|
def first(&block)
|
55
78
|
use_device(all.first, &block)
|
@@ -65,11 +88,18 @@ module UniMIDI
|
|
65
88
|
all_by_type.values.flatten
|
66
89
|
end
|
67
90
|
|
68
|
-
# returns the device at <em>index</em>
|
91
|
+
# returns the device at <em>index</em> and opens it
|
69
92
|
def use(index, &block)
|
93
|
+
index = case index
|
94
|
+
when :first then 0
|
95
|
+
when :last then all.size - 1
|
96
|
+
else index
|
97
|
+
end
|
70
98
|
use_device(all[index], &block)
|
71
99
|
end
|
100
|
+
alias_method :open, :use
|
72
101
|
|
102
|
+
# returns the device at <em>index</em>
|
73
103
|
def [](index)
|
74
104
|
all[index]
|
75
105
|
end
|
@@ -114,11 +144,20 @@ module UniMIDI
|
|
114
144
|
end
|
115
145
|
|
116
146
|
def use_device(device, &block)
|
117
|
-
device.open(&block)
|
147
|
+
device.open(&block)
|
118
148
|
device
|
119
149
|
end
|
120
150
|
|
121
151
|
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
def populate_type
|
156
|
+
@type = case @device.type
|
157
|
+
when :source, :input then :input
|
158
|
+
when :destination, :output then :output
|
159
|
+
end
|
160
|
+
end
|
122
161
|
|
123
162
|
end
|
124
163
|
|
data/test/helper.rb
CHANGED
@@ -12,20 +12,8 @@ module TestHelper
|
|
12
12
|
|
13
13
|
def self.select_devices
|
14
14
|
$test_device ||= {}
|
15
|
-
{ :input => UniMIDI::Input
|
16
|
-
|
17
|
-
puts "select an #{type.to_s}..."
|
18
|
-
while $test_device[type].nil?
|
19
|
-
devs.each do |device|
|
20
|
-
puts device.pretty_name
|
21
|
-
end
|
22
|
-
selection = $stdin.gets.chomp
|
23
|
-
if selection != ""
|
24
|
-
selection = selection.to_i
|
25
|
-
$test_device[type] = devs.find { |d| d.id == selection }
|
26
|
-
puts "selected #{selection} for #{type.to_s}" unless $test_device[type]
|
27
|
-
end
|
28
|
-
end
|
15
|
+
{ :input => UniMIDI::Input, :output => UniMIDI::Output }.each do |type, klass|
|
16
|
+
$test_device[type] = klass.gets
|
29
17
|
end
|
30
18
|
end
|
31
19
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class CongruousApiAdapterTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include UniMIDI
|
8
|
+
include TestHelper
|
9
|
+
|
10
|
+
def test_input_type
|
11
|
+
i = $test_device[:input]
|
12
|
+
assert_equal(:input, i.type)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_output_type
|
16
|
+
o = $test_device[:output]
|
17
|
+
assert_equal(:output, o.type)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/test_selectors.rb
CHANGED
@@ -48,6 +48,14 @@ class SelectorTest < Test::Unit::TestCase
|
|
48
48
|
assert_equal(Input.all.first, i)
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_use_with_symbol
|
52
|
+
sleep(1)
|
53
|
+
i = Input.use(:first)
|
54
|
+
assert_equal(true, i.enabled?)
|
55
|
+
assert_equal(Input.first, i)
|
56
|
+
assert_equal(Input.all.first, i)
|
57
|
+
end
|
58
|
+
|
51
59
|
def test_all
|
52
60
|
i = Input.all
|
53
61
|
assert_equal(Device.all_by_type[:input], Input.all)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unimidi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: java
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-04 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: midi-jruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70234497254760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70234497254760
|
25
25
|
description: Platform Independent, realtime MIDI input and output for Ruby
|
26
26
|
email:
|
27
27
|
- ari.russo@gmail.com
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/unimidi/type_conversion.rb
|
41
41
|
- lib/unimidi.rb
|
42
42
|
- test/helper.rb
|
43
|
+
- test/test_congruous_api_adapter.rb
|
43
44
|
- test/test_input_buffer.rb
|
44
45
|
- test/test_io.rb
|
45
46
|
- test/test_platform.rb
|