Start midi file processing.
This commit is contained in:
parent
59c6161fdb
commit
36826fa1d4
22 changed files with 528 additions and 44 deletions
81
src/core/ByteUtils.h
Normal file
81
src/core/ByteUtils.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
#pragma once
|
||||
#include <cstring>
|
||||
|
||||
class ByteUtils
|
||||
{
|
||||
public:
|
||||
using Word = int;
|
||||
using DWord = int;
|
||||
|
||||
static int GetWordFirstBit(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_FIRST_BIT;
|
||||
};
|
||||
|
||||
static int GetWordLastByte(const Word word)
|
||||
{
|
||||
return word & ByteUtils::WORD_LAST_BYTE;
|
||||
}
|
||||
|
||||
static void ReverseBuffer(char* buffer, char* reverse, unsigned size)
|
||||
{
|
||||
for(unsigned idx=0; idx<size; idx++)
|
||||
{
|
||||
reverse[idx] = buffer[size - 1 -idx];
|
||||
}
|
||||
}
|
||||
|
||||
static int ToInt(char* buffer, unsigned size, bool reverse = true)
|
||||
{
|
||||
int result;
|
||||
if(reverse)
|
||||
{
|
||||
char reversed[size];
|
||||
ReverseBuffer(buffer, reversed, size);
|
||||
std::memcpy(&result, reversed, sizeof(int));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(&result, buffer, sizeof(int));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Word ToWord(char* buffer, bool reverse = true)
|
||||
{
|
||||
return ToInt(buffer, BYTES_PER_WORD, reverse);
|
||||
}
|
||||
|
||||
static DWord ToDWord(char* buffer, bool reverse = true)
|
||||
{
|
||||
return ToInt(buffer, BYTES_PER_DWORD, reverse);
|
||||
}
|
||||
|
||||
static bool Compare(char* buffer, const char* tag, unsigned size)
|
||||
{
|
||||
for(unsigned idx=0; idx<size; idx++)
|
||||
{
|
||||
if(tag[idx] != buffer[idx])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool CompareDWords(char* buffer, const char* tag)
|
||||
{
|
||||
return Compare(buffer, tag, BYTES_PER_DWORD);
|
||||
}
|
||||
|
||||
static bool CompareWords(char* buffer, const char* tag)
|
||||
{
|
||||
return Compare(buffer, tag, BYTES_PER_WORD);
|
||||
}
|
||||
|
||||
static const int BYTES_PER_WORD = 2;
|
||||
static const int BYTES_PER_DWORD = 4;
|
||||
static const int BYTE_FIRST_BIT = 0x40; // 1000 0000
|
||||
static const int WORD_FIRST_BIT = 0x8000; // 1000 0000 - 0000 0000
|
||||
static const int WORD_LAST_BYTE = 0x00FF; // 0000 0000 - 1111 1111
|
||||
};
|
|
@ -3,7 +3,8 @@ list(APPEND core_LIB_INCLUDES
|
|||
Color.cpp
|
||||
CommandLineArgs.cpp
|
||||
loggers/FileLogger.cpp
|
||||
StringUtils.cpp)
|
||||
StringUtils.cpp
|
||||
http/HttpResponse.cpp)
|
||||
|
||||
# add the executable
|
||||
add_library(core SHARED ${core_LIB_INCLUDES})
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
#include "FileLogger.h"
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
|
||||
FileLogger::FileLogger()
|
||||
:mWorkDirectory(),
|
||||
mFileName("MT_Log.txt"),
|
||||
mFileStream()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FileLogger::~FileLogger()
|
||||
{
|
||||
|
@ -38,7 +33,9 @@ void FileLogger::LogLine(const std::string& line)
|
|||
mFileStream << line << std::endl;
|
||||
}
|
||||
|
||||
std::shared_ptr<FileLogger> FileLogger::Create()
|
||||
void FileLogger::LogLine(const std::string& logType, const std::string& line, const std::string& fileName, const std::string& functionName, int lineNumber)
|
||||
{
|
||||
return std::make_shared<FileLogger>();
|
||||
std::time_t t = std::time(nullptr);
|
||||
const std::string cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1);
|
||||
mFileStream << logType << "|" << std::put_time(std::gmtime(&t), "%T") << "|" << cleanedFileName << "::" << functionName << "::" << lineNumber << "|" << line << std::endl;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#pragma once
|
||||
#define MLOG_INFO(msg) FileLogger::GetInstance().LogLine("Info", msg, __FILE__, __FUNCTION__, __LINE__);
|
||||
#define MLOG_ERROR(msg) FileLogger::GetInstance().LogLine("Error", msg, __FILE__, __FUNCTION__, __LINE__);
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -12,9 +14,24 @@ class FileLogger
|
|||
|
||||
std::ofstream mFileStream;
|
||||
|
||||
FileLogger()
|
||||
:mWorkDirectory(),
|
||||
mFileName("MT_Log.txt"),
|
||||
mFileStream()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
FileLogger();
|
||||
static FileLogger& GetInstance()
|
||||
{
|
||||
static FileLogger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
FileLogger(FileLogger const&) = delete;
|
||||
void operator=(FileLogger const&) = delete;
|
||||
|
||||
~FileLogger();
|
||||
|
||||
|
@ -28,7 +45,7 @@ public:
|
|||
|
||||
void LogLine(const std::string& line);
|
||||
|
||||
static std::shared_ptr<FileLogger> Create();
|
||||
void LogLine(const std::string& logType, const std::string& line, const std::string& fileName = "", const std::string& functionName = "", int lineNumber=-1);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue