feature: Add SPIT-Source as is

This commit is contained in:
2024-08-19 03:29:37 +02:00
parent a5805aceb2
commit 500641a6e2
31 changed files with 10176 additions and 0 deletions
+933
View File
@@ -0,0 +1,933 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: MySPITApp.cpp
* Author: Hagi
*
* Created on 17. April 2019, 06:24 pm
* Changed on 01. May 2020, 12:00 am
*
* Description:
* A SPITClient defines actions (functions) and connects to a SPITServer.
* The actions are assigned to SPITTypes.
* The client may create its own SPITTypes, which are sended to the server or receives SPITTypes from the server.
* Each SPIType can trigger exactly one action.
* The server may use this SPITTypes to create and play SPITObjects, he can create several SPITObjects from one SPITType.
* Each SPITObject is assigned exactly one SPITType.
* When the server plays a SPITObject, an event function (eventPlayObject) is called in the client.
* The client can then trigger the action for the assigned SPITType.
* --------------------------------------------------------------------------------------------------
* all event.. functions are executed by a single SPIT_Handler thread.
* -> The event functions are called singlethreaded one after the other.
* --------------------------------------------------------------------------------------------------
*/
#include "MyApp.h"
string MyApp::s_ClientName = "MySPITApp_Client"; //Name of this Client
string MyApp::s_ClientProjectName = "MySPITAppProject"; //Name of the client'loaded project
string MyApp::s_ClientProjectID = s_ClientProjectName; //ID of the client's project - maybe the same as the name or a specific id
#if defined(OS_WINDOWS)
//Win32 Main Function - application entry
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, INT nCmdShow) {
return main();
}
#endif
//UNIX and Win64 Main function - application entry
int main() {
MyApp* ptrMyApp;
//Create a MyApp instance
ptrMyApp = new MyApp();
//load a client project
//the client project may belong to a server's project or may be independend of server's projects
//if the client project belongs to a specific server project
// -> add some code in the function eventProjectReport(..) (for excample create special SPITTypes or Actions
//if the client project is independend od server's project
// -> use loadClientProject() to create all SPITypes and actions
//An action is bound to a SPITType and called when the server plays a SPITObject that references the SPITType
// see eventPlayObject
ptrMyApp->loadClientProject();
//start autodetection of SPITServers
//autodetection of SPITServers ends automaticallay when this SPITClient is connected to a SPITServer
ptrMyApp->startServerAutoDetect();
//This application is multthreaded, in the background all is done by several threads
//all events are delegated to SPIT_Handler
//-> the eventxxx functions are called by the one and only SPIT_Handler's thread s_HandlerThread
//-> the eventxxx functions are called singlethreaded
//Normally MyApp will have a user interface to decide when the app has to be closed.
//Actual we have no user interface -> sleep a while
//We can put the actual thread to sleep, because the events are executed by the SPIT_Handler-Thread s_HandlerThread.
printf("---THE APPLICATION RUNS FOR 60 SECONDS AND STOPS AUTOMATICALLY---\n\n");
this_thread::sleep_for(chrono::milliseconds(30000));
ptrMyApp->testLiveShowRemote(); //This is an excample how to remote control the liveSHOWsoftware
this_thread::sleep_for(chrono::milliseconds(30000));
//perhaps you should save the client project
//close MyApp instance
delete ptrMyApp;
return 0;
}
MyApp::MyApp() {
//create a new SPIT_Client instance
//the SPIT_Client will do the main work for you (receiving/sending SPIT_Messages ....)
m_SPIT_Client = new SPIT_Client(this);
//You need to give your application a descriptive name
m_SPIT_Client->setName(s_ClientName);
//The following members are set in loadClientProject function.
m_ClientProjectName = "";
m_ClientProjectID = ""; //id can be the same as the project name
//The following members are set in the eventConnectionStatus
m_ServerID = "";
m_ServerComputerName = "";
m_ServerName = "";
m_ServerStepTime = -1;
//The follwing members are set in eventProjectReport
m_ServerProjectID = "";
m_ServerProjectName = "";
m_ServerFramesPerSecond = 44100; //is reset in eventProjectReport.
//perhaps you may save the value from the last connection and set it here
//liveSHOWsoftware will use 44100 frames per second as time resolution
//All times are given in frames,
//with this parameter you can convert the times into milliseconds/seconds ...
//Used to decide if a reconnection is tried after the connection is lost
//see eventServerDetected and eventConnectionStatus
m_FlagReconnect = false;
}
MyApp::~MyApp() {
//To close the connection and all other stuff delete the SPIT_Client instance
if (m_SPIT_Client != NULL) {
delete m_SPIT_Client;
}
}
//Following functions fullfill the SPIT_ClientInterface
//They are needed when the server sends his project, see eventProjectReport
//and they should be set in loadClientProject
string MyApp::getClientProjectID() {
return m_ClientProjectID;
}
string MyApp::getClientProjectName() {
return m_ClientProjectName;
}
void MyApp::loadClientProject() {
//----- close the actual client project -----
//inform the SPIT_Client that the actual project will close
//If there is actual no connection to the server nothing happens
if (m_SPIT_Client != NULL) {
m_SPIT_Client->clientProjectClose();
}
//close the project
//----- load new client project -----
// Add your loading code here
//If your application is a small one using only a few fixed actions
//you may keep the things simple and code all loading here
m_ClientProjectID = s_ClientProjectID; //maybe the same as s_ClientProjectName
m_ClientProjectName = s_ClientProjectName;
//Create SPITTypes for all functions of this client
//--- Excample ---
//the client owns two fixed functionality named "Action1" and "Action2"
if (m_SPIT_Client != NULL) {
//FIXED SPITTYPES
//Create SPITTypes for all discrete and unchangable functions of this client. Fixed means the server can't change or remove the SPITType.
//-> Create a SPITTypes according to the following patterns
//Excample "Action1"
SPITType* ptrSPITType1Fix;
ptrSPITType1Fix = m_SPIT_Client->createSPITTypeFixed("MySPITAPP_Action1ID", "MyActionGroupName", "FixedAction1", 0, 0);
//When an action exist which shpuld be done whenever a SPITObject with this SPITType is played, <br>
//then you should 'setAssignedActionType' to true
m_SPIT_Client->setActionSPITType(ptrSPITType1Fix->getID(), true);
//Excample "Action2"
SPITType* ptrSPITType2Fix;
ptrSPITType2Fix = m_SPIT_Client->createSPITTypeFixed("MySPITAPP_Action2ID", "MyActionGroupName", "FixedAction2", 0, 0);
//When an action exist which shpuld be done whenever a SPITObject with this SPITType is played, <br>
//then you should 'setAssignedActionType' to true
m_SPIT_Client->setActionSPITType(ptrSPITType2Fix->getID(), true);
//later in the eventPlayObject you can react with your action code for "Action1" and "Action2"
//CHANGABLE SPITYPES
//Create SPITTypes which are changable or temporarly, the server may change or delete them.
ptrSPITType2Fix = m_SPIT_Client->createSPITType("MySPITAPP_ActionTemp1ID", "MyActionGroupName", "TempAction1", 0, 0, false, true);
//When an action exist which shpuld be done whenever a SPITObject with this SPITType is played, <br>
//then you should 'setAssignedActionType' to true
m_SPIT_Client->setActionSPITType(ptrSPITType2Fix->getID(), true);
}
//--- End Excample ---
//----- inform the SPIT_Client that a new project is loaded -----
if (m_SPIT_Client != NULL) {
m_SPIT_Client->clientProjectLoaded();
}
}
//-----------------------------------------
//---------- ServerAutoDetection ----------
void MyApp::startServerAutoDetect() {
if (m_SPIT_Client != NULL) {
m_SPIT_Client->startServerAutoDetect();
}
}
void MyApp::stopServerAutoDetect() {
if (m_SPIT_Client != NULL) {
m_SPIT_Client->stopServerAutoDetect();
}
}
//------------------------------------------------------
//----- All events are delegated to the SPIT_Handler.
//----- The follwoing event functions are called
//----- by the one thread s_HandlerThread of the SPIT_Handler
//------------------------------------------------------
/**
* Is always called when a new SPIT server is found.<br>
* For this you have to call SPIT_Client::startServerAutoDetect.<br>
* @param p_DetectedServer a reference to a copy of a SAD_DetectedServer instance.<br>
* After this function call the copy of the SAD_DetectedServer will be deleted!!<br>
*/
void MyApp::eventServerDetected(const SAD_DetectedServer& p_DetectedServer) {
//fetch the infoemations from the p_DetectedServer
#if defined(DEBUGOUTPUT)
printf("mySPITApp\n");
printf("-----> SERVER DETECTED\n");
printf(" Name: %s\n", p_DetectedServer.getName().data());
printf(" ID: %s\n", p_DetectedServer.getID().data());
printf(" Computer: %s\n", p_DetectedServer.getComputerName().data());
printf(" IP: %s\n", p_DetectedServer.getIP().data());
printf(" Port: %s\n", p_DetectedServer.getPort().data());
printf(" Addition: %s\n", p_DetectedServer.getAdditions().data());
printf(" ClientIP: %s\n", p_DetectedServer.getClientIP().data());
printf("\n");
#endif
bool boolSuccess;
//---------- RECONNECTION ----------
//If a connection has been established and the connection is lost -> reconnect
boolSuccess = false;
if (m_FlagReconnect == true) {
//check if the server is the same as prior connected
if (m_ServerID == p_DetectedServer.getID()) {
//reconnect
if (m_SPIT_Client != NULL) {
stopServerAutoDetect();
#if defined(DEBUGOUTPUT)
printf("MySPITApp: reconnect to %s ", p_DetectedServer.getIP().data());
#endif
boolSuccess = m_SPIT_Client->connect(p_DetectedServer.getIP(), p_DetectedServer.getPort(), p_DetectedServer.getClientIP(), "0"); //ClientPort = "0" meeans use any port
if (boolSuccess == true) {
return;
}
}
}
}
// --------------------------------------
// You have three Options to use the detected server
// OPTION 1 Use the first server found
// OPTION 2 Use the first server found that fulfills specific conditions
// OPTION 3 take a copy of the p_DetectedServer and do connection later
// SAD_DetectedServer o_DetectedServer = p_DetectedServer; //this will call the copy constructor
// ---------------------------------------
//Excample use the first detected LOOPBACK server, means the server runs on the same computer as this client
//if (p_DetectedServer.getIpIsLoopback() == true) { //omit the if condition if you want to use the first server found
boolSuccess = false;
//Stop auto detection because a suitable server was found
stopServerAutoDetect();
if (m_SPIT_Client != NULL) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: connect to %s ", p_DetectedServer.getIP().data());
#endif
boolSuccess = m_SPIT_Client->connect(p_DetectedServer.getIP(), p_DetectedServer.getPort(), p_DetectedServer.getClientIP(), "0"); //ClientPort = "0" meeans use any port
}
if (boolSuccess == false) {
//connection message could not be sent
//perhaps restart AutoDetection
startServerAutoDetect();
}
// } //Excample
}
/**
* Is always called when a SPIT server does not respond anymore.<br>
* For this you have to call SPIT_Client::startServerAutoDetect.<br>
* This is an information used by autodetection and not by an established connection.<br>
* <br>
* When a connection to a SPITServer is established, the autodetection should be stopped.<br>
* The connection lost event is detected by eventConnectionStatus<br>
* <br>
* @param p_DetectedServer a reference to a copy of a SAD_DetectedServer instance.<br>
* After this function call the copy of the SAD_DetectedServer will be deleted!!<br>
*/
void MyApp::eventServerLost(const SAD_DetectedServer& p_DetectedServer) {
#if defined(DEBUGOUTPUT)
printf("\n");
printf("-----> SERVER LOST\n");
printf("Name: %s IP: %s\n", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
printf("\n");
#endif
}
//---------------------------------------
//---------- Connecting event ----------
void MyApp::eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventConnectionStatus %d ", p_ConnectionStatus);
#endif
switch(p_ConnectionStatus) {
case SPIT_Client::CONNECTION_NONE:
#if defined(DEBUGOUTPUT)
printf(" not connected\n");
#endif
break;
case SPIT_Client::CONNECTION_NONESERVER:
#if defined(DEBUGOUTPUT)
printf(" connection terminated by server\n");
#endif
//call eventProjectClosed because this may not be sended by the server,
//when the connstion is closed
eventProjectClosed(m_ServerProjectID);
//Server has terminated the connection -> start a new game
m_FlagReconnect = false;
startServerAutoDetect();
break;
case SPIT_Client::CONNECTION_OK:
#if defined(DEBUGOUTPUT)
printf(" connection established\n");
#endif
stopServerAutoDetect(); //normally you should stop the autodetection before you try a connection
//This is redundand
m_ServerID = p_ServerID;
m_ServerComputerName = p_ServerComputerName;
m_ServerName = p_ServerName;
m_ServerStepTime = p_ServerStepTime;
//Maybe you want to reconnect, see eventServerDetected(...)
//Here the connection is established -> don't reconnect at eventServerDetected(...)
m_FlagReconnect = false;
break;
case SPIT_Client::CONNECTION_LOST:
#if defined(DEBUGOUTPUT)
printf(" connection lost\n");
#endif
//Maybe you want to reconnect, see eventServerDetected(...)
//We have lost the connection -> set the flag to true and start the autodetection to reconnect at eventServerDetected(...)
m_FlagReconnect = true;
startServerAutoDetect();
break;
}
}
//-----------------------------------------------------------
//---------- Server's Project events ------------------------
/**
* The Server reports his loaded project
* Called when<br>
* a) the connection to the server is established.<br>
* b) server load a new project<br>
* c) server saves the project under a new name<br>
* @param p_ProjectID the server project's id<br>
* (maybe the filename of the project or a part o it or the same as p_ProjectName)
* @param p_ProjectName the server project's name
* @param p_FramesPerSeoond All times in SPIT are given in frames. FramesPerSecond can be used to convert frames to seconds....
*/
void MyApp::eventProjectReport(string p_ProjectID, string p_ProjectName, int p_FramesPerSeoond) {
#if defined(DEBUGOUTPUT)
printf("\n");
printf("MySPITApp: eventProjectReport ID: %s Name: %s FramesPerSecond: %d\n", p_ProjectID.data(), p_ProjectName.data(), p_FramesPerSeoond);
#endif
m_ServerProjectID = p_ProjectID;
m_ServerProjectName = p_ProjectName;
m_ServerFramesPerSecond = p_FramesPerSeoond;
//set the frames per second as the server - perhaps the client's time values have to be recalculated.
m_ServerFramesPerSecond = p_FramesPerSeoond;
//When the this client's project depends on the server's project -> load some specific informations here
}
/**
* Called when the server closes his project.<br>
* @param p_ProjectID the id of the project<br>
* The server loads only one project at time-> the ID is not actually necessary
*/
void MyApp::eventProjectClosed(string p_ProjectID) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventProjectClosed ID: %s\n", p_ProjectID.data());
printf("\n");
#endif
//If we don't save SPITServer's project specific information
//perhaps close all SPITObjects and RemoteSPITObjects to avoid conflicts, when the SPITServer loads a new project
//SPITObject::clearSPITObjects();
//SPITObject::clearSPITObjectsRemote();
}
/**
* The server starts the transfer of its project, that means:.<br>
* All SPITTypes and SPITObjects available on the server are transferred in the following.<br>
* Several calls of eventSPITType and eventSPITObject will occur.<br>
* At the end eventEndProjectTransfer is called.
*/
void MyApp::eventStartProjectTransfer() {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventStartProjectTransfer\n");
#endif
}
/**
* The transfer of the server's SPITTypes and SPITObjects is finished.<br>
* AFter this all eventSPITType and eventSPITObject means that new types , objects are created or changed.
*/
void MyApp::eventEndProjectTransfer() {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventEndProjectTransfer\n");
#endif
}
//----------------------------------------------------
//--------- SPITType events ----------
// SPITTypes describing an action or a type of an action.
// To trigger an action SPITObjects are used. Every SPITObject has one of the SPITTypes assigned.<br>
// There are two ways action can be triggered, either the server triggers an action on the client,
// or the client sends remote control commands to the server.
// a) normal types that are comitted to the client and played per SPITObjects by server, so the client can react with actions.
// b) Remote types are used for remote control of the server and are played by the client via SPIT objects.
//All normal SPITTypes are listet in a static unordered_map in the SPITType class.
//All remote SPITTypes are listet in a seperate static unordered_map in the SPITType class.
//You can use the SPITType::get... functions to deal with them.
//The SPITType class has a static recursive_mutex, you get a pointer of the mutex by: SPITType::getMutex();
//To be thread save you should cover your code with a lock sequence:
/*
{ //start of the lock sequence
unique_lock<recursive_mutex> o_LockType(*SPITType::getMutex());
//got the lock
//fetch SPITType and deal with, but don't waste time while you holding the lock
//Excample
SPITType* ptrSPITType;
for (int i = 0; i < SPITType::getSPITTypeCount(); i ++) {
ptrSPITType = SPITType::getSPITType(i);
if (ptrSPITType == NULL) break;
//Do something with ptrSPITType
//bew aware after you leave the lock sequence the ptrSPITType is no longer save!!
}
} //end of the lock sequence
//For Remote Types you can use the getSPITTypeRemote... functions
*/
/**
* Called when the server has created, loaded or changed a SPITType.<br>
* May also occur when the server confirms a SPITType created or changed by the client.<br>
* @param p_New true = server created a new SPITType<br>
* false = server changed a existing SPITType<br>
* @param p_SPITType a reference to a copy of the SPITType instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITType(bool p_New, const SPITType& p_SPITType) {
//fetch information of the SPITType
if (p_New) {
//a new SPITType is created
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITType NEW");
#endif
}
else {
//an existing SPITType is changed
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITType CHANGED");
#endif
}
#if defined(DEBUGOUTPUT)
printf(" ID: %s GroupName: %s Name: %s confirmed: %d\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
#endif
//Check your actions
//Whenever you provide an action for this SPITType take this over in your code.
//call m_SPIT_Client->setActionSPITType(p_SPITType.getID(), true);
//for our little excample as described in loadClientProject we do following
if (m_SPIT_Client != NULL) {
//This may be redundand, because we defined the SPITTypes as fixed, so the server can't change them
//But foe all SPITTypes which are not fixed we need to setActionSPITType
if ("MySPITAPP_Action1ID" == p_SPITType.getID()) {
m_SPIT_Client->setActionSPITType(p_SPITType.getID(), true);
}
if ("MySPITAPP_Action2ID" == p_SPITType.getID()) {
m_SPIT_Client->setActionSPITType(p_SPITType.getID(), true);
}
}
}
/**
* Called when the server has created or changed a Remote SPITType.<br>
* Remote SPITType are used in Remote SPITObjects. A Remote SPITObject is used to remote control the SPITServer.
* @param p_New true = server created a new SPITType<br>
* false = server changed a existing SPITType<br>
* @param p_SPITType a reference to a copy of the SPITType instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITTypeRemote(bool p_New, const SPITType& p_SPITType) {
if (p_New) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITTypeRemote NEW");
#endif
}
else {
//we had to inform all Remote SPITObjects using the p_SPITType
//perhaps the SPITObject uses information from the SPITType
SPITObject* ptrSPITObject;
int intSPITObjectCount;
intSPITObjectCount = SPITObject::getSPITObjectRemoteCount();
for (int intObject = 0; intObject < intSPITObjectCount; intObject++) {
ptrSPITObject = SPITObject::getSPITObjectRemote(intObject);
if (ptrSPITObject == NULL) continue;
if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) {
//call ecentSPITObjectRemote
eventSPITObjectRemote(false, p_SPITType, *ptrSPITObject);
}
}
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITTypeRemote CHANGED");
#endif
}
#if defined(DEBUGOUTPUT)
printf(" ID: %s GroupName: %s Name: %s confirmed: %d\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
#endif
//this is a remote SPITType, if you want you can list this for later remote use.
}
/**
* Called when the server has removed a SPITType.<br>
* After this function has been exited the SPITType is emeoved from the SPITType-List and the pointer is deleted.<br>
* So use the pointer immediately or use the copyconstructor to make a copy for extended use.
* You have to release the copy yourself later (delete ptr...)
* @param p_SPITType a reference to a copy of the SPITType instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITTypeRemoved(const SPITType& p_SPITType) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITType Removed");
printf(" ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data());
#endif
//Check your actions
//take the removal of the SPITType over in your code
//CAUTION: Deleted SPIT types can be added later again (perhaps per UNDO on the SPITServer)
//-> don't remove your assigned action immediately - keep it to reassign it later
}
/**
* Called when the server has removed a Remote SPITType.<br>
* Remote SPITType are used in Remote SPITObjects. A Remote SPITObject is used to remote control the SPITServer.
* After this function has been exited the SPITType is emeoved from the Remote SPITType-List and the pointer is deleted.<br>
* So use the pointer immediately or use the copyconstructor to make a copy for extended use.
* You have to release the copy yourself later (delete ptr...)
* @param p_SPITType a reference to a copy of the SPITType instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITTypeRemoteRemoved(const SPITType& p_SPITType) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITTypeRemote Removed");
printf(" ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data());
#endif
//This is a remote SPITType
//If you have listet this prior you should remove it from the list
}
//----------------------------------------------------
//--------- SPITObject events ----------
// Every SPITObjects has one one SPITType assigned.
// Whenever an action is to be triggered, play events are sent with the corresponding SPITObject.
// All SPITObjects are listet in a static unordered_map in the SPITObject class.
// All Remote SPITObjects are listet in a seperate unordered_map in the SPITObject class;
// You can use the SPITObject::get... functions to deal with them.
// The SPITObject class has a static recursive_mutex, you get a pointer of the mutex by: SPITObject::getMutex();
// To be thread save you should cover your code with a lock sequence:
/*
{ //start of the lock sequence
unique_lock<recursive_mutex> o_LockObject(*SPITObject::getMutex());
//got the lock
//fetch SPITObjects and deal with, but don't waste time while you holding the lock
//Excample
SPITObject* ptrSPITObject;
for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) {
ptrSPITObject = SPITObject::getSPITObject(i);
if (ptrSPITObject == NULL) break;
//Do something with ptrSPITObject
//bew aware after you leave the lock sequence the ptrSPITObject is no longer save!!
}
} //end of the lock sequence
//For Remote Objects you can use the getSPITObjectRemote... functions
*/
/**
* Called when the server has created, loaded or changed a SPITObject.<br>
* May also occur when the server confirms a SPITObject created by the client, what the client should never do!!.<br>
* @param p_New true = server created a new SPITObject<br>
* false = server changed a existing SPITObject<br>
* @param p_SPITType a reference to a copy of the associated SPITType instance.<br>
* The reference is deleted after this function call!!
* @param p_SPITObject a reference to a copy of the SPITObject instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITObject(bool p_New, const SPITType& p_SPITType, const SPITObject& p_SPITObject) {
if (p_New) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITObject NEW");
#endif
}
else {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITObject CHANGED");
#endif
}
#if defined(DEBUGOUTPUT)
printf(" ID: %s Name: %s -> SPITType: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
#endif
//check your actions
//Whenever you provide an action for this SPITObject take this over in your code.
//call m_SPIT_Client->setActionSPITObject(p_SPITObject.getID(), true);
//for our little excample as described in loadClientProject:
//We have only actions for SPITTypes - means every SPITObject with the associated "Actionx"-SPITTypes will trigger the action when it is played
//-> no need to do something here, because setActionSPITType has been set prior and the SPITObject will automatically inherits this
//SPITObjects with other SPITTypes asscciated will trigger no actions
}
/**
* Called when the server has created or changed a Remote SPITObject.<br>
* A Remote SPITObject is used to remote control the SPITServer.
* @param p_New true = server created a new remote SPITObject<br>
* false = server changed a existing remote SPITObject<br>
* @param p_SPITType a reference to a copy of the associated SPITType instance.<br>
* The reference is deleted after this function call!!
* @param p_SPITObject a reference to a copy of the SPITObject instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITObjectRemote(bool p_New, const SPITType& p_SPITType, const SPITObject& p_SPITObject) {
if (p_New) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITObjectRemote NEW");
#endif
}
else {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITObjectRemote CHANGED");
#endif
}
#if defined(DEBUGOUTPUT)
printf(" ID: %s Name: %s -> SPITType: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
#endif
//This is a remote SPITObject which can be used to remote control the server.
//If you want you can list this for later use
}
/**
* Called when the server has removed a SPITObject.<br>
* After this function has been exited the SPITObject is emeoved from the SPITObject-List and the pointer is deleted.<br>
* So use the pointer immediately or use the copyconstructor to make a copy for extended use.
* You have to release the copy yourself later (delete ptr...)
* @param p_SPITType a reference to a copy of the associated SPITType instance.<br>
* The reference is deleted after this function call!!
* @param p_SPITObject a reference to a copy of the SPITObject instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITObjectRemoved(const SPITType& p_SPITType, const SPITObject& p_SPITObject) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITObject Removed");
printf(" ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
#endif
//Check your actions
//take the removal of the SPITObject over in your code
//CAUTION: Deleted SPITObjects can be added later again (perhaps per UNDO on the SPITServer)
//-> don't remove your assigned action immediately - keep it to reassign it later
}
/**
* Called when the server has removed a Remote SPITObject.<br>
* A Remote SPITObject is used to remote control the SPITServer.
* After this function has been exited the SPITObject is emeoved from the SPITObject-List and the pointer is deleted.<br>
* So use the pointer immediately or use the copyconstructor to make a copy for extended use.
* You have to release the copy yourself later (delete ptr...)
* @param p_SPITType a reference to a copy of the associated SPITType instance.<br>
* The reference is deleted after this function call!!
* @param p_SPITObject a reference to a copy of the SPITObject instance.<br>
* The reference is deleted after this function call!!
*/
void MyApp::eventSPITObjectRemoteRemoved(const SPITType& p_SPITType, const SPITObject& p_SPITObject) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventSPITObjectRemote Removed");
printf(" ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
#endif
//This is a remote SPITObject
//If you have listet this prior you should remove it from the list
}
//--------------------------------------------------------------
//---------------- Playing SPITObjects ----------------
// Following is called when the SPITServer play SPITObjects.
// For every step the server does following sequence occurs:
// a) eventPlay
// b) several eventPlayObject for each actual played SPITObjectin this step
// NEXT STAP of the server
// a) eventPlay
// b) several eventPlayObject for each actual played SPITObject in this step
// ...
// SPITServer may use several methods for playing SPITObjects.
// e.g. liveSHOWsoftware has the timeline and jingles which plays objects, where the timeline the main player is.
// SPIT distinguishes between the different players. All eventPlay... functions contain the information which player plays the SPIT object.
void MyApp::eventPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventPlay Player: %s Runs: %d Time: %lld\n", p_PlayerName.data(), p_PlayerIsRunning, p_TimeFrames);
#endif
switch(p_PlayerType) {
case SPIT_Client::PLAYERTYPE_MAIN:
//p_FrameTimes contains the position inside the server's project, we can use it like a timecode
int intMilliseconds;
intMilliseconds= (int)(((double)p_TimeFrames / (double)m_ServerFramesPerSecond) * 1000);
break;
case SPIT_Client::PLAYERTYPE_CONTINOUS:
//The olayer is playing only single Object sequences sometime during the project
break;
case SPIT_Client::PLAYERTYPE_DISCRETE:
//Only discrete values where submitted, e.g the fader position of remote faders.
break;
}
}
/**
* Called when the SPITServer plays a SPITObject. For every played SPITObject one eventPlayObject is called.<br>
* You can decide here which action should be done or not.<br>
*
* @param p_Started true = The SPITObject is newly played (e.g. in liveSHOWsoftware the cursor enters the SPITObject)
* @param p_Ended Das true = Playback of SPITObject finished (e.g. in liveSHOWsoftware the cursor has exited the SPIT object)
* @param p_SPITType the associated SPITType of p_SPITObject
* @param p_SPITObject the actual played or stopped SPITObject
* @param p_PlayObject contains information about the play status:<br>
* frame where the cursor is inside the SPITObject<br>
* whether the player is running or not<br>
* the actual value of the SPITObject (in liveSHOWsoftware objects ma faded in or out or the main value is decreased, ..<br>
*/
void MyApp::eventPlayObject(string p_PlayerID, bool p_Started, bool p_Ended, const SPITType& p_SPITType, const SPITObject& p_SPITObject, const SPITPlayer::PlayObject& p_PlayObject) {
// p_PlayObject.getValue() contain the value in ppm (we can calculate value between 0.0 and 1.0)
// p_SPITObject.getValueFactor() or redundand p_PlayObject.getValueFactor()
// contains the factor the above value should be multiplicated to get the end value.
double doubleValue = ((double)p_PlayObject.getValue()/1000000)*((double)p_PlayObject.getValueFactor()/1000000);
//Other factors besides value may be of interest
//p_PlayObject.getFrameInside() contains the play position inside the SPITObject
//p_SPITObject.getFrameLength() contains the length of the SPITObject
//-> we can calculate the position 0.0 to 1.0 where the Object is played
//in liveSHOWsoftware the player may play two different position in the SPITObject to mix them down, e.g. a SceneBridge is played
//We can get the second (pre played) position: p_PlayObject.getFrameInsidePrePosition();
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventPlayObject Player: %s is running: %d Object Started: %d Stopped: %d\n", p_PlayObject.getPlayerName().data(), p_PlayObject.getPlayerIsRunning(), p_Started, p_Ended);
printf(" SPITType: %s SPITObject: %s Position: %lld Value: %f\n", p_SPITType.getName().data(), p_SPITObject.getName().data(), p_PlayObject.getFrameInside(), doubleValue);
#endif
//check for your actions to do
//In our little excample decribed in loadClientProject:
//We want to react to SPIT types, no matter which SPIT object is currently being played.
//-> check not the SPITObject itself but the associated SPITType
bool boolPLayerIsRunning = p_PlayObject.getPlayerIsRunning();
if (p_SPITType.getID() == "MySPITAPP_Action1ID") { //do Action 1
//we can get some information about the play status
if (p_Started == true) {
#if defined(DEBUGOUTPUT)
printf("MyApp AKTION 1 started Value: %f and running: %d\n", doubleValue, boolPLayerIsRunning);
#endif
}
else if (p_Ended == true) {
#if defined(DEBUGOUTPUT)
printf("MyApp AKTION 1 ended\n"); //p_PlayObject.getFrameInside() is -1
#endif
}
else {
#if defined(DEBUGOUTPUT)
printf("MyApp AKTION 1 is played Value: %f and running: %d\n", doubleValue, boolPLayerIsRunning);
#endif
}
}
else if (p_SPITType.getID() == "MySPITAPP_Action2ID") { //do Action 2
if (p_Started == true) {
#if defined(DEBUGOUTPUT)
printf("MyApp AKTION 2 started Value: %f and running: %d\n", doubleValue, boolPLayerIsRunning);
#endif
}
else if (p_Ended == true) {
#if defined(DEBUGOUTPUT)
printf("MyApp AKTION 2 ended\n"); //p_PlayObject.getFrameInside() is -1
#endif
}
else {
#if defined(DEBUGOUTPUT)
printf("MyApp AKTION 2 is played Value: %f and running: %d\n", doubleValue, boolPLayerIsRunning);
#endif
}
}
}
//--------------------------------------------------------------
//---------------- Remote Control SPITServer ----------------
// The SPITServer has sent all possibilities to control it remotely - remote SPITObjects - see eventSPITObjectRemote
// Some of them may control functionality with values (fader psotions for loudness of sound, ...).
// When the server changes one of these value objects, it sends an eventPlayRemoteObjectStatus.
/**
* Called when a remote SpitObject which value function is changed by the server.<br>
* This allows the Client to adjust its display for the remote command.<br>
* @param p_SPITType the assigned remote SPITType of p_SPITObject
* @param p_SPITObject the remote SPITObject which is changed
* @param p_FrameInsideObject can be discarded
* @param p_Value the new value
*/
void MyApp::eventPlayRemoteObjectStatus(const SPITType& p_SPITType, const SPITObject& p_SPITObject, long long p_FrameInsideObject, int p_Value) {
#if defined(DEBUGOUTPUT)
printf("MySPITApp: eventPlayRemoteObjectStatus RemoteSPITType: %s RemoteSPITObject: %s Position: %lld Value: %d\n", p_SPITType.getName().data(), p_SPITObject.getName().data(), p_FrameInsideObject, p_Value);
#endif
}
/**
* Send a remote control command to the SPITServer.<br>
* There may be different command types:
* a) Some don't use value e.g. go to next scene, olay a jingle, ..
* b) Some use values e.g. the main sound fader
* @param p_SPITObjectID the id of the remote SPITObject (this represents the remote control command)
* @param p_Valueppm the value in ppm <br>
* in case a) the value is ignored<br>
* in case b) the value is used
* @param p_ValueFlag indicates how the server should use p_Valueppm:<br>
* VALUEFLAG_DIRECT (0x00) The server will overwrite his existing value with p_Value<br>
* VALUEFLAG_INCREASE (0x01) The server increases his existing value by p_Valueppm
* VALUEFLAG_DECREASE (0x01) The server decreases his existing value by p_Valueppm
*/
void MyApp::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p_ValueFlag) {
if (m_SPIT_Client != NULL) {
m_SPIT_Client->sendRemoteObject(p_SPITObjectID, p_Valueppm, p_ValueFlag);
}
}
//liveSHOWsoftware excample for sending remote control
//the liveSHOW software has the remote control commands (SPITObjects) among other things:
// + next secenebridge with id "nextSceneBridge"
// + main mixer sound width id = "mainmixerSound_Volume00"
//You can detect this in eventSPITObjectRemote(...)
void MyApp::testLiveShowRemote() {
//We jump to the next Scenebridge - no Value is needed
m_SPIT_Client->sendRemoteObject("nextSceneBridge");
//we set the main sound volume to 0.1, SPIT uses ppm -> 0.1 = 100000
m_SPIT_Client->sendRemoteObject("mainmixerSound_Volume00", 100000, SPIT_Client::VALUEFLAG_DIRECT);
//we increase the main sound volume by 0.1, SPIT uses ppm -> 0.1 = 100000
m_SPIT_Client->sendRemoteObject("mainmixerSound_Volume00", 100000, SPIT_Client::VALUEFLAG_INCREASE);
}
//-------------------------------------------------
//---------- Options for the client user ----------
//Normally this should not be used, because because the server is master of things
//In some situations, however, it may be helpful
/**
* Removes the SPITType with id == p_SPITTypeID
* @param p_SPITTypeID the id of the SPITType
* @return
*/
int MyApp::removeSPITType(string p_SPITTypeID) {
if (m_SPIT_Client == NULL) return -1;
return m_SPIT_Client->removeSPITType(p_SPITTypeID);
}
/**
* Removes the SPITObject with id == p_SPITObjectID
* @param p_SPITObjectID the id of the SPITObject
* @return
*/
int MyApp::removeSPITObject(string p_SPITObjectID) {
if (m_SPIT_Client == NULL) return -1;
return m_SPIT_Client->removeSPITObject(p_SPITObjectID);
}
/**
* Changes the SPITType
* @param p_SPITType a pointer to a SPITType instance whith changed members
* @return
*/
int MyApp::changeSPITType(SPITType* p_SPITType) {
return m_SPIT_Client->changeSPITType(p_SPITType);
}
/**
* Changes the SPITObject
* @param p_SPITObject a pointer to a SPITObject with changed members
* @return
*/
int MyApp::changeSPITObject(SPITObject* p_SPITObject) {
return m_SPIT_Client->changeSPITObject(p_SPITObject);
}