cwMidiDevice.h/cpp,cwMidiAlsa.h/cpp : Implemented active sensing filter.

This commit is contained in:
kevin 2024-07-08 16:56:33 -04:00
parent 5f123f5f72
commit 065ff3f555
4 changed files with 43 additions and 11 deletions

View File

@ -55,6 +55,7 @@ namespace cw
unsigned devCnt; // MIDI devices attached to this computer
dev_t* devArray;
cbFunc_t cbFunc; // MIDI input application callback
bool filterRtSenseFl;
void* cbDataPtr;
snd_seq_t* h; // ALSA system sequencer handle
snd_seq_addr_t alsa_addr; // ALSA client/port address representing the application
@ -73,6 +74,7 @@ namespace cw
bool latency_meas_enable_out_fl;
latency_meas_result_t latency_meas_result;
} alsa_device_t;
#define _cmMpErrMsg( rc, alsaRc, str ) cwLogError(kOpFailRC,"%s : ALSA Error:%i %s",(str),(alsaRc),snd_strerror(alsaRc))
@ -254,7 +256,7 @@ namespace cw
case SND_SEQ_EVENT_START: status = kSysRtStartMdId; break;
case SND_SEQ_EVENT_CONTINUE: status = kSysRtContMdId; break;
case SND_SEQ_EVENT_STOP: status = kSysRtStopMdId; break;
case SND_SEQ_EVENT_SENSING: status = kSysRtSenseMdId; break;
case SND_SEQ_EVENT_SENSING: status = p->filterRtSenseFl ? 0 : kSysRtSenseMdId; break;
case SND_SEQ_EVENT_RESET: status = kSysRtResetMdId; break;
case SND_SEQ_EVENT_SYSEX:
@ -599,7 +601,12 @@ namespace cw
} // cw
cw::rc_t cw::midi::device::alsa::create( handle_t& h, cbFunc_t cbFunc, void* cbArg, unsigned parserBufByteCnt, const char* appNameStr )
cw::rc_t cw::midi::device::alsa::create( handle_t& h,
cbFunc_t cbFunc,
void* cbArg,
unsigned parserBufByteCnt,
const char* appNameStr,
bool filterRtSenseFl )
{
rc_t rc = kOkRC;
int arc = 0;
@ -633,6 +640,7 @@ cw::rc_t cw::midi::device::alsa::create( handle_t& h, cbFunc_t cbFunc, void* cb
p->cbFunc = cbFunc;
p->cbDataPtr = cbArg;
p->filterRtSenseFl = filterRtSenseFl;
// start the sequencer queue
if((arc = snd_seq_start_queue(p->h, p->alsa_queue, NULL)) < 0 )

View File

@ -9,7 +9,13 @@ namespace cw
typedef handle< struct alsa_device_str> handle_t;
rc_t create( handle_t& h, cbFunc_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr );
rc_t create( handle_t& h,
cbFunc_t cbFunc,
void* cbDataPtr,
unsigned parserBufByteCnt,
const char* appNameStr,
bool filterRtSenseFl );
rc_t destroy( handle_t& h);
bool isInitialized( handle_t h );

View File

@ -61,6 +61,8 @@ namespace cw
std::atomic<unsigned> buf_ii;
std::atomic<unsigned> buf_oi;
bool filterRtSenseFl;
} device_t;
device_t* _handleToPtr( handle_t h )
@ -238,7 +240,8 @@ cw::rc_t cw::midi::device::create( handle_t& hRef,
unsigned fileDevReadAheadMicros,
unsigned parserBufByteCnt,
bool enableBufFl,
unsigned bufferMsgCnt )
unsigned bufferMsgCnt,
bool filterRtSenseFl )
{
rc_t rc = kOkRC;
rc_t rc1 = kOkRC;
@ -252,7 +255,8 @@ cw::rc_t cw::midi::device::create( handle_t& hRef,
enableBufFl ? _callback : cbFunc,
enableBufFl ? p : cbArg,
parserBufByteCnt,
appNameStr )) != kOkRC )
appNameStr,
filterRtSenseFl)) != kOkRC )
{
rc = cwLogError(rc,"ALSA MIDI device create failed.");
goto errLabel;
@ -328,6 +332,7 @@ cw::rc_t cw::midi::device::create( handle_t& h,
unsigned bufMsgCnt = 0;
const object_t* file_ports = nullptr;
const object_t* port = nullptr;
bool filterRtSenseFl = true;;
if((rc = args->getv("appNameStr",appNameStr,
"fileDevName",fileDevName,
@ -335,7 +340,8 @@ cw::rc_t cw::midi::device::create( handle_t& h,
"parseBufByteCnt",parseBufByteCnt,
"enableBufFl",enableBufFl,
"bufferMsgCnt",bufMsgCnt,
"file_ports",file_ports)) != kOkRC )
"file_ports",file_ports,
"filterRtSenseFl",filterRtSenseFl)) != kOkRC )
{
rc = cwLogError(rc,"MIDI port parse args. failed.");
}
@ -361,7 +367,18 @@ cw::rc_t cw::midi::device::create( handle_t& h,
}
}
rc = create(h,cbFunc,cbArg,labelArray,fpi,appNameStr,fileDevName,fileDevReadAheadMicros,parseBufByteCnt,enableBufFl,bufMsgCnt);
rc = create(h,
cbFunc,
cbArg,
labelArray,
fpi,
appNameStr,
fileDevName,
fileDevReadAheadMicros,
parseBufByteCnt,
enableBufFl,
bufMsgCnt,
filterRtSenseFl);
}

View File

@ -32,7 +32,8 @@ namespace cw
unsigned fileDevReadAheadMicros = 3000,
unsigned parserBufByteCnt = 1024,
bool enableBufFl = false, // Enable buffer to hold all incoming msg's until RT thread can pick them up.
unsigned bufferMsgCnt = 4096); // Count of messages in input buffer.
unsigned bufferMsgCnt = 4096, // Count of messages in input buffer.
bool filterRtSenseFl = true);
rc_t create( handle_t& h,
cbFunc_t cbFunc,