Brickworks > API documentation > bw_note_queue

bw_note_queue

Description

Simple data structure that helps keeping track of note on/off events and pressed key status.

It is not concerned with timing.

Info

Module type: utility

Version: 1.0.1

Requires:

API

bw_note_queue_status

typedef struct {
	char  pressed;
	float velocity;
} bw_note_queue_status;

Note status:

bw_note_queue_event

typedef struct {
	unsigned char note;
	char          went_off;
} bw_note_queue_event;

Note on/off event:

bw_note_queue

typedef struct {
	bw_note_queue_event  events[128];
	bw_note_queue_status status[128];
	unsigned char        n_events;
	unsigned char        n_pressed;
} bw_note_queue;

Note on/off event queue and pressed key status:

bw_note_queue_reset()

static inline void bw_note_queue_reset(
	bw_note_queue * BW_RESTRICT queue);

Clear both the event queue (no events) and the note statuses (all notes off, all velocities 0.f) in queue.

bw_note_queue_clear()

static inline void bw_note_queue_clear(
	bw_note_queue * BW_RESTRICT queue);

Clears the event queue (no events) in queue without affecting the note statuses.

bw_note_queue_add()

static inline void bw_note_queue_add(
	bw_note_queue * BW_RESTRICT queue,
	unsigned char               note,
	char                        pressed,
	float                       velocity,
	char                        force_went_off);

Adds a new event to queue with the specified note number, pressed value, and velocity.

If force_went_off is set to non-0, went_off is always set to non-0.

bw_note_queue_is_valid()

static inline char bw_note_queue_is_valid(
	const bw_note_queue * BW_RESTRICT queue);

Tries to determine whether queue is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.

queue must at least point to a readable memory block of size greater than or equal to that of bw_note_queue.

C++ wrapper

Brickworks::NoteQueue
class NoteQueue {
public:
	NoteQueue();
	
	void clear();

	void add(
		unsigned char note,
		bool          pressed,
		float         velocity,
		bool          forceWentOff);
	
	bw_note_queue queue;
};

ChangeLog