setting the CMake env

This commit is contained in:
lathoub 2020-03-23 21:19:01 +01:00
parent f1ad860efb
commit 03707964ee
9 changed files with 216 additions and 5 deletions

View File

@ -6,6 +6,7 @@ add_library(midi STATIC
midi_Namespace.h midi_Namespace.h
midi_Defs.h midi_Defs.h
midi_Message.h midi_Message.h
midi_Platform.h
midi_Settings.h midi_Settings.h
MIDI.cpp MIDI.cpp
MIDI.hpp MIDI.hpp

View File

@ -7,6 +7,8 @@ add_library(test-mocks STATIC
test-mocks_SerialMock.cpp test-mocks_SerialMock.cpp
test-mocks_SerialMock.hpp test-mocks_SerialMock.hpp
test-mocks_SerialMock.h test-mocks_SerialMock.h
midi_RingBuffer.h
midi_RingBuffer.hpp
) )
target_link_libraries(test-mocks target_link_libraries(test-mocks

View File

@ -0,0 +1,62 @@
/*!
* @file midi_RingBuffer.h
* Project Arduino MIDI Library
* @brief MIDI Library for Arduino - Ring Buffer
* @author Francois Best
* @date 10/10/2016
* @license MIT - Copyright (c) 2016 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include "midi_Namespace.h"
BEGIN_MIDI_NAMESPACE
template<typename DataType, int Size>
class RingBuffer
{
public:
RingBuffer();
~RingBuffer();
public:
int getLength() const;
bool isEmpty() const;
public:
void write(DataType inData);
void write(const DataType* inData, int inSize);
void clear();
public:
DataType read();
void read(DataType* outData, int inSize);
private:
DataType mData[Size];
DataType* mWriteHead;
DataType* mReadHead;
};
END_MIDI_NAMESPACE
#include "midi_RingBuffer.hpp"

View File

@ -0,0 +1,121 @@
/*!
* @file midi_RingBuffer.hpp
* Project Arduino MIDI Library
* @brief MIDI Library for Arduino - Ring Buffer
* @author Francois Best
* @date 10/10/2016
* @license MIT - Copyright (c) 2016 Francois Best
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
BEGIN_MIDI_NAMESPACE
template<typename DataType, int Size>
RingBuffer<DataType, Size>::RingBuffer()
: mWriteHead(mData)
, mReadHead(mData)
{
memset(mData, DataType(0), Size * sizeof(DataType));
}
template<typename DataType, int Size>
RingBuffer<DataType, Size>::~RingBuffer()
{
}
// -----------------------------------------------------------------------------
template<typename DataType, int Size>
int RingBuffer<DataType, Size>::getLength() const
{
if (mReadHead == mWriteHead)
{
return 0;
}
else if (mWriteHead > mReadHead)
{
return int(mWriteHead - mReadHead);
}
else
{
return int(mWriteHead - mData) + Size - int(mReadHead - mData);
}
}
template<typename DataType, int Size>
bool RingBuffer<DataType, Size>::isEmpty() const
{
return mReadHead == mWriteHead;
}
// -----------------------------------------------------------------------------
template<typename DataType, int Size>
void RingBuffer<DataType, Size>::write(DataType inData)
{
*mWriteHead++ = inData;
if (mWriteHead >= mData + Size)
{
mWriteHead = mData;
}
}
template<typename DataType, int Size>
void RingBuffer<DataType, Size>::write(const DataType* inData, int inSize)
{
for (int i = 0; i < inSize; ++i)
{
write(inData[i]);
}
}
template<typename DataType, int Size>
void RingBuffer<DataType, Size>::clear()
{
memset(mData, DataType(0), Size * sizeof(DataType));
mReadHead = mData;
mWriteHead = mData;
}
// -----------------------------------------------------------------------------
template<typename DataType, int Size>
DataType RingBuffer<DataType, Size>::read()
{
const DataType data = *mReadHead++;
if (mReadHead >= mData + Size)
{
mReadHead = mData;
}
return data;
}
template<typename DataType, int Size>
void RingBuffer<DataType, Size>::read(DataType* outData, int inSize)
{
for (int i = 0; i < inSize; ++i)
{
outData[i] = read();
}
}
END_MIDI_NAMESPACE

View File

@ -2,7 +2,7 @@
#include "test-mocks.h" #include "test-mocks.h"
#include <inttypes.h> #include <inttypes.h>
#include <src/midi_RingBuffer.h> #include <midi_RingBuffer.h>
BEGIN_TEST_MOCKS_NAMESPACE BEGIN_TEST_MOCKS_NAMESPACE

View File

@ -6,7 +6,6 @@ include_directories(
"${unit-tests_SOURCE_DIR}" "${unit-tests_SOURCE_DIR}"
"${gtest_SOURCE_DIR}/include" "${gtest_SOURCE_DIR}/include"
"${gmock_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include"
"${ROOT_SOURCE_DIR}/external/midi-usb/src"
) )
add_executable(unit-tests add_executable(unit-tests
@ -17,14 +16,14 @@ add_executable(unit-tests
tests/unit-tests_MidiMessage.cpp tests/unit-tests_MidiMessage.cpp
tests/unit-tests_Settings.cpp tests/unit-tests_Settings.cpp
tests/unit-tests_Settings.h tests/unit-tests_Settings.h
tests/unit-tests_Platform.cpp
tests/unit-tests_Platform.h
tests/unit-tests_SysExCodec.cpp tests/unit-tests_SysExCodec.cpp
tests/unit-tests_RingBuffer.cpp tests/unit-tests_RingBuffer.cpp
tests/unit-tests_MidiInput.cpp tests/unit-tests_MidiInput.cpp
tests/unit-tests_MidiInputCallbacks.cpp tests/unit-tests_MidiInputCallbacks.cpp
tests/unit-tests_MidiOutput.cpp tests/unit-tests_MidiOutput.cpp
tests/unit-tests_MidiThru.cpp tests/unit-tests_MidiThru.cpp
tests/unit-tests_MidiUsbDefs.cpp
tests/unit-tests_MidiUsbPacketInterface.cpp
) )
target_link_libraries(unit-tests target_link_libraries(unit-tests

View File

@ -0,0 +1,15 @@
#include "unit-tests_Platform.h"
BEGIN_MIDI_NAMESPACE
END_MIDI_NAMESPACE
// -----------------------------------------------------------------------------
BEGIN_UNNAMED_NAMESPACE
TEST(Platform, hasTheRightDefaultValues)
{
}
END_UNNAMED_NAMESPACE

View File

@ -0,0 +1,12 @@
#pragma once
#include "unit-tests.h"
#include <src/midi_Platform.h>
BEGIN_UNIT_TESTS_NAMESPACE
struct VariablePlatform : public midi::DefaultPlatform
{
};
END_UNIT_TESTS_NAMESPACE

View File

@ -5,7 +5,6 @@ BEGIN_MIDI_NAMESPACE
const bool DefaultSettings::UseRunningStatus; const bool DefaultSettings::UseRunningStatus;
const bool DefaultSettings::HandleNullVelocityNoteOnAsNoteOff; const bool DefaultSettings::HandleNullVelocityNoteOnAsNoteOff;
const bool DefaultSettings::Use1ByteParsing; const bool DefaultSettings::Use1ByteParsing;
const long DefaultSettings::BaudRate;
const unsigned DefaultSettings::SysExMaxSize; const unsigned DefaultSettings::SysExMaxSize;
END_MIDI_NAMESPACE END_MIDI_NAMESPACE