15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/coremidi.rb', line 15
def self.parse(data)
spec = {
0x80 => Events::NoteOff,
0x90 => lambda {|data| (data[Events::NoteOn.members.index("velocity")] == 0) ? Events::NoteOff : Events::NoteOn },
0xA0 => Events::KeyPressure,
0xC0 => Events::ProgramChange,
0xD0 => Events::ChannelPressure
}
klass = spec.detect {|code, _|
data[0] & 0xF0 == code }
return Events::Unknown.new(data) if klass.nil?
klass = klass.last
klass = klass.call(data) if klass.respond_to?(:call)
klass.new(
data[0] & 0x0F, *data[1..-1]
)
end
|