/*--------------------------------------------------------------------*/ #region Construction /// <summary> /// Initializes a new instance of EmoStateWrapper class. /// </summary> /// <param name="emoState">An <see cref="EmoState"/> for the <see cref="EmoStateWrapper"/> properties.</param> public EmoStateWrapper(EmoState emoState) { if (emoState != null) { _emoState = emoState.Clone() as EmoState; } else { throw new ArgumentNullException("emoState", "must be assigned"); } }
/// <summary> /// Initializes a new instance of the <see cref="EmotivState"/> class. /// </summary> /// <param name="emoState">An <see cref="EmoState"/> to back the <see cref="EmotivState"/> properties.</param> public EmotivState(EmoState emoState) { if (emoState != null) { // Cache a copy. this._emoState = emoState.Clone() as EmoState; } else { throw new ArgumentNullException("emoState", "must be assigned"); } }
public void ProcessEvents(int maxTimeMilliseconds) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (EdkDll.EE_EngineGetNextEvent(this.hEvent) == 0) { if (maxTimeMilliseconds != 0 && stopwatch.ElapsedMilliseconds >= (long)maxTimeMilliseconds) { break; } uint num = 0u; EdkDll.EE_EmoEngineEventGetUserId(this.hEvent, out num); EmoEngineEventArgs e = new EmoEngineEventArgs(num); EdkDll.EE_Event_t eE_Event_t = EdkDll.EE_EmoEngineEventGetType(this.hEvent); EdkDll.EE_Event_t eE_Event_t2 = eE_Event_t; if (eE_Event_t2 != EdkDll.EE_Event_t.EE_UserAdded) { if (eE_Event_t2 != EdkDll.EE_Event_t.EE_UserRemoved) { if (eE_Event_t2 != EdkDll.EE_Event_t.EE_EmoStateUpdated) { if (eE_Event_t2 != EdkDll.EE_Event_t.EE_CognitivEvent) { if (eE_Event_t2 != EdkDll.EE_Event_t.EE_ExpressivEvent) { if (eE_Event_t2 == EdkDll.EE_Event_t.EE_InternalStateChanged) { this.OnInternalStateChanged(e); } } else { switch (EdkDll.EE_ExpressivEventGetType(this.hEvent)) { case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingStarted: this.OnExpressivTrainingStarted(e); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingSucceeded: this.OnExpressivTrainingSucceeded(e); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingFailed: this.OnExpressivTrainingFailed(e); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingCompleted: this.OnExpressivTrainingCompleted(e); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingDataErased: this.OnExpressivTrainingDataErased(e); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingRejected: this.OnExpressivTrainingRejected(e); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingReset: this.OnExpressivTrainingReset(e); break; } } } else { switch (EdkDll.EE_CognitivEventGetType(this.hEvent)) { case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingStarted: this.OnCognitivTrainingStarted(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingSucceeded: this.OnCognitivTrainingSucceeded(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingFailed: this.OnCognitivTrainingFailed(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingCompleted: this.OnCognitivTrainingCompleted(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingDataErased: this.OnCognitivTrainingDataErased(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingRejected: this.OnCognitivTrainingRejected(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingReset: this.OnCognitivTrainingReset(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivAutoSamplingNeutralCompleted: this.OnCognitivAutoSamplingNeutralCompleted(e); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivSignatureUpdated: this.OnCognitivSignatureUpdated(e); break; } } } else { EmoState emoState = new EmoState(); EmoEngine.errorHandler(EdkDll.EE_EmoEngineEventGetEmoState(this.hEvent, emoState.GetHandle())); EmoStateUpdatedEventArgs e2 = new EmoStateUpdatedEventArgs(num, emoState); this.OnEmoStateUpdated(e2); if (!emoState.EmoEngineEqual(this.lastEmoState[num])) { e2 = new EmoStateUpdatedEventArgs(num, new EmoState(emoState)); this.OnEmoEngineEmoStateUpdated(e2); } if (!emoState.AffectivEqual(this.lastEmoState[num])) { e2 = new EmoStateUpdatedEventArgs(num, new EmoState(emoState)); this.OnAffectivEmoStateUpdated(e2); } if (!emoState.CognitivEqual(this.lastEmoState[num])) { e2 = new EmoStateUpdatedEventArgs(num, new EmoState(emoState)); this.OnCognitivEmoStateUpdated(e2); } if (!emoState.ExpressivEqual(this.lastEmoState[num])) { e2 = new EmoStateUpdatedEventArgs(num, new EmoState(emoState)); this.OnExpressivEmoStateUpdated(e2); } this.lastEmoState[num] = (EmoState)emoState.Clone(); } } else { this.OnUserRemoved(e); } } else { this.OnUserAdded(e); } } }
/// <summary> /// Processes EmoEngine events until there is no more events or maximum processing time has elapsed /// </summary> /// <param name="maxTimeMilliseconds">maximum processing time in milliseconds</param> public void ProcessEvents(Int32 maxTimeMilliseconds) { Stopwatch st = new Stopwatch(); st.Start(); while (EdkDll.EE_EngineGetNextEvent(hEvent) == EdkDll.EDK_OK) { if (maxTimeMilliseconds != 0) { if (st.ElapsedMilliseconds >= maxTimeMilliseconds) break; } UInt32 userId = 0; EdkDll.EE_EmoEngineEventGetUserId(hEvent, out userId); EmoEngineEventArgs args = new EmoEngineEventArgs(userId); EdkDll.EE_Event_t eventType = EdkDll.EE_EmoEngineEventGetType(hEvent); switch (eventType) { case EdkDll.EE_Event_t.EE_UserAdded: OnUserAdded(args); break; case EdkDll.EE_Event_t.EE_UserRemoved: OnUserRemoved(args); break; case EdkDll.EE_Event_t.EE_EmoStateUpdated: EmoState curEmoState = new EmoState(); errorHandler(EdkDll.EE_EmoEngineEventGetEmoState(hEvent, curEmoState.GetHandle())); EmoStateUpdatedEventArgs emoStateUpdatedEventArgs = new EmoStateUpdatedEventArgs(userId, curEmoState); OnEmoStateUpdated(emoStateUpdatedEventArgs); if (!curEmoState.EmoEngineEqual(lastEmoState[userId])) { emoStateUpdatedEventArgs = new EmoStateUpdatedEventArgs(userId, new EmoState(curEmoState)); OnEmoEngineEmoStateUpdated(emoStateUpdatedEventArgs); } if (!curEmoState.AffectivEqual(lastEmoState[userId])) { emoStateUpdatedEventArgs = new EmoStateUpdatedEventArgs(userId, new EmoState(curEmoState)); OnAffectivEmoStateUpdated(emoStateUpdatedEventArgs); } if (!curEmoState.CognitivEqual(lastEmoState[userId])) { emoStateUpdatedEventArgs = new EmoStateUpdatedEventArgs(userId, new EmoState(curEmoState)); OnCognitivEmoStateUpdated(emoStateUpdatedEventArgs); } if (!curEmoState.ExpressivEqual(lastEmoState[userId])) { emoStateUpdatedEventArgs = new EmoStateUpdatedEventArgs(userId, new EmoState(curEmoState)); OnExpressivEmoStateUpdated(emoStateUpdatedEventArgs); } lastEmoState[userId] = (EmoState)curEmoState.Clone(); break; case EdkDll.EE_Event_t.EE_CognitivEvent: EdkDll.EE_CognitivEvent_t cogType = EdkDll.EE_CognitivEventGetType(hEvent); switch(cogType){ case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingStarted: OnCognitivTrainingStarted(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingSucceeded: OnCognitivTrainingSucceeded(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingFailed: OnCognitivTrainingFailed(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingCompleted: OnCognitivTrainingCompleted(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingDataErased: OnCognitivTrainingDataErased(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingRejected: OnCognitivTrainingRejected(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivTrainingReset: OnCognitivTrainingReset(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivAutoSamplingNeutralCompleted: OnCognitivAutoSamplingNeutralCompleted(args); break; case EdkDll.EE_CognitivEvent_t.EE_CognitivSignatureUpdated: OnCognitivSignatureUpdated(args); break; default: break; } break; case EdkDll.EE_Event_t.EE_ExpressivEvent: EdkDll.EE_ExpressivEvent_t expEvent = EdkDll.EE_ExpressivEventGetType(hEvent); switch (expEvent) { case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingStarted: OnExpressivTrainingStarted(args); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingSucceeded: OnExpressivTrainingSucceeded(args); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingFailed: OnExpressivTrainingFailed(args); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingCompleted: OnExpressivTrainingCompleted(args); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingDataErased: OnExpressivTrainingDataErased(args); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingRejected: OnExpressivTrainingRejected(args); break; case EdkDll.EE_ExpressivEvent_t.EE_ExpressivTrainingReset: OnExpressivTrainingReset(args); break; default: break; } break; case EdkDll.EE_Event_t.EE_InternalStateChanged: OnInternalStateChanged(args); break; default: break; } } }