Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0bc7ca

Browse files
committed
Eliminate the "clear" macro in favor of an inline function.
When compiling using libcxx and C++17 (see also PR#9!) the <atomic_flag> include is dragged in by one of the standard library headers. atomic_flag declares a clear() member. The clear macro causes this to expand to something that won't compile. This change creates a clear() function in utils.h. This seemed like a logical place for it to live.
1 parent 11f11e1 commit a0bc7ca

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

include/bytestreamToUMP.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525
#define BSTOUMP_BUFFER 4
2626

27-
#ifndef clear
28-
#define clear(dest, c,n ) for(uint16_t i = 0 ; i < n ; i ++) dest[i] = c;
29-
#endif
30-
3127
#include "utils.h"
3228

3329
class bytestreamToUMP{
@@ -194,6 +190,7 @@ class bytestreamToUMP{
194190
bool outputMIDI2 = false;
195191

196192
bytestreamToUMP(){
193+
using M2Utils::clear;
197194
clear(bankMSB, 255, sizeof(bankMSB));
198195
clear(bankLSB, 255, sizeof(bankLSB));
199196
clear(rpnMsbValue, 255, sizeof(rpnMsbValue));
@@ -243,7 +240,7 @@ class bytestreamToUMP{
243240
increaseWrite();
244241

245242
sysex7State = 0;
246-
clear(sysex, 0, sizeof(sysex));
243+
M2Utils::clear(sysex, 0, sizeof(sysex));
247244
}
248245
} else if(sysex7State >= 1){
249246
//Check IF new UMP Message Type 3
@@ -255,7 +252,7 @@ class bytestreamToUMP{
255252
increaseWrite();
256253
umpMess[writeIndex] = ((sysex[2] + 0L) << 24) + ((sysex[3] + 0L)<< 16) + (sysex[4] << 8) + sysex[5] + 0L;
257254
increaseWrite();
258-
clear(sysex, 0, sizeof(sysex));
255+
M2Utils::clear(sysex, 0, sizeof(sysex));
259256
sysex7State=2;
260257
sysex7Pos=0;
261258
}

include/utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@
168168
#define UMP_MIDI_ENDPOINT 0xF
169169

170170
namespace M2Utils {
171+
inline void clear(uint8_t * const dest, uint8_t const c, std::size_t const n) {
172+
for (auto i = std::size_t{0}; i < n; i++) {
173+
dest[i] = c;
174+
}
175+
}
176+
171177
inline uint32_t scaleUp(uint32_t srcVal, uint8_t srcBits, uint8_t dstBits){
172178
//Handle value of 0 - skip processing
173179
if(srcVal == 0){

src/mcoded7.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@
1919
* ********************************************************/
2020

2121
#include "mcoded7.h"
22-
23-
#ifndef clear
24-
#define clear(dest, c,n ) for(uint16_t i = 0 ; i < n ; i ++) dest[i] = c;
25-
#endif
26-
22+
#include "utils.h"
2723

2824
uint16_t mcoded7Decode::currentPos(){ return dumpPos;}
2925

3026
void mcoded7Decode::reset(){
31-
clear(dump,0,7);
27+
M2Utils::clear(dump,0,7);
3228
fBit=0; bits=0;dumpPos=255;
3329
}
3430

@@ -47,7 +43,7 @@ void mcoded7Decode::parseS7Byte(uint8_t s7Byte){
4743
uint16_t mcoded7Encode::currentPos(){ return dumpPos-1;}
4844

4945
void mcoded7Encode::reset(){
50-
clear(dump,0,8);
46+
M2Utils::clear(dump,0,8);
5147
dumpPos=1; cnt = 6;
5248
}
5349

0 commit comments

Comments
 (0)