cwMidiAlsa.cpp : Fixed _cmMpAllocStruct() to correctly report failure on send_seq_subscribe_port().

This commit is contained in:
kevin 2024-03-25 11:45:42 -04:00
parent 68bcf7306c
commit 1c678700b7

View File

@ -75,7 +75,8 @@ namespace cw
} alsa_device_t; } alsa_device_t;
#define _cmMpErrMsg( rc, alsaRc, str ) cwLogError(kOpFailRC,"%s : ALSA Error:%i %s",(str),(alsaRc),snd_strerror(alsaRc)) #define _cmMpErrMsg( rc, alsaRc, str ) cwLogError(kOpFailRC,"%s : ALSA Error:%i %s",(str),(alsaRc),snd_strerror(alsaRc))
#define _cmMpErrMsg1( rc, alsaRc, fmt, arg ) cwLogError(kOpFailRC, fmt"%s : ALSA Error:%i %s",(arg),(alsaRc),snd_strerror(alsaRc)) #define _cmMpErrMsg1( rc, alsaRc, fmt, arg ) cwLogError(kOpFailRC, fmt" : ALSA Error:%i %s",(arg),(alsaRc),snd_strerror(alsaRc))
#define _cmMpWarnMsg2( alsaRc, fmt, arg0, arg1 ) cwLogWarning(fmt" : ALSA Error:%i %s",(arg0),(arg1),(alsaRc),snd_strerror(alsaRc))
alsa_device_t* _handleToPtr( handle_t h ){ return handleToPtr<handle_t,alsa_device_t>(h); } alsa_device_t* _handleToPtr( handle_t h ){ return handleToPtr<handle_t,alsa_device_t>(h); }
@ -301,7 +302,8 @@ namespace cw
snd_seq_client_info_t* cip = NULL; snd_seq_client_info_t* cip = NULL;
snd_seq_port_info_t* pip = NULL; snd_seq_port_info_t* pip = NULL;
snd_seq_port_subscribe_t *subs = NULL; snd_seq_port_subscribe_t *subs = NULL;
unsigned i,j,k,arc; unsigned i,j,k;
int arc;
for(i=0; i<kCtoD_MapN; ++i) for(i=0; i<kCtoD_MapN; ++i)
p->clientIdToDevIdxMap[i] = kInvalidIdx; p->clientIdToDevIdxMap[i] = kInvalidIdx;
@ -354,11 +356,16 @@ namespace cw
snd_seq_port_info_set_timestamp_queue(pip, p->alsa_queue); snd_seq_port_info_set_timestamp_queue(pip, p->alsa_queue);
// create the client port // create the client port
if((p->alsa_addr.port = snd_seq_create_port(p->h,pip)) < 0 ) //if((p->alsa_addr.port = snd_seq_create_port(p->h,pip)) < 0 )
if((arc = snd_seq_create_port(p->h,pip)) < 0 )
{ {
rc = _cmMpErrMsg(kOpFailRC,p->alsa_addr.port,"ALSA client port creation failed."); rc = _cmMpErrMsg(kOpFailRC,arc,"ALSA client port creation failed.");
goto errLabel; goto errLabel;
} }
else
{
p->alsa_addr.port = arc;
}
p->devCnt = 0; p->devCnt = 0;
@ -426,7 +433,9 @@ namespace cw
unsigned caps = snd_seq_port_info_get_capability(pip); unsigned caps = snd_seq_port_info_get_capability(pip);
snd_seq_addr_t addr = *snd_seq_port_info_get_addr(pip); snd_seq_addr_t addr = *snd_seq_port_info_get_addr(pip);
if( cwIsFlag(caps,SND_SEQ_PORT_CAP_READ) ) //printf("0x%x 0x%x %s %s\n",type,caps,name,port);
if( cwIsFlag(caps,SND_SEQ_PORT_CAP_READ) && cwIsFlag(caps,SND_SEQ_PORT_CAP_SUBS_READ) )
{ {
assert(j<p->devArray[i].iPortCnt); assert(j<p->devArray[i].iPortCnt);
p->devArray[i].iPortArray[j].inputFl = true; p->devArray[i].iPortArray[j].inputFl = true;
@ -443,12 +452,12 @@ namespace cw
snd_seq_port_subscribe_set_time_update(subs, 1); snd_seq_port_subscribe_set_time_update(subs, 1);
snd_seq_port_subscribe_set_time_real(subs, 1); snd_seq_port_subscribe_set_time_real(subs, 1);
if((arc = snd_seq_subscribe_port(p->h, subs)) < 0) if((arc = snd_seq_subscribe_port(p->h, subs)) < 0)
rc = _cmMpErrMsg1(kOpFailRC,arc,"Input port to app. subscription failed on port '%s'.",cwStringNullGuard(port)); _cmMpWarnMsg2(arc,"Input port to app. subscription failed on device:%s port '%s'.",cwStringNullGuard(name),cwStringNullGuard(port));
++j; ++j;
} }
if( cwIsFlag(caps,SND_SEQ_PORT_CAP_WRITE) ) if( cwIsFlag(caps,SND_SEQ_PORT_CAP_WRITE) && cwIsFlag(caps,SND_SEQ_PORT_CAP_SUBS_WRITE) && cwIsNotFlag(type,SND_SEQ_PORT_TYPE_APPLICATION) )
{ {
assert(k<p->devArray[i].oPortCnt); assert(k<p->devArray[i].oPortCnt);
p->devArray[i].oPortArray[k].inputFl = false; p->devArray[i].oPortArray[k].inputFl = false;
@ -461,7 +470,7 @@ namespace cw
snd_seq_port_subscribe_set_sender(subs, &p->alsa_addr); snd_seq_port_subscribe_set_sender(subs, &p->alsa_addr);
snd_seq_port_subscribe_set_dest( subs, &addr); snd_seq_port_subscribe_set_dest( subs, &addr);
if((arc = snd_seq_subscribe_port(p->h, subs)) < 0 ) if((arc = snd_seq_subscribe_port(p->h, subs)) < 0 )
rc = _cmMpErrMsg1(kOpFailRC,arc,"App to output port subscription failed on port '%s'.",cwStringNullGuard(port)); _cmMpWarnMsg2(arc,"App to output port subscription failed on device:%s port '%s'.",cwStringNullGuard(name), cwStringNullGuard(port));
++k; ++k;
} }