#include "cwCommon.h" #include "cwLog.h" #include "cwCommonImpl.h" #include "cwMem.h" #include "cwObject.h" #include "cwTime.h" #include "cwMidiDecls.h" #include "cwMidi.h" #include "cwUiDecls.h" #include "cwIo.h" #include "cwIoTest.h" namespace cw { namespace io { // Application Id's for UI elements enum { // Resource Based elements kPanelDivId = 1000, kQuitBtnId, kPanelBtn1Id, kPanelCheck1Id, kPanelBtn2Id, kPanelCheck2Id, kPanelFloaterId, kSelId, kOpt1Id, kOpt2Id, kOpt3Id, 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 }; // 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" }, { SelId, kOpt3Id, "myOpt3" }, */ }; unsigned mapN = sizeof(mapA)/sizeof(mapA[0]); // Application object typedef struct app_str { handle_t ioH; } app_t; rc_t _uiCreateMeters( app_t* app, unsigned wsSessId, unsigned chCnt, bool inputFl ) { rc_t rc = kOkRC; unsigned parentUuId = ui::kRootAppId; unsigned divUuId = kInvalidId; unsigned titleUuId = kInvalidId; const char* title = inputFl ? "Input" : "Output"; const char* divEleName = inputFl ? "inMeterId" : "outMeterId"; unsigned divAppId = inputFl ? kInMeterDivId : kOutMeterDivId; unsigned baseMeterId = inputFl ? kInMeterBaseId : kOutMeterBaseId; unsigned baseToneId = inputFl ? kInToneBaseId : kOutToneBaseId; unsigned baseMuteId = inputFl ? kInMuteBaseId : kOutMuteBaseId; unsigned baseGainId = inputFl ? kInGainBaseId : kOutGainBaseId; unsigned colUuId; unsigned uuid; uiCreateTitle(app->ioH, titleUuId, wsSessId, parentUuId, nullptr, kInvalidId, nullptr, title ); uiCreateDiv( app->ioH, divUuId, wsSessId, parentUuId, divEleName, divAppId, "uiRow", nullptr ); uiCreateDiv( app->ioH, colUuId, wsSessId, divUuId, nullptr, kInvalidId, "uiCol", nullptr ); uiCreateTitle(app->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Tone" ); uiCreateTitle(app->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Mute" ); uiCreateTitle(app->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Gain" ); uiCreateTitle(app->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Meter" ); for(unsigned i=0; iioH, colUuId, wsSessId, divUuId, nullptr, kInvalidId, "uiCol", chLabel ); uiCreateCheck(app->ioH, uuid, wsSessId, colUuId, nullptr, baseToneId + i, "checkClass", nullptr, false ); uiCreateCheck(app->ioH, uuid, wsSessId, colUuId, nullptr, baseMuteId + i, "checkClass", nullptr, false ); uiCreateNumb( app->ioH, uuid, wsSessId, colUuId, nullptr, baseGainId + i, "floatClass", nullptr, 0.0, 3.0, 0.001, 3, 0 ); uiCreateNumb( app->ioH, uuid, wsSessId, colUuId, nullptr, baseMeterId + i, "floatClass", nullptr, -100.0, 100, 1, 2, 0 ); } return rc; } rc_t _uiCreateMeterPanel( app_t* app, unsigned wsSessId ) { unsigned devIdx = audioDeviceLabelToIndex( app->ioH, "main"); unsigned iChCnt = audioDeviceChannelCount( app->ioH, devIdx, kInFl); unsigned oChCnt = audioDeviceChannelCount( app->ioH, devIdx, kOutFl); _uiCreateMeters( app, wsSessId, iChCnt, true ); _uiCreateMeters( app, wsSessId, oChCnt, false ); return kOkRC; } rc_t _onUiInit(app_t* app, const ui_msg_t& m ) { rc_t rc = kOkRC; _uiCreateMeterPanel(app,m.wsSessId); 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; } if( kInMeterBaseId <= m.appId && m.appId < kInMeterMaxId ) { } else if( kInGainBaseId <= m.appId && m.appId < kInGainMaxId ) { } else if( kInToneBaseId <= m.appId && m.appId < kInToneMaxId ) { } else if( kInMuteBaseId <= m.appId && m.appId < kInMuteMaxId ) { } return rc; } rc_t _onUiEcho(app_t* app, const ui_msg_t& m ) { rc_t rc = kOkRC; return rc; } 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); // Copy the input to the output for(unsigned i=0; iflags,kInFl) ? kInMeterBaseId : kOutMeterBaseId; for(unsigned i=0; ichCnt; ++i) uiSendValue( app->ioH, kInvalidId, uiFindElementUuId(app->ioH,baseAppId+i), agd->meterA[i] ); return kOkRC; } // The main application callback rc_t testCb( void* arg, const msg_t* m ) { rc_t rc = kOkRC; app_t* app = reinterpret_cast(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 kAudioMeterTId: if( m->u.audioGroupDev != nullptr ) rc = _audioMeterCb(app,m->u.audioGroupDev); 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