Copyright (C) Kevin Larke 2009-2020

This file is part of libcm.

libcm is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

libcm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See the GNU General Public License distributed with the libcm package or look here: .


cmMsgProtocol : Global constants and data structures for transmiting messages between threads and network nodes.
  #define cmAudDspSys_FILENAME "aud_dsp.js"



// UI seletor id's used in the cmDspUiHdr_t selId field
enum 
{
  kPrintDuiId,        // ui&lt--eng print the value to the console
  kSliderDuiId,       // ui&lt--eng create a slider control
  kButtonDuiId,       // ui&lt--eng create button control
  kCheckDuiId,        // ui&lt--eng create a check box control
  kLabelDuiId,        // ui&lt--eng create a label control
  kTimeLineDuiId,     // ui&lt--eng create a time-line control
  kScoreDuiId,        // ui&lt--eng create a score control
  kTakeSeqBldrDuiId,  // ui&lt--eng create a take sequence builder
  kTakeSeqRendDuiId,  // ui&lt--eng create a take sequence renderer
  kTwodDuiId,         // ui&lt--eng create a 2d control
  kNumberDuiId,       // ui&lt--eng create a number box
  kTextDuiId,         // ui&lt--eng create a text entry control
  kFnameDuiId,        // ui&lt--eng create a file/directory picker control
  kMsgListDuiId,      // ui&lt--eng create a msg list control
  kMeterDuiId,        // ui&lt--eng create a meter display
  kValueDuiId,        // ui&lt-&gteng a control changed values 
  kColumnDuiId,       // ui&lt--eng start a new column
  kHBorderDuiId,      // ui&lt--eng insert a vertical border 
  kPageDuiId,         // ui&lt--eng insert a new control page
  
  kAudioSysCfgDuiId,      // ui&lt--audio system cfg label 
  kAudioSysCfgDfltDuiId,  // ui&lt--dflt audio system cfg label 
  kSubSysCntDuiId,        // ui&lt--eng audio sub-system count
  kDeviceDuiId,           // ui&lt--eng device label
  kProgramDuiId,          // ui&lt--eng program label
  kProgramDfltDuiId,      // ui&lt--eng dflt program label
  kPgmDoneDuiId,          // ui&lt--end the program is done 
  
  // The following selId's are used by cmAudDsp to indicate various commands.
  kSetAudioCfgDuiId,      // 1) select an audio system setup
  kSetAudioDevDuiId,      // 2) (optional) set an audio device on an audio sub-system
  kSetSampleRateDuiId,    // 3) (optional) set the sample rate of an audio sub-system
  kSetPgmDuiId,           // 4) select a program
  kEnableDuiId,           // 5) enable/disable the audio system (also resets the DSP system)
  kSyncDuiId,             // 6) sent by cmAudDsp to client to indicate sync success or failure.
  kSetNotifyEnableDuiId,  // enable/disable periodic status notification from the audio system.
  kClientMsgPollDuiId,    // Periodic check for and deliver messages waiting in the audio system for delivery to the client. 
  kSendMsgDuiId,          // forward msg to the audio system
  kDevReportDuiId,        // print a device report
  kPrintPgmDuiId,         // write the currently loaded pgm as a JSON file
  
  kRightAlignDuiId = 0,   // label alignment id used by kLabelDuiId 
  kLeftAlignDuiId,  
  kCenterAlignDuiId
};

enum
{
  kDuplexDuiFl = 0x01
};

// Header record for all messages between the host and the DSP controllers.
typedef struct
{
  unsigned     asSubIdx;   // the audio sub-system this UI belongs to
  unsigned     uiId;       // msg type kXXXAsId 
  unsigned     selId;      // action to perform see above
  unsigned     flags;      
  unsigned     instId;     // DSP instance id
  unsigned     instVarId;  // DSP instance var id
  
  // The cmDspValue_t field must come last in the structure in
  // order for the cmDsvSerialize() to work in cmDspUI.c:_cmDspUiMsg().  
  cmDspValue_t value;      // Data value associated with this msg. 
} cmDspUiHdr_t;


// cmDspNetMsg_t sub-selector id's
enum {
  kNetHelloSelAsId,      // node-&gtnode awake msg 
  kNetDstIdReqSelAsId,   // src-&gtdst request a dst id
  kNetDstIdReqDoneAsId,  // src-&gtdst all requests have been sent
  kNetDstIdSelAsId,      // dst-&gtsrc provide dst id
  kNetDoneSelAsId,       // node-&gtnode sync done
  kNetErrSelAsId,        // node-&gtnode sync error
  kNetEvtSelAsId         // src-&gtdst send cmDspEvnt_t
};

// Message Layout [ cmDspNetMsg_t dstInstLabel[] dstVarLabel[] ]
typedef struct
{
  unsigned asSubIdx;
  unsigned selId;        // kNetSyncSelAsId
  unsigned subSelId;     // see above kNetXXXSelAsId
  unsigned srcId; 
  unsigned dstId;
  cmDspValue_t value;
  // char dstInstLabel[] - with kNetSyncSelAsId only
  // char dstVarLabel[]  - with kNetSyncSelAsId only  
} cmDspNetMsg_t;

enum
{
  kOkMsgRC = cmOkRC,
  kSerializeFailMsgRC,
  kSendFailMsgRC,
  kDecodeFailMsgRC
};

typedef cmRC_t cmMsgRC_t;


typedef cmMsgRC_t (*cmMsgSendFuncPtr_t)(void* cbDataPtr, unsigned msgByteCnt, const void* msg );

cmMsgRC_t cmMsgSend( 
cmErr_t*            err, 
unsigned            asSubIdx,
unsigned            msgTypeId,
unsigned            selId,
unsigned            flags,
unsigned            instId,
unsigned            instVarId,
const cmDspValue_t* valPtr,
cmMsgSendFuncPtr_t  sendFunc,
void*               cbDataPtr );

cmMsgRC_t cmMsgPeekAsSubIndex( const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt, unsigned* retValPtr );
cmMsgRC_t cmMsgPeekMsgTypeId(  const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt, unsigned* retValPtr );
cmMsgRC_t cmMsgPeekSelId(      const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt, unsigned* retValPtr );
cmMsgRC_t cmMsgPeekFlags(      const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt, unsigned* retValPtr );
cmMsgRC_t cmMsgPeekInstId(     const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt, unsigned* retValPtr );
cmMsgRC_t cmMsgPeekInstVarId(  const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt, unsigned* retValPtr );