-
Notifications
You must be signed in to change notification settings - Fork 28
/
helper.rb
82 lines (69 loc) · 2.33 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby
dir = File.dirname(File.expand_path(__FILE__))
$LOAD_PATH.unshift dir + '/../lib'
require 'test/unit'
require 'unimidi'
module TestHelper
TestSysex = !RUBY_PLATFORM.include?("java")
def self.select_devices
$test_device ||= {}
{ :input => UniMIDI::Input, :output => UniMIDI::Output }.each do |type, klass|
$test_device[type] = klass.gets
end
end
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(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)
data = arr.map { |m| m[:data] }.join
output = []
until (bytestr = data.slice!(0,2)).eql?("")
output << bytestr.hex
end
output
end
class MIDIObj
def initialize(*bytes)
@bytes = bytes
end
def to_bytes
@bytes
end
end
# some MIDI messages
VariousMIDIObjects = [
TestSysex ? MIDIObj.new(0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7) : nil, # SysEx
MIDIObj.new(0x90, 100, 100), # note on
MIDIObj.new(0x90, 43, 100), # note on
MIDIObj.new(0x90, 76, 100), # note on
MIDIObj.new(0x90, 60, 100), # note on
MIDIObj.new(0x80, 100, 100) # note off
].compact
# some MIDI messages
VariousMIDIMessages = [
TestSysex ? [0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7] : nil, # SysEx
[0x90, 100, 100], # note on
[0x90, 43, 100], # note on
[0x90, 76, 100], # note on
[0x90, 60, 100], # note on
[0x80, 100, 100] # note off
].compact
# some MIDI messages
VariousMIDIByteStrMessages = [
TestSysex ? "F04110421240007F0041F7" : nil, # SysEx
"906440", # note on
"804340" # note off
].compact
end
TestHelper.select_devices