cwIo.h,cpp, cwIoTest.cpp : Many changes to get an initial working version of audio with a audio meter UI.
This commit is contained in:
parent
469df69857
commit
f123be0323
92
cwIo.h
92
cwIo.h
@ -15,11 +15,22 @@ namespace cw
|
||||
|
||||
typedef handle<struct io_str> handle_t;
|
||||
|
||||
enum
|
||||
{
|
||||
kDisableFl = 0x00,
|
||||
kEnableFl = 0x01,
|
||||
kInFl = 0x02,
|
||||
kOutFl = 0x04,
|
||||
|
||||
kMeterFl = 0x08
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
kSerialTId,
|
||||
kMidiTId,
|
||||
kAudioTId,
|
||||
kAudioMeterTId,
|
||||
kSockTid,
|
||||
kWebSockTId,
|
||||
kUiTId
|
||||
@ -41,21 +52,28 @@ namespace cw
|
||||
|
||||
typedef struct audio_group_dev_str
|
||||
{
|
||||
const char* name; // Audio device name
|
||||
const char* label; // User label
|
||||
const char* devName; // Audio device name
|
||||
unsigned devIdx; // Audio device index
|
||||
unsigned chCnt; // Count of audio channels on this device
|
||||
unsigned flags; // kInFl | kOutFl | kMeterFl
|
||||
unsigned chIdx; // First channel of this device in i/oBufArray
|
||||
unsigned chCnt; // Count of audio channels on this device
|
||||
unsigned cbCnt; // Count of device driver callbacks
|
||||
std::atomic_uint readyCnt;// Used internally do not read or write.
|
||||
sample_t* meterA; // Meter values for this device.
|
||||
|
||||
std::atomic_uint readyCnt;// Used internally do not read or write.
|
||||
|
||||
struct audio_group_dev_str* link; //
|
||||
} audio_group_dev_t;
|
||||
|
||||
typedef struct audio_msg_str
|
||||
{
|
||||
unsigned groupId; // Unique group id
|
||||
const char* label; // User provided label
|
||||
unsigned groupId; // User provided group id
|
||||
double srate; // Group sample rate.
|
||||
unsigned dspFrameCnt; // Count of samples in each buffer pointed to by iBufArray[] and oBufArray[]
|
||||
|
||||
sample_t** iBufArray; // Array of ptrs to buffers of size bufSmpCnt
|
||||
sample_t** iBufArray; // Array of iBufChCnt ptrs to buffers of size bufSmpCnt
|
||||
unsigned iBufChCnt; // Count of elements in iBufArray[]
|
||||
time::spec_t* iTimeStampPtr; //
|
||||
audio_group_dev_t* iDevL; // Linked list of input devices which map directly to channels in iBufArray[]
|
||||
@ -92,11 +110,12 @@ namespace cw
|
||||
unsigned tid;
|
||||
union
|
||||
{
|
||||
serial_msg_t* serial;
|
||||
midi_msg_t* midi;
|
||||
audio_msg_t* audio;
|
||||
socket_msg_t* sock;
|
||||
ui_msg_t ui;
|
||||
serial_msg_t* serial;
|
||||
midi_msg_t* midi;
|
||||
audio_msg_t* audio;
|
||||
audio_group_dev_t* audioGroupDev; // audioMeterTId
|
||||
socket_msg_t* sock;
|
||||
ui_msg_t ui;
|
||||
} u;
|
||||
} msg_t;
|
||||
|
||||
@ -148,33 +167,20 @@ namespace cw
|
||||
// Audio
|
||||
//
|
||||
|
||||
unsigned audioDeviceCount( handle_t h );
|
||||
unsigned audioDeviceLabelToIndex( handle_t h, const char* label );
|
||||
const char* audioDeviceLabel( handle_t h, unsigned devIdx );
|
||||
rc_t audioDeviceSetup(
|
||||
handle_t h,
|
||||
unsigned devIdx,
|
||||
double srate,
|
||||
unsigned framesPerDeviceCycle,
|
||||
unsigned devBufBufN,
|
||||
unsigned framesPerDspCycle,
|
||||
unsigned inputFlags,
|
||||
unsigned outputFlags );
|
||||
|
||||
unsigned audioDeviceChannelCount( handle_t h, unsigned devIdx, unsigned dirFl );
|
||||
double audioDeviceSampleRate( handle_t h, unsigned devIdx );
|
||||
unsigned audioDeviceFramesPerCycle( handle_t h, unsigned devIdx );
|
||||
unsigned audioDeviceChannelFlags( handle_t h, unsigned devIdx, unsigned chIdx, unsigned dirFl );
|
||||
rc_t audioDeviceChannelSetFlags(handle_t h, unsigned devidx, unsigned chIdx, unsigned dirFl, unsigned flags );
|
||||
sample_t audioDeviceChannelMeter( handle_t h, unsigned devIdx, unsigned chIdx, unsigned dirFl );
|
||||
rc_t audioDeviceChannelSetGain( handle_t h, unsigned devIdx, unsigned chIdx, unsigned dirFl, double gain );
|
||||
double audioDeviceChannelGain( handle_t h, unsigned devIdx, unsigned chIdx, unsigned dirFl );
|
||||
|
||||
unsigned audioGroupCount( handle_t h );
|
||||
const char* audioGroupLabel( handle_t h, unsigned groupIdx );
|
||||
unsigned audioGroupId( handle_t h, unsigned groupIdx );
|
||||
rc_t audioGroupSetId( handle_t h, unsigned groupIdx, unsigned groupId );
|
||||
|
||||
unsigned audioDeviceCount( handle_t h );
|
||||
unsigned audioDeviceLabelToIndex( handle_t h, const char* label );
|
||||
const char* audioDeviceName( handle_t h, unsigned devIdx );
|
||||
double audioDeviceSampleRate( handle_t h, unsigned devIdx );
|
||||
unsigned audioDeviceFramesPerCycle( handle_t h, unsigned devIdx );
|
||||
unsigned audioDeviceChannelCount( handle_t h, unsigned devIdx, unsigned inOrOutFlag );
|
||||
rc_t audioDeviceEnableMeters( handle_t h, unsigned devIdx, unsigned inOutEnaFlags );
|
||||
const sample_t* audioDeviceMeters( handle_t h, unsigned devIdx, unsigned& chCntRef, unsigned inOrOutFlag );
|
||||
rc_t audioDeviceEnableTone( handle_t h, unsigned devidx, unsigned inOutEnaFlags );
|
||||
rc_t audioDeviceToneFlags( handle_t h, unsigned devIdx, unsigned inOrOutFlag, bool* toneFlA, unsigned chCnt );
|
||||
rc_t audioDeviceEnableMute( handle_t h, unsigned devidx, unsigned inOutEnaFlags );
|
||||
rc_t audioDeviceMuteFlags( handle_t h, unsigned devIdx, unsigned inOrOutFlag, bool* muteFlA, unsigned chCnt );
|
||||
rc_t audioDeviceSetGain( handle_t h, unsigned devidx, unsigned inOrOutFlags, double gain );
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
@ -220,6 +226,7 @@ namespace cw
|
||||
|
||||
// Return the uuid of the first matching 'eleName'.
|
||||
unsigned uiFindElementUuId( handle_t h, const char* eleName );
|
||||
unsigned uiFindElementUuId( handle_t h, unsigned appId );
|
||||
|
||||
rc_t uiCreateFromObject( handle_t h, const object_t* o, unsigned wsSessId, unsigned parentUuId=kInvalidId, const char* eleName=nullptr);
|
||||
rc_t uiCreateFromFile( handle_t h, const char* fn, unsigned wsSessId, unsigned parentUuId=kInvalidId);
|
||||
@ -253,9 +260,14 @@ namespace cw
|
||||
// Register parent/child/name app id's
|
||||
rc_t uiRegisterAppIdMap( handle_t h, const ui::appIdMap_t* map, unsigned mapN );
|
||||
|
||||
// Send a value to the user interface
|
||||
template< typename T >
|
||||
rc_t uiValueToUI( handle_t h, unsigned wsSessId, unsigned uuId, const T& value );
|
||||
// Send a value from the application to the UI.
|
||||
rc_t uiSendValue( handle_t h, unsigned wsSessId, unsigned uuId, bool value );
|
||||
rc_t uiSendValue( handle_t h, unsigned wsSessId, unsigned uuId, int value );
|
||||
rc_t uiSendValue( handle_t h, unsigned wsSessId, unsigned uuId, unsigned value );
|
||||
rc_t uiSendValue( handle_t h, unsigned wsSessId, unsigned uuId, float value );
|
||||
rc_t uiSendValue( handle_t h, unsigned wsSessId, unsigned uuId, double value );
|
||||
rc_t uiSendValue( handle_t h, unsigned wsSessId, unsigned uuId, const char* value );
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
142
cwIoTest.cpp
142
cwIoTest.cpp
@ -18,7 +18,7 @@ namespace cw
|
||||
enum
|
||||
{
|
||||
// Resource Based elements
|
||||
kPanelDivId,
|
||||
kPanelDivId = 1000,
|
||||
kQuitBtnId,
|
||||
kPanelBtn1Id,
|
||||
kPanelCheck1Id,
|
||||
@ -28,7 +28,20 @@ namespace cw
|
||||
kSelId,
|
||||
kOpt1Id,
|
||||
kOpt2Id,
|
||||
kOpt3Id
|
||||
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.
|
||||
@ -36,6 +49,7 @@ namespace cw
|
||||
{
|
||||
{ ui::kRootAppId, kPanelDivId, "panelDivId" },
|
||||
{ kPanelDivId, kQuitBtnId, "quitBtnId" },
|
||||
/*
|
||||
{ kPanelDivId, kPanelBtn1Id, "myBtn1Id" },
|
||||
{ kPanelDivId, kPanelCheck1Id, "myCheck1Id" },
|
||||
{ kPanelDivId, kPanelBtn2Id, "myBtn2Id" },
|
||||
@ -44,7 +58,8 @@ namespace cw
|
||||
{ kPanelDivId, kSelId, "mySel" },
|
||||
{ kSelId, kOpt1Id, "myOpt1" },
|
||||
{ kSelId, kOpt2Id, "myOpt2" },
|
||||
{ kSelId, kOpt3Id, "myOpt3" },
|
||||
{ SelId, kOpt3Id, "myOpt3" },
|
||||
*/
|
||||
};
|
||||
|
||||
unsigned mapN = sizeof(mapA)/sizeof(mapA[0]);
|
||||
@ -55,9 +70,67 @@ namespace cw
|
||||
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;
|
||||
}
|
||||
|
||||
@ -71,6 +144,28 @@ namespace cw
|
||||
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;
|
||||
}
|
||||
|
||||
@ -133,17 +228,29 @@ namespace cw
|
||||
{
|
||||
// the input channel is not disabled
|
||||
if( m.iBufArray[i] != NULL )
|
||||
memcpy(m.oBufArray[i], m.iBufArray[i], byteCnt);
|
||||
{
|
||||
for(unsigned j=0; j<m.dspFrameCnt; ++j )
|
||||
m.oBufArray[i][j] = m.iBufArray[i][j];
|
||||
//memcpy(m.oBufArray[i],m.iBufArray[i],byteCnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// the input channel is disabled but the output is not - so fill the output with zeros
|
||||
memset(m.oBufArray[i], 0, byteCnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
@ -162,6 +269,11 @@ namespace cw
|
||||
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;
|
||||
@ -180,7 +292,7 @@ namespace cw
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void report( handle_t h )
|
||||
{
|
||||
for(unsigned i=0; i<serialDeviceCount(h); ++i)
|
||||
@ -197,10 +309,9 @@ namespace cw
|
||||
}
|
||||
|
||||
for(unsigned i=0; i<audioDeviceCount(h); ++i)
|
||||
printf("audio: %s\n", audioDeviceLabel(h,i));
|
||||
printf("audio: %s\n", audioDeviceName(h,i));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +329,18 @@ cw::rc_t cw::io::test( const object_t* cfg )
|
||||
if((rc = start(app.ioH)) != kOkRC )
|
||||
cwLogError(rc,"Test app start failed.");
|
||||
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 );
|
||||
//audioDeviceEnableTone( app.ioH, devIdx, kOutFl | kEnableFl );
|
||||
}
|
||||
|
||||
|
||||
while( !isShuttingDown(app.ioH))
|
||||
{
|
||||
exec(app.ioH);
|
||||
|
Loading…
Reference in New Issue
Block a user