Skip to content

Commit 94c3cd5

Browse files
committed
Automatically save ProbeInterface JSON files when recording starts
1 parent c14ee3a commit 94c3cd5

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

Source/OnixSource.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,90 @@ bool OnixSource::stopAcquisition()
12041204
return true;
12051205
}
12061206

1207+
bool OnixSource::dataStreamExists(std::string streamName, Array<const DataStream*> dataStreams)
1208+
{
1209+
for (const auto& stream : dataStreams)
1210+
{
1211+
if (stream->getName().contains(streamName))
1212+
{
1213+
return true;
1214+
}
1215+
}
1216+
1217+
return false;
1218+
}
1219+
1220+
void OnixSource::startRecording()
1221+
{
1222+
OnixDeviceVector devicesWithProbeInterface;
1223+
1224+
for (const auto& device : getEnabledDataSources())
1225+
{
1226+
if (device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1E
1227+
|| device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1F
1228+
|| device->getDeviceType() == OnixDeviceType::NEUROPIXELSV2E)
1229+
{
1230+
devicesWithProbeInterface.emplace_back(device);
1231+
}
1232+
}
1233+
1234+
if (devicesWithProbeInterface.empty())
1235+
return;
1236+
1237+
File recPath = CoreServices::getRecordingParentDirectory();
1238+
1239+
int recordNodeId = CoreServices::getAvailableRecordNodeIds().getFirst();
1240+
int experimentNumber = CoreServices::RecordNode::getExperimentNumber(recordNodeId);
1241+
1242+
auto dir = File(
1243+
recPath.getFullPathName() + File::getSeparatorString() +
1244+
CoreServices::getRecordingDirectoryName() + File::getSeparatorString() +
1245+
PLUGIN_NAME + " " + String(sn->getNodeId()) + File::getSeparatorString() +
1246+
"experiment" + String(experimentNumber));
1247+
1248+
if (!dir.exists())
1249+
{
1250+
auto result = dir.createDirectory();
1251+
1252+
if (result.failed())
1253+
{
1254+
Onix1::showWarningMessageBoxAsync("Unable to Create ONIX Source Folder",
1255+
"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.");
1256+
return;
1257+
}
1258+
}
1259+
1260+
for (const auto& device : devicesWithProbeInterface)
1261+
{
1262+
if (device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1E || device->getDeviceType() == OnixDeviceType::NEUROPIXELSV1F)
1263+
{
1264+
auto npx = std::static_pointer_cast<Neuropixels1>(device);
1265+
auto streamName = npx->createStreamName(); // NB: Create the automatic stream name, without any suffixes and including the port name
1266+
1267+
auto streamExists = dataStreamExists(streamName, sn->getDataStreams());
1268+
1269+
if (!streamExists)
1270+
return;
1271+
1272+
if (!npx->saveProbeInterfaceFile(dir, streamName))
1273+
return;
1274+
}
1275+
else if (device->getDeviceType() == OnixDeviceType::NEUROPIXELSV2E)
1276+
{
1277+
auto npx = std::static_pointer_cast<Neuropixels2e>(device);
1278+
auto streamName = npx->createStreamName(); // NB: Create the automatic stream name, without any suffixes and including the port name
1279+
1280+
auto streamExists = dataStreamExists(streamName, sn->getDataStreams());
1281+
1282+
if (!streamExists)
1283+
return;
1284+
1285+
if (!npx->saveProbeInterfaceFile(dir, streamName))
1286+
return;
1287+
}
1288+
}
1289+
}
1290+
12071291
bool OnixSource::updateBuffer()
12081292
{
12091293
for (const auto& source : enabledSources)

Source/OnixSource.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
#include <DataThreadHeaders.h>
2626

2727
#include "Devices/PortController.h"
28+
#include "Formats/ProbeInterface.h"
2829
#include "FrameReader.h"
2930
#include "Onix1.h"
3031
#include "OnixDevice.h"
3132
#include "OnixSourceEditor.h"
3233

34+
#define PLUGIN_NAME "ONIX Source"
35+
3336
namespace OnixSourcePlugin
3437
{
3538
/**
@@ -72,6 +75,8 @@ class OnixSource : public DataThread
7275
/** Stops data transfer.*/
7376
bool stopAcquisition() override;
7477

78+
void startRecording();
79+
7580
void updateDiscoveryParameters (PortName port, DiscoveryParameters parameters);
7681

7782
/** Takes a string from the editor. Can be an empty string to allow for automated discovery */
@@ -175,6 +180,8 @@ class OnixSource : public DataThread
175180
/** This method is expected to be called in a separate thread, and waits for acquisition to stop before gracefully disconnecting all devices */
176181
static void disconnectDevicesAfterAcquisition (OnixSourceEditor* editor);
177182

183+
static bool dataStreamExists (std::string streamName, Array<const DataStream*> dataStreams);
184+
178185
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OnixSource);
179186
};
180187
} // namespace OnixSourcePlugin

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.1";

0 commit comments

Comments
 (0)