ffi-coremidi 0.3.8 → 0.5.0

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/test/helper.rb DELETED
@@ -1,66 +0,0 @@
1
- dir = File.dirname(File.expand_path(__FILE__))
2
- $LOAD_PATH.unshift dir + "/../lib"
3
-
4
- require "minitest/autorun"
5
- require "mocha/test_unit"
6
- require "shoulda-context"
7
-
8
- require "coremidi"
9
-
10
- module TestHelper
11
-
12
- extend self
13
-
14
- def device
15
- @device ||= select_devices
16
- end
17
-
18
- def select_devices
19
- @device ||= {}
20
- { :input => CoreMIDI::Source.all, :output => CoreMIDI::Destination.all }.each do |type, devs|
21
- puts ""
22
- puts "select an #{type.to_s}..."
23
- while @device[type].nil?
24
- devs.each do |device|
25
- puts "#{device.id}: #{device.name}"
26
- end
27
- selection = $stdin.gets.chomp
28
- if selection != ""
29
- selection = selection.to_i
30
- @device[type] = devs.find { |d| d.id == selection }
31
- puts "selected #{selection} for #{type.to_s}" unless @device[type]
32
- end
33
- end
34
- end
35
- @device
36
- end
37
-
38
- def bytestrs_to_ints(arr)
39
- data = arr.map { |m| m[:data] }.join
40
- output = []
41
- until (bytestr = data.slice!(0,2)).eql?("")
42
- output << bytestr.hex
43
- end
44
- output
45
- end
46
-
47
- # some MIDI messages
48
- VariousMIDIMessages = [
49
- [0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7], # SysEx
50
- [0x90, 100, 100], # note on
51
- [0x90, 43, 100], # note on
52
- [0x90, 76, 100], # note on
53
- [0x90, 60, 100], # note on
54
- [0x80, 100, 100] # note off
55
- ]
56
-
57
- # some MIDI messages
58
- VariousMIDIByteStrMessages = [
59
- "F04110421240007F0041F7", # SysEx
60
- "906440", # note on
61
- "804340" # note off
62
- ]
63
-
64
- end
65
-
66
- TestHelper.select_devices
@@ -1,42 +0,0 @@
1
- require "helper"
2
-
3
- class InputBufferTest < Minitest::Test
4
-
5
- context "CoreMIDI" do
6
-
7
- setup do
8
- sleep(1)
9
- end
10
-
11
- context "Source#buffer" do
12
-
13
- setup do
14
- @messages = TestHelper::VariousMIDIMessages
15
- @messages_arr = @messages.inject { |a,b| a+b }.flatten
16
- @received_arr = []
17
- @pointer = 0
18
-
19
- @output = TestHelper.device[:output].open
20
- @input = TestHelper.device[:input].open
21
- @input.buffer.clear
22
- end
23
-
24
- should "have the correct messages in the buffer" do
25
- bytes = []
26
- @messages.each do |message|
27
- puts "sending: #{message.inspect}"
28
- @output.puts(message)
29
- bytes += message
30
-
31
- sleep(0.5)
32
-
33
- buffer = @input.buffer.map { |m| m[:data] }.flatten
34
- puts "received: #{buffer.to_s}"
35
- assert_equal(bytes, buffer)
36
- end
37
- assert_equal(bytes.length, @input.buffer.map { |m| m[:data] }.flatten.length)
38
- end
39
- end
40
-
41
- end
42
- end
data/test/io_test.rb DELETED
@@ -1,90 +0,0 @@
1
- require "helper"
2
-
3
- class CoreMIDI::IOTest < Minitest::Test
4
-
5
- # ** these tests assume that TestOutput is connected to TestInput
6
- context "CoreMIDI" do
7
-
8
- setup do
9
- sleep(1)
10
- end
11
-
12
- context "full IO" do
13
-
14
- context "using Arrays" do
15
-
16
- setup do
17
- @messages = TestHelper::VariousMIDIMessages
18
- @messages_arr = @messages.inject { |a,b| a+b }.flatten
19
- @received_arr = []
20
- @pointer = 0
21
- end
22
-
23
- should "do IO" do
24
- TestHelper.device[:output].open do |output|
25
- TestHelper.device[:input].open do |input|
26
-
27
- input.buffer.clear
28
-
29
- @messages.each do |msg|
30
-
31
- $>.puts "sending: " + msg.inspect
32
-
33
- output.puts(msg)
34
- sleep(1)
35
- received = input.gets.map { |m| m[:data] }.flatten
36
-
37
- $>.puts "received: " + received.inspect
38
-
39
- assert_equal(@messages_arr.slice(@pointer, received.length), received)
40
- @pointer += received.length
41
- @received_arr += received
42
- end
43
- assert_equal(@messages_arr.length, @received_arr.length)
44
- end
45
- end
46
-
47
- end
48
- end
49
-
50
- context "using byte Strings" do
51
-
52
- setup do
53
- @messages = TestHelper::VariousMIDIByteStrMessages
54
- @messages_str = @messages.join
55
- @received_str = ""
56
- @pointer = 0
57
- end
58
-
59
- should "do IO" do
60
- TestHelper.device[:output].open do |output|
61
- TestHelper.device[:input].open do |input|
62
-
63
- @messages.each do |msg|
64
-
65
- $>.puts "sending: " + msg.inspect
66
-
67
- output.puts(msg)
68
- sleep(1)
69
- received = input.gets_bytestr.map { |m| m[:data] }.flatten.join
70
- $>.puts "received: " + received.inspect
71
-
72
- assert_equal(@messages_str.slice(@pointer, received.length), received)
73
- @pointer += received.length
74
- @received_str += received
75
- end
76
- assert_equal(@messages_str, @received_str)
77
-
78
- end
79
- end
80
-
81
-
82
- end
83
-
84
- end
85
-
86
- end
87
-
88
- end
89
-
90
- end