Further midi file support.
This commit is contained in:
parent
36826fa1d4
commit
4d5ca4d654
12 changed files with 739 additions and 200 deletions
88
src/core/file_utilities/BinaryFile.cpp
Normal file
88
src/core/file_utilities/BinaryFile.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#include "BinaryFile.h"
|
||||
#include "ByteUtils.h"
|
||||
|
||||
bool BinaryFile::GetNextByteAsInt(std::ifstream& file, int& target)
|
||||
{
|
||||
char c;
|
||||
file.get(c);
|
||||
target = int(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextNBytes(std::ifstream& file, char* buffer, unsigned number)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<number; idx++)
|
||||
{
|
||||
if(file.get(c))
|
||||
{
|
||||
buffer[idx] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextWord(std::ifstream& file, char* buffer)
|
||||
{
|
||||
return GetNextNBytes(file, buffer, ByteUtils::BYTES_PER_WORD);
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextDWord(std::ifstream& file, char* buffer)
|
||||
{
|
||||
return GetNextNBytes(file, buffer, ByteUtils::BYTES_PER_DWORD);
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextWord(std::ifstream& file, int& target, bool reverse)
|
||||
{
|
||||
char buffer[ByteUtils::BYTES_PER_WORD];
|
||||
if(!BinaryFile::GetNextWord(file, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target = ByteUtils::ToWord(buffer, reverse);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextDWord(std::ifstream& file, int& target)
|
||||
{
|
||||
char buffer[ByteUtils::BYTES_PER_DWORD];
|
||||
if(!BinaryFile::GetNextDWord(file, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target = ByteUtils::ToDWord(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::CheckNextDWord(std::ifstream& file, const char* target)
|
||||
{
|
||||
char buffer[ByteUtils::BYTES_PER_DWORD];
|
||||
if(!BinaryFile::GetNextDWord(file, buffer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ByteUtils::CompareDWords(buffer, target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFile::GetNextString(std::ifstream& file, std::string& target, unsigned numBytes)
|
||||
{
|
||||
char c;
|
||||
for(unsigned idx=0; idx<numBytes; idx++)
|
||||
{
|
||||
if(!file.get(c))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
target += c;
|
||||
}
|
||||
return true;
|
||||
}
|
25
src/core/file_utilities/BinaryFile.h
Normal file
25
src/core/file_utilities/BinaryFile.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
class BinaryFile
|
||||
{
|
||||
public:
|
||||
|
||||
static bool GetNextByteAsInt(std::ifstream& file, int& target);
|
||||
|
||||
static bool GetNextNBytes(std::ifstream& file, char* buffer, unsigned numBytes);
|
||||
|
||||
static bool GetNextWord(std::ifstream& file, char* buffer);
|
||||
|
||||
static bool GetNextDWord(std::ifstream& file, char* buffer);
|
||||
|
||||
static bool GetNextWord(std::ifstream& file, int& target, bool reverse = true);
|
||||
|
||||
static bool GetNextDWord(std::ifstream& file, int& target);
|
||||
|
||||
static bool CheckNextDWord(std::ifstream& file, const char* target);
|
||||
|
||||
static bool GetNextString(std::ifstream& file, std::string& target, unsigned numBytes);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue