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"
|
2021-01-31 16:16:08 +00:00
|
|
|
#include "cwIoSocketChat.h"
|
|
|
|
#include "cwIoAudioPanel.h"
|
2020-01-27 22:53:44 +00:00
|
|
|
|
|
|
|
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
|
2021-01-22 14:49:57 +00:00
|
|
|
kPanelDivId = 1000,
|
2021-01-20 18:12:35 +00:00
|
|
|
kQuitBtnId,
|
2021-01-31 16:16:08 +00:00
|
|
|
kReportBtnId,
|
2021-01-22 14:49:57 +00:00
|
|
|
|
|
|
|
kInMeterDivId,
|
|
|
|
kOutMeterDivId,
|
|
|
|
kInMeterBaseId = 2000, kInMeterMaxId = 2999,
|
|
|
|
kInGainBaseId = 3000, kInGainMaxId = 3999,
|
|
|
|
kInToneBaseId = 4000, kInToneMaxId = 4999,
|
|
|
|
kInMuteBaseId = 5000, kInMuteMaxId = 5999,
|
|
|
|
kOutMeterBaseId = 6000, kOutMeterMaxId= 6999,
|
|
|
|
kOutGainBaseId = 7000, kOutGainMaxId = 7999,
|
|
|
|
kOutToneBaseId = 8000, kOutToneMaxId = 8999,
|
|
|
|
kOutMuteBaseId = 9000, kOutMuteMaxId = 9999
|
2021-01-20 18:12:35 +00:00
|
|
|
};
|
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" },
|
2021-01-31 16:16:08 +00:00
|
|
|
{ kPanelDivId, kReportBtnId, "reportBtnId" },
|
2021-01-20 18:12:35 +00:00
|
|
|
};
|
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
|
|
|
|
{
|
2021-01-31 16:16:08 +00:00
|
|
|
sock_chat::handle_t sockChat0H;
|
|
|
|
sock_chat::handle_t sockChat1H;
|
|
|
|
audio_panel::handle_t audioPanelH;
|
2021-01-20 18:12:35 +00:00
|
|
|
handle_t ioH;
|
|
|
|
} app_t;
|
2020-01-27 22:53:44 +00:00
|
|
|
|
2021-01-22 14:49:57 +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;
|
2021-01-22 14:49:57 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
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;
|
2021-01-22 14:49:57 +00:00
|
|
|
|
2021-01-31 16:16:08 +00:00
|
|
|
case kReportBtnId:
|
|
|
|
io::report( app->ioH );
|
|
|
|
break;
|
2021-01-22 14:49:57 +00:00
|
|
|
}
|
2021-01-31 16:16:08 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
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 )
|
2021-01-22 14:49:57 +00:00
|
|
|
{
|
|
|
|
for(unsigned j=0; j<m.dspFrameCnt; ++j )
|
|
|
|
m.oBufArray[i][j] = m.iBufArray[i][j];
|
|
|
|
//memcpy(m.oBufArray[i],m.iBufArray[i],byteCnt);
|
|
|
|
}
|
2021-01-20 18:12:35 +00:00
|
|
|
else
|
2021-01-22 14:49:57 +00:00
|
|
|
{
|
2021-01-20 18:12:35 +00:00
|
|
|
// the input channel is disabled but the output is not - so fill the output with zeros
|
|
|
|
memset(m.oBufArray[i], 0, byteCnt);
|
2021-01-22 14:49:57 +00:00
|
|
|
}
|
2021-01-20 18:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-10-11 15:53:36 +00:00
|
|
|
rc_t serialCb( app_t* app, const serial_msg_t* m )
|
|
|
|
{
|
|
|
|
if( m->byteN > 0 && m->dataA != nullptr )
|
|
|
|
{
|
|
|
|
for(unsigned i=0; i<m->byteN; ++i)
|
|
|
|
printf("%c",((const char*)m->dataA)[i]);
|
|
|
|
}
|
|
|
|
return kOkRC;
|
|
|
|
}
|
|
|
|
|
2021-01-22 14:49:57 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
// 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);
|
2021-01-31 16:16:08 +00:00
|
|
|
|
|
|
|
if( app->sockChat0H.isValid() )
|
|
|
|
sock_chat::exec( app->sockChat0H, *m );
|
|
|
|
|
|
|
|
if( app->sockChat1H.isValid() )
|
|
|
|
sock_chat::exec( app->sockChat1H, *m );
|
|
|
|
|
|
|
|
if( app->audioPanelH.isValid() )
|
|
|
|
audio_panel::exec( app->audioPanelH, *m );
|
2021-01-20 18:12:35 +00:00
|
|
|
|
|
|
|
switch( m->tid )
|
|
|
|
{
|
|
|
|
case kSerialTId:
|
2021-10-11 15:53:36 +00:00
|
|
|
serialCb(app,m->u.serial);
|
2021-01-20 18:12:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kMidiTId:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kAudioTId:
|
|
|
|
if( m->u.audio != nullptr )
|
|
|
|
rc = audioCb(app,*m->u.audio);
|
|
|
|
break;
|
2021-01-22 14:49:57 +00:00
|
|
|
|
|
|
|
case kAudioMeterTId:
|
|
|
|
break;
|
2021-01-20 18:12:35 +00:00
|
|
|
|
2021-01-31 16:16:08 +00:00
|
|
|
case kSockTId:
|
2021-01-20 18:12:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kWebSockTId:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kUiTId:
|
|
|
|
rc = uiCb(app,m->u.ui);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2021-01-22 14:49:57 +00:00
|
|
|
|
2021-01-31 16:16:08 +00:00
|
|
|
void _report( handle_t h )
|
2021-01-20 18:12:35 +00:00
|
|
|
{
|
|
|
|
for(unsigned i=0; i<serialDeviceCount(h); ++i)
|
2021-01-31 16:16:08 +00:00
|
|
|
printf("serial: %s\n", serialDeviceLabel(h,i));
|
2021-01-20 18:12:35 +00:00
|
|
|
|
|
|
|
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)
|
2021-01-22 14:49:57 +00:00
|
|
|
printf("audio: %s\n", audioDeviceName(h,i));
|
2021-01-20 18:12:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cw::rc_t cw::io::test( const object_t* cfg )
|
|
|
|
{
|
2020-01-27 22:53:44 +00:00
|
|
|
rc_t rc;
|
2021-01-31 16:16:08 +00:00
|
|
|
app_t app = {};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kSocket0BaseId = 30000,
|
|
|
|
kSocket1BaseId = 31000,
|
|
|
|
kAudioPanelBaseId = 32000
|
|
|
|
};
|
|
|
|
|
|
|
|
// create the io framework instance
|
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-31 16:16:08 +00:00
|
|
|
// create a socket chat app
|
|
|
|
if((rc = sock_chat::create(app.sockChat0H,app.ioH,"sock0",kSocket0BaseId)) != kOkRC )
|
|
|
|
{
|
|
|
|
rc = cwLogError(rc,"sock chat app create failed");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a socket chat app
|
|
|
|
if((rc = sock_chat::create(app.sockChat1H,app.ioH,"sock1",kSocket1BaseId)) != kOkRC )
|
|
|
|
{
|
|
|
|
rc = cwLogError(rc,"sock chat app create failed");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the audio panel application
|
|
|
|
if((rc = audio_panel::create(app.audioPanelH, app.ioH, kAudioPanelBaseId)) != kOkRC )
|
|
|
|
{
|
|
|
|
rc = cwLogError(rc,"Audio panel manager create failed.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
//report(app.ioH);
|
|
|
|
|
2021-01-31 16:16:08 +00:00
|
|
|
// start the io framework instance
|
2021-01-20 18:12:35 +00:00
|
|
|
if((rc = start(app.ioH)) != kOkRC )
|
2021-01-22 14:49:57 +00:00
|
|
|
{
|
2021-01-31 16:16:08 +00:00
|
|
|
rc = cwLogError(rc,"Test app start failed.");
|
|
|
|
goto errLabel;
|
2021-01-22 14:49:57 +00:00
|
|
|
|
2021-01-31 16:16:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
2021-01-22 14:49:57 +00:00
|
|
|
unsigned devIdx = audioDeviceLabelToIndex(app.ioH, "main");
|
|
|
|
if( devIdx == kInvalidIdx )
|
2021-05-10 12:32:20 +00:00
|
|
|
{
|
2021-01-22 14:49:57 +00:00
|
|
|
cwLogError(kOpFailRC, "Unable to locate the requested audio device.");
|
2021-05-10 12:32:20 +00:00
|
|
|
goto errLabel;
|
|
|
|
}
|
2021-01-22 14:49:57 +00:00
|
|
|
else
|
|
|
|
{
|
2021-01-31 16:16:08 +00:00
|
|
|
//audioDeviceEnableMeters( app.ioH, devIdx, kInFl | kOutFl | kEnableFl );
|
2021-01-22 14:49:57 +00:00
|
|
|
//audioDeviceEnableTone( app.ioH, devIdx, kOutFl | kEnableFl );
|
|
|
|
}
|
2020-01-27 22:53:44 +00:00
|
|
|
}
|
2021-01-20 18:12:35 +00:00
|
|
|
|
2021-01-31 16:16:08 +00:00
|
|
|
// execuite the io framework
|
|
|
|
while( !isShuttingDown(app.ioH))
|
|
|
|
{
|
|
|
|
exec(app.ioH);
|
|
|
|
sleepMs(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
errLabel:
|
|
|
|
sock_chat::destroy(app.sockChat0H);
|
|
|
|
sock_chat::destroy(app.sockChat1H);
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|