diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..bd1691e --- /dev/null +++ b/.clang-format @@ -0,0 +1,64 @@ +--- +Language: Cpp +# BasedOnStyle: JUCE (Custom) +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BreakAfterJavaFieldAnnotations: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList : BeforeColon +BreakStringLiterals: false +ColumnLimit: 0 +# ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +PackConstructorInitializers: CurrentLine +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: true +SpaceBeforeParens: NonEmptyParentheses +SpaceInEmptyParentheses: false +SpaceBeforeInheritanceColon: true +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: "c++17" +TabWidth: 4 +UseTab: Never +--- + diff --git a/Source/OpenEphysLib.cpp b/Source/OpenEphysLib.cpp index cf1b42c..3262fb0 100644 --- a/Source/OpenEphysLib.cpp +++ b/Source/OpenEphysLib.cpp @@ -20,76 +20,76 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include #include "PanelBase.h" +#include #include #ifdef _WIN32 #include -#define EXPORT __declspec(dllexport) +#define EXPORT __declspec (dllexport) #else -#define EXPORT __attribute__((visibility("default"))) +#define EXPORT __attribute__ ((visibility ("default"))) #endif using namespace Plugin; //Number of plugins defined on the library. Can be of different types (Processors, RecordEngines, etc...) #define NUM_PLUGINS 2 -extern "C" EXPORT void getLibInfo(Plugin::LibraryInfo* info) +extern "C" EXPORT void getLibInfo (Plugin::LibraryInfo* info) { - /* API version, defined by the GUI source. + /* API version, defined by the GUI source. Should not be changed to ensure it is always equal to the one used in the latest codebase. The GUI refueses to load plugins with mismatched API versions */ - info->apiVersion = PLUGIN_API_VER; + info->apiVersion = PLUGIN_API_VER; - //Name of the Library, used only for information - info->name = "TTL Panels"; + //Name of the Library, used only for information + info->name = "TTL Panels"; - //Version of the library, used only for information - info->libVersion = "0.1.0"; - info->numPlugins = NUM_PLUGINS; + //Version of the library, used only for information + info->libVersion = "0.1.0"; + info->numPlugins = NUM_PLUGINS; } -extern "C" EXPORT int getPluginInfo(int index, Plugin::PluginInfo* info) +extern "C" EXPORT int getPluginInfo (int index, Plugin::PluginInfo* info) { - switch (index) - { - //one case per plugin. - case 0: - // Sources, sinks, and visualizers are all "processors". - info->type = Plugin::Type::PROCESSOR; - //Processor name shown in the GUI. - info->processor.name = "TTL Toggle Panel"; - //Type of processor. - info->processor.type = Plugin::Processor::FILTER; - //Class factory pointer. Namespace and class name. - info->processor.creator = &(Plugin::createProcessor); - break; - - case 1: - // Sources, sinks, and visualizers are all "processors". - info->type = Plugin::Type::PROCESSOR; - //Processor name shown in the GUI. - info->processor.name = "TTL Display Panel"; - //Type of processor. - info->processor.type = Plugin::Processor::SINK; - //Class factory pointer. Namespace and class name. - info->processor.creator = &(Plugin::createProcessor); - break; - - default: - return -1; - break; - } - return 0; + switch (index) + { + //one case per plugin. + case 0: + // Sources, sinks, and visualizers are all "processors". + info->type = Plugin::Type::PROCESSOR; + //Processor name shown in the GUI. + info->processor.name = "TTL Toggle Panel"; + //Type of processor. + info->processor.type = Plugin::Processor::FILTER; + //Class factory pointer. Namespace and class name. + info->processor.creator = &(Plugin::createProcessor); + break; + + case 1: + // Sources, sinks, and visualizers are all "processors". + info->type = Plugin::Type::PROCESSOR; + //Processor name shown in the GUI. + info->processor.name = "TTL Display Panel"; + //Type of processor. + info->processor.type = Plugin::Processor::SINK; + //Class factory pointer. Namespace and class name. + info->processor.creator = &(Plugin::createProcessor); + break; + + default: + return -1; + break; + } + return 0; } #ifdef WIN32 -BOOL WINAPI DllMain(IN HINSTANCE hDllHandle, - IN DWORD nReason, - IN LPVOID Reserved) +BOOL WINAPI DllMain (IN HINSTANCE hDllHandle, + IN DWORD nReason, + IN LPVOID Reserved) { - return TRUE; + return TRUE; } #endif diff --git a/Source/PanelBase.cpp b/Source/PanelBase.cpp index fa95497..5ece126 100644 --- a/Source/PanelBase.cpp +++ b/Source/PanelBase.cpp @@ -1,51 +1,44 @@ -#include "PanelBaseEditor.h" #include "PanelBase.h" +#include "PanelBaseEditor.h" #include using namespace TTLDebugTools; - // Base class for front panel and toggle panel. - // Constructor. -TTLPanelBase::TTLPanelBase(const std::string &name, bool wantSource) : GenericProcessor(name) +TTLPanelBase::TTLPanelBase (const std::string& name, bool wantSource) : GenericProcessor (name) { isTTLSource = wantSource; - addIntParameter(Parameter::STREAM_SCOPE, - "ttl_word", - "Word", - "TTL word for a given stream", - 0, - INT_MIN, - INT_MAX, - false); - + addIntParameter (Parameter::STREAM_SCOPE, + "ttl_word", + "Word", + "TTL word for a given stream", + 0, + INT_MIN, + INT_MAX, + false); } - // Destructor. TTLPanelBase::~TTLPanelBase() { // Nothing to do. } - // Editor accessor. AudioProcessorEditor* TTLPanelBase::createEditor() { // NOTE - We need to set the "editor" variable in GenericProcessor. - editor = std::make_unique(this); + editor = std::make_unique (this); return editor.get(); } - // Rebuild external configuration information. // This is where we detect input geometry, for the front panel. void TTLPanelBase::updateSettings() { - localEventChannels.clear(); currentTTLWord.clear(); lastTTLWord.clear(); @@ -53,37 +46,35 @@ void TTLPanelBase::updateSettings() for (auto stream : getDataStreams()) { const uint16 streamId = stream->getStreamId(); - + if (isTTLSource) { // TTL Channel EventChannel* ttlChan; - EventChannel::Settings ttlChannelSettings{ + EventChannel::Settings ttlChannelSettings { EventChannel::Type::TTL, "TTL Toggle Panel output", "Triggers whenever a TTL button is toggled.", "togglepanel.ttl", - getDataStream(stream->getStreamId()) + getDataStream (stream->getStreamId()) }; - ttlChan = new EventChannel(ttlChannelSettings); - ttlChan->addProcessor(this); - eventChannels.add(ttlChan); + ttlChan = new EventChannel (ttlChannelSettings); + ttlChan->addProcessor (this); + eventChannels.add (ttlChan); localEventChannels[streamId] = eventChannels.getLast(); } - + currentTTLWord[streamId] = 0; lastTTLWord[streamId] = 0; - } pushStateToDisplay(); } - // Processing loop. -void TTLPanelBase::process(AudioSampleBuffer& buffer) +void TTLPanelBase::process (AudioSampleBuffer& buffer) { // If we're a filter, report queued changes to TTL output state. // If we're a sink, input events will be received via handleEvent(); we still need to call checkForEvents(). @@ -96,16 +87,16 @@ void TTLPanelBase::process(AudioSampleBuffer& buffer) for (auto stream : dataStreams) { const uint16 streamId = stream->getStreamId(); - + if (currentTTLWord[streamId] != lastTTLWord[streamId]) { Array events = TTLEvent::createTTLEvent (localEventChannels[streamId], - getFirstSampleNumberForBlock(streamId), + getFirstSampleNumberForBlock (streamId), static_cast (currentTTLWord[streamId])); for (auto event : events) { - addEvent(event, 0); + addEvent (event, 0); } lastTTLWord[streamId] = currentTTLWord[streamId]; @@ -121,12 +112,10 @@ void TTLPanelBase::process(AudioSampleBuffer& buffer) } } - // Input TTL events enter via this hook. -void TTLPanelBase::handleTTLEvent(TTLEventPtr event) +void TTLPanelBase::handleTTLEvent (TTLEventPtr event) { - - const uint16 streamId = event->getStreamId(); + const uint16 streamId = event->getStreamId(); bool ttlState = event->getState(); int ttlBit = event->getLine(); @@ -134,7 +123,6 @@ void TTLPanelBase::handleTTLEvent(TTLEventPtr event) currentTTLWord[streamId] |= (1 << ttlBit); else currentTTLWord[streamId] &= ~(1 << ttlBit); - } // Pushes latest state to display @@ -142,44 +130,38 @@ void TTLPanelBase::pushStateToDisplay() { TTLPanelBaseEditor* editor = (TTLPanelBaseEditor*) getEditor(); - editor->pushStateToEditor(currentTTLWord); - + editor->pushStateToEditor (currentTTLWord); } - // Parameter accessor. This is guaranteed to be called under safe conditions. // Variables used by "process" should only be modified here. -void TTLPanelBase::parameterValueChanged(Parameter* parameter) +void TTLPanelBase::parameterValueChanged (Parameter* parameter) { - LOGD("Parameter value changed!"); + LOGD ("Parameter value changed!"); const uint16 streamId = parameter->getStreamId(); - int64 valueI64 = int64(parameter->getValue()); - uint32 valueU32 = uint32(valueI64 + INT_MAX); + int64 valueI64 = int64 (parameter->getValue()); + uint32 valueU32 = uint32 (valueI64 + INT_MAX); - LOGD("New TTL word for stream ", streamId, ": ", valueU32); + LOGD ("New TTL word for stream ", streamId, ": ", valueU32); - currentTTLWord[streamId] = valueU32; - + currentTTLWord[streamId] = valueU32; } - // Accessors for querying and modifying state. // Modifying is done via setParameter, since that's guaranteed safe. // NOTE - We're not calling query accessors any more! - bool TTLPanelBase::isEventSourcePanel() { -// Don't tattle this except for debugging; it gets spammy. -//T_PRINT( "isEventSourcePanel() returning " << (isTTLSource ? "true." : "false.") ); + // Don't tattle this except for debugging; it gets spammy. + //T_PRINT( "isEventSourcePanel() returning " << (isTTLSource ? "true." : "false.") ); return isTTLSource; } - // Toggle panel (filter). -TTLTogglePanel::TTLTogglePanel() : TTLPanelBase("TTL Toggle Panel", true) +TTLTogglePanel::TTLTogglePanel() : TTLPanelBase ("TTL Toggle Panel", true) { } @@ -187,10 +169,9 @@ TTLTogglePanel::~TTLTogglePanel() { } - // Front panel (sink). -TTLFrontPanel::TTLFrontPanel() : TTLPanelBase("TTL Display Panel", false) +TTLFrontPanel::TTLFrontPanel() : TTLPanelBase ("TTL Display Panel", false) { } @@ -198,5 +179,4 @@ TTLFrontPanel::~TTLFrontPanel() { } - // This is the end of the file. diff --git a/Source/PanelBase.h b/Source/PanelBase.h index cce5f4b..30dbb98 100644 --- a/Source/PanelBase.h +++ b/Source/PanelBase.h @@ -15,88 +15,83 @@ namespace TTLDebugTools { - class TTLPanelBase : public GenericProcessor - { - public: - /** Constructor. +class TTLPanelBase : public GenericProcessor +{ +public: + /** Constructor. Set "wantSource" true to make this a toggle panel (filter), or false for a front panel (sink) */ - TTLPanelBase(const std::string &name, bool wantSource); + TTLPanelBase (const std::string& name, bool wantSource); - /** Destructor */ - ~TTLPanelBase(); + /** Destructor */ + ~TTLPanelBase(); - /** Create custom editor */ - AudioProcessorEditor* createEditor() override; + /** Create custom editor */ + AudioProcessorEditor* createEditor() override; - /** Create event channels */ - void updateSettings() override; + /** Create event channels */ + void updateSettings() override; - /** Processing loop. */ - void process(AudioBuffer& buffer) override; + /** Processing loop. */ + void process (AudioBuffer& buffer) override; - // If we're configured as a front panel, we need to handle events. - void handleTTLEvent(TTLEventPtr event) override; + // If we're configured as a front panel, we need to handle events. + void handleTTLEvent (TTLEventPtr event) override; - // This is guaranteed to be called under safe conditions. - // Variables used by "process" should only be modified here. - void parameterValueChanged(Parameter* parameter) override; + // This is guaranteed to be called under safe conditions. + // Variables used by "process" should only be modified here. + void parameterValueChanged (Parameter* parameter) override; - // Accessors for querying and modifying state. - // Modifying is done via parameterValueChanged, since that's guaranteed safe. - // NOTE - Calling query accessors while running isn't safe! - bool isEventSourcePanel(); + // Accessors for querying and modifying state. + // Modifying is done via parameterValueChanged, since that's guaranteed safe. + // NOTE - Calling query accessors while running isn't safe! + bool isEventSourcePanel(); - // Updates the display with latest state. - void pushStateToDisplay(); + // Updates the display with latest state. + void pushStateToDisplay(); - protected: - bool isTTLSource; - std::map currentTTLWord; - std::map lastTTLWord; - std::map localEventChannels; +protected: + bool isTTLSource; + std::map currentTTLWord; + std::map lastTTLWord; + std::map localEventChannels; - private: - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TTLPanelBase); - }; +private: + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TTLPanelBase); +}; - /** +/** Creates an array of buttons to toggle TTL events on and off */ - class TTLTogglePanel : public TTLPanelBase - { - public: - - /** Constructor */ - TTLTogglePanel(); - - /** Destructor */ - ~TTLTogglePanel(); +class TTLTogglePanel : public TTLPanelBase +{ +public: + /** Constructor */ + TTLTogglePanel(); - - private: + /** Destructor */ + ~TTLTogglePanel(); - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TTLTogglePanel); - }; +private: + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TTLTogglePanel); +}; - /** +/** Creates an array of indicators to show the state of individual TTL lines */ - class TTLFrontPanel : public TTLPanelBase - { - public: - - /** Constructor */ - TTLFrontPanel(); +class TTLFrontPanel : public TTLPanelBase +{ +public: + /** Constructor */ + TTLFrontPanel(); - /** Destructor*/ - ~TTLFrontPanel(); + /** Destructor*/ + ~TTLFrontPanel(); - - private: - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TTLFrontPanel); - }; -} +private: + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TTLFrontPanel); +}; +} // namespace TTLDebugTools #endif diff --git a/Source/PanelBaseEditor.cpp b/Source/PanelBaseEditor.cpp index cc584c0..0a6f3cd 100644 --- a/Source/PanelBaseEditor.cpp +++ b/Source/PanelBaseEditor.cpp @@ -1,11 +1,10 @@ #include "PanelBaseEditor.h" #include "PanelBase.h" -#include #include +#include using namespace TTLDebugTools; - // Private magic constants for GUI geometry. #define TITLEBAR_YOFFSET 35 @@ -28,156 +27,142 @@ using namespace TTLDebugTools; #define NUMLABEL_XGAP 8 #define NUMLABEL_XPITCH (NUMLABEL_XGAP + NUMLABEL_XTITLE + NUMLABEL_XSIZE) -#define BUTTONROW_XSIZE_EN_NO (BITBUTTON_SLAB_XSIZE + 2*NUMLABEL_XPITCH) +#define BUTTONROW_XSIZE_EN_NO (BITBUTTON_SLAB_XSIZE + 2 * NUMLABEL_XPITCH) #define BUTTONROW_XSIZE_EN_YES (ENBUTTON_XSIZE + ENBUTTON_XGAP + BUTTONROW_XSIZE_EN_NO) #define BUTTONROW_XHALO 10 -#define BUTTONROW_XPITCH_EN_NO (BUTTONROW_XSIZE_EN_NO + 2*BUTTONROW_XHALO) -#define BUTTONROW_XPITCH_EN_YES (BUTTONROW_XSIZE_EN_YES + 2*BUTTONROW_XHALO) - +#define BUTTONROW_XPITCH_EN_NO (BUTTONROW_XSIZE_EN_NO + 2 * BUTTONROW_XHALO) +#define BUTTONROW_XPITCH_EN_YES (BUTTONROW_XSIZE_EN_YES + 2 * BUTTONROW_XHALO) // // One bank of TTLs with associated controls. - // Constructor. -TTLPanelButton::TTLPanelButton(int line_, Colour colour_) : - Button(String(line)), line(line_), colour(colour_) +TTLPanelButton::TTLPanelButton (int line_, Colour colour_) : Button (String (line)), line (line_), colour (colour_) { - } - // Destructor. TTLPanelButton::~TTLPanelButton() { // Nothing to do. } - // GUI callbacks. -void TTLPanelButton::paintButton(Graphics& g, bool isHighlighted, bool isDown) +void TTLPanelButton::paintButton (Graphics& g, bool isHighlighted, bool isDown) { - if (getToggleState()) - g.setColour(colour); + g.setColour (colour); else - g.setColour(findColour (ThemeColours::widgetBackground)); + g.setColour (findColour (ThemeColours::widgetBackground)); - - - g.fillRect(0, 0, getWidth(), getHeight()); - - g.setColour(findColour (ThemeColours::defaultText)); - g.setFont(11.0f); - g.drawText(String(line + 1), Rectangle(getWidth(), getHeight()), Justification::centred); + g.fillRect (0, 0, getWidth(), getHeight()); - if (isHighlighted && getClickingTogglesState()) - g.setColour(colour); + g.setColour (findColour (ThemeColours::defaultText)); + g.setFont (11.0f); + g.drawText (String (line + 1), Rectangle (getWidth(), getHeight()), Justification::centred); - g.drawLine(0, getHeight(), getWidth(), getHeight(), 2.0); + if (isHighlighted && getClickingTogglesState()) + g.setColour (colour); + g.drawLine (0, getHeight(), getWidth(), getHeight(), 2.0); } - // // GUI tray holding a small number of TTL banks. // Constructor. -TTLPanelBaseEditor::TTLPanelBaseEditor(TTLPanelBase* newParent) : GenericEditor(newParent) +TTLPanelBaseEditor::TTLPanelBaseEditor (TTLPanelBase* newParent) : GenericEditor (newParent) { parent = newParent; Array eventColours = { - Colour(224, 185, 36), - Colour(243, 119, 33), - Colour(237, 37, 36), - Colour(217, 46, 171), - Colour(101, 31, 255), - Colour(48, 117, 255), - Colour(116, 227, 156), - Colour(82, 173, 0) + Colour (224, 185, 36), + Colour (243, 119, 33), + Colour (237, 37, 36), + Colour (217, 46, 171), + Colour (101, 31, 255), + Colour (48, 117, 255), + Colour (116, 227, 156), + Colour (82, 173, 0) }; for (int bidx = 0; bidx < TTLDEBUG_PANEL_UI_MAX_BUTTONS; bidx++) { - int row = bidx / TTLDEBUG_PANEL_UI_BUTTONS_PER_ROW; int column = bidx % TTLDEBUG_PANEL_UI_BUTTONS_PER_ROW; - TTLPanelButton* button = new TTLPanelButton(bidx, eventColours[column]); - buttons.add(button); + TTLPanelButton* button = new TTLPanelButton (bidx, eventColours[column]); + buttons.add (button); - button->setBounds(BUTTONROW_XHALO + column * BITBUTTON_XPITCH, - TITLEBAR_YOFFSET + row * BUTTONROW_YPITCH, - BITBUTTON_XSIZE, BUTTONROW_YSIZE); + button->setBounds (BUTTONROW_XHALO + column * BITBUTTON_XPITCH, + TITLEBAR_YOFFSET + row * BUTTONROW_YPITCH, + BITBUTTON_XSIZE, + BUTTONROW_YSIZE); - addAndMakeVisible(button); + addAndMakeVisible (button); if (parent->isEventSourcePanel()) - { - button->setClickingTogglesState(true); - button->addListener(this); + { + button->setClickingTogglesState (true); + button->addListener (this); } - else { - button->setToggleState(false, dontSendNotification); + else + { + button->setToggleState (false, dontSendNotification); } } - setDesiredWidth(260); + setDesiredWidth (260); - editableLabel = std::make_unique("TTL Word", "0", "0123456789", ""); - editableLabel->setFont(FontOptions("CP Mono", "Plain", 14.0f)); - editableLabel->setBounds(205, 50, 50, 18); - addAndMakeVisible(editableLabel.get()); - editableLabel->onTextChange = [this] { editableLabel->setTooltip (editableLabel->getText());}; + editableLabel = std::make_unique ("TTL Word", "0", "0123456789", ""); + editableLabel->setFont (FontOptions ("CP Mono", "Plain", 14.0f)); + editableLabel->setBounds (205, 50, 50, 18); + addAndMakeVisible (editableLabel.get()); + editableLabel->onTextChange = [this] + { editableLabel->setTooltip (editableLabel->getText()); }; - ttlWordLabel = std::make_unique