From 617be0820dbd38e6ecbec9f127cb03b841594239 Mon Sep 17 00:00:00 2001 From: Antiloope Date: Sat, 5 Dec 2020 15:16:13 -0300 Subject: [PATCH] Fixed sample execution errors --- src/interpreter/datatypes/sampledatatype.cpp | 50 ++++++++++---------- src/interpreter/languagedefinitions.cpp | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/interpreter/datatypes/sampledatatype.cpp b/src/interpreter/datatypes/sampledatatype.cpp index 655676f..208c88c 100644 --- a/src/interpreter/datatypes/sampledatatype.cpp +++ b/src/interpreter/datatypes/sampledatatype.cpp @@ -102,6 +102,11 @@ LiteralValue* SampleDataType::play( case DataTypesId::Argument: { double duration = player->getDurationInSeconds(); + if( ((list*)((ArgumentLiteralValue*)(*it))->getValue())->front()->getDataTypeId() == DataTypesId::Argument ) + { + argumentValues = (list*)((ArgumentLiteralValue*)(*it))->getValue(); + it = argumentValues->begin(); + } for( ; it != argumentValues->end(); it++ ) { list* argumentList = @@ -109,7 +114,7 @@ LiteralValue* SampleDataType::play( auto argIt = argumentList->begin(); - if( (*argIt)->getDataTypeId() != DataTypesId::Numeric ) + if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric ) return nullptr; double timeFactor = *(double*)(*argIt)->getValue(); @@ -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; } @@ -194,6 +199,11 @@ LiteralValue* SampleDataType::loop( { double duration = player->getDurationInSeconds(); double totalLoopDuration = 0; + if( ((list*)((ArgumentLiteralValue*)(*it))->getValue())->front()->getDataTypeId() == DataTypesId::Argument ) + { + argumentValues = (list*)((ArgumentLiteralValue*)(*it))->getValue(); + it = argumentValues->begin(); + } for( ; it != argumentValues->end(); it++ ) { list* argumentList = @@ -201,22 +211,17 @@ LiteralValue* SampleDataType::loop( 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(); @@ -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++ ) @@ -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); } diff --git a/src/interpreter/languagedefinitions.cpp b/src/interpreter/languagedefinitions.cpp index 228f23e..1d00ff1 100644 --- a/src/interpreter/languagedefinitions.cpp +++ b/src/interpreter/languagedefinitions.cpp @@ -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();