<commit_before>/*
 * NoteEvaluator.cpp
 *
 *  Created on: Dec 2, 2012
 *      Author: xo
 */

#include "NoteEvaluator.h"

namespace MidiEngine {

NoteEvaluator::NoteEvaluator() {
}

NoteEvaluator::~NoteEvaluator() {
}

int NoteEvaluator::set_fd(int fd) {
	if (fd > -1) {
		this->fd = fd;
		return 1;
	}
	//Invalid fd, return it
	return fd;
}

int NoteEvaluator::set_verbose(char verbose){
	this->verbose = verbose;
	return 1;
}

int NoteEvaluator::process_input_as_loop(char* message) {

	unsigned char ch;
	unsigned char iBitCount = 0;
	unsigned char iColumnWidth;
	unsigned long long iLastNoteTime = 0;
	unsigned long long iCurrentNoteTime;
	struct timespec time;

	while (1) {
		if (read(this->fd, &ch, 1) > 0) {
			if (ch != 0xf8 && ch != 0xfe) {
				if(iBitCount == 0){
					//iCurrentNoteTime
					clock_gettime(CLOCK_REALTIME,&time);
					iLastNoteTime = iCurrentNoteTime;
					iCurrentNoteTime = time.tv_sec * 1000000000+ time.tv_nsec;
				}
				if (verbose) {
					if(iBitCount == 0){
						iColumnWidth = 6;
						fprintf(stderr, "%lu %09lu - ",time.tv_sec,time.tv_nsec);
					}
					if(iBitCount == 1){
						if(ch == 0x04){
							iColumnWidth = 3;
						}
					}
					fprintf(stderr, "%02x ", ch);
					iBitCount = (iBitCount+1) % iColumnWidth;
					if(iBitCount == 0){
						fprintf(stderr, "\n");
					}
				}
				if (write(fd, &ch, 1) == -1) {
					sprintf(message, "Error writing to device\n");<commit_msg>Swapping out for buffer, will migrate to an object soon<commit_after>/*
 * NoteEvaluator.cpp
 *
 *  Created on: Dec 2, 2012
 *      Author: xo
 */

#include "NoteEvaluator.h"

namespace MidiEngine {

NoteEvaluator::NoteEvaluator() {
}

NoteEvaluator::~NoteEvaluator() {
}

int NoteEvaluator::set_fd(int fd) {
	if (fd > -1) {
		this->fd = fd;
		return 1;
	}
	//Invalid fd, return it
	return fd;
}

int NoteEvaluator::set_verbose(char verbose){
	this->verbose = verbose;
	return 1;
}

int NoteEvaluator::process_input_as_loop(char* message) {

	unsigned char ch;
	unsigned char iBitCount = 0;
	unsigned char iColumnWidth;
	unsigned long long iLastNoteTime = 0;
	unsigned long long iCurrentNoteTime = 0;
	char verb_buffer[60];
	char msg_buffer[60];
	struct timespec time;

	while (1) {
		if (read(this->fd, &ch, 1) > 0) {
			if (ch != 0xf8 && ch != 0xfe) {
				if(iBitCount == 0){
					//iCurrentNoteTime
					if(clock_gettime(CLOCK_MONOTONIC,&time) == -1){
						sprintf(message, "Error getting time\n");
						return -1;
					}
					iLastNoteTime = iCurrentNoteTime;
					iCurrentNoteTime = time.tv_sec * 1000000000+ time.tv_nsec;
				}
				if (this->verbose) {
					if(iBitCount == 0){
						iColumnWidth = 6;
						sprintf(msg_buffer, "%lu %09lu - ",time.tv_sec,time.tv_nsec);
						strcpy(verb_buffer,msg_buffer);
					}
					if(iBitCount == 1){
						if(ch == 0x04){
							iColumnWidth = 3;
						}
					}
					sprintf(msg_buffer, "%02x ", ch);
					strcat(verb_buffer,msg_buffer);
					iBitCount = (iBitCount+1) % iColumnWidth;
					if(iBitCount == 0){
						if(iCurrentNoteTime - iLastNoteTime < 5000000000){
							sprintf(msg_buffer, "  - % 9lu µs",(iCurrentNoteTime-iLastNoteTime)/1000);
							strcat(verb_buffer,msg_buffer);
						}
						fprintf(stderr, "%s\n",verb_buffer);
					}
				}
				if (write(fd, &ch, 1) == -1) {
					sprintf(message, "Error writing to device\n");
{'fraction_non_alphanumeric': 0.14264128135388335, 'fraction_numerical': 0.03203384708371109, 'mean_word_length': 3.061349693251534, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '2309180', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1246, 'n_words': 271}