Skip to content

Commit

Permalink
Implemented operator overload for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Antiloope committed Oct 10, 2020
1 parent 851d699 commit ba506cf
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions src/interpreter/values/mathoperationlinkedvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ LiteralValue* MathOperationLinkedValue::getValue() const {
{
case DataTypesId::Numeric:
case DataTypesId::Sound:
case DataTypesId::Sample:
case DataTypesId::String:
RPNStack.push(literalValue->clone());
break;
Expand Down Expand Up @@ -293,6 +294,16 @@ LiteralValue* MathOperationLinkedValue::getValue() const {
RPNStack.push(new SoundLiteralValue(op1->operator*(op2).clone()));
break;
}
case DataTypesId::Sample:
{
unique_ptr<SamplePlayer> op1 = unique_ptr<SamplePlayer>(((SamplePlayer*)RPNStack.top()->getValue())->clone());

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue(op1->operator*(op2).clone()));
break;
}
default:
while(!RPNStack.empty())
{
Expand Down Expand Up @@ -412,6 +423,16 @@ LiteralValue* MathOperationLinkedValue::getValue() const {
RPNStack.push(new SoundLiteralValue((*op1 + *op2).clone()));
break;
}
case DataTypesId::Sample:
{
unique_ptr<SamplePlayer> op1(((SamplePlayer*)RPNStack.top()->getValue())->clone());

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue((*op1 + *op2).clone()));
break;
}
default:
while(!RPNStack.empty())
{
Expand Down Expand Up @@ -448,6 +469,16 @@ LiteralValue* MathOperationLinkedValue::getValue() const {
RPNStack.push(new SoundLiteralValue(op1->operator*(*op2).clone()));
break;
}
case DataTypesId::Sample:
{
unique_ptr<SamplePlayer> op1 = unique_ptr<SamplePlayer>(((SamplePlayer*)RPNStack.top()->getValue())->clone());

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue(op1->operator*(*op2).clone()));
break;
}
default:
while(!RPNStack.empty())
{
Expand Down Expand Up @@ -499,6 +530,118 @@ LiteralValue* MathOperationLinkedValue::getValue() const {
}
break;
}
case DataTypesId::Sample:
{
unique_ptr<SamplePlayer> op2 = unique_ptr<SamplePlayer>(((SamplePlayer*)RPNStack.top()->getValue())->clone());

delete RPNStack.top();
RPNStack.pop();

if( RPNStack.empty() )
throw SyntaxException("Invalid operation",linkedValue->getCodeReference());

switch( *(char*)literalValue->getValue() )
{
case cCast(MathSymbols::Addition):
switch ( RPNStack.top()->getDataTypeId() )
{
case DataTypesId::Sound:
{
unique_ptr<SoundGenerator> op1(((SoundGenerator*)RPNStack.top()->getValue())->clone());

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue((*op2 + *op1).clone()));
break;
}
default:
while(!RPNStack.empty())
{
delete RPNStack.top();
RPNStack.pop();
}
throw SyntaxException(
"Invalid addition operation between a sample and a " + DataType::getDataTypeString(RPNStack.top()->getDataTypeId()),
linkedValue->getCodeReference());
break;
}
break;
case cCast(MathSymbols::Multiplication):
{
switch ( RPNStack.top()->getDataTypeId() )
{
case DataTypesId::Numeric:
{
double op1 = *(double*)RPNStack.top()->getValue();

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue(op2->operator*(op1).clone()));
break;
}
case DataTypesId::Sample:
{
unique_ptr<SoundGenerator> op1 = unique_ptr<SoundGenerator>(((SoundGenerator*)RPNStack.top()->getValue())->clone());

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue(op2->operator*(*op1).clone()));
break;
}
default:
while(!RPNStack.empty())
{
delete RPNStack.top();
RPNStack.pop();
}
throw SyntaxException(
"Invalid multiplication operation between a sample and a " + DataType::getDataTypeString(RPNStack.top()->getDataTypeId()),
linkedValue->getCodeReference());
break;
}
break;
}
case cCast(MathSymbols::Divition):
{
switch ( RPNStack.top()->getDataTypeId() )
{
case DataTypesId::Numeric:
{
double op1 = *(double*)RPNStack.top()->getValue();

delete RPNStack.top();
RPNStack.pop();

RPNStack.push(new SampleLiteralValue(op2->operator/(op1).clone()));
break;
}
default:
while(!RPNStack.empty())
{
delete RPNStack.top();
RPNStack.pop();
}
throw SyntaxException(
"Invalid divition operation between a sample and a " + DataType::getDataTypeString(RPNStack.top()->getDataTypeId()),
linkedValue->getCodeReference());
break;
}
break;
}
default:
while(!RPNStack.empty())
{
delete RPNStack.top();
RPNStack.pop();
}
throw SyntaxException("Invalid operation",linkedValue->getCodeReference());
break;
}
break;
}
default:
while(!RPNStack.empty())
{
Expand Down

0 comments on commit ba506cf

Please sign in to comment.