unimidi 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@
6
6
 
7
7
  module UniMIDI
8
8
 
9
- VERSION = "0.2.4"
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
- require 'pp'
26
- pp Device::all
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
@@ -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}: #{name}"
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,7 +144,7 @@ module UniMIDI
114
144
  end
115
145
 
116
146
  def use_device(device, &block)
117
- device.open(&block) unless block.nil?
147
+ device.open(&block)
118
148
  device
119
149
  end
120
150
 
@@ -12,20 +12,8 @@ module TestHelper
12
12
 
13
13
  def self.select_devices
14
14
  $test_device ||= {}
15
- { :input => UniMIDI::Input.all, :output => UniMIDI::Output.all }.each do |type, devs|
16
- puts ""
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
 
@@ -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.2.4
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-08 00:00:00.000000000Z
12
+ date: 2011-10-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: alsa-rawmidi
16
- requirement: &70272850205320 !ruby/object:Gem::Requirement
16
+ requirement: &70264495502020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70272850205320
24
+ version_requirements: *70264495502020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ffi-coremidi
27
- requirement: &70272850204440 !ruby/object:Gem::Requirement
27
+ requirement: &70264495501540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70272850204440
35
+ version_requirements: *70264495501540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: midi-jruby
38
- requirement: &70272850203760 !ruby/object:Gem::Requirement
38
+ requirement: &70264495501100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70272850203760
46
+ version_requirements: *70264495501100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: midi-winmm
49
- requirement: &70272850202940 !ruby/object:Gem::Requirement
49
+ requirement: &70264495500660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70272850202940
57
+ version_requirements: *70264495500660
58
58
  description: Platform Independent, realtime MIDI input and output for Ruby
59
59
  email:
60
60
  - ari.russo@gmail.com