#include "types.h" #include "JackConstants.h" #include "JackMidiPort.h" #include "JackExports.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Jack { typedef struct _session_params session_params_t; typedef struct _packet_header packet_header_t; typedef struct _midi_portbuf_desc midi_portbuf_desc_t; typedef struct sockaddr socket_address_t; typedef struct in_addr address_t; typedef jack_default_audio_sample_t sample_t; //session params ****************************************************************************** struct _session_params { char fPacketType[7]; //packet type ('param') char fProtocolVersion; //version int fPacketID; //indicates the packet type char fMasterNetName[256]; //master hostname (network) char fSlaveNetName[256]; //slave hostname (network) unsigned int fMtu; //connection mtu unsigned int fID; //slave's ID int fSendAudioChannels; //number of master->slave channels int fReturnAudioChannels; //number of slave->master channels int fSendMidiChannels; //number of master->slave midi channels int fReturnMidiChannels; //number of slave->master midi channels unsigned int fSampleRate; //session sample rate unsigned int fPeriodSize; //period size unsigned int fFramesPerPacket; //complete frames per packet unsigned int fBitdepth; //samples bitdepth (unused) char fName[JACK_CLIENT_NAME_SIZE]; //slave's name }; //net status ********************************************************************************** enum _net_status { SOCKET_ERROR, CONNECT_ERROR, NET_ERROR, SEND_ERROR, RECV_ERROR, CONNECTED, ROLLING }; typedef enum _net_status net_status_t; //sync packet type **************************************************************************** enum _sync_packet_type { INVALID, //... SLAVE_AVAILABLE, //a slave is available SLAVE_SETUP, //slave configuration START_MASTER, //slave is ready, start master START_SLAVE, //master is ready, activate slave KILL_MASTER //master must stop }; typedef enum _sync_packet_type sync_packet_type_t; //packet header ******************************************************************************* struct _packet_header { char fPacketType[7]; //packet type ( 'headr' ) char fDataType; //a for audio, m for midi char fDataStream; //s for send, r for return unsigned int fID; //to identify the slave unsigned int fBitdepth; //bitdepth of the data samples unsigned int fMidiDataSize; //size of midi data (if packet is 'midi typed') in bytes unsigned int fNMidiPckt; //number of midi packets of the cycle unsigned int fCycle; //process cycle counter unsigned int fSubCycle; //midi/audio subcycle counter char fIsLastPckt; //is it the last packet of a given cycle ('y' or 'n') char fFree[13]; //unused }; //midi data *********************************************************************************** class EXPORT NetMidiBuffer { private: int fNPorts; unsigned int fMaxBufsize; int fMaxPcktSize; //data char* fBuffer; char* fNetBuffer; public: NetMidiBuffer ( session_params_t* params, unsigned int nports, char* net_buffer ); ~NetMidiBuffer(); JackMidiBuffer** fPortBuffer; void Reset(); unsigned int GetSize(); //utility void DisplayEvents(); //jack<->buffer int RenderFromJackPorts(); int RenderToJackPorts(); //network<->buffer int RenderFromNetwork ( unsigned int subcycle, unsigned int copy_size ); int RenderToNetwork ( unsigned int subcycle, unsigned int copy_size ); }; // audio data ********************************************************************************* class EXPORT NetAudioBuffer { private: int fNPorts; jack_nframes_t fPeriodSize; jack_nframes_t fSubPeriodSize; unsigned int fSubPeriodBytesSize; char* fNetBuffer; public: NetAudioBuffer ( session_params_t* params, unsigned int nports, char* net_buffer ); ~NetAudioBuffer(); sample_t** fPortBuffer; unsigned int GetSize(); //jack<->buffer void RenderFromJackPorts ( unsigned int subcycle ); void RenderToJackPorts ( unsigned int subcycle ); }; //utility ************************************************************************************* //n<-->h functions EXPORT void SessionParamsHToN ( session_params_t* params ); EXPORT void SessionParamsNToH ( session_params_t* params ); EXPORT void PacketHeaderHToN ( packet_header_t* header ); EXPORT void PacketHeaderNToH ( packet_header_t* header ); //display session parameters EXPORT void SessionParamsDisplay ( session_params_t* params ); //display packet header EXPORT void PacketHeaderDisplay ( packet_header_t* header ); //get the packet type from a sesion parameters EXPORT sync_packet_type_t GetPacketType ( session_params_t* params ); //set the packet type in a session parameters EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type ); //step of network initialization EXPORT unsigned int SetFramesPerPacket ( session_params_t* params ); //get the midi packet number for a given cycle EXPORT unsigned int GetNMidiPckt ( session_params_t* params, unsigned int data_size ); //set the recv timeout on a socket EXPORT int SetRxTimeout ( int* sockfd, session_params_t* params ); //check if 'next' packet is really the next after 'previous' EXPORT bool IsNextPacket ( packet_header_t* previous, packet_header_t* next, unsigned int subcycles ); }