midi-nibbler 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +32 -36
  2. data/lib/nibbler.rb +1 -1
  3. data/lib/nibbler/nibbler.rb +3 -28
  4. metadata +2 -2
data/README.rdoc CHANGED
@@ -21,59 +21,59 @@ Parse MIDI Messages
21
21
  Enter a message piece by piece
22
22
 
23
23
  nibbler.parse("90")
24
- nil
24
+ => nil
25
25
 
26
26
  nibbler.parse("40")
27
- nil
27
+ => nil
28
28
 
29
29
  nibbler.parse("40")
30
- # #<MIDIMessage::NoteOn:0x98c9818
31
- # @channel=0,
32
- # @data=[64, 100],
33
- # @name="C3",
34
- # @note=64,
35
- # @status=[9, 0],
36
- # @velocity=100,
37
- # @verbose_name="Note On: C3">
30
+ => #<MIDIMessage::NoteOn:0x98c9818
31
+ @channel=0,
32
+ @data=[64, 100],
33
+ @name="C3",
34
+ @note=64,
35
+ @status=[9, 0],
36
+ @velocity=100,
37
+ @verbose_name="Note On: C3">
38
38
 
39
39
  Enter a message all at once
40
40
 
41
41
  nibbler.parse("904040")
42
42
 
43
- # #<MIDIMessage::NoteOn:0x98c9818
44
- # @channel=0,
45
- # @data=[64, 100],
46
- # @name="C3",
47
- # @note=64,
48
- # @status=[9, 0],
49
- # @velocity=100,
50
- # @verbose_name="Note On: C3">
43
+ => #<MIDIMessage::NoteOn:0x98c9818
44
+ @channel=0,
45
+ @data=[64, 100],
46
+ @name="C3",
47
+ @note=64,
48
+ @status=[9, 0],
49
+ @velocity=100,
50
+ @verbose_name="Note On: C3">
51
51
 
52
52
  Use bytes
53
53
 
54
54
  nibbler.parse(0x90, 0x40, 0x40)
55
- #<MIDIMessage::NoteOn:0x98c9818 ...>
55
+ => #<MIDIMessage::NoteOn:0x98c9818 ...>
56
56
 
57
57
  You can use nibbles in string format
58
58
 
59
59
  nibbler.parse("9", "0", "4", "0", "4", "0")
60
- #<MIDIMessage::NoteOn:0x98c9818 ...>
60
+ => #<MIDIMessage::NoteOn:0x98c9818 ...>
61
61
 
62
62
  Interchange the different types
63
63
 
64
64
  nibbler.parse("9", "0", 0x40, 64)
65
- #<MIDIMessage::NoteOn:0x98c9818 ...>
65
+ => #<MIDIMessage::NoteOn:0x98c9818 ...>
66
66
 
67
67
  Use running status
68
68
 
69
69
  nibbler.parse(0x40, 64)
70
- #<MIDIMessage::NoteOn:0x98c9818 ...>
70
+ => #<MIDIMessage::NoteOn:0x98c9818 ...>
71
71
 
72
72
  Look at the messages we've parsed
73
73
 
74
74
  nibbler.messages
75
- [#<MIDIMessage::NoteOn:0x98c9804 ...>
76
- #<MIDIMessage::NoteOn:0x98c9811 ...>]
75
+ => [#<MIDIMessage::NoteOn:0x98c9804 ...>
76
+ #<MIDIMessage::NoteOn:0x98c9811 ...>]
77
77
 
78
78
  Add an incomplete message
79
79
 
@@ -83,30 +83,26 @@ Add an incomplete message
83
83
  See progress
84
84
 
85
85
  nibbler.buffer
86
- ["9", "4", "0"]
86
+ => ["9", "4", "0"]
87
87
 
88
88
  nibbler.buffer_s
89
- "940"
89
+ => "940"
90
90
 
91
91
  Pass in a timestamp
92
92
 
93
93
  nibbler.parse("904040", :timestamp => Time.now.to_i)
94
- # { :messages=> #<MIDIMessage::NoteOn:0x92f4564 ..>, :timestamp=>1304488440 }
95
-
96
- Bind events
97
-
98
- nibbler.when({ :class => MIDIMessage::NoteOn }) { puts "bark" }
99
- nibbler.parse("904040")
100
-
101
- "bark"
102
- #<MIDIMessage::NoteOn:0x98c9818 ...>
94
+ => { :messages=> #<MIDIMessage::NoteOn:0x92f4564 ..>, :timestamp=>1304488440 }
103
95
 
104
96
  Nibbler defaults to generate {midi-message}[http://github.com/arirusso/midi-message] objects, but it is also possible to use {midilib}[https://github.com/jimm/midilib]
105
97
 
106
98
  Nibbler.new(:message_lib => :midilib)
107
99
 
108
100
  nibbler.parse("9", "0", 0x40, "40")
109
- "0: ch 00 on 40 40"
101
+ => "0: ch 00 on 40 40"
102
+
103
+ == Also see
104
+
105
+ * {midi-eye}[http://github.com/arirusso/midi-eye], a MIDI event listener based on nibbler
110
106
 
111
107
  == Author
112
108
 
data/lib/nibbler.rb CHANGED
@@ -16,7 +16,7 @@ require 'nibbler/hex_char_array_filter'
16
16
  #
17
17
  module Nibbler
18
18
 
19
- VERSION = "0.0.5"
19
+ VERSION = "0.1.0"
20
20
 
21
21
  # shortcut to Parser.new
22
22
  def self.new(*a, &block)
@@ -7,8 +7,7 @@ module Nibbler
7
7
 
8
8
  extend Forwardable
9
9
 
10
- attr_reader :callbacks,
11
- :messages,
10
+ attr_reader :messages,
12
11
  :processed,
13
12
  :rejected
14
13
 
@@ -60,37 +59,13 @@ module Nibbler
60
59
  queue = @typefilter.process(a)
61
60
  result = @parser.process(queue)
62
61
  record_message(result[:messages], timestamp)
63
- handle_events(result[:messages]) unless @callbacks.empty?
64
62
  @processed += result[:processed]
65
63
  @rejected += result[:rejected]
66
64
  get_parse_output(result[:messages], options)
67
- end
68
-
69
- def when(hash, &proc)
70
- if proc.nil?
71
- warn "callback must have proc"
72
- return false
73
- end
74
- hash[:proc] = proc
75
- @callbacks << hash
76
- true
77
- end
78
- alias_method :sees, :when
65
+ end
79
66
 
80
67
  private
81
-
82
- def handle_events(messages)
83
- @callbacks.each do |cb|
84
- messages.each do |msg|
85
- match = true
86
- cb.each do |key, val|
87
- match = false if !key.eql?(:proc) && !msg.send(key).eql?(val)
88
- end
89
- cb[:proc].call(msg) if match
90
- end
91
- end
92
- end
93
-
68
+
94
69
  def record_message(msg, timestamp = nil)
95
70
  !@timestamps ? @messages += msg : @messages << {
96
71
  :messages => msg,
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: midi-nibbler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ari Russo
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-16 00:00:00 -04:00
13
+ date: 2011-05-26 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency