Skip to content

Commit

Permalink
Fixed sample execution errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Antiloope committed Dec 5, 2020
1 parent 99bf693 commit 617be08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
50 changes: 24 additions & 26 deletions src/interpreter/datatypes/sampledatatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ LiteralValue* SampleDataType::play(
case DataTypesId::Argument:
{
double duration = player->getDurationInSeconds();
if( ((list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue())->front()->getDataTypeId() == DataTypesId::Argument )
{
argumentValues = (list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();
it = argumentValues->begin();
}
for( ; it != argumentValues->end(); it++ )
{
list<LiteralValue*>* argumentList =
(list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();

auto argIt = argumentList->begin();

if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
return nullptr;

double timeFactor = *(double*)(*argIt)->getValue();
Expand All @@ -122,20 +127,20 @@ LiteralValue* SampleDataType::play(
continue;
}

if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
return nullptr;

double preFactor = *(double*)(*argIt)->getValue();
double virtualDuration = *(double*)(*argIt)->getValue();
argIt++;
if( argIt != argumentList->end() )
return nullptr;
if( preFactor == 0 )
if( virtualDuration == 0 )
{
startTick += TimeHandler::getInstance()->segToTicks(timeFactor);
startTick += TimeHandler::getInstance()->segToTicks(duration * timeFactor);
continue;
}
player->play(timeFactor, startTick, variableName);
startTick += TimeHandler::getInstance()->segToTicks(duration*preFactor);
startTick += TimeHandler::getInstance()->segToTicks(virtualDuration);
}
break;
}
Expand Down Expand Up @@ -194,29 +199,29 @@ LiteralValue* SampleDataType::loop(
{
double duration = player->getDurationInSeconds();
double totalLoopDuration = 0;
if( ((list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue())->front()->getDataTypeId() == DataTypesId::Argument )
{
argumentValues = (list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();
it = argumentValues->begin();
}
for( ; it != argumentValues->end(); it++ )
{
list<LiteralValue*>* argumentList =
(list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();

auto argIt = argumentList->begin();

if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
return nullptr;

double timeFactor = *(double*)(*argIt)->getValue();

argIt++;
if( argIt == argumentList->end() )
{
if( timeFactor > 0 )
totalLoopDuration += timeFactor * duration;
else
totalLoopDuration += duration;
totalLoopDuration += duration;
continue;
}

if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
return nullptr;

double virtualDuration = *(double*)(*argIt)->getValue();
Expand All @@ -225,9 +230,9 @@ LiteralValue* SampleDataType::loop(
return nullptr;

if( virtualDuration == 0 )
continue;

totalLoopDuration += virtualDuration;
totalLoopDuration += duration;
else
totalLoopDuration += virtualDuration;
}
auto it = argumentValues->begin();
for( ; it != argumentValues->end(); it++ )
Expand All @@ -243,22 +248,15 @@ LiteralValue* SampleDataType::loop(
if( argIt == argumentList->end() )
{
player->loop(timeFactor, totalLoopDuration, startTick, variableName);
if( timeFactor )
startTick += TimeHandler::getInstance()->segToTicks(duration/timeFactor);
else
startTick += TimeHandler::getInstance()->segToTicks(duration);
startTick += TimeHandler::getInstance()->segToTicks(duration);
continue;
}

double virtualDuration = *(double*)(*argIt)->getValue();
argIt++;

if( virtualDuration == 0 )
{
player->loop(timeFactor, totalLoopDuration, startTick, variableName);
continue;
}
player->loop(timeFactor, totalLoopDuration, startTick, variableName);

startTick += TimeHandler::getInstance()->segToTicks(virtualDuration);
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/languagedefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void CS::Functions::sample() {
Context* ctx = Context::getInstance();

LiteralValue* argValue = ctx->getArgumentValue("fileName");
if( argValue->getDataTypeId() != DataTypesId::String )
if( argValue == nullptr || argValue->getDataTypeId() != DataTypesId::String )
throw SemanticException("Invalid argument for sample function. Expected a file name");

string fileName = *(string*)argValue->getValue();
Expand Down

0 comments on commit 617be08

Please sign in to comment.