Skip to content

Commit

Permalink
Fixed: ElseIf/Else sections were executed although the corresponding …
Browse files Browse the repository at this point in the history
…If evaluated to true

git-svn-id: svn://svn.code.sf.net/p/equalizerapo/code/trunk@39 177c5db2-39f6-4273-851a-b0754c4d5937
  • Loading branch information
jthedering committed Oct 18, 2014
1 parent ea4b280 commit b4b32c6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Wiki/Configuration reference.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Copy: <Target channel>=<Source channel>+...
Copy: <Target channel>=<Constant value>+...

**Description:**
Replaces the audio on the target channel by the sum of the given source channels with optional factors. To add instead of replace the audio on the target channel, the target channel itself can also be a source channel. The factor can also be specified in dB by appending dB. Multiple channel assignments can be specified on a single line by separating them with spaces, therefore a single assignment must not contain spaces. Instead of channel and factor, a constant value can be specified. To avoid ambiguity with numerical channel indices, the constant value must contain a decimal point.
Replaces the audio on the target channel by the sum of the given source channels with optional factors. To add instead of replace the audio on the target channel, the target channel itself can also be a source channel. The factor can also be specified in dB by appending dB. Multiple channel assignments can be specified on a single line by separating them with spaces, therefore a single assignment must not contain spaces. Instead of channel and factor, a constant value can be specified. To avoid ambiguity with numerical channel indices, the constant value must contain a decimal point. For more information about channel identifiers, see the [Channel](#channel-since-version-08) command.

**Example:**

Expand All @@ -142,6 +142,10 @@ Replaces the audio on the target channel by the sum of the given source channels
# Attention: Sets the audio on channel L to the audio on the second channel
# (not to constant value 2, because no decimal point is present)
Copy: L=2
# Real world example: Replaces the audio on the subwoofer channel with
# the audio on the left channel while muting all other channels of a 5.1 speaker system
# (useful for measuring the subwoofer response in REW)
Copy: SUB=L L=0.0 R=0.0 C=0.0 RL=0.0 RR=0.0

<br>
# Control commands
Expand Down
47 changes: 37 additions & 10 deletions filters/IfFilterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ std::vector<IFilter*> IfFilterFactory::startOfFile(const std::wstring& configPat
{
trueCountStack.push(trueCount);
trueCount = 0;
executeElse = false;
if(falseCount != 0)
{
LogF(L"File was included inside If that evaluated to false!");
Expand Down Expand Up @@ -74,9 +75,14 @@ vector<IFilter*> IfFilterFactory::createFilter(const wstring& configPath, wstrin
TraceF(L"If(%s) evaluated to %s (%s)", expression.c_str(), result.ToString().c_str(), isTrue ? L"true" : L"false");

if(isTrue)
{
trueCount++;
}
else
{
falseCount++;
executeElse = true;
}
}
catch(ParserError e)
{
Expand All @@ -91,7 +97,19 @@ vector<IFilter*> IfFilterFactory::createFilter(const wstring& configPath, wstrin
}
else if(command == L"ElseIf")
{
if(falseCount == 1)
if(falseCount == 0)
{
if(trueCount == 0)
{
LogF(L"ElseIf without If!");
}
else
{
falseCount++;
trueCount--;
}
}
else if(falseCount == 1 && executeElse)
{
try
{
Expand All @@ -107,28 +125,34 @@ vector<IFilter*> IfFilterFactory::createFilter(const wstring& configPath, wstrin
{
falseCount--;
trueCount++;
executeElse = false;
}
}
catch(ParserError e)
{
LogF(L"Error while evaluating ElseIf(%s): %s", expression.c_str(), e.GetMsg().c_str());
}
}
else if(falseCount == 0 && trueCount == 0)
{
LogF(L"ElseIf without If!");
}
}
else if(command == L"Else")
{
if(falseCount == 1)
if(falseCount == 0)
{
falseCount--;
trueCount++;
if(trueCount == 0)
{
LogF(L"Else without If!");
}
else
{
falseCount++;
trueCount--;
}
}
else if(falseCount == 0 && trueCount == 0)
else if(falseCount == 1 && executeElse)
{
LogF(L"Else without If!");
falseCount--;
trueCount++;
executeElse = false;
}
}
else if(command == L"EndIf")
Expand All @@ -144,6 +168,9 @@ vector<IFilter*> IfFilterFactory::createFilter(const wstring& configPath, wstrin
{
falseCount--;
}

if(falseCount == 0)
executeElse = false;
}

if(falseCount > 0)
Expand Down
1 change: 1 addition & 0 deletions filters/IfFilterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class IfFilterFactory : public IFilterFactory

unsigned trueCount;
unsigned falseCount;
bool executeElse;
std::stack<unsigned> trueCountStack;

bool toBoolean(const mup::Value& value);
Expand Down

0 comments on commit b4b32c6

Please sign in to comment.