unimidi 0.1.14 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,15 @@
1
- #!/usr/bin/env ruby
2
- #
3
-
4
- module UniMIDI
5
-
6
- module TypeConversion
7
-
8
- # byte array to string of hex bytes
9
- def numeric_byte_array_to_hex_string(bytes)
10
- bytes.map { |b| b.hex }.join
11
- end
12
-
13
- end
14
-
1
+ #!/usr/bin/env ruby
2
+ #
3
+
4
+ module UniMIDI
5
+
6
+ module TypeConversion
7
+
8
+ # byte array to string of hex bytes
9
+ def numeric_byte_array_to_hex_string(bytes)
10
+ bytes.map { |b| b.hex }.join
11
+ end
12
+
13
+ end
14
+
15
15
  end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module TestHelper::Config
4
+
5
+ # adjust these constants to suit your hardware configuration
6
+ # before running tests
7
+
8
+ TestInput = UniMIDI::Input.first # this is the device you wish to use to test input
9
+ TestOutput = UniMIDI::Output.first # likewise for output
10
+
11
+ puts "connect #{TestInput.name} (#{TestInput.id}) to #{TestOutput.name} (#{TestOutput.id}) and press enter"
12
+ $stdin.gets.chomp
13
+
14
+ end
15
+
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(File.expand_path(__FILE__))
4
+ $LOAD_PATH.unshift dir + '/../lib'
5
+
6
+ require 'test/unit'
7
+ require 'unimidi'
8
+
9
+ module TestHelper
10
+
11
+ TestSysex = !RUBY_PLATFORM.include?("java")
12
+
13
+ def platform_test(adapter, mod)
14
+ assert_equal(adapter, UniMIDI::Platform.instance.interface)
15
+ assert_not_same(mod::Input, UniMIDI::Input)
16
+ assert_not_same(mod::Output, UniMIDI::Output)
17
+ assert_not_same(mod::Device, UniMIDI::Device)
18
+ assert_equal(mod::Input.first.name, UniMIDI::Input.first.name)
19
+ assert_equal(mod::Input.first.id, UniMIDI::Input.first.id)
20
+ assert_not_same(mod::Output.first, UniMIDI::Output.first)
21
+ assert_equal(mod::Output.first.name, UniMIDI::Output.first.name)
22
+ assert_equal(mod::Output.first.id, UniMIDI::Output.first.id)
23
+ end
24
+
25
+ def bytestrs_to_ints(arr)
26
+ data = arr.map { |m| m[:data] }.join
27
+ output = []
28
+ until (bytestr = data.slice!(0,2)).eql?("")
29
+ output << bytestr.hex
30
+ end
31
+ output
32
+ end
33
+
34
+ class MIDIObj
35
+ def initialize(*bytes)
36
+ @bytes = bytes
37
+ end
38
+ def to_bytes
39
+ @bytes
40
+ end
41
+ end
42
+
43
+ # some MIDI messages
44
+ VariousMIDIObjects = [
45
+ TestSysex ? MIDIObj.new(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7) : nil, # SysEx
46
+ MIDIObj.new(0x90, 100, 100), # note on
47
+ MIDIObj.new(0x90, 43, 100), # note on
48
+ MIDIObj.new(0x90, 76, 100), # note on
49
+ MIDIObj.new(0x90, 60, 100), # note on
50
+ MIDIObj.new(0x80, 100, 100) # note off
51
+ ].compact
52
+
53
+ # some MIDI messages
54
+ VariousMIDIMessages = [
55
+ TestSysex ? [0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7] : nil, # SysEx
56
+ [0x90, 100, 100], # note on
57
+ [0x90, 43, 100], # note on
58
+ [0x90, 76, 100], # note on
59
+ [0x90, 60, 100], # note on
60
+ [0x80, 100, 100] # note off
61
+ ].compact
62
+
63
+ # some MIDI messages
64
+ VariousMIDIByteStrMessages = [
65
+ TestSysex ? "F04110421240007F0041F7" : nil, # SysEx
66
+ "906440", # note on
67
+ "804340" # note off
68
+ ].compact
69
+
70
+ end
71
+
72
+ require File.dirname(__FILE__) + '/config'
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'helper'
4
+
5
+ class InputBufferTest < Test::Unit::TestCase
6
+
7
+ include UniMIDI
8
+ include TestHelper
9
+ include TestHelper::Config # before running these tests, adjust the constants in config.rb to suit your hardware setup
10
+
11
+ def test_input_buffer
12
+ sleep(1)
13
+
14
+ messages = VariousMIDIMessages
15
+ bytes = []
16
+
17
+ TestOutput.open do |output|
18
+ TestInput.open do |input|
19
+
20
+ messages.each do |msg|
21
+
22
+ $>.puts "sending: " + msg.inspect
23
+
24
+ output.puts(msg)
25
+
26
+ bytes += msg
27
+
28
+ sleep(0.5)
29
+
30
+ buffer = input.buffer.map { |m| m[:data] }.flatten
31
+
32
+ $>.puts "received: " + buffer.to_s
33
+
34
+ assert_equal(bytes, buffer)
35
+
36
+ end
37
+
38
+ assert_equal(bytes.length, input.buffer.map { |m| m[:data] }.flatten.length)
39
+
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'helper'
4
+
5
+ class IoTest < Test::Unit::TestCase
6
+
7
+ include UniMIDI
8
+ include TestHelper
9
+ include TestHelper::Config # before running these tests, adjust the constants in config.rb to suit your hardware setup
10
+
11
+ # ** this test assumes that TestOutput is connected to TestInput
12
+ def test_full_io
13
+ sleep(1)
14
+ messages = VariousMIDIMessages
15
+ messages_arr = messages.inject { |a,b| a+b }.flatten
16
+ received_arr = []
17
+ pointer = 0
18
+ TestOutput.open do |output|
19
+ TestInput.open do |input|
20
+
21
+ messages.each do |msg|
22
+
23
+ $>.puts "sending: " + msg.inspect
24
+
25
+ output.puts(msg)
26
+ sleep(1)
27
+ received = input.gets.map { |m| m[:data] }.flatten
28
+
29
+
30
+ $>.puts "received: " + received.inspect
31
+
32
+ assert_equal(messages_arr.slice(pointer, received.length), received)
33
+
34
+ pointer += received.length
35
+
36
+ received_arr += received
37
+
38
+ end
39
+
40
+ assert_equal(messages_arr.length, received_arr.length)
41
+
42
+ end
43
+ end
44
+ end
45
+
46
+ # ** this test assumes that TestOutput is connected to TestInput
47
+ def test_full_io_bytestr
48
+ sleep(1) # pause between tests
49
+
50
+ messages = VariousMIDIByteStrMessages
51
+ messages_str = messages.join
52
+ received_str = ""
53
+ pointer = 0
54
+
55
+ TestOutput.open do |output|
56
+ TestInput.open do |input|
57
+
58
+ messages.each do |msg|
59
+
60
+ $>.puts "sending: " + msg.inspect
61
+
62
+ output.puts(msg)
63
+ sleep(1)
64
+ received = input.gets_bytestr.map { |m| m[:data] }.flatten.join
65
+ $>.puts "received: " + received.inspect
66
+
67
+ assert_equal(messages_str.slice(pointer, received.length), received)
68
+
69
+ pointer += received.length
70
+
71
+ received_str += received
72
+
73
+ end
74
+
75
+ assert_equal(messages_str, received_str)
76
+
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ # ** this test assumes that TestOutput is connected to TestInput
83
+ def test_full_io_objects
84
+ sleep(1)
85
+ messages = VariousMIDIObjects
86
+ messages_arr = messages.map { |m| m.to_bytes }.flatten
87
+ received_arr = []
88
+ pointer = 0
89
+ TestOutput.open do |output|
90
+ TestInput.open do |input|
91
+
92
+ messages.each do |msg|
93
+
94
+ $>.puts "sending: " + msg.inspect
95
+
96
+ output.puts(msg)
97
+ sleep(1)
98
+ received = input.gets.map { |m| m[:data] }.flatten
99
+
100
+
101
+ $>.puts "received: " + received.inspect
102
+
103
+ assert_equal(messages_arr.slice(pointer, received.length), received)
104
+
105
+ pointer += received.length
106
+
107
+ received_arr += received
108
+
109
+ end
110
+
111
+ assert_equal(messages_arr.length, received_arr.length)
112
+
113
+ end
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'helper'
4
+
5
+ class PlatformTest < Test::Unit::TestCase
6
+
7
+ include UniMIDI
8
+ include TestHelper
9
+ include TestHelper::Config
10
+
11
+ def test_jruby
12
+ if RUBY_PLATFORM.include?("java")
13
+ platform_test(MIDIJRubyAdapter, MIDIJRuby)
14
+ end
15
+ end
16
+
17
+ def test_linux
18
+ if RUBY_PLATFORM.include?("linux")
19
+ platform_test(AlsaRawMIDIAdapter, AlsaRawMIDI)
20
+ end
21
+ end
22
+
23
+ def test_osx
24
+ if RUBY_PLATFORM.include?("darwin")
25
+ platform_test(CoreMIDIAdapter, CoreMIDI)
26
+ end
27
+ end
28
+
29
+ def test_windows
30
+ if RUBY_PLATFORM.include?("mingw")
31
+ platform_test(MIDIWinMMAdapter, MIDIWinMM)
32
+ end
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,103 +1,115 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: unimidi
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.14
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.2.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ari Russo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-23 00:00:00.000000000 -04:00
12
+
13
+ date: 2011-07-07 00:00:00 -04:00
13
14
  default_executable: unimidi
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
16
17
  name: alsa-rawmidi
