Skip to content

Commit 1d4ff66

Browse files
New Class for converting string to range
1 parent 2228fbf commit 1d4ff66

6 files changed

Lines changed: 272 additions & 194 deletions

File tree

Builds/VisualStudio2013/open-ephys.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
<ClCompile Include="..\..\Source\AccessClass.cpp" />
262262
<ClCompile Include="..\..\Source\Network\PracticalSocket.cpp" />
263263
<ClCompile Include="..\..\Source\Audio\AudioComponent.cpp" />
264+
<ClCompile Include="..\..\Source\Processors\Editors\ListSliceParser.cpp" />
264265
<ClCompile Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessorEditor.cpp" />
265266
<ClCompile Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessor.cpp" />
266267
<ClCompile Include="..\..\Source\Processors\Dsp\Bessel.cpp" />
@@ -1464,6 +1465,7 @@
14641465
<ClInclude Include="..\..\Source\AccessClass.h" />
14651466
<ClInclude Include="..\..\Source\Network\PracticalSocket.h" />
14661467
<ClInclude Include="..\..\Source\Audio\AudioComponent.h" />
1468+
<ClInclude Include="..\..\Source\Processors\Editors\ListSliceParser.h" />
14671469
<ClInclude Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessorEditor.h" />
14681470
<ClInclude Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessor.h" />
14691471
<ClInclude Include="..\..\Source\Processors\Dsp\Bessel.h" />

Builds/VisualStudio2013/open-ephys.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,9 @@
17851785
<ClCompile Include="..\..\JuceLibraryCode\modules\juce_video\juce_video.cpp">
17861786
<Filter>Juce Library Code</Filter>
17871787
</ClCompile>
1788+
<ClCompile Include="..\..\Source\Processors\Editors\ListSliceParser.cpp">
1789+
<Filter>open-ephys\Source\Processors\Editors</Filter>
1790+
</ClCompile>
17881791
</ItemGroup>
17891792
<ItemGroup>
17901793
<ClInclude Include="..\..\Source\CoreServices.h">
@@ -3398,6 +3401,9 @@
33983401
<ClInclude Include="..\..\JuceLibraryCode\JuceHeader.h">
33993402
<Filter>Juce Library Code</Filter>
34003403
</ClInclude>
3404+
<ClInclude Include="..\..\Source\Processors\Editors\ListSliceParser.h">
3405+
<Filter>open-ephys\Source\Processors\Editors</Filter>
3406+
</ClInclude>
34013407
</ItemGroup>
34023408
<ItemGroup>
34033409
<None Include="..\..\Resources\Fonts\cpmono-black-serialized">

Source/Processors/Editors/ChannelSelector.cpp

Lines changed: 27 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2222
*/
2323

2424
#include "ChannelSelector.h"
25+
#include "ListSliceParser.h"
2526
#include <math.h>
2627

2728
#include "../../AccessClass.h"
@@ -75,40 +76,43 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) :
7576

7677
selectButtonParam = new EditorButton("+", titleFont);
7778
selectButtonParam->addListener(this);
78-
addAndMakeVisible(selectButtonParam);
7979

8080
deselectButtonParam = new EditorButton("-", titleFont);
8181
deselectButtonParam->addListener(this);
82-
addAndMakeVisible(deselectButtonParam);
8382

8483
selectButtonRecord = new EditorButton("+", titleFont);
8584
selectButtonRecord->addListener(this);
86-
addAndMakeVisible(selectButtonRecord);
8785

8886
deselectButtonRecord = new EditorButton("-", titleFont);
8987
deselectButtonRecord->addListener(this);
90-
addAndMakeVisible(deselectButtonRecord);
9188

9289
selectButtonAudio = new EditorButton("+", titleFont);
9390
selectButtonAudio->addListener(this);
94-
addAndMakeVisible(selectButtonAudio);
9591

9692
deselectButtonAudio = new EditorButton("-", titleFont);
9793
deselectButtonAudio->addListener(this);
98-
addAndMakeVisible(deselectButtonAudio);
9994

10095
channelSelectorRegion = new ChannelSelectorRegion(this);
10196
//channelSelectorRegion->setBounds(0,20,0,getHeight()-35);
10297
addAndMakeVisible(channelSelectorRegion);
10398
channelSelectorRegion->toBack();
10499

