Skip to content

Commit 2c1e0d2

Browse files
committed
Merge branch 'main' into issue-108
2 parents 1020ec1 + 03af98e commit 2c1e0d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2041
-714
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "liboni"]
2+
path = liboni
3+
url = https://github.com/open-ephys/liboni

CMakeLists.txt

Lines changed: 77 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required(VERSION 3.5.0)
2+
23
if (NOT DEFINED GUI_BASE_DIR)
34
if (DEFINED ENV{GUI_BASE_DIR})
45
set(GUI_BASE_DIR $ENV{GUI_BASE_DIR})
@@ -12,12 +13,6 @@ get_filename_component(PLUGIN_NAME ${PROJECT_FOLDER} NAME)
1213

1314
project(OE_PLUGIN_${PLUGIN_NAME})
1415
set(CMAKE_SHARED_LIBRARY_PREFIX "")
15-
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
16-
set(LINUX 1)
17-
if(NOT CMAKE_BUILD_TYPE)
18-
set(CMAKE_BUILD_TYPE Debug)
19-
endif()
20-
endif()
2116

2217
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
2318
OEPLUGIN
@@ -29,7 +24,6 @@ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
2924
$<$<CONFIG:Release>:NDEBUG=1>
3025
)
3126

32-
3327
set(SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Source)
3428
file(GLOB_RECURSE SRC_FILES LIST_DIRECTORIES false "${SOURCE_PATH}/*.cpp" "${SOURCE_PATH}/*.h")
3529
set(GUI_COMMONLIB_DIR ${GUI_BASE_DIR}/installed_libs)
@@ -38,11 +32,7 @@ set(CONFIGURATION_FOLDER $<$<CONFIG:Debug>:Debug>$<$<NOT:$<CONFIG:Debug>>:Releas
3832

3933
list(APPEND CMAKE_PREFIX_PATH ${GUI_COMMONLIB_DIR} ${GUI_COMMONLIB_DIR}/${CONFIGURATION_FOLDER})
4034

41-
if (APPLE)
42-
add_library(${PLUGIN_NAME} MODULE ${SRC_FILES})
43-
else()
44-
add_library(${PLUGIN_NAME} SHARED ${SRC_FILES})
45-
endif()
35+
add_library(${PLUGIN_NAME} SHARED ${SRC_FILES})
4636

4737
target_compile_features(${PLUGIN_NAME} PUBLIC cxx_auto_type cxx_generalized_initializers)
4838
target_include_directories(${PLUGIN_NAME} PUBLIC ${GUI_BASE_DIR}/JuceLibraryCode ${GUI_BASE_DIR}/JuceLibraryCode/modules ${GUI_BASE_DIR}/Plugins/Headers ${GUI_COMMONLIB_DIR}/include)
@@ -60,30 +50,13 @@ if (NOT CMAKE_LIBRARY_ARCHITECTURE)
6050
endif()
6151

6252
#Libraries and compiler options
63-
if(MSVC)
64-
target_link_libraries(${PLUGIN_NAME} ${GUI_BIN_DIR}/open-ephys.lib)
65-
target_compile_options(${PLUGIN_NAME} PRIVATE /sdl- /W0)
66-
67-
install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION ${GUI_BIN_DIR}/plugins CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
68-
install(FILES $<TARGET_PDB_FILE:${PLUGIN_NAME}> DESTINATION ${GUI_BIN_DIR}/plugins OPTIONAL)
69-
70-
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../libs)
71-
elseif(LINUX)
72-
target_link_libraries(${PLUGIN_NAME} GL X11 Xext Xinerama asound dl freetype pthread rt)
73-
set_property(TARGET ${PLUGIN_NAME} APPEND_STRING PROPERTY LINK_FLAGS
74-
"-fvisibility=hidden -fPIC -rdynamic -Wl,-rpath,'$$ORIGIN/../shared'")
75-
target_compile_options(${PLUGIN_NAME} PRIVATE -fPIC -rdynamic)
76-
target_compile_options(${PLUGIN_NAME} PRIVATE -O3) #enable optimization for linux debug
77-
78-
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${GUI_BIN_DIR}/plugins)
79-
elseif(APPLE)
80-
set_target_properties(${PLUGIN_NAME} PROPERTIES BUNDLE TRUE)
81-
set_property(TARGET ${PLUGIN_NAME} APPEND_STRING PROPERTY LINK_FLAGS
82-
"-undefined dynamic_lookup -rpath @loader_path/../../../../shared")
83-
84-
install(TARGETS ${PLUGIN_NAME} DESTINATION $ENV{HOME}/Library/Application\ Support/open-ephys/plugins-api8)
85-
set(CMAKE_PREFIX_PATH /opt/local)
86-
endif()
53+
target_link_libraries(${PLUGIN_NAME} ${GUI_BIN_DIR}/open-ephys.lib)
54+
target_compile_options(${PLUGIN_NAME} PRIVATE /sdl- /W0 /MP)
55+
56+
install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION ${GUI_BIN_DIR}/plugins CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
57+
install(FILES $<TARGET_PDB_FILE:${PLUGIN_NAME}> DESTINATION ${GUI_BIN_DIR}/plugins OPTIONAL)
58+
59+
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../libs)
8760

