//| Copyright: (C) 2020-2024 Kevin Larke //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file. #include "cwCommon.h" #include "cwLog.h" #include "cwCommonImpl.h" #include "cwTest.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" #include "cwIoSocketChat.h" #include "cwIoAudioPanel.h" namespace cw { namespace io { // Application Id's for UI elements enum { // Resource Based elements kPanelDivId = 1000, kQuitBtnId, kReportBtnId, 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, kReportBtnId, "reportBtnId" }, }; unsigned mapN = sizeof(mapA)/sizeof(mapA[0]); // Application object typedef struct app_str { sock_chat::handle_t sockChat0H; sock_chat::handle_t sockChat1H; audio_panel::handle_t audioPanelH; handle_t ioH; } app_t; 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; case kReportBtnId: io::report( app->ioH ); break; } 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; ibyteN > 0 && m->dataA != nullptr ) { for(unsigned i=0; ibyteN; ++i) printf("%c",((const char*)m->dataA)[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); 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 ); switch( m->tid ) { case kSerialTId: serialCb(app,m->u.serial); break; case kMidiTId: break; case kAudioTId: if( m->u.audio != nullptr ) rc = audioCb(app,*m->u.audio); break; case kAudioMeterTId: break; case kSockTId: break; case kWebSockTId: break; case kUiTId: rc = uiCb(app,m->u.ui); break; case kExecTId: break; default: assert(0); } return rc; } void _report( handle_t h ) { for(unsigned i=0; i