2020-01-27 22:53:44 +00:00
|
|
|
#include "cwCommon.h"
|
|
|
|
#include "cwLog.h"
|
|
|
|
#include "cwCommonImpl.h"
|
|
|
|
#include "cwMem.h"
|
2021-01-20 18:12:35 +00:00
|
|
|
#include "cwObject.h"
|
2020-03-23 17:14:42 +00:00
|
|
|
#include "cwTime.h"
|
|
|
|
#include "cwMidiDecls.h"
|
2020-01-27 22:53:44 +00:00
|
|
|
#include "cwMidi.h"
|
2021-01-20 18:12:35 +00:00
|
|
|
#include "cwUiDecls.h"
|
2020-01-27 22:53:44 +00:00
|
|
|
#include "cwIo.h"
|
|
|
|
#include "cwIoTest.h"
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
2021-01-20 18:12:35 +00:00
|
|
|
// Application Id's for UI elements
|
|
|
|
enum
|
2020-01-27 22:53:44 +00:00
|
|
|
{
|
2021-01-20 18:12:35 +00:00
|
|
|
// Resource Based elements
|
|
|
|
kPanelDivId,
|
|
|
|
kQuitBtnId,
|
|
|
|
kPanelBtn1Id,
|
|
|
|
kPanelCheck1Id,
|
|
|
|
kPanelBtn2Id,
|
|
|
|
kPanelCheck2Id,
|
|
|
|
kPanelFloaterId,
|
|
|
|
kSelId,
|
|
|
|
kOpt1Id,
|
|
|
|
kOpt2Id,
|
|
|
|
kOpt3Id
|
|
|
|
};
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
// Application Id's for the resource based UI elements.
|
|
|
|
ui::appIdMap_t mapA[] =
|
|
|
|
{
|
|
|
|
{ ui::kRootAppId, kPanelDivId, "panelDivId" },
|
|
|
|
{ kPanelDivId, kQuitBtnId, "quitBtnId" },
|
|
|
|
{ kPanelDivId, kPanelBtn1Id, "myBtn1Id" },
|
|
|
|
{ kPanelDivId, kPanelCheck1Id, "myCheck1Id" },
|
|
|
|
{ kPanelDivId, kPanelBtn2Id, "myBtn2Id" },
|
|
|
|
{ kPanelDivId, kPanelCheck2Id, "myCheck2Id" },
|
|
|
|
{ kPanelDivId, kPanelFloaterId, "myFloater" },
|
|
|
|
{ kPanelDivId, kSelId, "mySel" },
|
|
|
|
{ kSelId, kOpt1Id, "myOpt1" },
|
|
|
|
{ kSelId, kOpt2Id, "myOpt2" },
|
|
|
|
{ kSelId, kOpt3Id, "myOpt3" },
|
|
|
|
};
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
unsigned mapN = sizeof(mapA)/sizeof(mapA[0]);
|
|
|
|
|
|
|
|
// Application object
|
|
|
|
typedef struct app_str
|
|
|
|
{
|
|
|
|
handle_t ioH;
|
|
|
|
} app_t;
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
rc_t _onUiInit(app_t* app, const ui_msg_t& m )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc_t _onUiValue(app_t* app, const ui_msg_t& m )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
|
|
|
|
switch( m.appId )
|
|
|
|
{
|
|
|
|
case kQuitBtnId:
|
|
|
|
io::stop( app->ioH );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
rc_t _onUiEcho(app_t* app, const ui_msg_t& m )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
return rc;
|
|
|
|
}
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
rc_t uiCb( app_t* app, const ui_msg_t& m )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
|
|
|
|
switch( m.opId )
|
|
|
|
{
|
|
|
|
case ui::kConnectOpId:
|
|
|
|
cwLogInfo("IO Test Connect: wsSessId:%i.",m.wsSessId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ui::kDisconnectOpId:
|
|
|
|
cwLogInfo("IO Test Disconnect: wsSessId:%i.",m.wsSessId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ui::kInitOpId:
|
|
|
|
_onUiInit(app,m);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ui::kValueOpId:
|
|
|
|
_onUiValue( app, m );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ui::kEchoOpId:
|
|
|
|
_onUiEcho( app, m );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ui::kIdleOpId:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ui::kInvalidOpId:
|
|
|
|
// fall through
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc_t audioCb( app_t* app, const audio_msg_t& m )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
|
|
|
|
unsigned chN = std::min(m.iBufChCnt,m.oBufChCnt);
|
|
|
|
unsigned byteCnt = m.dspFrameCnt * sizeof(sample_t);
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
// Copy the input to the output
|
|
|
|
for(unsigned i=0; i<chN; ++i)
|
|
|
|
if( m.oBufArray[i] != NULL )
|
|
|
|
{
|
|
|
|
// the input channel is not disabled
|
|
|
|
if( m.iBufArray[i] != NULL )
|
|
|
|
memcpy(m.oBufArray[i], m.iBufArray[i], byteCnt);
|
|
|
|
else
|
|
|
|
// the input channel is disabled but the output is not - so fill the output with zeros
|
|
|
|
memset(m.oBufArray[i], 0, byteCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The main application callback
|
|
|
|
rc_t testCb( void* arg, const msg_t* m )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
app_t* app = reinterpret_cast<app_t*>(arg);
|
|
|
|
|
|
|
|
switch( m->tid )
|
|
|
|
{
|
|
|
|
case kSerialTId:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kMidiTId:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioTId:
|
|
|
|
if( m->u.audio != nullptr )
|
|
|
|
rc = audioCb(app,*m->u.audio);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kSockTid:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kWebSockTId:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kUiTId:
|
|
|
|
rc = uiCb(app,m->u.ui);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void report( handle_t h )
|
|
|
|
{
|
|
|
|
for(unsigned i=0; i<serialDeviceCount(h); ++i)
|
|
|
|
printf("serial: %s\n", serialDeviceName(h,i));
|
|
|
|
|
|
|
|
for(unsigned i=0; i<midiDeviceCount(h); ++i)
|
|
|
|
for(unsigned j=0; j<2; ++j)
|
|
|
|
{
|
|
|
|
bool inputFl = j==0;
|
|
|
|
unsigned m = midiDevicePortCount(h,i,inputFl);
|
|
|
|
for(unsigned k=0; k<m; ++k)
|
|
|
|
printf("midi: %s: %s : %s\n", inputFl ? "in ":"out", midiDeviceName(h,i), midiDevicePortName(h,i,inputFl,k));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned i=0; i<audioDeviceCount(h); ++i)
|
|
|
|
printf("audio: %s\n", audioDeviceLabel(h,i));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cw::rc_t cw::io::test( const object_t* cfg )
|
|
|
|
{
|
2020-01-27 22:53:44 +00:00
|
|
|
rc_t rc;
|
2021-01-20 18:12:35 +00:00
|
|
|
app_t app = {};
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
if((rc = create(app.ioH,cfg,testCb,&app,mapA,mapN)) != kOkRC )
|
2020-01-27 22:53:44 +00:00
|
|
|
return rc;
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
//report(app.ioH);
|
|
|
|
|
|
|
|
if((rc = start(app.ioH)) != kOkRC )
|
|
|
|
cwLogError(rc,"Test app start failed.");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( !isShuttingDown(app.ioH))
|
|
|
|
{
|
|
|
|
exec(app.ioH);
|
|
|
|
sleepMs(50);
|
|
|
|
}
|
2020-01-27 22:53:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
|
|
|
|
destroy(app.ioH);
|
|
|
|
printf("ioTest Done.\n");
|
2020-01-27 22:53:44 +00:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|