From da4caab0fd6c675951b29e6a4f076b2ab91d9d23 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 31 Jan 2021 11:16:08 -0500 Subject: [PATCH] cwIoAudioPanel.h/cpp,cwIoSocketChat.h/cpp, Makefile.am, cwIoTest.cpp : Initial commit of cwIoAudioPanel and cwIoSocketChat. --- Makefile.am | 4 +- cwIoAudioPanel.cpp | 364 +++++++++++++++++++++++++++++++++++++++++++++ cwIoAudioPanel.h | 26 ++++ cwIoSocketChat.cpp | 319 +++++++++++++++++++++++++++++++++++++++ cwIoSocketChat.h | 23 +++ cwIoTest.cpp | 200 ++++++++++--------------- 6 files changed, 810 insertions(+), 126 deletions(-) create mode 100644 cwIoAudioPanel.cpp create mode 100644 cwIoAudioPanel.h create mode 100644 cwIoSocketChat.cpp create mode 100644 cwIoSocketChat.h diff --git a/Makefile.am b/Makefile.am index 87fb83f..6d0f261 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,8 +50,8 @@ libcwHDR += src/libcw/cwMidiPort.h src/libcw/cwAudioD libcwSRC += src/libcw/cwMidiPort.cpp src/libcw/cwMidiAlsa.cpp src/libcw/cwAudioDeviceAlsa.cpp src/libcw/cwAudioDeviceTest.cpp if cwWEBSOCK -libcwHDR += src/libcw/cwIo.h src/libcw/cwIoTest.h -libcwSRC += src/libcw/cwIo.cpp src/libcw/cwIoTest.cpp +libcwHDR += src/libcw/cwIo.h src/libcw/cwIoTest.h src/libcw/cwIoSocketChat.h src/libcw/cwIoAudioPanel.h +libcwSRC += src/libcw/cwIo.cpp src/libcw/cwIoTest.cpp src/libcw/cwIoSocketChat.cpp src/libcw/cwIoAudioPanel.cpp endif endif diff --git a/cwIoAudioPanel.cpp b/cwIoAudioPanel.cpp new file mode 100644 index 0000000..27d1b09 --- /dev/null +++ b/cwIoAudioPanel.cpp @@ -0,0 +1,364 @@ +#include "cwCommon.h" +#include "cwLog.h" +#include "cwCommonImpl.h" +#include "cwMem.h" +#include "cwTime.h" +#include "cwObject.h" +#include "cwUiDecls.h" +#include "cwIo.h" +#include "cwIoAudioPanel.h" + +namespace cw { + namespace io { + namespace audio_panel { + + enum + { + kMaxChCnt = 250 + + }; + enum + { + kPanelDivAppId, + + kInMeterDivId, + kOutMeterDivId, + + kInMeterBaseId = 1*kMaxChCnt, kInMeterMaxId = kInMeterBaseId + kMaxChCnt-1, + kInGainBaseId = 2*kMaxChCnt, kInGainMaxId = kInGainBaseId + kMaxChCnt-1, + kInToneBaseId = 3*kMaxChCnt, kInToneMaxId = kInToneBaseId + kMaxChCnt-1, + kInMuteBaseId = 4*kMaxChCnt, kInMuteMaxId = kInMuteBaseId + kMaxChCnt-1, + kOutMeterBaseId = 5*kMaxChCnt, kOutMeterMaxId= kOutMeterBaseId + kMaxChCnt-1, + kOutGainBaseId = 6*kMaxChCnt, kOutGainMaxId = kOutGainBaseId + kMaxChCnt-1, + kOutToneBaseId = 7*kMaxChCnt, kOutToneMaxId = kOutToneBaseId + kMaxChCnt-1, + kOutMuteBaseId = 8*kMaxChCnt, kOutMuteMaxId = kOutMuteBaseId + kMaxChCnt-1, + + kMaxAppId + }; + + typedef struct audio_panel_device_str + { + unsigned devIdx; // + float dfltGain; // + unsigned iChCnt; // count of input channels + unsigned oChCnt; // count of output channels + unsigned baseAppId; // device appId range: baseAppId:baseAppId+kMaxAppId + struct audio_panel_device_str* link; + } audio_panel_device_t; + + typedef struct audio_panel_str + { + io::handle_t ioH; + unsigned maxAppId; + audio_panel_device_t* devL; + } audio_panel_t; + + audio_panel_t* _handleToPtr( handle_t h ) + { return handleToPtr(h); } + + rc_t _destroy( audio_panel_t* p ) + { + rc_t rc = kOkRC; + mem::release(p); + return rc; + } + + audio_panel_device_t* _get_device( audio_panel_t* p, unsigned devIdx ) + { + audio_panel_device_t* d = p->devL; + for(; d!=nullptr; d=d->link) + if( d->devIdx == devIdx ) + return d; + + cwLogError(kInvalidArgRC,"The audio meter device with index '%i' was not found. ", devIdx); + return nullptr; + } + + audio_panel_device_t* _app_id_to_device( audio_panel_t* p, unsigned appId ) + { + if( appId == kInvalidId ) + return nullptr; + + audio_panel_device_t* d = p->devL; + for(; d!=nullptr; d=d->link) + if( d->baseAppId <= appId && appId < d->baseAppId + kMaxAppId ) + return d; + + return nullptr; + } + + rc_t _registerDevice( audio_panel_t* p, unsigned baseAppId, unsigned devIdx, float dfltGain ) + { + rc_t rc = kOkRC; + audio_panel_device_t* d = nullptr; + + if((rc = audioDeviceEnableMeters( p->ioH, devIdx, kInFl | kOutFl | kEnableFl )) != kOkRC ) + goto errLabel; + + if((rc = audioDeviceEnableTone( p->ioH, devIdx, kOutFl | kEnableFl )) != kOkRC ) + goto errLabel; + + + d = mem::allocZ(); + d->baseAppId = baseAppId; + d->devIdx = devIdx; + d->dfltGain = dfltGain; + d->iChCnt = audioDeviceChannelCount( p->ioH, devIdx, io::kInFl ); + d->oChCnt = audioDeviceChannelCount( p->ioH, devIdx, io::kOutFl ); + d->link = p->devL; + p->devL = d; + p->maxAppId = std::max(baseAppId+kMaxAppId,p->maxAppId); + + errLabel: + if( rc != kOkRC ) + rc = cwLogError(rc,"Audio meter device registration failed."); + + return rc; + } + + + rc_t _create_meters( audio_panel_t* p, audio_panel_device_t* d, unsigned wsSessId, unsigned chCnt, bool inputFl ) + { + rc_t rc = kOkRC; + + if( chCnt == 0 ) + return rc; + + 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(p->ioH, titleUuId, wsSessId, parentUuId, nullptr, kInvalidId, nullptr, title ); + uiCreateDiv( p->ioH, divUuId, wsSessId, parentUuId, divEleName, d->baseAppId + divAppId, "uiRow", nullptr ); + + uiCreateDiv( p->ioH, colUuId, wsSessId, divUuId, nullptr, kInvalidId, "uiCol", nullptr ); + uiCreateTitle(p->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Tone" ); + uiCreateTitle(p->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Mute" ); + uiCreateTitle(p->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Gain" ); + uiCreateTitle(p->ioH, uuid, wsSessId, colUuId, nullptr, kInvalidId, nullptr, "Meter" ); + + for(unsigned i=0; iioH, colUuId, wsSessId, divUuId, nullptr, kInvalidId, "uiCol", chLabel ); + uiCreateCheck(p->ioH, uuid, wsSessId, colUuId, nullptr, d->baseAppId + baseToneId + i, "checkClass", nullptr, false ); + uiCreateCheck(p->ioH, uuid, wsSessId, colUuId, nullptr, d->baseAppId + baseMuteId + i, "checkClass", nullptr, false ); + uiCreateNumb( p->ioH, uuid, wsSessId, colUuId, nullptr, d->baseAppId + baseGainId + i, "floatClass", nullptr, 0.0, 3.0, 0.001, 3, 0 ); + uiCreateNumb( p->ioH, uuid, wsSessId, colUuId, nullptr, d->baseAppId + baseMeterId + i, "floatClass", nullptr, -100.0, 100, 1, 2, 0 ); + } + + return rc; + } + + // Called when an new UI connects to the engine. + rc_t _uiInit( audio_panel_t* p, const ui_msg_t& m ) + { + rc_t rc = kOkRC; + audio_panel_device_t* d = p->devL; + + for(; d!=nullptr; d=d->link) + { + _create_meters( p, d, m.wsSessId, d->iChCnt, true ); + _create_meters( p, d, m.wsSessId, d->oChCnt, false ); + } + + return rc; + } + + // Messages from UI to engine. + rc_t _uiValue( audio_panel_t* p, const ui_msg_t& m ) + { + rc_t rc = kOkRC; + audio_panel_device_t* d; + + if((d = _app_id_to_device(p, m.appId )) != nullptr) + { + + } + + return rc; + } + + + // Request from UI for engine value. + rc_t _uiEcho( audio_panel_t* p, const ui_msg_t& m ) + { + rc_t rc = kOkRC; + return rc; + } + + rc_t _uiCb( audio_panel_t* p, 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: + rc = _uiInit(p,m); + break; + + case ui::kValueOpId: + rc = _uiValue(p, m ); + break; + + case ui::kEchoOpId: + rc = _uiEcho( p, m ); + break; + + case ui::kIdleOpId: + break; + + case ui::kInvalidOpId: + // fall through + default: + assert(0); + break; + + } + return rc; + } + + rc_t _audioMeterCb( audio_panel_t* p, const audio_group_dev_t& agd ) + { + rc_t rc = kOkRC; + audio_panel_device_t* apd; + + if(( apd = _get_device(p,agd.devIdx)) != nullptr ) + { + unsigned meterAppId = cwIsFlag(agd.flags,kInFl) ? kInMeterBaseId : kOutMeterBaseId; + unsigned chCnt = cwIsFlag(agd.flags,kInFl) ? apd->iChCnt : apd->oChCnt; + + for(unsigned i=0; ibaseAppId + meterAppId + i; + uiSendValue( p->ioH, kInvalidId, uiFindElementUuId(p->ioH,appId), agd.meterA[i] ); + } + return kOkRC; + + } + return rc; + } + } + } +} + +cw::rc_t cw::io::audio_panel::create( handle_t& hRef, io::handle_t ioH, unsigned baseAppId ) +{ + rc_t rc = kOkRC; + if((rc = destroy(hRef)) != kOkRC ) + return rc; + + audio_panel_t* p = mem::allocZ(); + + + // create the audio panels for each audio device + for(unsigned i=0; iioH = ioH; + hRef.set(p); + + errLabel: + return rc; + +} + +cw::rc_t cw::io::audio_panel::destroy( handle_t& hRef ) +{ + rc_t rc = kOkRC; + if( !hRef.isValid() ) + return rc; + + audio_panel_t* p = _handleToPtr(hRef); + if((rc = _destroy(p)) != kOkRC ) + return rc; + + hRef.clear(); + + return rc; +} + + + +cw::rc_t cw::io::audio_panel::registerDevice( handle_t h, unsigned baseAppId, unsigned devIdx, float dfltGain ) +{ + audio_panel_t* p = _handleToPtr(h); + return _registerDevice(p,baseAppId,devIdx,dfltGain); +} + +cw::rc_t cw::io::audio_panel::exec( handle_t h, const msg_t& m ) +{ + rc_t rc = kOkRC; + audio_panel_t* p = _handleToPtr(h); + + switch( m.tid ) + { + case kSerialTId: + break; + + case kMidiTId: + break; + + case kAudioTId: + break; + + case kAudioMeterTId: + printf("."); fflush(stdout); + if( m.u.audioGroupDev != nullptr ) + rc = _audioMeterCb(p,*m.u.audioGroupDev); + break; + + case kSockTId: + break; + + case kWebSockTId: + break; + + case kUiTId: + rc = _uiCb(p,m.u.ui); + break; + + default: + assert(0); + + } + + return rc; + +} + +unsigned cw::io::audio_panel::maxAppId( handle_t h ) +{ + audio_panel_t* p = _handleToPtr(h); + return p->maxAppId; +} diff --git a/cwIoAudioPanel.h b/cwIoAudioPanel.h new file mode 100644 index 0000000..ed05a43 --- /dev/null +++ b/cwIoAudioPanel.h @@ -0,0 +1,26 @@ +#ifndef cwIoAudioMeterUi_H +#define cwIoAudioMeterUi_H + +namespace cw +{ + namespace io + { + namespace audio_panel + { + typedef handle handle_t; + + rc_t create( handle_t& hRef, io::handle_t ioH, unsigned baseAppId ); + rc_t destroy( handle_t& hRef ); + + rc_t registerDevice( handle_t h, unsigned baseAppId, unsigned devIdx, float dfltGain ); + + rc_t exec( handle_t h, const msg_t& msg ); + + unsigned maxAppId( handle_t h ); + + } + } +} + + +#endif diff --git a/cwIoSocketChat.cpp b/cwIoSocketChat.cpp new file mode 100644 index 0000000..f5f8686 --- /dev/null +++ b/cwIoSocketChat.cpp @@ -0,0 +1,319 @@ +#include "cwCommon.h" +#include "cwLog.h" +#include "cwCommonImpl.h" +#include "cwMem.h" +#include "cwObject.h" +#include "cwTime.h" +#include "cwUiDecls.h" +#include "cwIo.h" +#include "cwIoSocketChat.h" +#include "cwSocketDecls.h" +#include "cwText.h" + +namespace cw { + namespace io { + namespace sock_chat { + + enum + { + kUiDivAppId, + kUiSendTextAppId, + kUiRemoteAddrAppId, + kUiRemotePortAppId, + kUiSendBtnAppId, + kUiRecvTextAppId, + kMaxAppId + }; + + // Application values. + typedef struct sock_chat_str + { + io::handle_t ioH; // io framework handle + unsigned baseAppId; // minimum app id + unsigned sockIdx; // io socket associated with this application + char* sendText; // current text to send to remote socket + char* remoteAddr; // remote address to which this socket will send values + unsigned remotePort; // " port " " " " " " " + char* recvText; // last text recv'd from remote socket + unsigned recvTextUuId; // Uuid associated with the 'recv' text control + } sock_chat_t; + + sock_chat_t* _handleToPtr( handle_t h ) + { + return handleToPtr(h); + } + + bool _isAppId( sock_chat_t* p, unsigned appId ) + { return appId != kInvalidId && p->baseAppId <= appId && appId < p->baseAppId + kMaxAppId; } + + // Close the application + rc_t _destroy( sock_chat_t* p ) + { + rc_t rc = kOkRC; + mem::release(p->sendText); + mem::release(p->remoteAddr); + mem::release(p->recvText); + mem::release(p); + return rc; + } + + // Called when an new UI connects to the engine. + rc_t _uiInit( sock_chat_t* p, const ui_msg_t& m ) + { + rc_t rc = kOkRC; + unsigned parentUuId = ui::kRootAppId; + unsigned divUuId; + unsigned uuid; + + const int sn = 63; + char s[sn+1]; + snprintf(s,sn,"Chat: %i", io::socketPort(p->ioH, p->sockIdx )); + + uiCreateDiv( p->ioH, divUuId, m.wsSessId, parentUuId, nullptr, p->baseAppId + kUiDivAppId, "uiCol", s ); + uiCreateStr( p->ioH, uuid, m.wsSessId, divUuId, nullptr, p->baseAppId + kUiSendTextAppId, "uiText", "Send" ); + uiCreateStr( p->ioH, uuid, m.wsSessId, divUuId, nullptr, p->baseAppId + kUiRemoteAddrAppId, "uiText", "Addr", "127.0.0.1" ); + uiCreateNumb( p->ioH, uuid, m.wsSessId, divUuId, nullptr, p->baseAppId + kUiRemotePortAppId, "uiNumb", "Port", 0, 0xffff, 1, 0, 0 ); + uiCreateButton(p->ioH, uuid, m.wsSessId, divUuId, nullptr, p->baseAppId + kUiSendBtnAppId, "uiBtn", "Send" ); + uiCreateStr( p->ioH, p->recvTextUuId, m.wsSessId, divUuId, nullptr, p->baseAppId + kUiRecvTextAppId, "uiText", "Recv" ); + + return rc; + } + + // Messages from UI to engine. + rc_t _uiValue( sock_chat_t* p, const ui_msg_t& m ) + { + rc_t rc = kOkRC; + + // filter out callbacks not meant for this app + if( !_isAppId(p,m.appId) ) + return rc; + + switch( m.appId - p->baseAppId ) + { + case kUiSendTextAppId: + if( m.value->tid == ui::kStringTId ) + p->sendText = mem::duplStr(m.value->u.s); + break; + + case kUiRemoteAddrAppId: + if( m.value->tid == ui::kStringTId ) + p->remoteAddr = mem::duplStr(m.value->u.s); + break; + + case kUiRemotePortAppId: + switch( m.value->tid) + { + case ui::kIntTId: + p->remotePort = m.value->u.i; + break; + + case ui::kUIntTId: + p->remotePort = m.value->u.u; + break; + + default: + break; + } + break; + + case kUiRecvTextAppId: + if( m.value->tid == ui::kStringTId ) + p->recvText = mem::duplStr(m.value->u.s); + break; + + case kUiSendBtnAppId: + if( p->sendText ) + io::socketSend( p->ioH, p->sockIdx, p->sendText, textLength(p->sendText)+1, p->remoteAddr, p->remotePort ); + break; + + default: + break; + } + return rc; + } + + // Request from UI for engine value. + rc_t _uiEcho( sock_chat_t* p, const ui_msg_t& m ) + { + rc_t rc = kOkRC; + + // filter out callbacks not meant for this app + if( !_isAppId(p,m.appId) ) + return rc; + + switch( m.appId-p->baseAppId ) + { + case kUiSendTextAppId: + if( p->sendText ) + io::uiSendValue( p->ioH, m.wsSessId, m.uuId, p->sendText ); + break; + + case kUiRemoteAddrAppId: + if( p->remoteAddr) + io::uiSendValue( p->ioH, m.wsSessId, m.uuId, p->remoteAddr ); + break; + + case kUiRecvTextAppId: + if( p->recvText ) + io::uiSendValue( p->ioH, m.wsSessId, m.uuId, p->recvText ); + break; + + case kUiRemotePortAppId: + io::uiSendValue( p->ioH, m.wsSessId, m.uuId, p->remotePort ); + break; + + default: + break; + } + return rc; + } + + rc_t _uiCb( sock_chat_t* p, 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: + rc = _uiInit(p,m); + break; + + case ui::kValueOpId: + rc = _uiValue(p, m ); + break; + + case ui::kEchoOpId: + rc = _uiEcho( p, m ); + break; + + case ui::kIdleOpId: + break; + + case ui::kInvalidOpId: + // fall through + default: + assert(0); + break; + + } + return rc; + } + + rc_t _sockCb( sock_chat_t* p, const socket_msg_t& m ) + { + rc_t rc = kOkRC; + switch( m.cbId ) + { + case sock::kConnectCbId: + break; + + case sock::kReceiveCbId: + if( m.byteA && p->sockIdx == m.sockIdx ) + { + p->recvText = mem::duplStr((const char*)m.byteA); + io::uiSendValue(p->ioH, kInvalidId, p->recvTextUuId, (const char*)m.byteA ); + } + + break; + + case sock::kDisconnectCbId: + break; + } + return rc; + } + + } + } +} + + +cw::rc_t cw::io::sock_chat::create( handle_t& hRef, io::handle_t ioH, const char* socketLabel, unsigned baseAppId ) +{ + rc_t rc = kOkRC; + + if((rc = destroy(hRef)) != kOkRC ) + return rc; + + sock_chat_t* p = mem::allocZ(); + + p->ioH = ioH; + p->sockIdx = io::socketLabelToIndex( ioH, socketLabel ); + p->baseAppId = baseAppId; + + hRef.set(p); + + return rc; +} + +cw::rc_t cw::io::sock_chat::destroy( handle_t& hRef ) +{ + rc_t rc = kOkRC; + sock_chat_t* p = nullptr; + + if(!hRef.isValid()) + return rc; + + if((p = _handleToPtr(hRef)) == nullptr ) + return rc; + + if((rc = _destroy(p)) != kOkRC ) + return rc; + + hRef.clear(); + + return rc; + +} + +cw::rc_t cw::io::sock_chat::exec( handle_t h, const msg_t& m ) +{ + rc_t rc = kOkRC; + sock_chat_t* p = _handleToPtr(h); + + switch( m.tid ) + { + case kSerialTId: + break; + + case kMidiTId: + break; + + case kAudioTId: + break; + + case kAudioMeterTId: + break; + + case kSockTId: + if( m.u.sock != nullptr ) + rc = _sockCb(p,*m.u.sock); + break; + + case kWebSockTId: + break; + + case kUiTId: + rc = _uiCb(p,m.u.ui); + break; + + default: + assert(0); + + } + + return rc; +} + +unsigned cw::io::sock_chat::maxAppId( handle_t h ) +{ + sock_chat_t* p = _handleToPtr(h); + return p->baseAppId + kMaxAppId; +} + diff --git a/cwIoSocketChat.h b/cwIoSocketChat.h new file mode 100644 index 0000000..baecefc --- /dev/null +++ b/cwIoSocketChat.h @@ -0,0 +1,23 @@ +#ifndef cwIoSocketChat_h +#define cwIoSocketChat_h + +namespace cw +{ + namespace io + { + namespace sock_chat + { + typedef handle handle_t; + + rc_t create( handle_t& hRef, io::handle_t ioH, const char* socketLabel, unsigned baseAppId ); + rc_t destroy( handle_t& hRef ); + + rc_t exec( handle_t h, const msg_t& msg ); + + unsigned maxAppId( handle_t h ); + } + } +} + + +#endif diff --git a/cwIoTest.cpp b/cwIoTest.cpp index 237d0e7..507ed16 100644 --- a/cwIoTest.cpp +++ b/cwIoTest.cpp @@ -9,6 +9,8 @@ #include "cwUiDecls.h" #include "cwIo.h" #include "cwIoTest.h" +#include "cwIoSocketChat.h" +#include "cwIoAudioPanel.h" namespace cw { @@ -20,15 +22,7 @@ namespace cw // Resource Based elements kPanelDivId = 1000, kQuitBtnId, - kPanelBtn1Id, - kPanelCheck1Id, - kPanelBtn2Id, - kPanelCheck2Id, - kPanelFloaterId, - kSelId, - kOpt1Id, - kOpt2Id, - kOpt3Id, + kReportBtnId, kInMeterDivId, kOutMeterDivId, @@ -40,8 +34,6 @@ namespace cw kOutGainBaseId = 7000, kOutGainMaxId = 7999, kOutToneBaseId = 8000, kOutToneMaxId = 8999, kOutMuteBaseId = 9000, kOutMuteMaxId = 9999 - - }; // Application Id's for the resource based UI elements. @@ -49,17 +41,7 @@ namespace cw { { 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" }, - */ + { kPanelDivId, kReportBtnId, "reportBtnId" }, }; unsigned mapN = sizeof(mapA)/sizeof(mapA[0]); @@ -67,69 +49,17 @@ namespace cw // 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 _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; } @@ -143,29 +73,12 @@ namespace cw case kQuitBtnId: io::stop( app->ioH ); break; + + case kReportBtnId: + io::report( 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; } @@ -243,19 +156,21 @@ namespace cw return rc; } - rc_t _audioMeterCb( app_t* app, const audio_group_dev_t* agd ) - { - unsigned baseAppId = cwIsFlag(agd->flags,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); + + 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 ) { @@ -271,11 +186,9 @@ namespace cw break; case kAudioMeterTId: - if( m->u.audioGroupDev != nullptr ) - rc = _audioMeterCb(app,m->u.audioGroupDev); break; - case kSockTid: + case kSockTId: break; case kWebSockTId: @@ -293,10 +206,10 @@ namespace cw return rc; } - void report( handle_t h ) + void _report( handle_t h ) { for(unsigned i=0; i