bwp_note_track

Pressed note tracker by pitch and time.

API

Module type: Utility

bwp_note_track

typedef struct {
	bwp_list		by_pitch;
	bwp_list		by_time;
	bwp_list_elem		by_pitch_elems[128];
	bwp_list_elem		by_time_elems[128];
	char			pressed[128];
	float			velocities[128];
	uint8_t			n_pressed;
	// here it will take a while before an overflow smashes everything :-)
	uint64_t		time_tokens[128];
	uint64_t		time_token_next;
} bwp_note_track;

Note tracking data:

  • by pitch: list of pressed notes ordered by increasing pitch;
  • by time: list of pressed notes ordered by time (first to last);
  • by pitch_elems: potential elements of by_pitch, where the array index corresponds to the note number;
  • by time_elems: potential elements of by_time, where the array index corresponds to the note number;
  • pressed: whether each note is pressed, where the array index corresponds to the note number;
  • velocities: last note on/off velocities in [0.f, 1.f] or otherwise negative to indicate unknown / not available, where the array index corresponds to the note number;
  • n_pressed: number of currently pressed notes;
  • time_tokens: numbers representing the time order in which notes are pressed, where the array index corresponds to the note number (only valid for notes that are currently pressed);
  • time_token_next: next time token (sequential, increasing take-a-number system).

bwp_note_track_reset()

static inline void bwp_note_track_reset(
	bwp_note_track * BW_RESTRICT track);

Resets the note tracker to its initial state (all notes off, next time token is 1).

bwp_note_track_process_on()

static inline void bwp_note_track_process_on(
	bwp_note_track * BW_RESTRICT track,
	unsigned char                note,
	float                        velocity);

Feeds track with a note on event with the given note number and velocity.

bwp_note_track_process_off()

static inline void bwp_note_track_process_off(
	bwp_note_track * BW_RESTRICT track,
	unsigned char                note,
	float                        velocity);

Feeds track with a note on event with the given note number and velocity.

bwp_note_track_is_valid()

static inline char bwp_note_track_is_valid(
	const bwp_note_track * BW_RESTRICT track);

Tries to determine whether track 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.

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

C++ wrapper

BrickworksPro::NoteTrack
class NoteTrack {
public:
	NoteTrack();

	void processOn(
		unsigned char note,
		float         velocity);

	void processOff(
		unsigned char note,
		float         velocity);

	bwp_note_track track;
};

Changelog

  • Version 1.0.0:
    • First release.