Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,60 @@ require 'nibbler'
nibbler = Nibbler.new
```

Enter a MIDI message represented as string bytes
Enter a MIDI message represented as numeric bytes

```ruby
nibbler.parse('904064')
nibbler.parse(0x90, 0x40, 0x64)

=> #<MIDIMessage::NoteOn:0x98c9818
=> [#<MIDIMessage::NoteOn:0x98c9818
@channel=0,
@data=[64, 100],
@name="C3",
@note=64,
@status=[9, 0],
@velocity=100,
@verbose_name="Note On: C3">
@verbose_name="Note On: C3">]
```

Enter a message byte by byte

```ruby
nibbler.parse('90')
=> nil
nibbler.parse(0x90)
=> []

nibbler.parse('40')
=> nil
nibbler.parse(0x40)
=> []

nibbler.parse('64')
=> #<MIDIMessage::NoteOn:0x98c9818
nibbler.parse(0x64)
=> [#<MIDIMessage::NoteOn:0x98c9818
@channel=0,
@data=[64, 100],
@name="C3",
@note=64,
@status=[9, 0],
@velocity=100,
@verbose_name="Note On: C3">
```

Use numeric bytes

```ruby
nibbler.parse(0x90, 0x40, 0x64)
=> #<MIDIMessage::NoteOn:0x98c9818 ...>
@verbose_name="Note On: C3">]
```

You can enter nibbles in string format
There's also a method to parse a string

```ruby
nibbler.parse('9', '0', '4', '0', '6', '4')
=> #<MIDIMessage::NoteOn:0x98c9818 ...>
nibbler.parse_s('904064')
=> [#<MIDIMessage::NoteOn:0x98c9818 ...>]
```

Interchange the different types
Use string bytes

```ruby
nibbler.parse('9', '0', 0x40, 100)
=> #<MIDIMessage::NoteOn:0x98c9818 ...>
nibbler.parse_s('90', '40', '64')
=> [#<MIDIMessage::NoteOn:0x98c9818 ...>]
```

Use running status

```ruby
nibbler.parse(0x40, 100)
=> #<MIDIMessage::NoteOn:0x98c9818 ...>
=> [#<MIDIMessage::NoteOn:0x98c9818 ...>]
```

Look at the messages we've parsed so far
Expand All @@ -94,34 +87,47 @@ nibbler.messages
Add an incomplete message

```ruby
nibbler.parse('9')
nibbler.parse('40')
nibbler.parse_s('90')
nibbler.parse_s('40')
```

See progress

```ruby
nibbler.buffer
=> ["9", "4", "0"]

nibbler.buffer_s
=> "940"
```
=> [0x90, 0x40]

Pass in a timestamp

```ruby
nibbler.parse('904064', timestamp: Time.now.to_i)
=> { :messages=> #<MIDIMessage::NoteOn:0x92f4564 ..>, :timestamp=>1304488440 }
nibbler.parse(0x90, 0x40, 0x40, timestamp: Time.now.to_i)
=> [#<MIDIMessage::NoteOn:0x92f4564 ..>]
nibbler.events
=> #<struct Nibbler::Session::Event
report=
#<struct Nibbler::Parser::Report
messages=
[#<MIDIMessage::NoteOn:0x000000010484b9f8..>],
other=[],
processed=[144, 64, 64]>,
timestamp=1658626536>]
```

Nibbler defaults to generate [midi-message](http://github.com/arirusso/midi-message) objects, but it's also possible to use [midilib](https://github.com/jimm/midilib)

```ruby
Nibbler.new(message_lib: :midilib)

nibbler.parse('9', '0', 0x40, '40')
=> "0: ch 00 on 40 40"
nibbler.parse(0x90, 0x40, 0x40)
=> [
#<MIDI::NoteOn:0x0000000102ed7558
@channel=0,
@delta_time=0,
@note=64,
@status=144,
@time_from_start=0,
@velocity=64>
]
```

## Also see
Expand Down
49 changes: 22 additions & 27 deletions examples/usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,59 @@
#

require 'nibbler'
require 'pp'

nibbler = Nibbler.new

pp 'Enter a message piece by piece'
pp 'Enter a message using numeric bytes'

pp nibbler.parse('90')
pp nibbler.parse(0x90, 0x40, 0x40) # this should return a message

pp nibbler.parse('40')
pp 'Go byte by byte'

pp nibbler.parse('40')
pp nibbler.parse(0x90)

pp 'Enter a message all at once'
pp nibbler.parse(0x40)

pp nibbler.parse('904040')
pp nibbler.parse(0x40) # this should return a message

pp 'Use Bytes'
pp "There's also a method to parse a string"

pp nibbler.parse(0x90, 0x40, 0x40) # this should return a message
pp nibbler.parse_s('904040') # this should return a message

pp 'Use nibbles in string format'
pp 'You can also go byte by byte with strings'

pp nibbler.parse('9', '0', 0x40, 0x40) # this should return a message
pp nibbler.parse_s('90')

pp 'Interchange the different types'
pp nibbler.parse_s('40')

pp nibbler.parse('9', '0', 0x40, 64)
pp nibbler.parse_s('40') # this should return a message

pp 'Use running status'

pp nibbler.parse(0x40, 64)
pp nibbler.parse(0x40, 64) # this should return a message

pp "Look at the messages we've parsed"

pp nibbler.messages # this should return an array of messages
pp nibbler.events

pp 'Add an incomplete message'

pp nibbler.parse('9')
pp nibbler.parse('40')
pp nibbler.parse_s('90')
pp nibbler.parse_s('40')

pp 'See progress'

pp nibbler.buffer # should give you an array of bits

pp nibbler.buffer_s # should give you an array of bytestrs
pp nibbler.buffer # should give you an array of bytes
pp nibbler.clear
pp nibbler.buffer # should be empty array

pp 'Pass in a timestamp'

# NOTE: once you pass in a timestamp for the first time, nibbler.messages will then return
# an array of message/timestamp hashes
# if there was no timestamp for a particular message it will be nil
#

pp nibbler.parse('904040', timestamp: Time.now.to_i)
pp nibbler.parse_s('904040', timestamp: Time.now.to_i)
pp nibbler.events

pp 'Generate midilib messages'

midilib_nibbler = Nibbler.new(message_lib: :midilib)

pp midilib_nibbler.parse('9', '0', 0x40, '40')
pp midilib_nibbler.parse(0x90, 0x40, 0x40)
12 changes: 7 additions & 5 deletions lib/nibbler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
require 'forwardable'

# modules
require 'nibbler/data_processor'
require 'nibbler/type_conversion'
require 'nibbler/message'
require 'nibbler/util'

# classes
require 'nibbler/message_builder'
Expand All @@ -23,10 +23,12 @@
# Parse MIDI Messages
#
module Nibbler
VERSION = '0.2.4'
VERSION = '0.3.0'

# Shortcut to a new session object
def self.new(*args, &block)
Session.new(*args, &block)
# @param [Symbol] message_lib The name of a message library module eg :midilib or :midi_message
# @return [Nibbler::Session]
def self.new(message_lib: nil)
Session.new(message_lib: message_lib)
end
end
51 changes: 0 additions & 51 deletions lib/nibbler/data_processor.rb

This file was deleted.

Loading