Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/fix_android'
Browse files Browse the repository at this point in the history
  • Loading branch information
Geromatic committed Nov 2, 2017
2 parents e64876d + 5682914 commit 258585e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../Event/MidiEvent.h"
#include "../Util/MidiUtil.h"

MidiProcessor::MidiProcessor() : PlayRate(1.0) {
MidiProcessor::MidiProcessor() : PlayRate(1.0), mClockType(0) {
mMidiFile = NULL;
mMetronome = NULL;

Expand Down Expand Up @@ -119,6 +119,18 @@ void MidiProcessor::update(const double& deltaTime /*= clock()*/) {

double now = deltaTime;
double msElapsed = now - mLastMs;
// #define CLOCKS_PER_MS (CLOCKS_PER_SEC / 1000)
switch(mClockType) {
case 0: // clock()
// msElapsed /= CLOCKS_PER_MS;
break;
case 1: // FPlatformTime::Cycles()
msElapsed = FPlatformTime::ToMilliseconds(msElapsed);
case 2: // Other
break;

}

double ticksElapsed = MidiUtil::msToTicks(msElapsed, mMPQN, mPPQ) * PlayRate;
if (ticksElapsed < 1) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class MidiProcessor
void setStartClock(double time) {
mLastMs = time;
}
/* clock() = 0, FPlatformTime = 1, Other = 2 */
int mClockType;

void update(const double& deltaTime = clock());

Expand Down
12 changes: 8 additions & 4 deletions Procedural-Midi/MidiAsset/Source/Midi/Private/MidiComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void UMidiComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActor
mProcessor.update(GetWorld()->TimeSeconds * 1000.0f);
}
else
mProcessor.update();
mProcessor.update(FPlatformTime::Cycles());
}

else
Expand Down Expand Up @@ -205,10 +205,14 @@ void UMidiComponent::start(bool background, bool UseGameTime) {
this->isGameTime = UseGameTime;
}

if(UseGameTime)
if(UseGameTime) {
mProcessor.start(GetWorld()->TimeSeconds * 1000.0f);
else
mProcessor.start();
mProcessor.mClockType = 2;
}
else {
mProcessor.start(FPlatformTime::Cycles());
mProcessor.mClockType = 1;
}
}

void UMidiComponent::stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,21 @@ uint32 FMidiProcessorWorker::Run() {
if (!world)
return 0;

if(isGameTime)
if(isGameTime) {
ThePC->setStartClock(world->TimeSeconds * 1000.0f);
ThePC->mClockType = 2;
}
else {
ThePC->setStartClock(FPlatformTime::Cycles());
ThePC->mClockType = 1;
}

while (!IsFinished())
{
if (isGameTime)
ThePC->update(world->TimeSeconds * 1000.0f);
else
ThePC->update();
ThePC->update(FPlatformTime::Cycles());
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//prevent thread from using too many resources
FPlatformProcess::Sleep(0.008f);
Expand Down

0 comments on commit 258585e

Please sign in to comment.