Skip to content

Commit 08768e3

Browse files
committed
Automatically save ProbeInterface JSON files when recording starts
1 parent d3f0211 commit 08768e3

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

Source/OnixSource.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,90 @@ bool OnixSource::stopAcquisition()
11931193
return true;
11941194
}
11951195

1196+
bool OnixSource::dataStreamExists(std::string streamName, Array<const DataStream*> dataStreams)
1197+
{
1198+
for (const auto& stream : dataStreams)
1199+
{
1200+
if (stream->getName().contains(streamName))
1201+
{
1202+
return true;
1203+
}
1204+
}
1205+
1206+
return false;
1207+
}
1208+
1209+
void OnixSource::startRecording()
1210+
{
1211+
OnixDeviceVector devicesWithProbeInterface;
1212+
1213+
for (const auto& device : getEnabledDataSources())
1214+
{
1215+
if (device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1E
1216+
|| device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1F
1217+
|| device->getDeviceType() == OnixDeviceType::NEUROPIXELSV2E)
1218+
{
1219+
devicesWithProbeInterface.emplace_back(device);
1220+
}
1221+
}
1222+
1223+
if (devicesWithProbeInterface.empty())
1224+
return;
1225+
1226+
File recPath = CoreServices::getRecordingParentDirectory();
1227+
1228+
int recordNodeId = CoreServices::getAvailableRecordNodeIds().getFirst();
1229+
int experimentNumber = CoreServices::RecordNode::getExperimentNumber(recordNodeId);
1230+
1231+
auto dir = File(
1232+
recPath.getFullPathName() + File::getSeparatorString() +
1233+
CoreServices::getRecordingDirectoryName() + File::getSeparatorString() +
1234+
PLUGIN_NAME + " " + String(sn->getNodeId()) + File::getSeparatorString() +
1235+
"experiment" + String(experimentNumber));
1236+
1237+
if (!dir.exists())
1238+
{
1239+
auto result = dir.createDirectory();
1240+
1241+
if (result.failed())
1242+
{
1243+
Onix1::showWarningMessageBoxAsync("Unable to Create ONIX Source Folder",
1244+
"The plugin was unable to create a recording directory at '" + dir.getFullPathName().toStdString() + "'. No Probe Interface files will be saved for this recording, please stop recording and determine why the directory could not be created.");
1245+
return;
1246+
}
1247+
}
1248+
1249+
for (const auto& device : devicesWithProbeInterface)
1250+
{
1251+
if (device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1E || device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1F)
1252+
{
1253+
auto npx = std::static_pointer_cast<Neuropixels1>(device);
1254+
auto streamName = npx->createStreamName(); // NB: Create the automatic stream name, without any suffixes and including the port name
1255+
1256+
auto streamExists = dataStreamExists(streamName, sn->getDataStreams());
1257+
1258+
if (!streamExists)
1259+
return;
1260+
1261+
if (!npx->saveProbeInterfaceFile(dir, streamName))
1262+
return;
1263+
}
1264+
else if (device->getDeviceType() == OnixDeviceType::NEUROPIXELSV2E)
1265+
{
1266+
auto npx = std::static_pointer_cast<Neuropixels2e>(device);
1267+
auto streamName = npx->createStreamName(); // NB: Create the automatic stream name, without any suffixes and including the port name
1268+
1269+
auto streamExists = dataStreamExists(streamName, sn->getDataStreams());
1270+
1271+
if (!streamExists)
1272+
return;
1273+
1274+
if (!npx->saveProbeInterfaceFile(dir, streamName))
1275+
return;
1276+
}
1277+
}
1278+
}
1279+
11961280
bool OnixSource::updateBuffer()
11971281
{
11981282
for (const auto& source : enabledSources)

Source/OnixSource.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include "OnixSourceEditor.h"
3030
#include "FrameReader.h"
3131
#include "Devices/PortController.h"
32+
#include "Formats/ProbeInterface.h"
33+
34+
#define PLUGIN_NAME "ONIX Source"
3235

3336
namespace OnixSourcePlugin
3437
{
@@ -73,6 +76,8 @@ namespace OnixSourcePlugin
7376
/** Stops data transfer.*/
7477
bool stopAcquisition() override;
7578

79+
void startRecording();
80+
7681
void updateDiscoveryParameters(PortName port, DiscoveryParameters parameters);
7782

7883
/** Takes a string from the editor. Can be an empty string to allow for automated discovery */
@@ -177,6 +182,8 @@ namespace OnixSourcePlugin
177182
/** This method is expected to be called in a separate thread, and waits for acquisition to stop before gracefully disconnecting all devices */
178183
static void disconnectDevicesAfterAcquisition(OnixSourceEditor* editor);
179184

185+
static bool dataStreamExists(std::string streamName, Array<const DataStream*> dataStreams);
186+
180187
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OnixSource);
181188
};
182189
}

Source/OnixSourceEditor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ void OnixSourceEditor::stopAcquisition()
540540
canvas->stopAcquisition();
541541
}
542542

543+
void OnixSourceEditor::startRecording()
544+
{
545+
source->startRecording();
546+
}
547+
543548
Visualizer* OnixSourceEditor::createNewCanvas(void)
544549
{
545550
GenericProcessor* processor = (GenericProcessor*)getProcessor();

Source/OnixSourceEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace OnixSourcePlugin
6363

6464
void stopAcquisition() override;
6565

66+
void startRecording() override;
67+
6668
Visualizer* createNewCanvas(void) override;
6769

6870
void saveVisualizerEditorParameters(XmlElement* xml) override;

Source/OpenEphysLib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern "C" EXPORT void getLibInfo(Plugin::LibraryInfo* info)
4444
info->apiVersion = PLUGIN_API_VER;
4545

4646
//Name of the Library, used only for information
47-
info->name = "ONIX Source";
47+
info->name = PLUGIN_NAME;
4848

4949
//Version of the library, used only for information
5050
info->libVersion = "0.2.0";

0 commit comments

Comments
 (0)