2020-01-27 22:53:44 +00:00
|
|
|
#ifndef cwIo_h
|
|
|
|
#define cwIo_h
|
|
|
|
|
2020-03-23 17:14:42 +00:00
|
|
|
#include "cwTime.h"
|
|
|
|
#include "cwMidiDecls.h"
|
|
|
|
#include "cwSerialPortDecls.h"
|
|
|
|
#include "cwAudioDeviceDecls.h"
|
|
|
|
#include "cwSocketDecls.h"
|
2021-01-20 18:12:35 +00:00
|
|
|
#include "cwUiDecls.h"
|
2020-03-23 17:14:42 +00:00
|
|
|
|
2020-01-27 22:53:44 +00:00
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef handle<struct io_str> handle_t;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kSerialTId,
|
|
|
|
kMidiTId,
|
|
|
|
kAudioTId,
|
2020-03-23 17:14:42 +00:00
|
|
|
kSockTid,
|
2021-01-20 18:12:35 +00:00
|
|
|
kWebSockTId,
|
|
|
|
kUiTId
|
2020-01-27 22:53:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct serial_msg_str
|
|
|
|
{
|
|
|
|
unsigned devId;
|
|
|
|
const void* dataA;
|
|
|
|
unsigned byteN;
|
|
|
|
} serial_msg_t;
|
|
|
|
|
|
|
|
typedef struct midi_msg_str
|
|
|
|
{
|
|
|
|
midi::packet_t* pkt;
|
|
|
|
} midi_msg_t;
|
|
|
|
|
2020-03-23 17:14:42 +00:00
|
|
|
typedef audio::device::sample_t sample_t;
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
typedef struct audio_group_dev_str
|
|
|
|
{
|
|
|
|
const char* name; // Audio device name
|
|
|
|
unsigned devIdx; // Audio device index
|
|
|
|
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.
|
|
|
|
struct audio_group_dev_str* link; //
|
|
|
|
} audio_group_dev_t;
|
|
|
|
|
2020-02-29 05:12:57 +00:00
|
|
|
typedef struct audio_msg_str
|
|
|
|
{
|
2021-01-20 18:12:35 +00:00
|
|
|
unsigned groupId; // Unique group id
|
|
|
|
double srate; // Group sample rate.
|
|
|
|
unsigned dspFrameCnt; // Count of samples in each buffer pointed to by iBufArray[] and oBufArray[]
|
2020-03-23 17:14:42 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
sample_t** iBufArray; // Array of 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[]
|
|
|
|
|
|
|
|
sample_t** oBufArray; //
|
|
|
|
unsigned oBufChCnt; //
|
|
|
|
time::spec_t* oTimeStampPtr; //
|
|
|
|
audio_group_dev_t* oDevL; // Linked list of output devices which map directly to channels in oBufArray[]
|
2020-03-23 17:14:42 +00:00
|
|
|
|
2020-02-29 05:12:57 +00:00
|
|
|
} audio_msg_t;
|
|
|
|
|
2020-03-23 17:14:42 +00:00
|
|
|
typedef struct socket_msg_str
|
|
|
|
{
|
2021-01-20 18:12:35 +00:00
|
|
|
sock::cbOpId_t cbId;
|
2020-03-23 17:14:42 +00:00
|
|
|
unsigned userId;
|
|
|
|
unsigned connId;
|
|
|
|
const void* byteA;
|
|
|
|
unsigned byteN;
|
|
|
|
const struct sockaddr_in* srcAddr;
|
|
|
|
} socket_msg_t;
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
typedef struct ui_msg_str
|
|
|
|
{
|
|
|
|
ui::opId_t opId;
|
|
|
|
unsigned wsSessId;
|
|
|
|
unsigned parentAppId;
|
|
|
|
unsigned uuId;
|
|
|
|
unsigned appId;
|
|
|
|
const ui::value_t* value;
|
|
|
|
} ui_msg_t;
|
|
|
|
|
2020-01-27 22:53:44 +00:00
|
|
|
typedef struct msg_str
|
|
|
|
{
|
|
|
|
unsigned tid;
|
|
|
|
union
|
|
|
|
{
|
2021-01-20 18:12:35 +00:00
|
|
|
serial_msg_t* serial;
|
|
|
|
midi_msg_t* midi;
|
|
|
|
audio_msg_t* audio;
|
|
|
|
socket_msg_t* sock;
|
|
|
|
ui_msg_t ui;
|
2020-01-27 22:53:44 +00:00
|
|
|
} u;
|
|
|
|
} msg_t;
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
typedef rc_t (*cbFunc_t)( void* arg, const msg_t* m );
|
2020-01-27 22:53:44 +00:00
|
|
|
|
|
|
|
rc_t create(
|
2021-01-20 18:12:35 +00:00
|
|
|
handle_t& h,
|
|
|
|
const object_t* cfg, // configuration object
|
|
|
|
cbFunc_t cbFunc,
|
|
|
|
void* cbArg,
|
|
|
|
const ui::appIdMap_t* mapA = nullptr,
|
|
|
|
unsigned mapN = 0,
|
|
|
|
const char* cfgLabel = "io" );
|
2020-01-27 22:53:44 +00:00
|
|
|
|
|
|
|
rc_t destroy( handle_t& h );
|
|
|
|
|
|
|
|
rc_t start( handle_t h );
|
|
|
|
rc_t pause( handle_t h );
|
2021-01-20 18:12:35 +00:00
|
|
|
rc_t stop( handle_t h );
|
|
|
|
rc_t exec( handle_t h );
|
|
|
|
bool isShuttingDown( handle_t h );
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Serial
|
|
|
|
//
|
2020-01-27 22:53:44 +00:00
|
|
|
|
|
|
|
unsigned serialDeviceCount( handle_t h );
|
|
|
|
const char* serialDeviceName( handle_t h, unsigned devIdx );
|
|
|
|
unsigned serialDeviceIndex( handle_t h, const char* name );
|
|
|
|
rc_t serialDeviceSend( handle_t h, unsigned devIdx, const void* byteA, unsigned byteN );
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MIDI
|
|
|
|
//
|
|
|
|
|
2020-01-27 22:53:44 +00:00
|
|
|
unsigned midiDeviceCount( handle_t h );
|
|
|
|
const char* midiDeviceName( handle_t h, unsigned devIdx );
|
|
|
|
unsigned midiDeviceIndex( handle_t h, const char* devName );
|
|
|
|
unsigned midiDevicePortCount( handle_t h, unsigned devIdx, bool inputFl );
|
|
|
|
const char* midiDevicePortName( handle_t h, unsigned devIdx, bool inputFl, unsigned portIdx );
|
|
|
|
unsigned midiDevicePortIndex( handle_t h, unsigned devIdx, bool inputFl, const char* portName );
|
2020-03-23 17:14:42 +00:00
|
|
|
rc_t midiDeviceSend( handle_t h, unsigned devIdx, unsigned portIdx, uint8_t status, uint8_t d0, uint8_t d1 );
|
|
|
|
|
2020-02-13 16:30:46 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Audio
|
|
|
|
//
|
|
|
|
|
2020-02-29 05:12:57 +00:00
|
|
|
unsigned audioDeviceCount( handle_t h );
|
|
|
|
unsigned audioDeviceLabelToIndex( handle_t h, const char* label );
|
|
|
|
const char* audioDeviceLabel( handle_t h, unsigned devIdx );
|
2020-03-23 17:14:42 +00:00
|
|
|
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 );
|
2020-02-29 05:12:57 +00:00
|
|
|
double audioDeviceSampleRate( handle_t h, unsigned devIdx );
|
2020-03-23 17:14:42 +00:00
|
|
|
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 );
|
2020-02-13 16:30:46 +00:00
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
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 );
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Socket
|
|
|
|
//
|
2020-02-13 16:30:46 +00:00
|
|
|
|
2020-03-23 17:14:42 +00:00
|
|
|
rc_t socketSetup( handle_t h, unsigned timeOutMs, unsigned recvBufByteN, unsigned maxSocketN );
|
2021-01-20 18:12:35 +00:00
|
|
|
|
2020-03-23 17:14:42 +00:00
|
|
|
rc_t socketCreate(
|
2021-01-20 18:12:35 +00:00
|
|
|
handle_t h,
|
|
|
|
unsigned userId,
|
|
|
|
short port,
|
|
|
|
unsigned flags,
|
|
|
|
const char* remoteAddr = nullptr,
|
|
|
|
sock::portNumber_t remotePort = sock::kInvalidPortNumber,
|
|
|
|
const char* localAddr = nullptr );
|
2020-03-23 17:14:42 +00:00
|
|
|
|
|
|
|
rc_t socketDestroy( handle_t h, unsigned userId );
|
|
|
|
|
|
|
|
// Send to the remote endpoint represented by connId over a connected socket.
|
|
|
|
// If 'connId' is kInvalidId then this data is sent to all connected endpoints.
|
|
|
|
rc_t socketSend( handle_t h, unsigned userId, unsigned connId, const void* data, unsigned dataByteN );
|
|
|
|
|
|
|
|
// Send a message to a specific remote node over an unconnected UDP socket.
|
|
|
|
// Use the function initAddr() to setup the 'sockaddr_in';
|
|
|
|
rc_t socketSend( handle_t h, unsigned userId, const void* data, unsigned dataByteCnt, const struct sockaddr_in* remoteAddr );
|
|
|
|
rc_t socketSend( handle_t h, unsigned userId, const void* data, unsigned dataByteCnt, const char* remoteAddr, sock::portNumber_t port );
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 18:12:35 +00:00
|
|
|
//----------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// UI
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
// Find id's associated with elements.
|
|
|
|
unsigned uiFindElementAppId( handle_t h, unsigned parentUuId, const char* eleName );
|
|
|
|
unsigned uiFindElementUuId( handle_t h, unsigned parentUuId, const char* eleName );
|
|
|
|
unsigned uiFindElementUuId( handle_t h, unsigned parentUuId, unsigned appId );
|
|
|
|
const char* uiFindElementName( handle_t h, unsigned uuId );
|
|
|
|
unsigned uiFindElementAppId( handle_t h, unsigned uuId );
|
|
|
|
|
|
|
|
// Return the uuid of the first matching 'eleName'.
|
|
|
|
unsigned uiFindElementUuId( handle_t h, const char* eleName );
|
|
|
|
|
|
|
|
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);
|
|
|
|
rc_t uiCreateFromText( handle_t h, const char* text, unsigned wsSessId, unsigned parentUuId=kInvalidId);
|
|
|
|
rc_t uiCreateDiv( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
rc_t uiCreateTitle( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
rc_t uiCreateButton( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
|
|
|
|
// Create check: w/o value. The value will be read from the engine via the UI 'echo' event.
|
|
|
|
// Create check: w/ value. The value will be sent to the engine as the new value of the associated varaible.
|
|
|
|
rc_t uiCreateCheck( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
rc_t uiCreateCheck( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, bool value );
|
|
|
|
|
|
|
|
rc_t uiCreateSelect( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
rc_t uiCreateOption( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
|
|
|
|
rc_t uiCreateStr( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
rc_t uiCreateStr( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, const char* value );
|
|
|
|
|
|
|
|
rc_t uiCreateNumbDisplay(handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, unsigned decPl );
|
|
|
|
rc_t uiCreateNumbDisplay(handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, unsigned decPl, double value );
|
|
|
|
|
|
|
|
rc_t uiCreateNumb( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue, double stepValue, unsigned decPl );
|
|
|
|
rc_t uiCreateNumb( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue, double stepValue, unsigned decPl, double value );
|
|
|
|
|
|
|
|
rc_t uiCreateProg( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue );
|
|
|
|
rc_t uiCreateProg( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title, double minValue, double maxValue, double value );
|
|
|
|
|
|
|
|
rc_t uiCreateText( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title );
|
|
|
|
|
|
|
|
// 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 );
|
2020-03-23 17:14:42 +00:00
|
|
|
|
2020-01-27 22:53:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|