Skip to content

Commit 8520293

Browse files
committed
Fix bug in config StorageLocation parsing
1 parent 3f888bd commit 8520293

3 files changed

Lines changed: 33 additions & 31 deletions

File tree

LabRecorder.cfg

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
; the default file name can be something like C:\\Recordings\\untitled.xdf, but can also contain
33
; placeholders. Two placeholder formats are supported: Legacy and BIDS.
44
;
5+
; For BIDS format, only a StudyRoot can be provided.
6+
; If the full StorageLocation or PathTemplate is provided
7+
; then it will be assumed that a non-BIDS format is being used.
8+
;
59
; Legacy may contain a running number (incremented per experiment session) called %n, and a
610
; placeholder for a "block" label %b (if the config script provides a list of block names that
711
; consitute a session.
8-
; The syntax is as in: StorageLocation = "C:\\Recordings\\subject%n\\block_%b.xdf"
912
;
1013
; For BIDS, the path may contain %p for participant label, %s for session label,
1114
; %b for task label (same as block in Legacy), %a for name of acquisition parameter set, and %r index.
12-
; The BIDS syntax is: path/to/CurrentStudy/sub-%p/ses-%s/eeg/sub-%p_ses-%s_task-%b[_acq-%a]_run-%r_eeg.xdf
15+
; The BIDS syntax is: path/to/StudyRoot/sub-%p/ses-%s/eeg/sub-%p_ses-%s_task-%b[_acq-%a]_run-%r_eeg.xdf
1316
;
14-
; If StorageLocation is not provided then the default is QStandardPaths::DocumentsLocation/CurrentStudy/exp%n/untitled.xdf
15-
; StorageLocation=C:/Recordings/CurrentStudy/sub-%p/ses-%s/behav/sub-%p_ses-%s_task-%b[_acq-%a]_run-%r_eeg.xdf
17+
; If neither StorageLocation or StudyRoot is provided then the default root is QStandardPaths::DocumentsLocation/CurrentStudy/
18+
; If neither StorageLocation or PathTemplate are provided, then the BIDS format is assumed, or the file template exp%n/block_%b.xdf if BIDS is unchecked.
1619

17-
; === Study Root ===
18-
; You can optionally provide only the study root folder and it will be used to build a file name automatically.
19-
; The default filename builder is Legacy (see above).
20-
; StudyRoot=C:/Recordings/CurrentStudy
20+
; StorageLocation=C:/Recordings/CurrentStudy/sub-%p/ses-%s/behav/sub-%p_ses-%s_task-%b_acq-%a_run-%r_eeg.xdf
21+
; StudyRoot=C:/Recordings/CurrentStudy/
22+
; PathTemplate=exp%n/block_%b.xdf
2123

2224
; === Block Names ===
2325
; This is optionally a list of blocks that make up a recording session. The blocks are displayed in

LabRecorder_BIDS.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
; BIDS config, files are saved in the specified StudyRoot
1+
; BIDS config, provide only the StudyRoot
22
StudyRoot=C:/Recordings/CurrentStudy

src/mainwindow.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,12 @@ void MainWindow::load_config(QString filename) {
163163
// StorageLocation
164164
QString studyRoot;
165165
legacyTemplate.clear();
166-
// StudyRoot
167-
if (pt.contains("StudyRoot")) { studyRoot = pt.value("StudyRoot").toString(); }
168-
166+
169167
if (pt.contains("StorageLocation")) {
170-
if (!studyRoot.isEmpty())
171-
throw std::runtime_error("Both StudyRoot and StorageLocation specified");
168+
if (pt.contains("StudyRoot"))
169+
throw std::runtime_error("StorageLocation cannot be used if StudyRoot is also specified.");
172170
if (pt.contains("PathTemplate"))
173-
throw std::runtime_error("Both StorageLocation and PathTemplate specified");
171+
throw std::runtime_error("StorageLocation cannot be used if PathTemplate is also specified.");
174172

175173
QString str_path = pt.value("StorageLocation").toString();
176174
QString path_root;
@@ -181,16 +179,18 @@ void MainWindow::load_config(QString filename) {
181179
// foo/bar/baz%a/untitled.xdf gets split into
182180
// foo/bar and baz%a/untitled.xdf
183181
path_root = str_path.left(index);
184-
} else
182+
} else {
185183
// Otherwise, it's split into folder and constant filename
186184
path_root = str_path;
187-
path_root = QFileInfo(path_root).path();
188-
legacyTemplate = str_path.remove(0, path_root.length() + 1);
189-
// absolute path, nothing to be done
185+
}
190186
studyRoot = QFileInfo(path_root).absolutePath();
191-
ui->lineEdit_template->setText(QDir::toNativeSeparators(legacyTemplate));
187+
legacyTemplate = str_path.remove(0, studyRoot.length() + 1);
188+
// absolute path, nothing to be done
189+
// studyRoot = QFileInfo(path_root).absolutePath();
192190
}
193-
if (pt.contains("PathTemplate")) legacyTemplate = pt.value("PathTemplate").toString();
191+
// StudyRoot
192+
if (pt.contains("StudyRoot")) { studyRoot = pt.value("StudyRoot").toString(); }
193+
if (pt.contains("PathTemplate")) { legacyTemplate = pt.value("PathTemplate").toString(); }
194194

195195
if (studyRoot.isEmpty())
196196
studyRoot = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) +
@@ -199,7 +199,7 @@ void MainWindow::load_config(QString filename) {
199199

200200
if (legacyTemplate.isEmpty()) {
201201
ui->check_bids->setChecked(true);
202-
// Legacy takes the form path/to/study/exp%n/%b.xdf
202+
// Use default, exp%n/%b.xdf , only to be used if BIDS gets unchecked.
203203
legacyTemplate = "exp%n/block_%b.xdf";
204204
} else {
205205
ui->check_bids->setChecked(false);
@@ -211,20 +211,20 @@ void MainWindow::load_config(QString filename) {
211211
ui->input_modality->count(), pt.value("BidsModalities", bids_modalities_default).toStringList());
212212
ui->input_modality->setCurrentIndex(0);
213213

214-
buildFilename();
214+
buildFilename();
215215

216216
// Remote Control Socket options
217217
if (pt.contains("RCSPort")) {
218-
int rcs_port = pt.value("RCSPort").toInt();
218+
int rcs_port = pt.value("RCSPort").toInt();
219219
ui->rcsport->setValue(rcs_port);
220-
// In case it's already running (how?), stop the RCS listener.
220+
// In case it's already running (how?), stop the RCS listener.
221221
ui->rcsCheckBox->setChecked(false);
222-
}
223-
224-
if (pt.contains("RCSEnabled")) {
225-
bool b_enable_rcs = pt.value("RCSEnabled").toBool();
222+
}
223+
224+
if (pt.contains("RCSEnabled")) {
225+
bool b_enable_rcs = pt.value("RCSEnabled").toBool();
226226
ui->rcsCheckBox->setChecked(b_enable_rcs);
227-
}
227+
}
228228

229229
// Check the wild-card-replaced filename to see if it exists already.
230230
// If it does then increment the exp number.
@@ -445,7 +445,7 @@ void MainWindow::buildFilename() {
445445
// This function is only called when a widget within Location Builder is activated.
446446

447447
// Build the file location in parts, starting with the root folder.
448-
if (ui->check_bids->isChecked()) buildBidsTemplate();
448+
if (ui->check_bids->isChecked()) { buildBidsTemplate(); }
449449
QString tpl = QDir::cleanPath(ui->lineEdit_template->text());
450450

451451
// Auto-increment Spin/Run Number if necessary.

0 commit comments

Comments
 (0)