105100
paramBox = new ChannelSelectorBox();
101+
channelSelectorRegion->addAndMakeVisible(paramBox);
106102
recordBox = new ChannelSelectorBox();
103+
channelSelectorRegion->addAndMakeVisible(recordBox);
107104
audioBox = new ChannelSelectorBox();
105+
channelSelectorRegion->addAndMakeVisible(audioBox);
106+
107+
channelSelectorRegion->addAndMakeVisible(selectButtonParam);
108+
channelSelectorRegion->addAndMakeVisible(deselectButtonParam);
109+
channelSelectorRegion->addAndMakeVisible(selectButtonRecord);
110+
channelSelectorRegion->addAndMakeVisible(deselectButtonRecord);
111+
channelSelectorRegion->addAndMakeVisible(selectButtonAudio);
112+
channelSelectorRegion->addAndMakeVisible(deselectButtonAudio);
108113

109114
numColumnsLessThan100 = 8;
110115
numColumnsGreaterThan100 = 6;
111-
112116
}
113117

114118
ChannelSelector::~ChannelSelector()
@@ -255,12 +259,9 @@ void ChannelSelector::refreshButtonBoundaries()
255259
/*
256260
definition of textbox
257261
*/
258-
paramBox->setBounds(px, py+20, 90, 20);
259-
addAndMakeVisible(paramBox);
260-
recordBox->setBounds(rx, ry+20, 90, 20);
261-
addAndMakeVisible(recordBox);
262-
audioBox->setBounds(ax, ay+20, 90, 20);
263-
addAndMakeVisible(audioBox);
262+
paramBox->setBounds(px, py, 90, 20);
263+
recordBox->setBounds(rx, ry, 90, 20);
264+
audioBox->setBounds(ax, ay, 90, 20);
264265

265266
/*
266267
audio,record and param tabs
@@ -272,14 +273,14 @@ void ChannelSelector::refreshButtonBoundaries()
272273
/*
273274
select and deselect button under each tab
274275
*/
275-
selectButtonParam->setBounds(px + 95, py + 20, 20, 20);
276-
deselectButtonParam->setBounds(px + 117, py + 20, 20, 20);
276+
selectButtonParam->setBounds(px + 95, py, 20, 20);
277+
deselectButtonParam->setBounds(px + 117, py, 20, 20);
277278

278-
selectButtonRecord->setBounds(rx + 95, ry + 20, 20, 20);
279-
deselectButtonRecord->setBounds(rx + 117, ry + 20, 20, 20);
279+
selectButtonRecord->setBounds(rx + 95, ry, 20, 20);
280+
deselectButtonRecord->setBounds(rx + 117, ry, 20, 20);
280281

