Skip to content

Commit 4e29948

Browse files
Feature added: Select/deselect multiple ranges
1 parent c4b1fc5 commit 4e29948

1 file changed

Lines changed: 119 additions & 90 deletions

File tree

Source/Processors/Editors/ChannelSelector.cpp

Lines changed: 119 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) :
3737
{
3838

3939
// initialize buttons
40-
audioButton = new EditorButton("AUDIO", titleFont);
41-
audioButton->addListener(this);
40+
audioButton = new EditorButton("AUDIO", titleFont);
41+
audioButton->addListener(this);
4242
addAndMakeVisible(audioButton);
4343
if (!createButtons)
4444
audioButton->setState(false);
@@ -1236,23 +1236,34 @@ ChannelSelectorBox::~ChannelSelectorBox()
12361236
*/
12371237
int ChannelSelectorBox::convertToInteger(std::string s)
12381238
{
1239-
if (s.size() > 9)
1240-
{
1241-
return INT_MAX;
1242-
}
12431239
char ar[20];
1244-
int i,j=0;
1245-
for (i = 0; i < s.size(); i++)
1240+
int i,j,k=0;
1241+
for (i = 0; i < s.size(); i++)
1242+
{
1243+
if ((int)s[i] != 32)
1244+
{
1245+
break;
1246+
}
1247+
}
1248+
for (j = s.size() - 1; j >= 0; j--)
1249+
{
1250+
if ((int)s[j] != 32)
1251+
{
1252+
break;
1253+
}
1254+
}
1255+
1256+
for (; i <= j; i++)
12461257
{
12471258
if (s[i] >= 48 && s[i] <= 57)
12481259
{
1249-
ar[j] = s[i];
1250-
j++;
1260+
ar[k] = s[i];
1261+
k++;
12511262
}
12521263
}
1253-
ar[j] = '\0';
1254-
j = atoi(ar);
1255-
return j;
1264+
ar[k] = '\0';
1265+
k = atoi(ar);
1266+
return k;
12561267
}
12571268

12581269

@@ -1266,84 +1277,102 @@ std::vector<int> ChannelSelectorBox::getBoxInfo(int len)
12661277
{
12671278
std::string s = getText().toStdString();
12681279
std::vector<std::string> parsed;
1269-
std::vector<int> finalList,colonNum;
1280+
std::vector<int> finalList,colonNum,boxList;
12701281
finalList.clear();
1271-
int i, j, k, a, otherChar = 0, b, openb = 0, closeb = 0;
1272-
1273-
for (i = 0; i < s.size(); i++) // Fetch the box ([a:b:c]) from the string.
1274-
{
1275-
if (s[i] == ':')
1276-
{
1277-
colonNum.push_back(i);
1278-
}
1279-
else if (s[i] == '[')
1280-
{
1281-
openb++;
1282-
}
1283-
else if (s[i] == ']')
1284-
{
1285-
closeb++;
1286-
break;
1287-
}
1288-
else if (s[i] < 48 && s[i]>57 && s[i] != 32)
1289-
{
1290-
otherChar++;
1291-
}
1292-
}
1293-
1294-
if (colonNum.size() > 2 || colonNum.size() < 1 || openb != 1 || closeb != 1 || otherChar > 0) // If proper syntax not maintained, return.
1295-
{
1296-
return finalList;
1297-
}
1298-
1299-
if (colonNum.size() == 1) // Case when input is in the form [a:b]
1300-
{
1301-
a = convertToInteger(s.substr(0, colonNum[0] + 1));
1302-
b = convertToInteger(s.substr(colonNum[0], s.size() - colonNum[0] + 1));
1303-
if (a > len || b > len || a > b)
1304-
{
1305-
return finalList;
1306-
}
1307-
if (a == 0)
1308-
{
1309-
a = 1;
1310-
}
1311-
if (b == 0)
1312-
{
1313-
b = len;
1314-
}
1315-
finalList.push_back(a - 1);
1316-
finalList.push_back(b - 1);
1317-
finalList.push_back(1);
1318-
return finalList;
1319-
}
1320-
else if (colonNum.size() == 2) // Case when input is in the form [a:b:c]
1321-
{
1322-
a = convertToInteger(s.substr(0, colonNum[0] + 1));
1323-
k = convertToInteger(s.substr(colonNum[0], colonNum[1] - colonNum[0] + 1));
1324-
b = convertToInteger(s.substr(colonNum[1], s.size() - colonNum[1] + 1));
1325-
if (k == 0)
1326-
{
1327-
k = 1;
1328-
}
1329-
if (a == 0)
1330-
{
1331-
a = 1;
1332-
}
1333-
if (b == 0)
1334-
{
1335-
b = len;
1336-
}
1337-
1338-
if (a > len || b > len || a > b)
1339-
{
1340-
return finalList;
1341-
}
1342-
finalList.push_back(a - 1);
1343-
finalList.push_back(b - 1);
1344-
finalList.push_back(k);
1345-
return finalList;
1346-
}
1282+
int i, j, k, a, otherChar = 0, b, x;
1283+
1284+
for (i = 0; i < s.size(); i++)
1285+
{
1286+
if (s[i] == '[')
1287+
{
1288+
boxList.push_back(i);
1289+
j = i + 1;
1290+
for (; j < s.size(); j++)
1291+
{
1292+
if (s[j] == ']')
1293+
{
1294+
boxList.push_back(j); break;
1295+
}
1296+
}
1297+
i = j;
1298+
}
1299+
}
1300+
1301+
if (boxList.size() % 2 != 0)
1302+
{
1303+
boxList.pop_back();
1304+
}
1305+
1306+
for (i = 0; i < boxList.size(); i+=2)
1307+
{
1308+
colonNum.clear(); otherChar = 0;
1309+
for (x = boxList[i] + 1; x < boxList[i + 1]; x++)
1310+
{
1311+
if (s[x] == ':')
1312+
{
1313+
colonNum.push_back(x);
1314+
}
1315+
else if ((int)s[x] == 32)
1316+
{
1317+
continue;
1318+
}
1319+
else if (((int)s[x] < 48 || (int)s[x]>57))
1320+
{
1321+
otherChar++;
1322+
}
1323+
}
1324+
if (colonNum.size()>2 || colonNum.size() < 1 || otherChar > 0)
1325+
{
1326+
continue;
1327+
}
1328+
1329+
if (colonNum.size() == 1)
1330+
{
1331+
a = convertToInteger(s.substr(boxList[i], colonNum[0] - boxList[i] + 1));
1332+
b = convertToInteger(s.substr(colonNum[0], boxList[i+1] - colonNum[0] + 1));
1333+
if (a == 0)
1334+
{
1335+
a = 1;
1336+
}
1337+
if (b == 0)
1338+
{
1339+
b = len;
1340+
}
1341+
if (a > len || b > len || a > b)
1342+
{
1343+
continue;
1344+
}
1345+
finalList.push_back(a - 1);
1346+
finalList.push_back(b - 1);
1347+
finalList.push_back(1);
1348+
}
1349+
else if (colonNum.size() == 2)
1350+
{
1351+
a = convertToInteger(s.substr(boxList[i], colonNum[0] - boxList[i] + 1));
1352+
k = convertToInteger(s.substr(colonNum[0], colonNum[1] - colonNum[0] + 1));
1353+
b = convertToInteger(s.substr(colonNum[1], boxList[i+1] - colonNum[1] + 1));
1354+
if (k == 0)
1355+
{
1356+
k = 1;
1357+
}
1358+
if (a == 0)
1359+
{
1360+
a = 1;
1361+
}
1362+
if (b == 0)
1363+
{
1364+
b = len;
1365+
}
1366+
1367+
if (a > len || b > len || a > b)
1368+
{
1369+
continue;
1370+
}
1371+
finalList.push_back(a - 1);
1372+
finalList.push_back(b - 1);
1373+
finalList.push_back(k);
1374+
}
1375+
}
13471376

13481377
return finalList;
13491378
}

0 commit comments

Comments
 (0)