17
- requirement: &9446868 !ruby/object:Gem::Requirement
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
18
20
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
23
25
  type: :runtime
24
- prerelease: false
25
- version_requirements: *9446868
26
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
27
28
  name: ffi-coremidi
28
- requirement: &9446532 !ruby/object:Gem::Requirement
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
29
31
  none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
34
36
  type: :runtime
35
- prerelease: false
36
- version_requirements: *9446532
37
- - !ruby/object:Gem::Dependency
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
38
39
  name: midi-jruby
39
- requirement: &9446244 !ruby/object:Gem::Requirement
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
40
42
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
45
47
  type: :runtime
46
- prerelease: false
47
- version_requirements: *9446244
48
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
49
50
  name: midi-winmm
50
- requirement: &9445956 !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
51
53
  none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
56
58
  type: :runtime
57
- prerelease: false
58
- version_requirements: *9445956
59
- description: Platform Independent, realtime MIDI input and output for Ruby.
60
- email:
59
+ version_requirements: *id004
60
+ description: Platform Independent, realtime MIDI input and output for Ruby
61
+ email:
61
62
  - ari.russo@gmail.com
62
- executables:
63
+ executables:
63
64
  - unimidi
64
65
  extensions: []
66
+
65
67
  extra_rdoc_files: []
66
- files:
68
+
69
+ files:
67
70
  - bin/unimidi
68
- - lib/unimidi/adapter/alsa-rawmidi.rb
71
+ - lib/unimidi.rb
69
72
  - lib/unimidi/adapter/ffi-coremidi.rb
70
- - lib/unimidi/adapter/midi-jruby.rb
71
73
  - lib/unimidi/adapter/midi-winmm.rb
74
+ - lib/unimidi/adapter/alsa-rawmidi.rb
75
+ - lib/unimidi/adapter/midi-jruby.rb
72
76
  - lib/unimidi/congruous_api_adapter.rb
73
77
  - lib/unimidi/platform.rb
74
78
  - lib/unimidi/type_conversion.rb
75
- - lib/unimidi.rb
79
+ - test/helper.rb
80
+ - test/config.rb
81
+ - test/test_io.rb
82
+ - test/test_input_buffer.rb
83
+ - test/test_platform.rb
76
84
  - LICENSE
77
85
  - README.rdoc
78
86
  has_rdoc: true
79
87
  homepage: http://github.com/arirusso/unimidi
80
88
  licenses: []
89
+
81
90
  post_install_message:
82
91
  rdoc_options: []
83
- require_paths:
92
+
93
+ require_paths:
84
94
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
95
+ required_ruby_version: !ruby/object:Gem::Requirement
86
96
  none: false
87
- requirements:
88
- - - ! '>='
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
102
  none: false
93
- requirements:
94
- - - ! '>='
95
- - !ruby/object:Gem::Version
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
96
106
  version: 1.3.6
97
107
  requirements: []
108
+
98
109
  rubyforge_project: unimidi
99
- rubygems_version: 1.5.2
110
+ rubygems_version: 1.6.2
100
111
  signing_key:
101
112
  specification_version: 3
102
- summary: Realtime MIDI input and output for Ruby.
113
+ summary: Realtime MIDI input and output for Ruby
103
114
  test_files: []
115
+