281-
selectButtonAudio->setBounds(ax + 95, ay + 20, 20, 20);
282-
deselectButtonAudio->setBounds(ax + 117, ay + 20, 20, 20);
282+
selectButtonAudio->setBounds(ax + 95, ay, 20, 20);
283+
deselectButtonAudio->setBounds(ax + 117, ay, 20, 20);
283284
/*
284285
All and None buttons
285286
*/
@@ -580,6 +581,7 @@ int ChannelSelector::getDesiredWidth()
580581
void ChannelSelector::buttonClicked(Button* button)
581582
{
582583
//checkChannelSelectors();
584+
ListSliceParser* sp = new ListSliceParser("");
583585
if (button == paramsButton)
584586
{
585587
// make sure param buttons are visible
@@ -683,9 +685,8 @@ void ChannelSelector::buttonClicked(Button* button)
683685
{ // select channels in parameter tab
684686
selectButtonParam->removeListener(this);
685687
deselectButtonParam->removeListener(this);
686-
std::vector<int> getBoxList;
687688
int fa, lim, comd, i, j;
688-
getBoxList = paramBox->getBoxInfo(parameterButtons.size());
689+
std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(),parameterButtons.size());
689690
if (getBoxList.size() < 3)
690691
{
691692
selectButtonParam->addListener(this);
@@ -711,9 +712,8 @@ void ChannelSelector::buttonClicked(Button* button)
711712
{ // select channels in record tab
712713
selectButtonRecord->removeListener(this);
713714
deselectButtonRecord->removeListener(this);
714-
std::vector<int> getBoxList;
715+
std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
715716
int fa, lim, comd, i, j;
716-
getBoxList = recordBox->getBoxInfo(recordButtons.size());
717717
if (getBoxList.size() < 3)
718718
{
719719
selectButtonRecord->addListener(this);
@@ -739,9 +739,8 @@ void ChannelSelector::buttonClicked(Button* button)
739739
{ // select channels in audio tab
740740
selectButtonAudio->removeListener(this);
741741
deselectButtonAudio->removeListener(this);
742-
std::vector<int> getBoxList;
742+
std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
743743
int fa, lim, comd, i, j;
744-
getBoxList = audioBox->getBoxInfo(audioButtons.size());
745744
if (getBoxList.size() < 3)
746745
{
747746
selectButtonAudio->addListener(this);
@@ -767,9 +766,8 @@ void ChannelSelector::buttonClicked(Button* button)
767766
{ // deselect channels in param tab
768767
selectButtonParam->removeListener(this);
769768
deselectButtonParam->removeListener(this);
770-
std::vector<int> getBoxList;
769+
std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(), parameterButtons.size());
771770
int fa, lim, comd, i, j;
772-
getBoxList = paramBox->getBoxInfo(parameterButtons.size());
773771
if (getBoxList.size() < 3)
774772
{
775773
selectButtonParam->addListener(this);
@@ -795,9 +793,8 @@ void ChannelSelector::buttonClicked(Button* button)
795793
{ // deselect channels in record tab
796794
selectButtonRecord->removeListener(this);
797795
deselectButtonRecord->removeListener(this);
798-
std::vector<int> getBoxList;
796+
std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
799797
int fa, lim, comd, i, j;
800-
getBoxList = recordBox->getBoxInfo(recordButtons.size());
801798
if (getBoxList.size() < 3)
802799
{
803800
selectButtonRecord->addListener(this);
@@ -823,9 +820,8 @@ void ChannelSelector::buttonClicked(Button* button)
823820
{ // deselect channels in audio tab
824821
selectButtonAudio->removeListener(this);
825822
deselectButtonAudio->removeListener(this);
826-
std::vector<int> getBoxList;
823+
std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
827824
int fa, lim, comd, i, j;
828-
getBoxList = audioBox->getBoxInfo(audioButtons.size());
829825
if (getBoxList.size() < 3)
830826
{
831827
selectButtonAudio->addListener(this);
@@ -1229,164 +1225,4 @@ ChannelSelectorBox::ChannelSelectorBox()
12291225
ChannelSelectorBox::~ChannelSelectorBox()
12301226
{
12311227

1232-
}
1233-
1234-
/*
1235-
convert a string to integer.
1236-
*/
1237-
int ChannelSelectorBox::convertToInteger(std::string s)
1238-
{
1239-
char ar[20];
1240-
int i, j, k = 0;
1241-
for (i = 0; i < s.size(); i++)
1242-
{
1243-
if (s[i] >= 48 && s[i] <= 57)
1244-
{
1245-
ar[k] = s[i];
1246-
k++;
1247-
}
1248-
}
1249-
if (k>7)
1250-
{
1251-
return 1000000;
1252-
}
1253-
ar[k] = '\0';
1254-
k = atoi(ar);
1255-
return k;
1256-
}
1257-
1258-
1259-
/*
1260-
TextBox to take input. Valid formats:
1261-
1. [ : ] -> select/deselect all channels
1262-
2. [ a : b] -> select/deselect all channels from a to b.
1263-
3. [ a : c : b] -> select/deselect all channels from a to b such that the difference between in each consecutive selected channel is c.
1264-
*/
1265-
std::vector<int> ChannelSelectorBox::getBoxInfo(int len)
1266-
{
1267-
std::string s = ",";
1268-
s += getText().toStdString();
1269-
std::vector<int> finalList,separator,rangeseparator;
1270-
int i, j, a, b, k, openb, closeb, otherchar,x,y;
1271-
s += ",";
1272-
for (i = 0; i < s.size(); i++) //split string by ' , ' or ' ; '
1273-
{
1274-
if (s[i] == ';' || s[i] == ',')
1275-
{
1276-
separator.push_back(i);
1277-
}
1278-
}
1279-
for (i = 0; i < separator.size()-1; i++) // split ranges by ' : ' or ' - '
1280-
{
1281-
j = k = separator[i] + 1;
1282-
openb = closeb = otherchar = 0;
1283-
rangeseparator.clear();
1284-
for (; j < separator[i + 1]; j++)
1285-
{
1286-
if (s[j] == '-' || s[j] == ':')
1287-
{
1288-
rangeseparator.push_back(j);
1289-
}
1290-
else if (((int)s[j] == 32))
1291-
{
1292-
continue;
1293-
}
1294-
else if (s[j] == '[' || s[j] == '{' || s[j] == '(')
1295-
{
1296-
openb++;
1297-
}
1298-
else if (s[j] == ']' || s[j] == '}' || s[j] == ')')
1299-
{
1300-
closeb++;
1301-
}
1302-
else if ( (int)s[j] > 57 || (int)s[j] < 48)
1303-
{
1304-
otherchar++;
1305-
}
1306-
}
1307-
1308-
if (openb != closeb || openb > 1 || closeb > 1 || otherchar > 0) //Invalid input
1309-
{
1310-
continue;
1311-
}
1312-
1313-
1314-
for (x = separator[i] + 1; x < separator[i + 1]; x++) //trim whitespace and brackets from front
1315-
{
1316-
if (((int)s[x] >= 48 && (int)s[x] <= 57) || s[x] == ':' || s[x] == '-')
1317-
{
1318-
break;
1319-
}
1320-
}
1321-
for (y = separator[i + 1] - 1; y > separator[i]; y--) //trim whitespace and brackets from end
1322-
{
1323-
if (((int)s[y] >= 48 && (int)s[y] <= 57) || s[y] == ':' || s[y] == '-')
1324-
{
1325-
break;
1326-
}
1327-
}
1328-
if (x > y)
1329-
{
1330-
continue;
1331-
}
1332-
1333-
1334-
if (rangeseparator.size() == 0) //syntax of form - x or [x]
1335-
{
1336-
a = convertToInteger(s.substr(x, y - x + 1));
1337-
if (a == 0||a>len)
1338-
{
1339-
continue;
1340-
}
1341-
finalList.push_back(a - 1);
1342-
finalList.push_back(a - 1);
1343-
finalList.push_back(1);
1344-
}
1345-
else if (rangeseparator.size() == 1) // syntax of type - x-y or [x-y]
1346-
{
1347-
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
1348-
b = convertToInteger(s.substr(rangeseparator[0], y - rangeseparator[0] + 1));
1349-
if (a == 0)
1350-
{
1351-
a = 1;
1352-
}
1353-
if (b == 0)
1354-
{
1355-
b = len;
1356-
}
1357-
if (a > b || a > len || b > len)
1358-
{
1359-
continue;
1360-
}
1361-
finalList.push_back(a - 1);
1362-
finalList.push_back(b - 1);
1363-
finalList.push_back(1);
1364-
}
1365-
else if (rangeseparator.size() == 2) // syntax of type [x:y:z] or x-y-z
1366-
{
1367-
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
1368-
k = convertToInteger(s.substr(rangeseparator[0], rangeseparator[1] - rangeseparator[0] + 1));
1369-
b = convertToInteger(s.substr(rangeseparator[1], y - rangeseparator[1] + 1));
1370-
if (a == 0)
1371-
{
1372-
a = 1;
1373-
}
1374-
if (b == 0)
1375-
{
1376-
b = len;
1377-
}
1378-
if (k == 0)
1379-
{
1380-
k = 1;
1381-
}
1382-
if (a > b || a > len || b > len)
1383-
{
1384-
continue;
1385-
}
1386-
finalList.push_back(a - 1);
1387-
finalList.push_back(b - 1);
1388-
finalList.push_back(k);
1389-
}
1390-
}
1391-
return finalList;
13921228
}

Source/Processors/Editors/ChannelSelector.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,5 @@ class ChannelSelectorBox :public TextEditor
310310
public:
311311
ChannelSelectorBox();
312312
~ChannelSelectorBox();
313-
314-
std::vector<int> getBoxInfo(int len); // Extract Information from the box.
315-
int convertToInteger(std::string s); // Conversion of string to integer.
316313
};
317314
#endif // __CHANNELSELECTOR_H_68124E35__

0 commit comments

Comments
 (0)