<commit_before>#include "midi.h"

void USBMIDI_Send(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* midi);

bool USBMIDI_EnqueueBlock(const USBMIDI_Behaviour_Struct* behaviour, uint8_t* block) {
	uint16_t wrIdx = *(behaviour->cmdFifoWrIdx);
	uint16_t nextWrIdx = (wrIdx + 4) % (behaviour->cmdFifoSize);
	if (nextWrIdx == *(behaviour->cmdFifoRdIdx)) return false;	//Would be full
	behaviour->cmdFifo[wrIdx  ] = block[0];
	behaviour->cmdFifo[wrIdx+1] = block[1];
	behaviour->cmdFifo[wrIdx+2] = block[2];
	behaviour->cmdFifo[wrIdx+3] = block[3];
	*(behaviour->cmdFifoWrIdx) = nextWrIdx;
	return true;
}

bool USBMIDI_SendNoteOn(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* behaviour, uint8_t cableNumber, uint8_t channel, uint8_t note, uint8_t velocity) {
	uint8_t block[4];
	block[0] = ((cableNumber & 0x0f) << 4) | 0x09;
	block[1] = 0x90 | (channel & 0x0f);
	block[2] = note & 0x7f;
	block[3] = velocity & 0x7f;
	return USBMIDI_EnqueueBlock(behaviour, block);
}

bool USBMIDI_SendNoteOff(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* behaviour, uint8_t cableNumber, uint8_t channel, uint8_t note) {
	uint8_t block[4];
	block[0] = ((cableNumber & 0x0f) << 4) | 0x09;
	block[1] = 0x90 | (channel & 0x0f);
	block[2] = note & 0x7f;
	return USBMIDI_EnqueueBlock(behaviour, block);
}

bool USBMIDI_SendControlChange(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* behaviour, uint8_t cableNumber, uint8_t channel, uint8_t control, uint8_t value) {
	uint8_t block[4];
	block[0] = ((cableNumber & 0x0f) << 4) | 0x0B;
	block[1] = 0xB0 | (channel & 0x0f);
	block[2] = control & 0x7f;
	block[3] = value & 0x7f;
	return USBMIDI_EnqueueBlock(behaviour, block);<commit_msg>Fixed note off bug<commit_after>#include "midi.h"

void USBMIDI_Send(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* midi);

bool USBMIDI_EnqueueBlock(const USBMIDI_Behaviour_Struct* behaviour, uint8_t* block) {
	uint16_t wrIdx = *(behaviour->cmdFifoWrIdx);
	uint16_t nextWrIdx = (wrIdx + 4) % (behaviour->cmdFifoSize);
	if (nextWrIdx == *(behaviour->cmdFifoRdIdx)) return false;	//Would be full
	behaviour->cmdFifo[wrIdx  ] = block[0];
	behaviour->cmdFifo[wrIdx+1] = block[1];
	behaviour->cmdFifo[wrIdx+2] = block[2];
	behaviour->cmdFifo[wrIdx+3] = block[3];
	*(behaviour->cmdFifoWrIdx) = nextWrIdx;
	return true;
}

bool USBMIDI_SendNoteOn(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* behaviour, uint8_t cableNumber, uint8_t channel, uint8_t note, uint8_t velocity) {
	uint8_t block[4];
	block[0] = ((cableNumber & 0x0f) << 4) | 0x09;
	block[1] = 0x90 | (channel & 0x0f);
	block[2] = note & 0x7f;
	block[3] = velocity & 0x7f;
	return USBMIDI_EnqueueBlock(behaviour, block);
}

bool USBMIDI_SendNoteOff(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* behaviour, uint8_t cableNumber, uint8_t channel, uint8_t note) {
	uint8_t block[4];
	block[0] = ((cableNumber & 0x0f) << 4) | 0x08;
	block[1] = 0x80 | (channel & 0x0f);
	block[2] = note & 0x7f;
	block[3] = 0;
	return USBMIDI_EnqueueBlock(behaviour, block);
}

bool USBMIDI_SendControlChange(USB_Device_Struct* device, const USBMIDI_Behaviour_Struct* behaviour, uint8_t cableNumber, uint8_t channel, uint8_t control, uint8_t value) {
	uint8_t block[4];
	block[0] = ((cableNumber & 0x0f) << 4) | 0x0B;
	block[1] = 0xB0 | (channel & 0x0f);
	block[2] = control & 0x7f;
	block[3] = value & 0x7f;
	return USBMIDI_EnqueueBlock(behaviour, block);
{'fraction_non_alphanumeric': 0.1346153846153846, 'fraction_numerical': 0.04836829836829837, 'mean_word_length': 6.335470085470085, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1629623', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1444, 'n_words': 282}