Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp update #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions LogicGate/Build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore

21 changes: 21 additions & 0 deletions LogicGate/CMAKE_README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
To generate build files for your platform run in a command terminal:
cd Build
cmake -G GENERATOR ..

Valid generators are:
Windows:
"Visual Studio 12 2013 Win64"
"Visual Studio 14 2015 Win64"
"Visual Studio 15 2017 Win64"
Mac:
"Xcode"
Linux: (see note below)
"Unix Makefiles"

Example: cmake -G "Visual Studio 12 2013 Win64" ..

For Linux Only:
On linux, Debug and Release options are generated by cmake and must be specified like so:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
or
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
101 changes: 101 additions & 0 deletions LogicGate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
cmake_minimum_required(VERSION 3.5.0)
if (NOT DEFINED GUI_BASE_DIR)
if (DEFINED ENV{GUI_BASE_DIR})
set(GUI_BASE_DIR $ENV{GUI_BASE_DIR})
else()
set(GUI_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../plugin-GUI)
endif()
endif()

get_filename_component(PROJECT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
get_filename_component(PLUGIN_NAME ${PROJECT_FOLDER} NAME)

project(OE_PLUGIN_${PLUGIN_NAME})
set(CMAKE_SHARED_LIBRARY_PREFIX "")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LINUX 1)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
endif()

set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
OEPLUGIN
"$<$<PLATFORM_ID:Windows>:JUCE_API=__declspec(dllimport)>"
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
$<$<PLATFORM_ID:Linux>:JUCE_DISABLE_NATIVE_FILECHOOSERS=1>
$<$<CONFIG:Debug>:DEBUG=1>
$<$<CONFIG:Debug>:_DEBUG=1>
$<$<CONFIG:Release>:NDEBUG=1>
)


set(SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Source)
file(GLOB_RECURSE SRC_FILES LIST_DIRECTORIES false "${SOURCE_PATH}/*.cpp" "${SOURCE_PATH}/*.h")
set(GUI_COMMONLIB_DIR ${GUI_BASE_DIR}/installed_libs)

set(CONFIGURATION_FOLDER $<$<CONFIG:Debug>:Debug>$<$<NOT:$<CONFIG:Debug>>:Release>)

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

if (APPLE)
add_library(${PLUGIN_NAME} MODULE ${SRC_FILES})
else()
add_library(${PLUGIN_NAME} SHARED ${SRC_FILES})
endif()

target_compile_features(${PLUGIN_NAME} PUBLIC cxx_auto_type cxx_generalized_initializers)
target_include_directories(${PLUGIN_NAME} PUBLIC ${GUI_BASE_DIR}/JuceLibraryCode ${GUI_BASE_DIR}/JuceLibraryCode/modules ${GUI_BASE_DIR}/Plugins/Headers ${GUI_COMMONLIB_DIR}/include)

set(GUI_BIN_DIR ${GUI_BASE_DIR}/Build/${CONFIGURATION_FOLDER})

if (NOT CMAKE_LIBRARY_ARCHITECTURE)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_LIBRARY_ARCHITECTURE "x64")
else()
set(CMAKE_LIBRARY_ARCHITECTURE "x86")
endif()
endif()

#Libraries and compiler options
if(MSVC)
target_link_libraries(${PLUGIN_NAME} ${GUI_BIN_DIR}/open-ephys.lib)
target_compile_options(${PLUGIN_NAME} PRIVATE /sdl-)

install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION ${GUI_BIN_DIR}/plugins CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})

set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../libs)
elseif(LINUX)
target_link_libraries(${PLUGIN_NAME} GL X11 Xext Xinerama asound dl freetype pthread rt)
set_property(TARGET ${PLUGIN_NAME} APPEND_STRING PROPERTY LINK_FLAGS
"-fvisibility=hidden -fPIC -rdynamic -Wl,-rpath,'$$ORIGIN/../shared'")
target_compile_options(${PLUGIN_NAME} PRIVATE -fPIC -rdynamic)
target_compile_options(${PLUGIN_NAME} PRIVATE -O3) #enable optimization for linux debug