8861
#create filters for vs and xcode
8962

@@ -94,22 +67,71 @@ foreach( src_file IN ITEMS ${SRC_FILES})
9467
source_group("${group_name}" FILES "${src_file}")
9568
endforeach()
9669

97-
#additional libraries, if needed
98-
set(LIBONI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libONI)
99-
target_include_directories(${PLUGIN_NAME} PRIVATE ${LIBONI_DIR}/include)
100-
101-
if (MSVC)
102-
set(LIBONI_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libONI/win64)
103-
target_link_libraries(${PLUGIN_NAME} "${LIBONI_LIB_DIR}/liboni.lib")
104-
target_link_libraries(${PLUGIN_NAME} "${LIBONI_LIB_DIR}/riffa.lib")
105-
target_link_libraries(${PLUGIN_NAME} "${LIBONI_LIB_DIR}/onidriver_riffa.lib")
106-
install(DIRECTORY ${LIBONI_LIB_DIR}/ DESTINATION ${GUI_BIN_DIR}/shared FILES_MATCHING PATTERN "*.dll")
107-
elseif(LINUX)
108-
find_library(LIBONI_LIBRARIES oni liboni PATHS ${CMAKE_CURRENT_SOURCE_DIR}/libONI/linux)
109-
target_link_libraries(${PLUGIN_NAME} ${LIBONI_LIBRARIES})
110-
install(DIRECTORY ${LIBONI_DIR}/linux/ DESTINATION ${GUI_BIN_DIR}/shared FILES_MATCHING PATTERN "*.so")
111-
elseif(APPLE)
112-
set(LIBONI_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libONI/osx)
113-
target_link_libraries(${PLUGIN_NAME} "${LIBONI_LIB_DIR}/liboni.dylib")
114-
install(FILES ${LIBONI_LIB_DIR}/liboni.dylib DESTINATION $ENV{HOME}/Library/Application\ Support/open-ephys/shared-api8)
115-
endif()
70+
71+
function(vs_set_all_configurations target_name target_config_name)
72+
foreach(config ${CMAKE_CONFIGURATION_TYPES})
73+
string(TOUPPER ${config} config_upper)
74+
set_property(
75+
TARGET ${target_name}
76+
APPEND PROPERTY MAP_IMPORTED_CONFIG_${config_upper} "${target_config_name}"
77+
)
78+
endforeach()
79+
endfunction()
80+
81+
82+
# add liboni project
83+
84+
set(LIBONI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/liboni/api/liboni")
85+
set(LIBONI_NAME liboni)
86+
set(LIBONI_PNAME "submodule_${LIBONI_NAME}")
87+
88+
include_external_msproject (
89+
${LIBONI_PNAME}
90+
"${LIBONI_DIR}/liboni.vcxproj"
91+
PLATFORM ${CMAKE_LIBRARY_ARCHITECTURE}
92+
)
93+
94+
vs_set_all_configurations(${LIBONI_PNAME} "ReleaseStatic")
95+
96+
add_library("${LIBONI_NAME}" STATIC IMPORTED)
97+
set_target_properties("${LIBONI_NAME}" PROPERTIES
98+
IMPORTED_LOCATION "${LIBONI_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}/ReleaseStatic/liboni.lib"
99+
INTERFACE_INCLUDE_DIRECTORIES "${LIBONI_DIR}")
100+
101+
add_dependencies(${LIBONI_NAME} ${LIBONI_PNAME})
102+
target_link_libraries(${PLUGIN_NAME} "${LIBONI_NAME}")
103+
104+
# add riffa project
105+
106+
set(RIFFA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/liboni/drivers/riffa/windows/lib")
107+
set(RIFFA_NAME riffa)
108+
set(RIFFA_PNAME "submodule_${RIFFA_NAME}")
109+
110+
include_external_msproject (
111+
${RIFFA_PNAME}
112+
"${RIFFA_DIR}/riffa.vcxproj"
113+
PLATFORM ${CMAKE_LIBRARY_ARCHITECTURE}
114+
)
115+
116+
vs_set_all_configurations(${RIFFA_PNAME} "Release")
117+
118+
# add onidriver_riffa project
119+
120+
set(ONIDRIVER_RIFFA_DIR "${LIBONI_DIR}/drivers/riffa")
121+
set(ONIDRIVER_RIFFA_NAME libonidriver_riffa)
122+
set(ONIDRIVER_RIFFA_PNAME "submodule_${ONIDRIVER_RIFFA_NAME}")
123+
124+
include_external_msproject (
125+
${ONIDRIVER_RIFFA_PNAME}
126+
"${ONIDRIVER_RIFFA_DIR}/onidriver_riffa.vcxproj"
127+
PLATFORM ${CMAKE_LIBRARY_ARCHITECTURE}
128+
)
129+
130+
vs_set_all_configurations(${ONIDRIVER_RIFFA_PNAME} "Release")
131+
132+
133+
add_dependencies(${ONIDRIVER_RIFFA_PNAME} ${RIFFA_PNAME})
134+
135+
# Ensure needed DLLs are installed to the shared folder
136+
137+
install(FILES "${CMAKE_BINARY_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}/$<CONFIG>/riffa.dll" "${CMAKE_BINARY_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}/$<CONFIG>/${ONIDRIVER_RIFFA_NAME}.dll" DESTINATION ${GUI_BIN_DIR}/shared)

README.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ Code
2929
│ └── ...
3030
```
3131

32+
To get a fresh install of the repository, use `git clone --recurse-submodules` to fetch the submodule as well.
33+
34+
For existing clones of the repo, run `git submodule update --init --recursive` to initialize the submodule and update it simultaneously.
35+
3236
### Windows
3337

3438
**Requirements:** [Visual Studio](https://visualstudio.microsoft.com/) and [CMake](https://cmake.org/install/)
3539

40+
#### Create OnixSource project using CMAKE
41+
3642
From the `Build` directory, enter:
3743

3844
```bash
@@ -42,38 +48,4 @@ cmake -G "Visual Studio 17 2022" -A x64 ..
4248
Next, launch Visual Studio and open the `OE_PLUGIN_onix-source.sln` file that was just created. Select the appropriate configuration (Debug/Release) and build the solution.
4349

4450
Selecting the `INSTALL` project and manually building it will copy the `.dll` and any other required files into the GUI's `plugins` directory. The next time you launch the GUI from Visual Studio, the ONIX Source plugin should be available.
45-
46-
47-
### Linux
48-
49-
**Requirements:** [CMake](https://cmake.org/install/)
50-
51-
From the `Build` directory, enter:
52-
53-
```bash
54-
cmake -G "Unix Makefiles" ..
55-
cd Debug
56-
make -j
57-
make install
58-
```
59-
60-
This will build the plugin and copy the `.so` file into the GUI's `plugins` directory. The next time you launch the compiled version of the GUI, the ONIX Source plugin should be available.
61-
62-
63-
### macOS
64-
65-
**Requirements:** [Xcode](https://developer.apple.com/xcode/) and [CMake](https://cmake.org/install/)
66-
67-
From the `Build` directory, enter:
68-
69-
```bash
70-
cmake -G "Xcode" ..
71-
```
72-
73-
Next, launch Xcode and open the `onix-source.xcodeproj` file that now lives in the “Build” directory.
74-
75-
Running the `ALL_BUILD` scheme will compile the plugin; running the `INSTALL` scheme will install the `.bundle` file to `/Users/<username>/Library/Application Support/open-ephys/plugins-api8`. the ONIX Source plugin should be available the next time you launch the GUI from Xcode.
76-
77-
78-
7951

Source/Devices/AnalogIO.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,9 @@ void AnalogIO::startAcquisition()
195195
analogInputSamples.fill(0);
196196
}
197197

198-
void AnalogIO::stopAcquisition()
199-
{
200-
while (!frameArray.isEmpty())
201-
{
202-
oni_destroy_frame(frameArray.removeAndReturn(0));
203-
}
204-
}
205-
206-
void AnalogIO::addFrame(oni_frame_t* frame)
207-
{
208-
frameArray.add(frame);
209-
}
210-
211198
int AnalogIO::getNumberOfFrames()
212199
{
213-
return frameArray.size();
200+
return frameQueue.size_approx();
214201
}
215202

216203
void AnalogIO::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
@@ -221,7 +208,10 @@ void AnalogIO::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
221208

222209
void AnalogIO::processFrame(uint64_t eventWord)
223210
{
224-
oni_frame_t* frame = frameArray.removeAndReturn(0);
211+
oni_frame_t* frame;
212+
if (!frameQueue.try_dequeue(frame)) { //NB: This method should never be called unless a frame is sure to be there
213+
jassertfalse;
214+
}
225215

226216
int16_t* dataPtr = (int16_t*)frame->data;
227217

@@ -272,7 +262,7 @@ void AnalogIO::processFrame(uint64_t eventWord)
272262

273263
void AnalogIO::processFrames()
274264
{
275-
while (!frameArray.isEmpty())
265+
while (frameQueue.peek() != nullptr )
276266
{
277267
processFrame();
278268
}

Source/Devices/AnalogIO.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ namespace OnixSourcePlugin
7474
int configureDevice() override;
7575
bool updateSettings() override;
7676
void startAcquisition() override;
77-
void stopAcquisition() override;
7877
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override;
79-
void addFrame(oni_frame_t*) override;
8078
void processFrames() override;
8179

8280
void processFrame(uint64_t eventWord = 0);
@@ -117,8 +115,6 @@ namespace OnixSourcePlugin
117115

118116
AnalogIODataType dataType = AnalogIODataType::Volts;
119117

120-
Array<oni_frame_t*, CriticalSection, numFrames> frameArray;
121-
122118
unsigned short currentFrame = 0;
123119
unsigned short currentAverageFrame = 0;
124120
int sampleNumber = 0;

Source/Devices/AuxiliaryIO.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,9 @@ bool AuxiliaryIO::isEnabled() const
5656

5757
void AuxiliaryIO::processFrames()
5858
{
59-
if (!digitalIO->isEnabled() && !analogIO->isEnabled())
60-
{
61-
return;
62-
}
63-
else if (!digitalIO->isEnabled())
64-
{
65-
analogIO->processFrames();
66-
return;
67-
}
68-
else if (!analogIO->isEnabled())
69-
{
70-
digitalIO->processFrames();
71-
while (digitalIO->hasEventWord())
72-
{
73-
digitalIO->getEventWord();
74-
}
75-
76-
return;
77-
}
78-
7959
digitalIO->processFrames();
8060

81-
while (analogIO->getNumberOfFrames() >= AnalogIO::framesToAverage && digitalIO->getNumberOfWords() >= 1)
61+
while (digitalIO->hasEventWord() && analogIO->getNumberOfFrames() >= AnalogIO::framesToAverage)
8262
{
8363
auto eventWord = digitalIO->getEventWord();
8464

Source/Devices/Bno055.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,6 @@ void Bno055::startAcquisition()
153153
sampleNumber = 0;
154154
}
155155

156-
void Bno055::stopAcquisition()
157-
{
158-
while (!frameArray.isEmpty())
159-
{
160-
oni_destroy_frame(frameArray.removeAndReturn(0));
161-
}
162-
163-
currentFrame = 0;
164-
sampleNumber = 0;
165-
}
166-
167-
void Bno055::addFrame(oni_frame_t* frame)
168-
{
169-
frameArray.add(frame);
170-
}
171-
172156
void Bno055::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
173157
{
174158
sourceBuffers.add(new DataBuffer(numberOfChannels, (int)sampleRate * bufferSizeInSeconds));
@@ -177,10 +161,9 @@ void Bno055::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
177161

178162
void Bno055::processFrames()
179163
{
180-
while (!frameArray.isEmpty())
164+
oni_frame_t* frame;
165+
while (frameQueue.try_dequeue(frame))
181166
{
182-
oni_frame_t* frame = frameArray.removeAndReturn(0);
183-
184167
int16_t* dataPtr = ((int16_t*)frame->data) + 4;
185168

186169
bnoTimestamps[currentFrame] = deviceContext->convertTimestampToSeconds(frame->time);

Source/Devices/Bno055.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,9 @@ namespace OnixSourcePlugin
4242
Bno055(std::string name, std::string hubName, const oni_dev_idx_t, std::shared_ptr<Onix1> ctx);
4343

4444
int configureDevice() override;
45-
46-
/** Update the settings of the device */
4745
bool updateSettings() override;
48-
49-
/** Starts probe data streaming */
5046
void startAcquisition() override;
51-
52-
/** Stops probe data streaming*/
53-
void stopAcquisition() override;
54-
55-
void addFrame(oni_frame_t*) override;
56-
5747
void processFrames() override;
58-
5948
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override;
6049

6150
static OnixDeviceType getDeviceType();
@@ -70,8 +59,6 @@ namespace OnixSourcePlugin
7059

7160
static const int numFrames = 2;
7261

73-
Array<oni_frame_t*, CriticalSection, numFrames> frameArray;
74-
7562
bool shouldAddToBuffer = false;
7663

7764
static const int numberOfChannels = 3 + 3 + 4 + 3 + 1 + 4;

0 commit comments

Comments
 (0)