Class el.MidiBuffer
A MIDI buffer designed for real time performance.
- **Safety**: For speed, virtually no type checking in method calls. - **Indexing**: Sample positions and channel numbers are 1-indexed.
Constructors
MidiBuffer.new () | Create an empty MIDI Buffer |
MidiBuffer.new (size) | Create a new MIDI Buffer |
Methods
MidiBuffer:clear () | Removes all events from the buffer. |
MidiBuffer:empty () | Returns true if the buffer is empty. |
MidiBuffer:size () | Counts the number of events in the buffer. |
MidiBuffer:reserve (size) | Reserve an amount of space. |
MidiBuffer:swap (other) | Exchanges the contents of this buffer with another one. |
MidiBuffer:insert (data, frame) | Insert MIDI. |
MidiBuffer:insertPacked (data, frame) | Insert packed MIDI in the buffer. |
MidiBuffer:messages () | Iterate over MIDI Messages. |
MidiBuffer:insertMessage (msg, frame) | Add a message to the buffer. |
MidiBuffer:addBuffer (buf) | Add messages from another buffer. |
Constructors
- MidiBuffer.new ()
-
Create an empty MIDI Buffer
Returns:
-
A new midi buffer
- MidiBuffer.new (size)
-
Create a new MIDI Buffer
Parameters:
- size Size in bytes
Returns:
-
A new MIDI Buffer
Methods
- MidiBuffer:clear ()
- Removes all events from the buffer.
- MidiBuffer:empty ()
-
Returns true if the buffer is empty.
Returns:
-
True if no events present
- MidiBuffer:size ()
- Counts the number of events in the buffer. This is actually quite a slow operation, as it has to iterate through all the events, so you might prefer to call MidiBuffer:empty if that's all you need to know.
- MidiBuffer:reserve (size)
-
Reserve an amount of space.
Parameters:
- size int Size in bytes to reserve
Returns:
-
Size reserved in bytes or false
- MidiBuffer:swap (other)
-
Exchanges the contents of this buffer with another one.
This is a quick operation, because no memory allocating or copying is done, it
just swaps the internal state of the two buffers.
Parameters:
- other el.MidiBuffer Buffer to swap with
- MidiBuffer:insert (data, frame)
-
Insert MIDI.
Inserts MIDI from a packed integer or a el.MidiMessage. If performance
seems to be an issue, then use a specialized insert method.
Parameters:
- data an el.MidiMessage or a packed integer.
- frame int Sample position to insert at
See also:
- MidiBuffer:insertPacked (data, frame)
-
Insert packed MIDI in the buffer.
Parameters:
- data int Packed integer data
- frame int Sample position to insert at
- MidiBuffer:messages ()
-
Iterate over MIDI Messages.
Iterate over messages el.MidiMessage in the buffer
Returns:
-
message iterator
Usage:
-- @msg A el.MidiMessage -- @frame Sample position in buffer for msg, frame in buffer:messages() do -- do something with midi data end
- MidiBuffer:insertMessage (msg, frame)
-
Add a message to the buffer.
Parameters:
- msg el.MidiMessage Message to add
- frame int Sample position to insert at
- MidiBuffer:addBuffer (buf)
-
Add messages from another buffer.
Parameters:
- buf el.MidiBuffer Buffer to copy from