Skip to content
Snippets Groups Projects
Commit 3a4bfcf6 authored by Priyanjit Dey's avatar Priyanjit Dey
Browse files

Feature added: Select/deselect multiple ranges

parent 4e299483
No related branches found
No related tags found
No related merge requests found
...@@ -37,8 +37,8 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) : ...@@ -37,8 +37,8 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) :
{ {
// initialize buttons // initialize buttons
audioButton = new EditorButton("AUDIO", titleFont); audioButton = new EditorButton("AUDIO", titleFont);
audioButton->addListener(this); audioButton->addListener(this);
addAndMakeVisible(audioButton); addAndMakeVisible(audioButton);
if (!createButtons) if (!createButtons)
audioButton->setState(false); audioButton->setState(false);
...@@ -1238,22 +1238,22 @@ int ChannelSelectorBox::convertToInteger(std::string s) ...@@ -1238,22 +1238,22 @@ int ChannelSelectorBox::convertToInteger(std::string s)
{ {
char ar[20]; char ar[20];
int i,j,k=0; int i,j,k=0;
for (i = 0; i < s.size(); i++) for (i = 0; i < s.size(); i++) //trim whitespace from front
{ {
if ((int)s[i] != 32) if ((int)s[i] != 32)
{ {
break; break;
} }
} }
for (j = s.size() - 1; j >= 0; j--) for (j = s.size() - 1; j >= 0; j--) //trim whitespaces from end
{ {
if ((int)s[j] != 32) if ((int)s[j] != 32)
{ {
break; break;
} }
} }
for (; i <= j; i++) for (; i <= j; i++)
{ {
if (s[i] >= 48 && s[i] <= 57) if (s[i] >= 48 && s[i] <= 57)
{ {
...@@ -1279,100 +1279,105 @@ std::vector<int> ChannelSelectorBox::getBoxInfo(int len) ...@@ -1279,100 +1279,105 @@ std::vector<int> ChannelSelectorBox::getBoxInfo(int len)
std::vector<std::string> parsed; std::vector<std::string> parsed;
std::vector<int> finalList,colonNum,boxList; std::vector<int> finalList,colonNum,boxList;
finalList.clear(); finalList.clear();
int i, j, k, a, otherChar = 0, b, x; int i, j, k, a, otherChar = 0, b, x;
for (i = 0; i < s.size(); i++) for (i = 0; i < s.size(); i++) //fetch all valid ranges from text box
{ {
if (s[i] == '[') if (s[i] == '[')
{ {
boxList.push_back(i); boxList.push_back(i);
j = i + 1; j = i + 1;
for (; j < s.size(); j++) for (; j < s.size(); j++)
{ {
if (s[j] == ']') if (s[j] == ']')
{ {
boxList.push_back(j); break; boxList.push_back(j);
} break;
} }
i = j; }
} i = j;
} }
}
if (boxList.size() % 2 != 0)
{ if (boxList.size() % 2 != 0)
boxList.pop_back(); {
} boxList.pop_back();
}
for (i = 0; i < boxList.size(); i+=2)
{ /*
colonNum.clear(); otherChar = 0; for each valid ranges fetch the start value, end value, common difference.
for (x = boxList[i] + 1; x < boxList[i + 1]; x++) */
{ for (i = 0; i < boxList.size(); i+=2)
if (s[x] == ':') {
{ colonNum.clear();
colonNum.push_back(x); otherChar = 0;
} for (x = boxList[i] + 1; x < boxList[i + 1]; x++)
else if ((int)s[x] == 32) {
{ if (s[x] == ':')
continue; {
} colonNum.push_back(x);
else if (((int)s[x] < 48 || (int)s[x]>57)) }
{ else if ((int)s[x] == 32)
otherChar++; {
} continue;
} }
if (colonNum.size()>2 || colonNum.size() < 1 || otherChar > 0) else if (((int)s[x] < 48 || (int)s[x]>57))
{ {
continue; otherChar++;
} }
}
if (colonNum.size() == 1) if (colonNum.size()>2 || colonNum.size() < 1 || otherChar > 0)
{ {
a = convertToInteger(s.substr(boxList[i], colonNum[0] - boxList[i] + 1)); continue;
b = convertToInteger(s.substr(colonNum[0], boxList[i+1] - colonNum[0] + 1)); }
if (a == 0)
{ if (colonNum.size() == 1) //when range is of form [x:y]
a = 1; {
} a = convertToInteger(s.substr(boxList[i], colonNum[0] - boxList[i] + 1));
if (b == 0) b = convertToInteger(s.substr(colonNum[0], boxList[i+1] - colonNum[0] + 1));
{ if (a == 0)
b = len; {
} a = 1;
if (a > len || b > len || a > b) }
{ if (b == 0)
continue; {
} b = len;
finalList.push_back(a - 1); }
finalList.push_back(b - 1); if (a > len || b > len || a > b)
finalList.push_back(1); {
} continue;
else if (colonNum.size() == 2) }
{ finalList.push_back(a - 1);
a = convertToInteger(s.substr(boxList[i], colonNum[0] - boxList[i] + 1)); finalList.push_back(b - 1);
k = convertToInteger(s.substr(colonNum[0], colonNum[1] - colonNum[0] + 1)); finalList.push_back(1);
b = convertToInteger(s.substr(colonNum[1], boxList[i+1] - colonNum[1] + 1)); }
if (k == 0) else if (colonNum.size() == 2) //when range is of form [x:k:y]
{ {
k = 1; a = convertToInteger(s.substr(boxList[i], colonNum[0] - boxList[i] + 1));
} k = convertToInteger(s.substr(colonNum[0], colonNum[1] - colonNum[0] + 1));
if (a == 0) b = convertToInteger(s.substr(colonNum[1], boxList[i+1] - colonNum[1] + 1));
{ if (k == 0)
a = 1; {
} k = 1;
if (b == 0) }
{ if (a == 0)
b = len; {
} a = 1;
}
if (a > len || b > len || a > b) if (b == 0)
{ {
continue; b = len;
} }
finalList.push_back(a - 1);
finalList.push_back(b - 1); if (a > len || b > len || a > b)
finalList.push_back(k); {
} continue;
} }
finalList.push_back(a - 1);
finalList.push_back(b - 1);
finalList.push_back(k);
}
}
return finalList; return finalList;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment