Added 'decls' include files to hold public declarations for audio,midi,serial,socket, and websock modules.

Other minor changes to prepare for integration into cwIo.
In cwMidi* replaced 'byte_t' with 'uint8_t'.
In cwAudioDevice* removed redundant 'device' prefix from function names.
This commit is contained in:
kpl 2020-03-23 10:41:28 -04:00
parent 11f6d38330
commit 5cda838a93
20 changed files with 315 additions and 241 deletions

View File

@ -14,26 +14,31 @@ SRC += cwThread.cpp cwMutex.cpp
HDR += cwWebSock.h cwWebSockSvr.h cwLib.h
SRC += cwWebSock.cpp cwWebSockSvr.cpp cwLib.cpp
HDR += cwSerialPort.h cwSerialPortSrv.h
HDR += cwUiDecls.h cwUi.h cwUiTest.h
SRC += cwUi.cpp cwUiTest.cpp
HDR += cwSerialPortDecls.h cwSerialPort.h cwSerialPortSrv.h
SRC += cwSerialPort.cpp cwSerialPortSrv.cpp
HDR += cwMidi.h cwMidiPort.h
HDR += cwMidiDecls.h cwMidi.h cwMidiPort.h
SRC += cwMidi.cpp cwMidiPort.cpp cwMidiAlsa.cpp
HDR += cwAudioBuf.h cwAudioDevice.h cwAudioDeviceAlsa.h
HDR += cwAudioBufDecls.h cwAudioBuf.h cwAudioDeviceDecls.h cwAudioDevice.h cwAudioDeviceAlsa.h
SRC += cwAudioBuf.cpp cwAudioDevice.cpp cwAudioDeviceAlsa.cpp cwAudioDeviceTest.cpp
HDR += cwSocketDecls.h cwSocket.h
SRC += cwSocket.cpp
HDR += cwIo.h cwIoTest.h
SRC += cwIo.cpp cwIoTest.cpp
HDR += cwTcpSocket.h cwTcpSocketSrv.h cwTcpSocketTest.h
SRC += cwTcpSocket.cpp cwTcpSocketSrv.cpp cwTcpSocketTest.cpp
HDR += cwSocket.h
SRC += cwSocket.cpp
HDR += cwMdns.h cwEuCon.h cwDnsSd.h dns_sd/dns_sd.h dns_sd/dns_sd_print.h dns_sd/dns_sd_const.h dns_sd/fader.h dns_sd/rpt.h
SRC += cwMdns.cpp cwEuCon.cpp cwDnsSd.cpp dns_sd/dns_sd.cpp dns_sd/dns_sd_print.cpp dns_sd/fader.cpp dns_sd/rpt.cpp
HDR += cwIo.h cwIoTest.h
SRC += cwIo.cpp cwIoTest.cpp
# -ldl = dlopen,dlclose,dlsym
LIBS = -lpthread -lwebsockets -lasound -ldl

View File

@ -29,8 +29,10 @@
// out - outgoing samples are filled with a 1k sine tone
//)
#ifndef cmApBuf_H
#define cmApBuf_H
#ifndef cwAudioBuf_H
#define cwAudioBuf_H
#include "cwAudioBufDecls.h"
namespace cw
{
@ -113,7 +115,7 @@ namespace cw
// Return the meter window period as set by initialize()
unsigned meterMs(handle_t h);
// Set the meter update period. THis function limits the value to between 10 and 1000.
// Set the meter update period. This function limits the value to between 10 and 1000.
void setMeterMs( handle_t h, unsigned meterMs );
// Returns the channel count set via setup().
@ -211,7 +213,8 @@ namespace cw
// 3) This function just returns audio information it does not
// change any internal states.
// 4) The timestamp pointers are optional.
void getIO( handle_t h, unsigned iDevIdx, sample_t* iBufArray[], unsigned iBufChCnt, time::spec_t* iTimeStampPtr,
void getIO( handle_t h,
unsigned iDevIdx, sample_t* iBufArray[], unsigned iBufChCnt, time::spec_t* iTimeStampPtr,
unsigned oDevIdx, sample_t* oBufArray[], unsigned oBufChCnt, time::spec_t* oTimeStampPtr );

16
cwAudioBufDecls.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef cwAudioBufDecls_H
#define cwAudioBufDecls_H
namespace cw
{
namespace audio
{
namespace buf
{
}
}
}
#endif

View File

@ -112,19 +112,19 @@ cw::rc_t cw::audio::device::registerDriver( handle_t h, driver_t* drv )
return kOkRC;
}
unsigned cw::audio::device::deviceCount( handle_t h )
unsigned cw::audio::device::count( handle_t h )
{
device_t* p = _handleToPtr(h);
return p->nextDrvIdx;
}
unsigned cw::audio::device::deviceLabelToIndex( handle_t h, const char* label )
unsigned cw::audio::device::labelToIndex( handle_t h, const char* label )
{
unsigned n = deviceCount(h);
unsigned n = count(h);
unsigned i;
for(i=0; i<n; ++i)
{
const char* s = deviceLabel(h,i);
const char* s = device::label(h,i);
if( textCompare(s,label)==0)
return i;
}
@ -132,7 +132,7 @@ unsigned cw::audio::device::deviceLabelToIndex( handle_t h, const char* lab
}
const char* cw::audio::device::deviceLabel( handle_t h, unsigned devIdx )
const char* cw::audio::device::label( handle_t h, unsigned devIdx )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -140,7 +140,7 @@ const char* cw::audio::device::deviceLabel( handle_t h, unsigned devIdx )
return nullptr;
}
unsigned cw::audio::device::deviceChannelCount( handle_t h, unsigned devIdx, bool inputFl )
unsigned cw::audio::device::channelCount( handle_t h, unsigned devIdx, bool inputFl )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -148,7 +148,7 @@ unsigned cw::audio::device::deviceChannelCount( handle_t h, unsigned devIdx, boo
return 0;
}
double cw::audio::device::deviceSampleRate( handle_t h, unsigned devIdx )
double cw::audio::device::sampleRate( handle_t h, unsigned devIdx )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -156,7 +156,7 @@ double cw::audio::device::deviceSampleRate( handle_t h, unsigned devIdx )
return 0;
}
unsigned cw::audio::device::deviceFramesPerCycle( handle_t h, unsigned devIdx, bool inputFl )
unsigned cw::audio::device::framesPerCycle( handle_t h, unsigned devIdx, bool inputFl )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -164,7 +164,7 @@ unsigned cw::audio::device::deviceFramesPerCycle( handle_t h, unsigned devIdx, b
return 0;
}
cw::rc_t cw::audio::device::deviceSetup( handle_t h, unsigned devIdx, double sr, unsigned frmPerCycle, cbFunc_t cb, void* cbData )
cw::rc_t cw::audio::device::setup( handle_t h, unsigned devIdx, double sr, unsigned frmPerCycle, cbFunc_t cb, void* cbData )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -172,7 +172,7 @@ cw::rc_t cw::audio::device::deviceSetup( handle_t h, unsigned devIdx, double sr
return kInvalidArgRC;
}
cw::rc_t cw::audio::device::deviceStart( handle_t h, unsigned devIdx )
cw::rc_t cw::audio::device::start( handle_t h, unsigned devIdx )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -180,7 +180,7 @@ cw::rc_t cw::audio::device::deviceStart( handle_t h, unsigned devIdx )
return kInvalidArgRC;
}
cw::rc_t cw::audio::device::deviceStop( handle_t h, unsigned devIdx )
cw::rc_t cw::audio::device::stop( handle_t h, unsigned devIdx )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -188,7 +188,7 @@ cw::rc_t cw::audio::device::deviceStop( handle_t h, unsigned devIdx )
return kInvalidArgRC;
}
bool cw::audio::device::deviceIsStarted(handle_t h, unsigned devIdx )
bool cw::audio::device::isStarted(handle_t h, unsigned devIdx )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -196,7 +196,7 @@ bool cw::audio::device::deviceIsStarted(handle_t h, unsigned devIdx )
return false;
}
void cw::audio::device::deviceRealTimeReport( handle_t h, unsigned devIdx )
void cw::audio::device::realTimeReport( handle_t h, unsigned devIdx )
{
drv_t* d;
if((d = _indexToDriver(h,devIdx)) != nullptr )
@ -205,13 +205,13 @@ void cw::audio::device::deviceRealTimeReport( handle_t h, unsigned devIdx )
void cw::audio::device::report( handle_t h )
{
for(unsigned i=0; i<deviceCount(h); ++i)
for(unsigned i=0; i<count(h); ++i)
{
cwLogInfo( "%8.1f in:%i (%i) out:%i (%i) %s",
deviceSampleRate(h,i),
deviceChannelCount(h,i,true), deviceFramesPerCycle(h,i,true),
deviceChannelCount(h,i,false), deviceFramesPerCycle(h,i,false),
deviceLabel(h,i));
sampleRate(h,i),
channelCount(h,i,true), framesPerCycle(h,i,true),
channelCount(h,i,false), framesPerCycle(h,i,false),
label(h,i));
}
}

View File

@ -22,36 +22,14 @@
#ifndef cwAudioDevice_H
#define cwAudioDevice_H
#include "cwAudioDeviceDecls.h"
namespace cw
{
namespace audio
{
namespace device
{
typedef float sample_t;
// audioPacket_t flags
enum
{
kInterleavedApFl = 0x01, // The audio samples are interleaved.
kFloatApFl = 0x02 // The audio samples are single precision floating point values.
};
// Audio packet record used by the audioPacket_t callback.
// Audio ports send and receive audio using this data structure.
typedef struct
{
unsigned devIdx; // device associated with packet
unsigned begChIdx; // first device channel
unsigned chCnt; // count of channels
unsigned audioFramesCnt; // samples per channel (see note below)
unsigned bitsPerSample; // bits per sample word
unsigned flags; // kInterleavedApFl | kFloatApFl
void* audioBytesPtr; // pointer to sample data
void* cbArg; // user defined argument passed in via deviceSetup()
time::spec_t timeStamp; // Packet time stamp.
} audioPacket_t;
// Audio port callback signature.
// inPktArray[inPktCnt] are full packets of audio coming from the ADC to the application.
@ -94,12 +72,12 @@ namespace cw
rc_t registerDriver( handle_t h, driver_t* drv );
unsigned deviceCount( handle_t h );
unsigned deviceLabelToIndex( handle_t h, const char* label );
const char* deviceLabel( handle_t h, unsigned devIdx );
unsigned deviceChannelCount( handle_t h, unsigned devIdx, bool inputFl );
double deviceSampleRate( handle_t h, unsigned devIdx );
unsigned deviceFramesPerCycle( handle_t h, unsigned devIdx, bool inputFl );
unsigned count( handle_t h );
unsigned labelToIndex( handle_t h, const char* label );
const char* label( handle_t h, unsigned devIdx );
unsigned channelCount( handle_t h, unsigned devIdx, bool inputFl );
double sampleRate( handle_t h, unsigned devIdx );
unsigned framesPerCycle( handle_t h, unsigned devIdx, bool inputFl );
// Configure a device.
// All devices must be setup before they are started.
@ -111,7 +89,7 @@ namespace cw
// If the device is started when this function is called then it will be
// automatically stopped and then restarted following the reconfiguration.
// If the reconfiguration fails then the device may not be restared.
rc_t deviceSetup(
rc_t setup(
handle_t h,
unsigned devIdx,
double sr,
@ -119,10 +97,10 @@ namespace cw
cbFunc_t cb,
void* cbData );
rc_t deviceStart( handle_t h, unsigned devIdx );
rc_t deviceStop( handle_t h, unsigned devIdx );
bool deviceIsStarted( handle_t h, unsigned devIdx );
void deviceRealTimeReport( handle_t h, unsigned devIdx );
rc_t start( handle_t h, unsigned devIdx );
rc_t stop( handle_t h, unsigned devIdx );
bool isStarted( handle_t h, unsigned devIdx );
void realTimeReport( handle_t h, unsigned devIdx );
void report( handle_t h );
}

36
cwAudioDeviceDecls.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef cwAudioDeviceDefs_H
#define cwAudioDeviceDefs_H
namespace cw
{
namespace audio
{
namespace device
{
typedef float sample_t;
// audioPacket_t flags
enum
{
kInterleavedApFl = 0x01, // The audio samples are interleaved.
kFloatApFl = 0x02 // The audio samples are single precision floating point values.
};
// Audio packet record used by the audioPacket_t callback.
// Audio ports send and receive audio using this data structure.
typedef struct
{
unsigned devIdx; // device associated with packet
unsigned begChIdx; // first device channel
unsigned chCnt; // count of channels
unsigned audioFramesCnt; // samples per channel (see note below)
unsigned bitsPerSample; // bits per sample word
unsigned flags; // kInterleavedApFl | kFloatApFl
void* audioBytesPtr; // pointer to sample data
void* cbArg; // user defined argument passed in via deviceSetup()
time::spec_t timeStamp; // Packet time stamp.
} audioPacket_t;
}
}
}
#endif

View File

@ -25,11 +25,7 @@ namespace cw
typedef struct
{
unsigned bufCnt; // 2=double buffering 3=triple buffering
unsigned chIdx; // first test channel
//unsigned chCnt; // count of channels to test
unsigned framesPerCycle; // DSP frames per cycle
unsigned bufFrmCnt; // count of DSP frames used by the audio buffer (bufCnt * framesPerCycle)
unsigned bufSmpCnt; // count of samples used by the audio buffer (chCnt * bufFrmCnt)
unsigned inDevIdx; // input device index
unsigned outDevIdx; // output device index
double srate; // audio sample rate
@ -51,8 +47,6 @@ namespace cw
"-r <srate> -c <chcnt> -b <bufcnt> -f <frmcnt> -i <idevidx> -o <odevidx> -t -p -h \n"
"\n"
"-r <srate> = sample rate\n"
"-a <chidx> = first channel\n"
"-c <chcnt> = audio channels\n"
"-b <bufcnt> = count of buffers\n"
"-f <frmcnt> = count of samples per buffer\n"
"-i <idevidx> = input device index\n"
@ -119,16 +113,10 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv )
if( _cmApGetOpt(argc,argv,"-h",0,true) )
_cmApPrintUsage();
runFl = _cmApGetOpt(argc,argv,"-p",0,true) ? false : true;
r.srate = _cmApGetOpt(argc,argv,"-r",44100);
//r.chIdx = _cmApGetOpt(argc,argv,"-a",0);
//r.chCnt = _cmApGetOpt(argc,argv,"-c",2);
r.bufCnt = _cmApGetOpt(argc,argv,"-b",3);
r.framesPerCycle = _cmApGetOpt(argc,argv,"-f",512);
//r.bufFrmCnt = (r.bufCnt*r.framesPerCycle);
//r.bufSmpCnt = (r.chCnt * r.bufFrmCnt);
//r.logCnt = 100;
r.meterMs = 50;
r.inDevIdx = _cmGlobalInDevIdx = _cmApGetOpt(argc,argv,"-i",0);
@ -161,9 +149,9 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv )
}
// report the current audio device configuration
for(i=0; i<deviceCount(h); ++i)
for(i=0; i<device::count(h); ++i)
{
cwLogInfo("%i [in: chs=%i frames=%i] [out: chs=%i frames=%i] srate:%8.1f %s",i,deviceChannelCount(h,i,true),deviceFramesPerCycle(h,i,true),deviceChannelCount(h,i,false),deviceFramesPerCycle(h,i,false),deviceSampleRate(h,i),deviceLabel(h,i));
cwLogInfo("%i [in: chs=%i frames=%i] [out: chs=%i frames=%i] srate:%8.1f %s",i,device::channelCount(h,i,true),framesPerCycle(h,i,true),channelCount(h,i,false),framesPerCycle(h,i,false),sampleRate(h,i),label(h,i));
}
// report the current audio devices using the audio port interface function
@ -172,29 +160,29 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv )
if( runFl )
{
// initialize the audio bufer
buf::create( r.audioBufH, deviceCount(h), r.meterMs );
buf::create( r.audioBufH, device::count(h), r.meterMs );
// setup the buffer for the output device
buf::setup( r.audioBufH, r.outDevIdx, r.srate, r.framesPerCycle, r.bufCnt, deviceChannelCount(h,r.outDevIdx,true), r.framesPerCycle, deviceChannelCount(h,r.outDevIdx,false), r.framesPerCycle );
buf::setup( r.audioBufH, r.outDevIdx, r.srate, r.framesPerCycle, r.bufCnt, channelCount(h,r.outDevIdx,true), r.framesPerCycle, channelCount(h,r.outDevIdx,false), r.framesPerCycle );
// setup the buffer for the input device
//if( r.inDevIdx != r.outDevIdx )
buf::setup( r.audioBufH, r.inDevIdx, r.srate, r.framesPerCycle, r.bufCnt, deviceChannelCount(h,r.inDevIdx,true), r.framesPerCycle, deviceChannelCount(h,r.inDevIdx,false), r.framesPerCycle );
buf::setup( r.audioBufH, r.inDevIdx, r.srate, r.framesPerCycle, r.bufCnt, channelCount(h,r.inDevIdx,true), r.framesPerCycle, channelCount(h,r.inDevIdx,false), r.framesPerCycle );
// setup an output device
if(deviceSetup(h, r.outDevIdx,r.srate,r.framesPerCycle,_cmApPortCb2,&r) != kOkRC )
if(setup(h, r.outDevIdx,r.srate,r.framesPerCycle,_cmApPortCb2,&r) != kOkRC )
cwLogInfo("Out device setup failed.");
else
// setup an input device
if( deviceSetup(h, r.inDevIdx,r.srate,r.framesPerCycle,_cmApPortCb2,&r) != kOkRC )
if( setup(h, r.inDevIdx,r.srate,r.framesPerCycle,_cmApPortCb2,&r) != kOkRC )
cwLogInfo("In device setup failed.");
else
// start the input device
if( deviceStart(h, r.inDevIdx) != kOkRC )
if( start(h, r.inDevIdx) != kOkRC )
cwLogInfo("In device start failed.");
else
// start the output device
if( deviceStart(h, r.outDevIdx) != kOkRC )
if( start(h, r.outDevIdx) != kOkRC )
cwLogInfo("Out Device start failed.");
else
cwLogInfo("Setup complete!");
@ -208,7 +196,7 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv )
char c;
while((c=getchar()) != 'q')
{
deviceRealTimeReport(h, r.outDevIdx );
realTimeReport(h, r.outDevIdx );
switch(c)
{
@ -241,13 +229,13 @@ cw::rc_t cw::audio::device::test( int argc, const char** argv )
}
// stop the input device
if( deviceIsStarted(h,r.inDevIdx) )
if( deviceStop(h,r.inDevIdx) != kOkRC )
if( isStarted(h,r.inDevIdx) )
if( stop(h,r.inDevIdx) != kOkRC )
cwLogInfo("In device stop failed.");
// stop the output device
if( deviceIsStarted(h,r.outDevIdx) )
if( deviceStop(h,r.outDevIdx) != kOkRC )
if( isStarted(h,r.outDevIdx) )
if( stop(h,r.outDevIdx) != kOkRC )
cwLogInfo("Out device stop failed.");
}

View File

@ -2,6 +2,7 @@
#include "cwLog.h"
#include "cwCommonImpl.h"
#include "cwMem.h"
#include "cwTime.h"
#include "cwMidi.h"
namespace cw {
@ -9,8 +10,8 @@ namespace cw {
typedef struct statusDesc_str
{
byte_t status;
byte_t byteCnt;
uint8_t status;
uint8_t byteCnt;
const char* label;
} statusDesc_t;
@ -84,7 +85,7 @@ namespace cw {
//====================================================================================================
const char* cw::midi::statusToLabel( byte_t status )
const char* cw::midi::statusToLabel( uint8_t status )
{
unsigned i;
@ -102,7 +103,7 @@ const char* cw::midi::statusToLabel( byte_t status )
return _statusDescArray[i].label;
}
const char* cw::midi::metaStatusToLabel( byte_t metaStatus )
const char* cw::midi::metaStatusToLabel( uint8_t metaStatus )
{
int i;
for(i=0; _metaStatusDescArray[i].status != kInvalidMetaMdId; ++i)
@ -112,7 +113,7 @@ const char* cw::midi::metaStatusToLabel( byte_t metaStatus )
return _metaStatusDescArray[i].label;
}
const char* cw::midi::pedalLabel( byte_t d0 )
const char* cw::midi::pedalLabel( uint8_t d0 )
{
int i;
for(i=0; _pedalLabel[i].status != kInvalidMidiByte; ++i)
@ -122,7 +123,7 @@ const char* cw::midi::pedalLabel( byte_t d0 )
return _pedalLabel[i].label;
}
cw::midi::byte_t cw::midi::statusToByteCount( byte_t status )
uint8_t cw::midi::statusToByteCount( uint8_t status )
{
unsigned i;
@ -142,7 +143,7 @@ cw::midi::byte_t cw::midi::statusToByteCount( byte_t status )
return 0;
}
unsigned cw::midi::to14Bits( byte_t d0, byte_t d1 )
unsigned cw::midi::to14Bits( uint8_t d0, uint8_t d1 )
{
unsigned val = d0;
val <<= 7;
@ -150,26 +151,26 @@ unsigned cw::midi::to14Bits( byte_t d0, byte_t d1 )
return val;
}
void cw::midi::split14Bits( unsigned v, byte_t& d0Ref, byte_t& d1Ref )
void cw::midi::split14Bits( unsigned v, uint8_t& d0Ref, uint8_t& d1Ref )
{
d0Ref = (v & 0x3f80) >> 7;
d1Ref = v & 0x7f;
}
int cw::midi::toPbend( byte_t d0, byte_t d1 )
int cw::midi::toPbend( uint8_t d0, uint8_t d1 )
{
int v = to14Bits(d0,d1);
return v - 8192;
}
void cw::midi::splitPbend( int v, byte_t& d0Ref, byte_t& d1Ref )
void cw::midi::splitPbend( int v, uint8_t& d0Ref, uint8_t& d1Ref )
{
unsigned uv = v + 8192;
split14Bits(uv,d0Ref,d1Ref);
}
//====================================================================================================
const char* cw::midi::midiToSciPitch( byte_t pitch, char* label, unsigned labelCharCnt )
const char* cw::midi::midiToSciPitch( uint8_t pitch, char* label, unsigned labelCharCnt )
{
static char buf[ kMidiSciPitchCharCnt ];
@ -214,7 +215,7 @@ const char* cw::midi::midiToSciPitch( byte_t pitch, char* label, unsigned la
}
cw::midi::byte_t cw::midi::sciPitchToMidiPitch( char pitch, int acc, int octave )
uint8_t cw::midi::sciPitchToMidiPitch( char pitch, int acc, int octave )
{
int idx = -1;
@ -240,7 +241,7 @@ cw::midi::byte_t cw::midi::sciPitchToMidiPitch( char pitch, int acc, int octa
}
cw::midi::byte_t cw::midi::sciPitchToMidi( const char* sciPitchStr )
uint8_t cw::midi::sciPitchToMidi( const char* sciPitchStr )
{
const char* cp = sciPitchStr;
bool sharpFl = false;

View File

@ -77,8 +77,6 @@ namespace cw
};
typedef unsigned char byte_t;
typedef struct timespec timestamp_t;
//===============================================================================================
// Utility Functions
@ -104,41 +102,23 @@ namespace cw
template< typename T> bool isPedalUp( T s, T d0, T d1 ) { return ( cmMidiIsPedal(s,d0) && (d1)<64 ); }
const char* statusToLabel( byte_t status );
const char* metaStatusToLabel( byte_t metaStatus );
const char* pedalLabel( byte_t d0 );
const char* statusToLabel( uint8_t status );
const char* metaStatusToLabel( uint8_t metaStatus );
const char* pedalLabel( uint8_t d0 );
// Returns kInvalidMidiByte if status is not a valid status byte
byte_t statusToByteCount( byte_t status );
uint8_t statusToByteCount( uint8_t status );
unsigned to14Bits( byte_t d0, byte_t d1 );
void split14Bits( unsigned v, byte_t& d0Ref, byte_t& d1Ref );
int toPbend( byte_t d0, byte_t d1 );
void splitPbend( int v, byte_t& d0Ref, byte_t& d1Ref );
unsigned to14Bits( uint8_t d0, uint8_t d1 );
void split14Bits( unsigned v, uint8_t& d0Ref, uint8_t& d1Ref );
int toPbend( uint8_t d0, uint8_t d1 );
void splitPbend( int v, uint8_t& d0Ref, uint8_t& d1Ref );
//===============================================================================================
// MIDI Communication data types
//
typedef struct msg_str
{
//unsigned deltaUs; // time since last MIDI msg in microseconds
timestamp_t timeStamp;
byte_t status; // midi status byte
byte_t d0; // midi data byte 0
byte_t d1; // midi data byte 1
byte_t pad;
} msg_t;
typedef struct packet_str
{
void* cbDataPtr; // application supplied reference value from mdParserCreate()
unsigned devIdx; // the device the msg originated from
unsigned portIdx; // the port index on the source device
msg_t* msgArray; // pointer to an array of 'msgCnt' mdMsg records or NULL if sysExMsg is non-NULL
byte_t* sysExMsg; // pointer to a sys-ex msg or NULL if msgArray is non-NULL (see note below)
unsigned msgCnt; // count of mdMsg records or sys-ex bytes
} packet_t;
// Notes: If the sys-ex message can be contained in a single msg then
// then the first msg byte is kSysExMdId and the last is kSysComEoxMdId.
@ -150,12 +130,12 @@ namespace cw
// buffer is returned. If label[] is given the it
// should have at least 5 (kMidiPitchCharCnt) char's (including the terminating zero).
// If 'pitch' is outside of the range 0-127 then a blank string is returned.
const char* midiToSciPitch( byte_t pitch, char* label, unsigned labelCharCnt );
const char* midiToSciPitch( uint8_t pitch, char* label, unsigned labelCharCnt );
// Convert a scientific pitch to MIDI pitch. acc == 1 == sharp, acc == -1 == flat.
// The pitch character must be in the range 'A' to 'G'. Upper or lower case is valid.
// Return kInvalidMidiPitch if the arguments are not valid.
byte_t sciPitchToMidiPitch( char pitch, int acc, int octave );
uint8_t sciPitchToMidiPitch( char pitch, int acc, int octave );
// Scientific pitch string: [A-Ga-g][#b][#] where # may be -1 to 9.
@ -163,7 +143,7 @@ namespace cw
// scientific pitch string. This function will convert C-1 to G9 to
// valid MIDI pitch values 0 to 127. Scientific pitch strings outside
// of this range will be returned as kInvalidMidiPitch.
byte_t sciPitchToMidi( const char* sciPitchStr );
uint8_t sciPitchToMidi( const char* sciPitchStr );
}
}

View File

@ -2,8 +2,8 @@
#include "cwLog.h"
#include "cwCommonImpl.h"
#include "cwMem.h"
#include "cwMidi.h"
#include "cwTime.h"
#include "cwMidi.h"
#include "cwTextBuf.h"
#include "cwMidiPort.h"
#include "cwThread.h"
@ -111,7 +111,7 @@ namespace cw
}
void _cmMpSplit14Bits( unsigned v, byte_t* d0, byte_t* d1 )
void _cmMpSplit14Bits( unsigned v, uint8_t* d0, uint8_t* d1 )
{
*d0 = (v & 0x3f80) >> 7;
*d1 = v & 0x7f;
@ -156,9 +156,9 @@ namespace cw
unsigned microSecs1 = (ev->time.time.tv_sec * 1000000) + (ev->time.time.tv_nsec/1000);
//unsigned deltaMicroSecs = p->prvTimeMicroSecs==0 ? 0 : microSecs1 - p->prvTimeMicroSecs;
byte_t d0 = 0xff;
byte_t d1 = 0xff;
byte_t status = 0;
uint8_t d0 = 0xff;
uint8_t d1 = 0xff;
uint8_t status = 0;
switch(ev->type)
{
@ -244,7 +244,7 @@ namespace cw
if( status != 0 )
{
byte_t ch = ev->data.note.channel;
uint8_t ch = ev->data.note.channel;
time::spec_t ts;
ts.tv_sec = p->baseTimeStamp.tv_sec + ev->time.time.tv_sec;
ts.tv_nsec = p->baseTimeStamp.tv_nsec + ev->time.time.tv_nsec;
@ -709,7 +709,7 @@ const char* cw::midi::device::portName( handle_t h, unsigned devIdx, unsign
}
cw::rc_t cw::midi::device::send( handle_t h, unsigned devIdx, unsigned portIdx, byte_t status, byte_t d0, byte_t d1 )
cw::rc_t cw::midi::device::send( handle_t h, unsigned devIdx, unsigned portIdx, uint8_t status, uint8_t d0, uint8_t d1 )
{
rc_t rc = kOkRC;
snd_seq_event_t ev;
@ -797,7 +797,7 @@ cw::rc_t cw::midi::device::send( handle_t h, unsigned devIdx, unsigned portIdx,
return rc;
}
cw::rc_t cw::midi::device::sendData( handle_t h, unsigned devIdx, unsigned portIdx, const byte_t* dataPtr, unsigned byteCnt )
cw::rc_t cw::midi::device::sendData( handle_t h, unsigned devIdx, unsigned portIdx, const uint8_t* dataPtr, unsigned byteCnt )
{
return cwLogError(kInvalidOpRC,"cmMpDeviceSendData() has not yet been implemented for ALSA.");
}

29
cwMidiDecls.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef cwMidiDecls_H
#define cwMidiDecls_H
namespace cw
{
namespace midi
{
typedef struct msg_str
{
//unsigned deltaUs; // time since last MIDI msg in microseconds
time::spec_t timeStamp;
uint8_t status; // midi status byte
uint8_t d0; // midi data byte 0
uint8_t d1; // midi data byte 1
uint8_t pad;
} msg_t;
typedef struct packet_str
{
void* cbDataPtr; // application supplied reference value from mdParserCreate()
unsigned devIdx; // the device the msg originated from
unsigned portIdx; // the port index on the source device
msg_t* msgArray; // pointer to an array of 'msgCnt' mdMsg records or NULL if sysExMsg is non-NULL
uint8_t* sysExMsg; // pointer to a sys-ex msg or NULL if msgArray is non-NULL (see note below)
unsigned msgCnt; // count of mdMsg records or sys-ex bytes
} packet_t;
}
}
#endif

View File

@ -2,8 +2,8 @@
#include "cwLog.h"
#include "cwCommonImpl.h"
#include "cwMem.h"
#include "cwMidi.h"
#include "cwTime.h"
#include "cwMidi.h"
#include "cwTextBuf.h"
#include "cwMidiPort.h"
@ -43,11 +43,11 @@ namespace cw
unsigned state; // parser state id
unsigned errCnt; // accumlated error count
byte_t status; // running status
byte_t data0; // data byte 0
uint8_t status; // running status
uint8_t data0; // data byte 0
unsigned dataCnt; // data byte cnt for current status
unsigned dataIdx; // index (0 or 1) of next data byte
byte_t* buf; // output buffer
uint8_t* buf; // output buffer
unsigned bufByteCnt; // output buffer byte cnt
unsigned bufIdx; // next output buffer index
unsigned msgCnt; // count of channel messages in the buffer
@ -95,7 +95,7 @@ namespace cw
}
void _cmMpParserStoreChMsg( parser_t* p, const time::spec_t* timeStamp, byte_t d )
void _cmMpParserStoreChMsg( parser_t* p, const time::spec_t* timeStamp, uint8_t d )
{
// if there is not enough room left in the buffer then transmit
// the current messages
@ -176,7 +176,7 @@ cw::rc_t cw::midi::parser::create( handle_t& hRef, unsigned devIdx, unsigned por
//p->cbChain->cbDataPtr = cbDataPtr;
//p->cbChain->linkPtr = NULL;
p->cbChain = NULL;
p->buf = mem::allocZ<byte_t>( bufByteCnt );
p->buf = mem::allocZ<uint8_t>( bufByteCnt );
p->bufByteCnt = bufByteCnt;
p->bufIdx = 0;
p->msgCnt = 0;
@ -227,7 +227,7 @@ unsigned cw::midi::parser::errorCount( handle_t h )
}
void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp, const byte_t* iBuf, unsigned iByteCnt )
void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp, const uint8_t* iBuf, unsigned iByteCnt )
{
parser_t* p = _handleToPtr(h);
@ -235,8 +235,8 @@ void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp,
if( p == NULL )
return;
const byte_t* ip = iBuf;
const byte_t* ep = iBuf + iByteCnt;
const uint8_t* ip = iBuf;
const uint8_t* ep = iBuf + iByteCnt;
for(; ip < ep; ++ip )
{
@ -354,11 +354,11 @@ void cw::midi::parser::parseMidiData( handle_t h, const time::spec_t* timeStamp,
}
cw::rc_t cw::midi::parser::midiTriple( handle_t h, const time::spec_t* timeStamp, byte_t status, byte_t d0, byte_t d1 )
cw::rc_t cw::midi::parser::midiTriple( handle_t h, const time::spec_t* timeStamp, uint8_t status, uint8_t d0, uint8_t d1 )
{
rc_t rc = kOkRC;
parser_t* p = _handleToPtr(h);
byte_t mb = 0xff; // a midi triple may never have a status of 0xff
uint8_t mb = 0xff; // a midi triple may never have a status of 0xff
if( d0 == 0xff )
p->dataCnt = 0;

View File

@ -1,6 +1,7 @@
#ifndef cwMidiPort_H
#define cwMidiPort_H
#include "cwMidiDecls.h"
namespace cw
{
@ -37,13 +38,13 @@ namespace cw
rc_t create( handle_t& hRef, unsigned devIdx, unsigned portIdx, cbFunc_t cbFunc, void* cbArg, unsigned bufByteCnt );
rc_t destroy( handle_t& hRef );
unsigned errorCount( handle_t h );
void parseMidiData( handle_t h, const time::spec_t* timestamp, const byte_t* buf, unsigned bufByteCnt );
void parseMidiData( handle_t h, const time::spec_t* timestamp, const uint8_t* buf, unsigned bufByteCnt );
// The following two functions are intended to be used togetther.
// Use midiTriple() to insert pre-parsed msg's to the output buffer,
// and then use transmit() to send the buffer via the parsers callback function.
// Set the data bytes to 0xff if they are not used by the message.
rc_t midiTriple( handle_t h, const time::spec_t* timestamp, byte_t status, byte_t d0, byte_t d1 );
rc_t midiTriple( handle_t h, const time::spec_t* timestamp, uint8_t status, uint8_t d0, uint8_t d1 );
rc_t transmit( handle_t h );
// Install/Remove additional callbacks.
@ -79,8 +80,8 @@ namespace cw
unsigned portCount( handle_t h, unsigned devIdx, unsigned flags );
const char* portName( handle_t h, unsigned devIdx, unsigned flags, unsigned portIdx );
unsigned portNameToIndex( handle_t h, unsigned devIdx, unsigned flags, const char* portName );
rc_t send( handle_t h, unsigned devIdx, unsigned portIdx, byte_t st, byte_t d0, byte_t d1 );
rc_t sendData( handle_t h, unsigned devIdx, unsigned portIdx, const byte_t* dataPtr, unsigned byteCnt );
rc_t send( handle_t h, unsigned devIdx, unsigned portIdx, uint8_t st, uint8_t d0, uint8_t d1 );
rc_t sendData( handle_t h, unsigned devIdx, unsigned portIdx, const uint8_t* dataPtr, unsigned byteCnt );
// Set devIdx to -1 to assign the callback to all devices.
// Set portIdx to -1 to assign the callback to all ports on the specified devices.

View File

@ -1,35 +1,12 @@
#ifndef cwSerialPort_H
#define cwSerialPort_H
#include "cwSerialPortDecls.h"
namespace cw
{
namespace serialPort
{
enum
{
kDataBits5Fl = 0x0001,
kDataBits6Fl = 0x0002,
kDataBits7Fl = 0x0004,
kDataBits8Fl = 0x0008,
kDataBitsMask = 0x000f,
k1StopBitFl = 0x0010,
k2StopBitFl = 0x0020,
kEvenParityFl = 0x0040,
kOddParityFl = 0x0080,
kNoParityFl = 0x0000,
/*
kCTS_OutFlowCtlFl = 0x0100,
kRTS_InFlowCtlFl = 0x0200,
kDTR_InFlowCtlFl = 0x0400,
kDSR_OutFlowCtlFl = 0x0800,
kDCD_OutFlowCtlFl = 0x1000
*/
kDefaultCfgFlags = kDataBits8Fl | k1StopBitFl | kNoParityFl
};
typedef handle<struct device_str> handle_t;
typedef void (*callbackFunc_t)( void* cbArg, unsigned userId, const void* byteA, unsigned byteN );

35
cwSerialPortDecls.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef cwSerialPortDecls_H
#define cwSerialPortDecls_H
namespace cw
{
namespace serialPort
{
enum
{
kDataBits5Fl = 0x0001,
kDataBits6Fl = 0x0002,
kDataBits7Fl = 0x0004,
kDataBits8Fl = 0x0008,
kDataBitsMask = 0x000f,
k1StopBitFl = 0x0010,
k2StopBitFl = 0x0020,
kEvenParityFl = 0x0040,
kOddParityFl = 0x0080,
kNoParityFl = 0x0000,
/*
kCTS_OutFlowCtlFl = 0x0100,
kRTS_InFlowCtlFl = 0x0200,
kDTR_InFlowCtlFl = 0x0400,
kDSR_OutFlowCtlFl = 0x0800,
kDCD_OutFlowCtlFl = 0x1000
*/
kDefaultCfgFlags = kDataBits8Fl | k1StopBitFl | kNoParityFl
};
}
}
#endif

View File

@ -1,47 +1,18 @@
#ifndef cwSocket_H
#define cwSocket_H
#include "cwSocketDecls.h"
namespace cw
{
namespace sock
{
typedef handle< struct mgr_str > handle_t;
typedef uint16_t portNumber_t;
typedef enum
{
kReceiveCbId,
kConnectCbId,
kDisconnectCbId
} cbId_t;
// userId is the id assigned to the receiving socket
// connId is an automatically assigned id which represents the remote endpoint which is connected to 'userId'.
typedef void (*callbackFunc_t)( void* cbArg, cbId_t cbId, unsigned userId, unsigned connId, const void* byteA, unsigned byteN, const struct sockaddr_in* srcAddr );
enum
{
kNonBlockingFl = 0x000, // Create a non-blocking socket.
kBlockingFl = 0x001, // Create a blocking socket.
kTcpFl = 0x002, // Create a TCP socket rather than a UDP socket.
kBroadcastFl = 0x004, //
kReuseAddrFl = 0x008, //
kReusePortFl = 0x010, //
kMultiCastTtlFl = 0x020, //
kMultiCastLoopFl = 0x040, //
kListenFl = 0x080, // Use this socket to listen for incoming connections
kStreamFl = 0x100, // Connected stream (not Datagram)
};
enum
{
// port 0 is reserved by and is therefore a convenient invalid port number
kInvalidPortNumber = 0
};
rc_t createMgr( handle_t& hRef, unsigned recvBufByteN, unsigned maxSocketN );
rc_t destroyMgr( handle_t& hRef );

42
cwSocketDecls.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef cwSocketDecls_H
#define cwSocketDecls_H
namespace cw
{
namespace sock
{
typedef uint16_t portNumber_t;
typedef enum
{
kReceiveCbId,
kConnectCbId,
kDisconnectCbId
} cbId_t;
enum
{
kNonBlockingFl = 0x000, // Create a non-blocking socket.
kBlockingFl = 0x001, // Create a blocking socket.
kTcpFl = 0x002, // Create a TCP socket rather than a UDP socket.
kBroadcastFl = 0x004, //
kReuseAddrFl = 0x008, //
kReusePortFl = 0x010, //
kMultiCastTtlFl = 0x020, //
kMultiCastLoopFl = 0x040, //
kListenFl = 0x080, // Use this socket to listen for incoming connections
kStreamFl = 0x100, // Connected stream (not Datagram)
};
enum
{
// port 0 is reserved by and is therefore a convenient invalid port number
kInvalidPortNumber = 0
};
}
}
#endif

View File

@ -25,8 +25,8 @@ namespace cw
typedef struct websock_str
{
cbFunc_t _cbFunc;
void* _cbArg;
cbFunc_t _cbFunc; //
void* _cbArg; //
struct lws_context* _ctx = nullptr; //
struct lws_protocols* _protocolA = nullptr; // Websocket internal protocol state array
unsigned _protocolN = 0; // Count of protocol records in _protocolA[].
@ -37,7 +37,8 @@ namespace cw
} websock_t;
inline websock_t* _handleToPtr(handle_t h){ return handleToPtr<handle_t,websock_t>(h); }
inline websock_t* _handleToPtr(handle_t h)
{ return handleToPtr<handle_t,websock_t>(h); }
// Internal session record.

View File

@ -26,6 +26,7 @@ need to make the protocol state queue thread-safe.
*/
#include "cwWebSockDecls.h"
namespace cw
{
@ -34,22 +35,6 @@ namespace cw
{
typedef handle<struct websock_str> handle_t;
typedef struct protocol_str
{
const char* label; // unique label identifying this protocol
unsigned id; // unique id identifying this protocol
unsigned rcvBufByteN; // larger rcv'd packages will be broken into multiple parts
unsigned xmtBufByteN; // larger xmt'd packages are broken into multiple parts
} protocol_t;
typedef enum
{
kConnectTId,
kDisconnectTId,
kMessageTId
} msgTypeId_t;
typedef void (*cbFunc_t)( void* cbArg, unsigned protocolId, unsigned connectionId, msgTypeId_t msg_type, const void* msg, unsigned byteN );
rc_t create(

26
cwWebSockDecls.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef cwWebSockDecls_H
#define cwWebSockDecls_H
namespace cw
{
namespace websock
{
typedef struct protocol_str
{
const char* label; // unique label identifying this protocol
unsigned id; // unique id identifying this protocol
unsigned rcvBufByteN; // larger rcv'd packages will be broken into multiple parts
unsigned xmtBufByteN; // larger xmt'd packages are broken into multiple parts
} protocol_t;
typedef enum
{
kConnectTId,
kDisconnectTId,
kMessageTId
} msgTypeId_t;
}
}
#endif