Skip to content

Commit 617be08

Browse files
committed
Fixed sample execution errors
1 parent 99bf693 commit 617be08

2 files changed

Lines changed: 25 additions & 27 deletions

File tree

src/interpreter/datatypes/sampledatatype.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,19 @@ LiteralValue* SampleDataType::play(
102102
case DataTypesId::Argument:
103103
{
104104
double duration = player->getDurationInSeconds();
105+
if( ((list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue())->front()->getDataTypeId() == DataTypesId::Argument )
106+
{
107+
argumentValues = (list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();
108+
it = argumentValues->begin();
109+
}
105110
for( ; it != argumentValues->end(); it++ )
106111
{
107112
list<LiteralValue*>* argumentList =
108113
(list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();
109114

110115
auto argIt = argumentList->begin();
111116

112-
if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
117+
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
113118
return nullptr;
114119

115120
double timeFactor = *(double*)(*argIt)->getValue();
@@ -122,20 +127,20 @@ LiteralValue* SampleDataType::play(
122127
continue;
123128
}
124129

125-
if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
130+
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
126131
return nullptr;
127132

128-
double preFactor = *(double*)(*argIt)->getValue();
133+
double virtualDuration = *(double*)(*argIt)->getValue();
129134
argIt++;
130135
if( argIt != argumentList->end() )
131136
return nullptr;
132-
if( preFactor == 0 )
137+
if( virtualDuration == 0 )
133138
{
134-
startTick += TimeHandler::getInstance()->segToTicks(timeFactor);
139+
startTick += TimeHandler::getInstance()->segToTicks(duration * timeFactor);
135140
continue;
136141
}
137142
player->play(timeFactor, startTick, variableName);
138-
startTick += TimeHandler::getInstance()->segToTicks(duration*preFactor);
143+
startTick += TimeHandler::getInstance()->segToTicks(virtualDuration);
139144
}
140145
break;
141146
}
@@ -194,29 +199,29 @@ LiteralValue* SampleDataType::loop(
194199
{
195200
double duration = player->getDurationInSeconds();
196201
double totalLoopDuration = 0;
202+
if( ((list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue())->front()->getDataTypeId() == DataTypesId::Argument )
203+
{
204+
argumentValues = (list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();
205+
it = argumentValues->begin();
206+
}
197207
for( ; it != argumentValues->end(); it++ )
198208
{
199209
list<LiteralValue*>* argumentList =
200210
(list<LiteralValue*>*)((ArgumentLiteralValue*)(*it))->getValue();
201211

202212
auto argIt = argumentList->begin();
203213

204-
if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
214+
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
205215
return nullptr;
206216

207-
double timeFactor = *(double*)(*argIt)->getValue();
208-
209217
argIt++;
210218
if( argIt == argumentList->end() )
211219
{
212-
if( timeFactor > 0 )
213-
totalLoopDuration += timeFactor * duration;
214-
else
215-
totalLoopDuration += duration;
220+
totalLoopDuration += duration;
216221
continue;
217222
}
218223

219-
if( (*argIt)->getDataTypeId() != DataTypesId::Numeric )
224+
if( (*argIt) == nullptr || (*argIt)->getDataTypeId() != DataTypesId::Numeric )
220225
return nullptr;
221226

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

227232
if( virtualDuration == 0 )
228-
continue;
229-
230-
totalLoopDuration += virtualDuration;
233+
totalLoopDuration += duration;
234+
else
235+
totalLoopDuration += virtualDuration;
231236
}
232237
auto it = argumentValues->begin();
233238
for( ; it != argumentValues->end(); it++ )
@@ -243,22 +248,15 @@ LiteralValue* SampleDataType::loop(
243248
if( argIt == argumentList->end() )
244249
{
245250
player->loop(timeFactor, totalLoopDuration, startTick, variableName);
246-
if( timeFactor )
247-
startTick += TimeHandler::getInstance()->segToTicks(duration/timeFactor);
248-
else
249-
startTick += TimeHandler::getInstance()->segToTicks(duration);
251+
startTick += TimeHandler::getInstance()->segToTicks(duration);
250252
continue;
251253
}
252254

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

256-
if( virtualDuration == 0 )
257-
{
258-
player->loop(timeFactor, totalLoopDuration, startTick, variableName);
259-
continue;
260-
}
261258
player->loop(timeFactor, totalLoopDuration, startTick, variableName);
259+
262260
startTick += TimeHandler::getInstance()->segToTicks(virtualDuration);
263261
}
264262

src/interpreter/languagedefinitions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void CS::Functions::sample() {
3030
Context* ctx = Context::getInstance();
3131

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

3636
string fileName = *(string*)argValue->getValue();

0 commit comments

Comments
 (0)