Start font reading support.
This commit is contained in:
parent
92e7a78710
commit
ed925afabf
22 changed files with 599 additions and 220 deletions
|
@ -1,6 +1,6 @@
|
|||
#include "MidiChannelEventAdapter.h"
|
||||
|
||||
#include "BinaryFile.h"
|
||||
#include "BinaryStream.h"
|
||||
#include "ByteUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -15,7 +15,7 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
|
|||
unsigned byteCount = 0;
|
||||
std::cout << "Channel: " << midi_channel << std::endl;
|
||||
|
||||
const bool isStatusByte = ByteUtils::MSBIsOne(firstByte);
|
||||
const bool isStatusByte = ByteUtils::MostSignificantBitIsOne(firstByte);
|
||||
if(isStatusByte)
|
||||
{
|
||||
event->SetTypeAndChannel(firstByte);
|
||||
|
@ -44,8 +44,7 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
|
|||
}
|
||||
case MidiChannelEvent::Type::PROGRAM:
|
||||
{
|
||||
int value0 = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, value0);
|
||||
int value0 = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount ++;
|
||||
break;
|
||||
}
|
||||
|
@ -59,19 +58,15 @@ int MidiChannelEventAdapter::ReadEvent(std::ifstream* file, char firstByte, Midi
|
|||
int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent* event, char c)
|
||||
{
|
||||
int value0 = int(c);
|
||||
int value1 = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, value1);
|
||||
int value1 = *BinaryStream::getNextByteAsInt(file);
|
||||
event->SetValues(value0, value1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int MidiChannelEventAdapter::ReadEventData(std::ifstream* file, MidiChannelEvent* event)
|
||||
{
|
||||
int value0 = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, value0);
|
||||
|
||||
int value1 = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, value1);
|
||||
int value0 = *BinaryStream::getNextByteAsInt(file);
|
||||
int value1 = *BinaryStream::getNextByteAsInt(file);
|
||||
event->SetValues(value0, value1);
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "MidiMetaEventAdapter.h"
|
||||
|
||||
#include "BinaryFile.h"
|
||||
#include "BinaryStream.h"
|
||||
#include "ByteUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -35,8 +35,7 @@ int MidiMetaEventAdapter::ReadEvent(std::ifstream* file, MetaMidiEvent* event, i
|
|||
break;
|
||||
case MetaMidiEvent::Type::END_TRACK:
|
||||
{
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount ++;
|
||||
break;
|
||||
}
|
||||
|
@ -66,8 +65,7 @@ int MidiMetaEventAdapter::ReadEvent(std::ifstream* file, MetaMidiEvent* event, i
|
|||
|
||||
int MidiMetaEventAdapter::ReadUnknownEvent(std::ifstream* file)
|
||||
{
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
|
||||
char c;
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
|
@ -81,12 +79,11 @@ int MidiMetaEventAdapter::ReadStringEvent(std::ifstream* file, MetaMidiEvent* ev
|
|||
{
|
||||
unsigned byteCount = 0;
|
||||
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount++;
|
||||
|
||||
std::string name;
|
||||
BinaryFile::GetNextString(file, name, length);
|
||||
BinaryStream::getNextString(file, name, length);
|
||||
byteCount += length;
|
||||
event->SetLabel(name);
|
||||
return byteCount;
|
||||
|
@ -102,15 +99,15 @@ int MidiMetaEventAdapter::ReadIntEvent(std::ifstream* file, MetaMidiEvent* event
|
|||
}
|
||||
else
|
||||
{
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount ++;
|
||||
}
|
||||
|
||||
std::string buffer;
|
||||
BinaryFile::GetNextNBytes(file, buffer.data(), length);
|
||||
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
||||
byteCount += length;
|
||||
|
||||
const int value = ByteUtils::ToInt(buffer.data(), length);
|
||||
const int value = ByteUtils::ToType<ByteUtils::DWord>(buffer.data(), length);
|
||||
event->SetValue(value);
|
||||
return byteCount;
|
||||
}
|
||||
|
@ -118,15 +115,14 @@ int MidiMetaEventAdapter::ReadIntEvent(std::ifstream* file, MetaMidiEvent* event
|
|||
int MidiMetaEventAdapter::ReadChannelPrefixEvent(std::ifstream* file, MetaMidiEvent* event, int& lastMidiChannel)
|
||||
{
|
||||
unsigned byteCount = 0;
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount ++;
|
||||
|
||||
std::string buffer;
|
||||
BinaryFile::GetNextNBytes(file, buffer.data(), length);
|
||||
BinaryStream::getNextNBytes(file, buffer.data(), length);
|
||||
byteCount += length;
|
||||
|
||||
const int value = ByteUtils::ToInt(buffer.data(), length);
|
||||
const int value = ByteUtils::ToType<ByteUtils::DWord>(buffer.data(), length);
|
||||
event->SetValue(value);
|
||||
lastMidiChannel = value;
|
||||
return byteCount;
|
||||
|
@ -135,15 +131,14 @@ int MidiMetaEventAdapter::ReadChannelPrefixEvent(std::ifstream* file, MetaMidiEv
|
|||
int MidiMetaEventAdapter::ReadTimeSignatureEvent(std::ifstream* file, MetaMidiEvent* event)
|
||||
{
|
||||
unsigned byteCount = 0;
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount++;
|
||||
|
||||
MidiTimeSignature timeSig;
|
||||
BinaryFile::GetNextByteAsInt(file, timeSig.mNumer);
|
||||
BinaryFile::GetNextByteAsInt(file, timeSig.mDenom);
|
||||
BinaryFile::GetNextByteAsInt(file, timeSig.mMetro);
|
||||
BinaryFile::GetNextByteAsInt(file, timeSig.mF32);
|
||||
timeSig.mNumer = *BinaryStream::getNextByteAsInt(file);
|
||||
timeSig.mDenom = *BinaryStream::getNextByteAsInt(file);
|
||||
timeSig.mMetro = *BinaryStream::getNextByteAsInt(file);
|
||||
timeSig.mF32 = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount +=4;
|
||||
|
||||
if (length > 4)
|
||||
|
@ -161,13 +156,12 @@ int MidiMetaEventAdapter::ReadTimeSignatureEvent(std::ifstream* file, MetaMidiEv
|
|||
int MidiMetaEventAdapter::ReadKeySignatureEvent(std::ifstream* file, MetaMidiEvent* event)
|
||||
{
|
||||
unsigned byteCount = 0;
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount++;
|
||||
|
||||
MidiKeySignature keySig;
|
||||
BinaryFile::GetNextByteAsInt(file, keySig.mSharpsFlats);
|
||||
BinaryFile::GetNextByteAsInt(file, keySig.mMinor);
|
||||
keySig.mSharpsFlats = *BinaryStream::getNextByteAsInt(file);
|
||||
keySig.mMinor = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount +=2;
|
||||
return byteCount;
|
||||
}
|
||||
|
@ -175,16 +169,15 @@ int MidiMetaEventAdapter::ReadKeySignatureEvent(std::ifstream* file, MetaMidiEve
|
|||
int MidiMetaEventAdapter::ReadTimeCodeEvent(std::ifstream* file, MetaMidiEvent* event)
|
||||
{
|
||||
unsigned byteCount = 0;
|
||||
int length = 0;
|
||||
BinaryFile::GetNextByteAsInt(file, length);
|
||||
int length = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount++;
|
||||
|
||||
MidiSmtpeTimecode timeCode;
|
||||
BinaryFile::GetNextByteAsInt(file, timeCode.mHr);
|
||||
BinaryFile::GetNextByteAsInt(file, timeCode.mMin);
|
||||
BinaryFile::GetNextByteAsInt(file, timeCode.mSec);
|
||||
BinaryFile::GetNextByteAsInt(file, timeCode.mFrame);
|
||||
BinaryFile::GetNextByteAsInt(file, timeCode.mFrameFrac);
|
||||
timeCode.mHr = *BinaryStream::getNextByteAsInt(file);
|
||||
timeCode.mMin = *BinaryStream::getNextByteAsInt(file);
|
||||
timeCode.mSec = *BinaryStream::getNextByteAsInt(file);
|
||||
timeCode.mFrame = *BinaryStream::getNextByteAsInt(file);
|
||||
timeCode.mFrameFrac = *BinaryStream::getNextByteAsInt(file);
|
||||
byteCount +=5;
|
||||
return byteCount;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "MidiDocument.h"
|
||||
#include "ByteUtils.h"
|
||||
#include "MidiTrack.h"
|
||||
#include "BinaryFile.h"
|
||||
#include "BinaryStream.h"
|
||||
#include "FileLogger.h"
|
||||
#include "MidiElements.h"
|
||||
#include "MidiTimeAdapter.h"
|
||||
|
@ -29,30 +29,30 @@ MidiDocument* MidiReader::GetDocument() const
|
|||
|
||||
bool MidiReader::ProcessHeader()
|
||||
{
|
||||
if(!BinaryFile::CheckNextDWord(mFile->GetInHandle(), HeaderLabel))
|
||||
if(!BinaryStream::checkNextDWord(mFile->GetInHandle(), HeaderLabel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int length = 0;
|
||||
if(!BinaryFile::GetNextDWord(mFile->GetInHandle(), length))
|
||||
const auto length = BinaryStream::getNextDWord(mFile->GetInHandle());
|
||||
if(!length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int formatType { 0 };
|
||||
if(!BinaryFile::GetNextWord(mFile->GetInHandle(), formatType))
|
||||
const auto formatType = BinaryStream::getNextWord(mFile->GetInHandle());
|
||||
if(!formatType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mDocument->SetFormatType(formatType);
|
||||
mDocument->SetFormatType(*formatType);
|
||||
|
||||
int expectedTracks { 0 };
|
||||
if(!BinaryFile::GetNextWord(mFile->GetInHandle(), expectedTracks))
|
||||
const auto expectedTracks = BinaryStream::getNextWord(mFile->GetInHandle());
|
||||
if(!expectedTracks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mDocument->SetExpectedTracks(expectedTracks);
|
||||
mDocument->SetExpectedTracks(*expectedTracks);
|
||||
|
||||
MidiTimeDivision timeDivision;
|
||||
MidiTimeAdapter::ReadTimeDivision(mFile->GetInHandle(), timeDivision);
|
||||
|
@ -95,13 +95,13 @@ int MidiReader::ProcessEvent(MidiTrack* track)
|
|||
|
||||
bool MidiReader::ProcessTrackChunk(bool debug)
|
||||
{
|
||||
if(!BinaryFile::CheckNextDWord(mFile->GetInHandle(), TrackChunkLabel))
|
||||
if(!BinaryStream::checkNextDWord(mFile->GetInHandle(), TrackChunkLabel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int chunkSize = 0;
|
||||
if(!BinaryFile::GetNextDWord(mFile->GetInHandle(), chunkSize))
|
||||
const auto chunkSize = BinaryStream::getNextDWord(mFile->GetInHandle());
|
||||
if(!chunkSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -109,11 +109,11 @@ bool MidiReader::ProcessTrackChunk(bool debug)
|
|||
unsigned byteCount = 0;
|
||||
auto track = std::make_unique<MidiTrack>();
|
||||
unsigned iter_count = 0;
|
||||
while(byteCount < unsigned(chunkSize))
|
||||
while(byteCount < static_cast<unsigned>(*chunkSize))
|
||||
{
|
||||
std::cout << "-------------" << std::endl;
|
||||
byteCount += ProcessEvent(track.get());
|
||||
std::cout << "Track byte count: " << byteCount << " of " << chunkSize << std::endl;
|
||||
std::cout << "Track byte count: " << byteCount << " of " << *chunkSize << std::endl;
|
||||
if(debug && iter_count == 40)
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "MidiTimeAdapter.h"
|
||||
|
||||
#include "BinaryFile.h"
|
||||
#include "BinaryStream.h"
|
||||
#include "ByteUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -13,7 +13,7 @@ int MidiTimeAdapter::ReadEventTimeDelta(std::ifstream* file, int& delta)
|
|||
file->get(c);
|
||||
byteCount++;
|
||||
|
||||
if(!ByteUtils::MSBIsOne(c))
|
||||
if(!ByteUtils::MostSignificantBitIsOne(c))
|
||||
{
|
||||
delta = int(c);
|
||||
std::cout << "Time delta final: " << delta << std::endl;
|
||||
|
@ -48,19 +48,19 @@ int MidiTimeAdapter::ReadEventTimeDelta(std::ifstream* file, int& delta)
|
|||
|
||||
int MidiTimeAdapter::ReadTimeDivision(std::ifstream* file, MidiTimeDivision& division)
|
||||
{
|
||||
int time_division;
|
||||
if(!BinaryFile::GetNextWord(file, time_division, false))
|
||||
const auto time_division = BinaryStream::getNextWord(file, false);
|
||||
if(!time_division)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
division.mUseFps = ByteUtils::GetWordFirstBit(time_division);
|
||||
division.mUseFps = ByteUtils::GetWordFirstBit(*time_division);
|
||||
if (division.mUseFps)
|
||||
{
|
||||
const int TOP_7_BITS = 0x7F00; // 0111 1111 - 0000 0000
|
||||
division.mFps = ((~time_division & TOP_7_BITS) >> 8) - 1; // Reverse 2complement of next 7 bits
|
||||
division.mFps = ((~(*time_division) & TOP_7_BITS) >> 8) - 1; // Reverse 2complement of next 7 bits
|
||||
}
|
||||
|
||||
division.mTicks = ByteUtils::GetWordLastByte(time_division);
|
||||
division.mTicks = ByteUtils::GetWordLastByte(*time_division);
|
||||
return 2; // Bytes advanced
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue