Skip to content
Merged
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
52 changes: 52 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# Style for Clang-Format version 10
# https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
# Alignment of Consecutive Assignments/Declarations/Macros can be changed to `AcrossEmptyLinesAndComments` with Clang-Format version 12
#AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
#AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
#AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: DontAlign
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
ColumnLimit: 150
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentPPDirectives: AfterHash
IndentWidth: 4
PenaltyBreakString: 1000
PenaltyReturnTypeOnItsOwnLine: 1060
PointerAlignment: Left
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeParens: NonEmptyParentheses
SpacesInConditionalStatement: true
SpacesInParentheses: true
84 changes: 42 additions & 42 deletions android/androiddebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,60 @@
*
\******************************************************************************/

const char*const applicationName = "Jamulus";
const char* const applicationName = "Jamulus";

#ifdef ANDROIDDEBUG // Set in my myapp.pro file for android builds
#include <android/log.h>
#include <QString>
#include <QEvent>
#include <QDebug>
#include <stdio.h>
#include <math.h>
#include <string>
# include <android/log.h>
# include <QString>
# include <QEvent>
# include <QDebug>
# include <stdio.h>
# include <math.h>
# include <string>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected? It looks strange to me having # separated from include.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected? It looks strange to me having # separated from include.

Yes, I think it was the decision to do that when discussing the options (no indentation at all, indent with #, indent but keep # on first column). I wanted to link the discussion here, but I suspect it's hidden in one of the conversations as part of this PR.

Such things could be changed again in a rather simple way later, if we decide otherwise. I think we should really focus on getting this long-term, huge PR merged. It will not be the last one. :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found one part of the conversation here, for reference: #1127 (comment)


void myMessageHandler ( QtMsgType type, const QMessageLogContext& context, const QString& msg )
{
QString report = msg;
QString report = msg;

if ( context.file && !QString ( context.file ).isEmpty() )
{
report += " in file ";
report += QString ( context.file );
report += " line ";
report += QString::number ( context.line );
}
if ( context.file && !QString ( context.file ).isEmpty() )
{
report += " in file ";
report += QString ( context.file );
report += " line ";
report += QString::number ( context.line );
}

if ( context.function && !QString ( context.function ).isEmpty() )
{
report +=+" function ";
report += QString(context.function);
}
if ( context.function && !QString ( context.function ).isEmpty() )
{
report += +" function ";
report += QString ( context.function );
}

const char*const local = report.toLocal8Bit().constData();
const char* const local = report.toLocal8Bit().constData();

switch ( type )
{
case QtDebugMsg:
__android_log_write ( ANDROID_LOG_DEBUG, applicationName, local) ;
break;
switch ( type )
{
case QtDebugMsg:
__android_log_write ( ANDROID_LOG_DEBUG, applicationName, local );
break;

case QtInfoMsg:
__android_log_write ( ANDROID_LOG_INFO, applicationName, local );
break;
case QtInfoMsg:
__android_log_write ( ANDROID_LOG_INFO, applicationName, local );
break;

case QtWarningMsg:
__android_log_write ( ANDROID_LOG_WARN, applicationName, local );
break;
case QtWarningMsg:
__android_log_write ( ANDROID_LOG_WARN, applicationName, local );
break;

case QtCriticalMsg:
__android_log_write ( ANDROID_LOG_ERROR, applicationName, local );
break;
case QtCriticalMsg:
__android_log_write ( ANDROID_LOG_ERROR, applicationName, local );
break;

case QtFatalMsg:
default:
__android_log_write ( ANDROID_LOG_FATAL, applicationName, local );
abort();
break;
}
case QtFatalMsg:
default:
__android_log_write ( ANDROID_LOG_FATAL, applicationName, local );
abort();
break;
}
}
#endif
114 changes: 70 additions & 44 deletions android/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,42 @@
* Data is contained in a vector dynamically allocated.
*/
template<typename T>
class RingBuffer {
class RingBuffer
{
public:
/**
* @brief RingBuffer
* @param max maximum number of elements that can be contained in the ring buffer
*/
RingBuffer(std::size_t max = 0):mData(max),mRead(0),mWrite(0),mFull(false) { }
RingBuffer ( std::size_t max = 0 ) : mData ( max ), mRead ( 0 ), mWrite ( 0 ), mFull ( false ) {}

/**
* @brief Resets the ring_buffer
* @param max maximum number of elements that can be contained in the ring buffer.
*/
void reset(std::size_t max = 0) {
mData = std::vector<T>(max);
mRead = 0;
void reset ( std::size_t max = 0 )
{
mData = std::vector<T> ( max );
mRead = 0;
mWrite = 0;
mFull = false;
mFull = false;
}

/**
* @brief Current number of elements contained in the ring buffer
* @return
*/
std::size_t size() const {
std::size_t size() const
{
std::size_t size = capacity();
if(!mFull) {
if(mWrite >= mRead) {
if ( !mFull )
{
if ( mWrite >= mRead )
{
size = mWrite - mRead;
} else {
}
else
{
size = capacity() + mWrite - mRead;
}
}
Expand All @@ -75,7 +82,7 @@ class RingBuffer {
* @brief whether the ring buffer is empty.
* @return
*/
bool isEmpty() const { return !isFull() && (mRead == mWrite); }
bool isEmpty() const { return !isFull() && ( mRead == mWrite ); }

/**
* @brief Maximum number of elements in the ring buffer
Expand All @@ -87,7 +94,8 @@ class RingBuffer {
* @brief Adds a single value
* @param v the value to add
*/
void put(const T &v) {
void put ( const T& v )
{
mData[mWrite] = v;
forward();
}
Expand All @@ -97,12 +105,16 @@ class RingBuffer {
* @param v the value read
* @return true if the value was read
*/
bool get(T&v) {
if(!isEmpty()) {
bool get ( T& v )
{
if ( !isEmpty() )
{
v = mData[mRead];
backward();
return true;
} else {
}
else
{
return false;
}
}
Expand All @@ -112,13 +124,15 @@ class RingBuffer {
* @param v pointer to the consecutive values
* @param count number of consecutive values.
*/
void put(const T *v, std::size_t count) {
std::size_t avail = mWrite - capacity();
std::size_t to_copy = std::min(count,avail);
memcpy(mData.data() + mWrite,v, to_copy*sizeof(T));
forward(to_copy);
if(to_copy < count) {
put(v+to_copy,count - to_copy);
void put ( const T* v, std::size_t count )
{
std::size_t avail = mWrite - capacity();
std::size_t to_copy = std::min ( count, avail );
memcpy ( mData.data() + mWrite, v, to_copy * sizeof ( T ) );
forward ( to_copy );
if ( to_copy < count )
{
put ( v + to_copy, count - to_copy );
}
}

Expand All @@ -128,45 +142,57 @@ class RingBuffer {
* @param count Maximum available size in the memory area
* @return actual number of elements read.
*/
std::size_t get(T *v, std::size_t count) {
std::size_t get ( T* v, std::size_t count )
{
std::size_t avail = 0;
if(mRead < mWrite) {
if ( mRead < mWrite )
{
avail = mWrite - mRead;
} else {
}
else
{
avail = mRead - capacity();
}
std::size_t to_copy = std::min(count, avail);
memcpy(v, mData.data() + mRead, to_copy * sizeof(T));
backward(to_copy);
if((size()>0)&&(count > to_copy)) {
return to_copy + get(v + to_copy, count - to_copy);
} else {
std::size_t to_copy = std::min ( count, avail );
memcpy ( v, mData.data() + mRead, to_copy * sizeof ( T ) );
backward ( to_copy );
if ( ( size() > 0 ) && ( count > to_copy ) )
{
return to_copy + get ( v + to_copy, count - to_copy );
}
else
{
return to_copy;
}
}

private:
void forward() {
if(isFull()) {
mRead = (mRead + 1) % capacity();
void forward()
{
if ( isFull() )
{
mRead = ( mRead + 1 ) % capacity();
}
mWrite = (mWrite + 1) % capacity();
mFull = (mRead == mWrite);
mWrite = ( mWrite + 1 ) % capacity();
mFull = ( mRead == mWrite );
}

void forward(std::size_t count) {
for(std::size_t i=0; i<count;i++) {
void forward ( std::size_t count )
{
for ( std::size_t i = 0; i < count; i++ )
{
forward();
}
}

void backward(std::size_t count) {
void backward ( std::size_t count )
{
mFull = false;
mRead = (mRead + count) % capacity();
mRead = ( mRead + count ) % capacity();
}

std::vector<T> mData;
std::size_t mRead; /** offset to reading point */
std::size_t mWrite; /** offset to writing point */
bool mFull;
std::size_t mRead; /** offset to reading point */
std::size_t mWrite; /** offset to writing point */
bool mFull;
};

Loading