install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${GUI_BIN_DIR}/plugins)
elseif(APPLE)
set_target_properties(${PLUGIN_NAME} PROPERTIES BUNDLE TRUE)
set_property(TARGET ${PLUGIN_NAME} APPEND_STRING PROPERTY LINK_FLAGS
"-undefined dynamic_lookup -rpath @loader_path/../../../../shared")

install(TARGETS ${PLUGIN_NAME} DESTINATION $ENV{HOME}/Library/Application\ Support/open-ephys/PlugIns)
set(CMAKE_PREFIX_PATH /opt/local)
endif()

#create filters for vs and xcode

foreach( src_file IN ITEMS ${SRC_FILES})
get_filename_component(src_path "${src_file}" PATH)
file(RELATIVE_PATH src_path_rel "${SOURCE_PATH}" "${src_path}")
string(REPLACE "/" "\\" group_name "${src_path_rel}")
source_group("${group_name}" FILES "${src_file}")
endforeach()

#additional libraries, if needed
#find_package(LIBNAME)
#or
#find_library(LIBNAME_LIBRARIES NAMES libname)
#find_path(LIBNAME_INCLUDE_DIRS includefile.h)
#
#target_link_libraries(${PLUGIN_NAME} ${LIBNAME_LIBRARIES})
#target_include_directories(${PLUGIN_NAME} PRIVATE ${LIBNAME_INCLUDE_DIRS})
39 changes: 0 additions & 39 deletions LogicGate/Makefile

This file was deleted.

92 changes: 75 additions & 17 deletions LogicGate/LogicGate.cpp → LogicGate/Source/LogicGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@


LogicGate::LogicGate()
: GenericProcessor ("Logic Gate"),
m_logicOp(0),
m_outputChan(0),
m_window(DEF_WINDOW),
m_input1(-1),
m_input2(-1),
m_input1gate(false),
m_input2gate(false),
m_pulseDuration(2)
: GenericProcessor("Logic Gate"),
m_logicOp(0),
m_outputChan(0),
m_window(DEF_WINDOW),
m_input1(-1),
m_input2(-1),
m_input1gate(false),
m_input2gate(false),
m_pulseDuration(2),
A_ts(0),
B_ts(0),
turnOffEvent(nullptr),
nSamples(0)
{
setProcessorType (PROCESSOR_TYPE_FILTER);
}
Expand All @@ -64,11 +68,34 @@ AudioProcessorEditor* LogicGate::createEditor()

void LogicGate::createEventChannels()
{
// grab a channel to look at source
const DataChannel* in = getDataChannel(0);

if (!in)
{
eventChannelPtr = nullptr;
return;
}

EventChannel* ev = new EventChannel(EventChannel::TTL, 8, 1, CoreServices::getGlobalSampleRate(), this);
ev->setName("Logic Gate TTL output" );
ev->setDescription("Triggers when logic operator is satisfied.");
ev->setIdentifier ("dataderived.logicgate.trigger");
eventChannelArray.add (ev);

// metadata storing source data channel

MetaDataDescriptor sourceChanDesc(MetaDataDescriptor::UINT16, 3, "Source Channel",
"Index at its source, Source processor ID and Sub Processor index of the channel that triggers this event", "source.channel.identifier.full");
MetaDataValue sourceChanVal(sourceChanDesc);
uint16 sourceInfo[3];
sourceInfo[0] = in->getSourceIndex();
sourceInfo[1] = in->getSourceNodeID();
sourceInfo[2] = in->getSubProcessorIdx();
sourceChanVal.setValue(static_cast<const uint16*>(sourceInfo));
ev->addMetaData(sourceChanDesc, sourceChanVal);


eventChannelPtr = eventChannelArray.add (ev);
}

