cwIoAudioPanel.h/cpp,cwIoSocketChat.h/cpp, Makefile.am, cwIoTest.cpp : Initial commit of cwIoAudioPanel and cwIoSocketChat.

This commit is contained in:
kevin 2021-01-31 11:16:08 -05:00
parent 2b325ad334
commit da4caab0fd
6 changed files with 810 additions and 126 deletions

View File

@ -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

364
cwIoAudioPanel.cpp Normal file
View File

@ -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<handle_t,audio_panel_t>(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<audio_panel_device_t>();
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; i<chCnt; ++i)
{
unsigned chLabelN = 32;
char chLabel[ chLabelN+1 ];
snprintf(chLabel,chLabelN,"%i",i+1);
uiCreateDiv( p->ioH, 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; i<chCnt; ++i)
{
unsigned appId = apd->baseAppId + 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<audio_panel_t>();
// create the audio panels for each audio device
for(unsigned i=0; i<audioDeviceCount(ioH); ++i)
if( io::audioDeviceIsEnabled(ioH,i))
{
if((rc = _registerDevice(p, baseAppId, i, 0 )) != kOkRC )
{
rc = cwLogError(rc,"Audio panel device registration failed.");
goto errLabel;
}
baseAppId += kMaxAppId;
}
p->ioH = 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;
}

26
cwIoAudioPanel.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef cwIoAudioMeterUi_H
#define cwIoAudioMeterUi_H
namespace cw
{
namespace io
{
namespace audio_panel
{
typedef handle<struct audio_panel_str> 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

319
cwIoSocketChat.cpp Normal file
View File

@ -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<handle_t,sock_chat_t>(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<sock_chat_t>();
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;
}

23
cwIoSocketChat.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef cwIoSocketChat_h
#define cwIoSocketChat_h
namespace cw
{
namespace io
{
namespace sock_chat
{
typedef handle<struct sock_chat_str> 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

View File

@ -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; i<chCnt; ++i)
{
unsigned chLabelN = 32;
char chLabel[ chLabelN+1 ];
snprintf(chLabel,chLabelN,"%i",i+1);
uiCreateDiv( app->ioH, 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; i<agd->chCnt; ++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<app_t*>(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<serialDeviceCount(h); ++i)
printf("serial: %s\n", serialDeviceName(h,i));
printf("serial: %s\n", serialDeviceLabel(h,i));
for(unsigned i=0; i<midiDeviceCount(h); ++i)
for(unsigned j=0; j<2; ++j)
@ -319,36 +232,75 @@ namespace cw
cw::rc_t cw::io::test( const object_t* cfg )
{
rc_t rc;
app_t app = {};
app_t app = {};
enum
{
kSocket0BaseId = 30000,
kSocket1BaseId = 31000,
kAudioPanelBaseId = 32000
};
// create the io framework instance
if((rc = create(app.ioH,cfg,testCb,&app,mapA,mapN)) != kOkRC )
return rc;
//report(app.ioH);
// 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;
}
if((rc = start(app.ioH)) != kOkRC )
cwLogError(rc,"Test app start failed.");
// 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
{
}
//report(app.ioH);
// start the io framework instance
if((rc = start(app.ioH)) != kOkRC )
{
rc = cwLogError(rc,"Test app start failed.");
goto errLabel;
}
else
{
//
unsigned devIdx = audioDeviceLabelToIndex(app.ioH, "main");
if( devIdx == kInvalidIdx )
cwLogError(kOpFailRC, "Unable to locate the requested audio device.");
else
{
audioDeviceEnableMeters( app.ioH, devIdx, kInFl | kOutFl | kEnableFl );
//audioDeviceEnableMeters( app.ioH, devIdx, kInFl | kOutFl | kEnableFl );
//audioDeviceEnableTone( app.ioH, devIdx, kOutFl | kEnableFl );
}
while( !isShuttingDown(app.ioH))
{
exec(app.ioH);
sleepMs(50);
}
}
// execuite the io framework
while( !isShuttingDown(app.ioH))
{
exec(app.ioH);
sleepMs(50);
}
errLabel:
sock_chat::destroy(app.sockChat0H);
sock_chat::destroy(app.sockChat1H);
destroy(app.ioH);
printf("ioTest Done.\n");
return rc;