void LogicGate::handleEvent (const EventChannel* eventInfo, const MidiMessage& event, int sampleNum)
Expand All @@ -80,6 +107,7 @@ void LogicGate::handleEvent (const EventChannel* eventInfo, const MidiMessage& e
const int eventId = ttl->getSourceIndex();
const int sourceId = ttl->getSourceID();
const int eventChannel = ttl->getChannel();
const int64 ts = ttl->getTimestamp(); // Need to save exact timestamp of event for LFP viewer

if (m_input1 != -1)
{
Expand All @@ -89,6 +117,7 @@ void LogicGate::handleEvent (const EventChannel* eventInfo, const MidiMessage& e
{
std::cout << "Received A " << std::endl;
A = true;
A_ts = ts;

if ((m_input1gate) || (!m_input1gate && !m_input2gate))
m_previousTime = Time::currentTimeMillis();
Expand All @@ -103,6 +132,8 @@ void LogicGate::handleEvent (const EventChannel* eventInfo, const MidiMessage& e
{
std::cout << "Received B " << std::endl;
B = true;
B_ts = ts;

if ((m_input2gate) || (!m_input1gate && !m_input2gate))
m_previousTime = Time::currentTimeMillis();
}
Expand Down Expand Up @@ -184,6 +215,16 @@ void LogicGate::process (AudioSampleBuffer& buffer)
m_currentTime = Time::currentTimeMillis();
m_timePassed = float(m_currentTime - m_previousTime);

// turn off event from previous buffer if necessary
int64 bufferTs = CoreServices::getGlobalTimestamp();
nSamples = getNumSamples(0);
int turnoffOffset = turnOffEvent ? jmax(0, int(turnOffEvent->getTimestamp() - bufferTs)) : -1;
if (turnoffOffset >= 0 && turnoffOffset < nSamples) // is Off event in this buffer?
{
addEvent(eventChannelPtr, turnOffEvent, turnoffOffset);
turnOffEvent = nullptr;
}

switch (m_logicOp)
{
case 0:
Expand Down Expand Up @@ -286,17 +327,33 @@ void LogicGate::process (AudioSampleBuffer& buffer)

void LogicGate::triggerEvent()
{
int64 timestamp = CoreServices::getGlobalTimestamp();
setTimestampAndSamples(timestamp, 0);
// On event
int64 ts;
A_ts > B_ts ? ts = A_ts : ts = B_ts; // which event happened later? Save ts as start of event.
int64 bufferTs = CoreServices::getGlobalTimestamp();
int64 tsOffset = ts - bufferTs; // How many samples from start of buffer
uint8 ttlData = 1 << m_outputChan;
const EventChannel* chan = getEventChannel(getEventChannelIndex(0, getNodeId()));
TTLEventPtr event = TTLEvent::createTTLEvent(chan, timestamp, &ttlData, sizeof(uint8), m_outputChan);
addEvent(chan, event, 0);
TTLEventPtr event = TTLEvent::createTTLEvent(eventChannelPtr, ts, &ttlData, sizeof(uint8), m_outputChan);
addEvent(eventChannelPtr, event, tsOffset);

// Off event
int eventDurationSamp = static_cast<int>(ceil(m_pulseDuration / 1000.0f * getSampleRate()));
uint8 ttlDataOff = 0;
TTLEventPtr eventOff = TTLEvent::createTTLEvent(chan, timestamp + eventDurationSamp, &ttlDataOff, sizeof(uint8), m_outputChan);
addEvent(chan, eventOff, 0);
int64 eventTsOff = ts + eventDurationSamp;
int64 tsOffsetOff = tsOffset + eventDurationSamp;
TTLEventPtr eventOff = TTLEvent::createTTLEvent(eventChannelPtr, eventTsOff, &ttlDataOff, sizeof(uint8), m_outputChan);

// Check if to do the turn off event now, or in a later buffer
if (tsOffsetOff <= nSamples)
{
// add event now
addEvent(eventChannelPtr, eventOff, tsOffsetOff);
}
else
{
// save for later
turnOffEvent = eventOff;
}
}

void LogicGate::addEventSource(EventSources s)
Expand All @@ -310,6 +367,7 @@ void LogicGate::clearEventSources()
}



void LogicGate::saveCustomParametersToXml(XmlElement *parentElement)
{
XmlElement* mainNode = parentElement->createNewChildElement("LogicGate");
Expand Down
8 changes: 8 additions & 0 deletions LogicGate/LogicGate.h → LogicGate/Source/LogicGate.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class LogicGate : public GenericProcessor
int m_outputChan;
int m_window;
Array<EventSources> m_sources;
EventChannel* eventChannelPtr;

// Time
float m_timePassed;
Expand All @@ -130,7 +131,14 @@ class LogicGate : public GenericProcessor
bool A;
bool B;

// Save TS
int64 A_ts;
int64 B_ts;


void triggerEvent();
TTLEventPtr turnOffEvent;
int nSamples;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LogicGate);
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.