Beispiel #1
0
        /**
         * @brief StopRecord Остановить запись данных в файл
         */
        public void StopRecord()
        {
            Debug.WriteLine("StopRecord");
            if (!m_Started || !m_Recording || m_TranslationPaused || m_File == null)
            {
                return;
            }

            if (m_FileWriteBuffer != null && m_FileWriteBuffer.Count > 0)
            {
                m_File.Write(m_FileWriteBuffer.ToArray(), 0, m_FileWriteBuffer.Count);
            }

            if (m_WrittenDataCount > 0)
            {
                string recordsCountText = FixEdfString(m_WrittenDataCount.ToString(), 8);
                m_File.Seek(236, SeekOrigin.Begin);
                byte[] writeBuf = Encoding.ASCII.GetBytes(recordsCountText);
                m_File.Write(writeBuf, 0, writeBuf.Length);
            }

            m_FileWriteBuffer = null;

            m_File.Close();
            m_File             = null;
            m_WrittenDataCount = 0;
            m_Recording        = false;
            m_RecordPaused     = false;
            Debug.WriteLine("Record stopped");

            if (RecordingStateChanged != null)
            {
                RecordingStateChanged.Invoke(this, (int)GARANT_EEG_DEVICE_RECORDING_STATE.DRS_RECORD_STOPPED);
            }
        }
Beispiel #2
0
        private void T_Tick(object sender, EventArgs e)
        {
            if (RecordingState)
            {
                ((Timer)sender).Stop();
            }

            RecordingStateChanged?.Invoke(!RecordingState);
            RecordingState  = false;
            blinker.Enabled = false;
            Text            = "Record";
        }
Beispiel #3
0
        /**
         * @brief PauseRecord Приостановить запись данных в файл (без фактической остановки записи, с возможностью продолжения записи)
         */
        public void PauseRecord()
        {
            if (m_Started && m_Recording)
            {
                m_RecordPaused = true;

                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged.Invoke(this, (int)GARANT_EEG_DEVICE_RECORDING_STATE.DRS_RECORD_PAUSED);
                }
            }
        }
Beispiel #4
0
 private void RecordButton_Click(object sender, EventArgs e)
 {
     RecordingStateChanged?.Invoke(!RecordingState);
     if (RecordingState == false)
     {
         RecordingState        = true;
         blinker.Enabled       = true;
         showRed               = true;
         Text                  = "Stop";
         timeOutTimer.Interval = maxt;
         timeOutTimer.Tick    += T_Tick;
         timeOutTimer.Start();
     }
     else
     {
         RecordingState  = false;
         blinker.Enabled = false;
         Text            = "Record";
     }
 }
Beispiel #5
0
        /// <summary>
        /// Update message handler
        /// </summary>
        /// <param name="eventType">Value of "event-type" in the JSON body</param>
        /// <param name="body">full JSON message body</param>
        protected void ProcessEventType(string eventType, JObject body)
        {
            StreamStatus status;

            switch (eventType)
            {
            case "SwitchScenes":
                SceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "ScenesChanged":
                SceneListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SourceOrderChanged":
                SourceOrderChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "SceneItemAdded":
                SceneItemAdded?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemRemoved":
                SceneItemRemoved?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemVisibilityChanged":
                SceneItemVisibilityChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneCollectionChanged":
                SceneCollectionChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SceneCollectionListChanged":
                SceneCollectionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SwitchTransition":
                TransitionChanged?.Invoke(this, (string)body["transition-name"]);
                break;

            case "TransitionDurationChanged":
                TransitionDurationChanged?.Invoke(this, (int)body["new-duration"]);
                break;

            case "TransitionListChanged":
                TransitionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "TransitionBegin":
                TransitionBegin?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileChanged":
                ProfileChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileListChanged":
                ProfileListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStarting":
                StreamingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "StreamStarted":
                StreamingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "StreamStopping":
                StreamingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "StreamStopped":
                StreamingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingStarting":
                RecordingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "RecordingStarted":
                RecordingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "RecordingStopping":
                RecordingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "RecordingStopped":
                RecordingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "StreamStatus":
                if (StreamStatus != null)
                {
                    status = new StreamStatus(body);
                    StreamStatus(this, status);
                }
                break;

            case "PreviewSceneChanged":
                PreviewSceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "StudioModeSwitched":
                StudioModeSwitched?.Invoke(this, (bool)body["new-state"]);
                break;

            case "ReplayStarting":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "ReplayStarted":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "ReplayStopping":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "ReplayStopped":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "Exiting":
                OBSExit?.Invoke(this, EventArgs.Empty);
                break;

            case "Heartbeat":
                Heartbeat?.Invoke(this, new Heartbeat(body));
                break;

            case "SceneItemDeselected":
                SceneItemDeselected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemSelected":
                SceneItemSelected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemTransformChanged":
                SceneItemTransformChanged?.Invoke(this, new SceneItemTransformInfo(body));
                break;

            case "SourceAudioMixersChanged":
                SourceAudioMixersChanged?.Invoke(this, new AudioMixersChangedInfo(body));
                break;

            case "SourceAudioSyncOffsetChanged":
                SourceAudioSyncOffsetChanged?.Invoke(this, (string)body["sourceName"], (int)body["syncOffset"]);
                break;

            case "SourceCreated":
                SourceCreated?.Invoke(this, new SourceSettings(body));
                break;

            case "SourceDestroyed":
                SourceDestroyed?.Invoke(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                break;

            case "SourceRenamed":
                SourceRenamed?.Invoke(this, (string)body["newName"], (string)body["previousName"]);
                break;

            case "SourceMuteStateChanged":
                SourceMuteStateChanged?.Invoke(this, (string)body["sourceName"], (bool)body["muted"]);
                break;

            case "SourceVolumeChanged":
                SourceVolumeChanged?.Invoke(this, (string)body["sourceName"], (float)body["volume"]);
                break;

            case "SourceFilterAdded":
                SourceFilterAdded?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                break;

            case "SourceFilterRemoved":
                SourceFilterRemoved?.Invoke(this, (string)body["sourceName"], (string)body["filterName"]);
                break;

            case "SourceFiltersReordered":
                List <FilterReorderItem> filters = new List <FilterReorderItem>();
                JsonConvert.PopulateObject(body["filters"].ToString(), filters);
                SourceFiltersReordered?.Invoke(this, (string)body["sourceName"], filters);
                break;
            }
        }
        /// <summary>
        /// Update message handler
        /// </summary>
        /// <param name="eventType">Value of "event-type" in the JSON body</param>
        /// <param name="body">full JSON message body</param>
        protected void ProcessEventType(string eventType, JObject body)
        {
            StreamStatus status;

            switch (eventType)
            {
            case "SwitchScenes":
                SceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "ScenesChanged":
                SceneListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SourceOrderChanged":
                SourceOrderChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "SceneItemAdded":
                SceneItemAdded?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemRemoved":
                SceneItemRemoved?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemVisibilityChanged":
                SceneItemVisibilityChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (bool)body["item-visible"]);
                break;

            case "SceneItemLockChanged":
                SceneItemLockChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (int)body["item-id"], (bool)body["item-locked"]);
                break;

            case "SceneCollectionChanged":
                SceneCollectionChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SceneCollectionListChanged":
                SceneCollectionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SwitchTransition":
                TransitionChanged?.Invoke(this, (string)body["transition-name"]);
                break;

            case "TransitionDurationChanged":
                TransitionDurationChanged?.Invoke(this, (int)body["new-duration"]);
                break;

            case "TransitionListChanged":
                TransitionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "TransitionBegin":
                TransitionBegin?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["from-scene"], (string)body["to-scene"]);
                break;

            case "TransitionEnd":
                TransitionEnd?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["to-scene"]);
                break;

            case "TransitionVideoEnd":
                TransitionVideoEnd?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["from-scene"], (string)body["to-scene"]);
                break;

            case "ProfileChanged":
                ProfileChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileListChanged":
                ProfileListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStarting":
                StreamingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "StreamStarted":
                StreamingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "StreamStopping":
                StreamingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "StreamStopped":
                StreamingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingStarting":
                RecordingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "RecordingStarted":
                RecordingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "RecordingStopping":
                RecordingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "RecordingStopped":
                RecordingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingPaused":
                RecordingPaused?.Invoke(this, EventArgs.Empty);
                break;

            case "RecordingResumed":
                RecordingResumed?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStatus":
                if (StreamStatus != null)
                {
                    status = new StreamStatus(body);
                    StreamStatus(this, status);
                }
                break;

            case "PreviewSceneChanged":
                PreviewSceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "StudioModeSwitched":
                StudioModeSwitched?.Invoke(this, (bool)body["new-state"]);
                break;

            case "ReplayStarting":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "ReplayStarted":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "ReplayStopping":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "ReplayStopped":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "Exiting":
                OBSExit?.Invoke(this, EventArgs.Empty);
                break;

            case "Heartbeat":
                Heartbeat?.Invoke(this, new Heartbeat(body));
                break;

            case "SceneItemDeselected":
                SceneItemDeselected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemSelected":
                SceneItemSelected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemTransformChanged":
                SceneItemTransformChanged?.Invoke(this, new SceneItemTransformInfo(body));
                break;

            case "SourceAudioMixersChanged":
                SourceAudioMixersChanged?.Invoke(this, new AudioMixersChangedInfo(body));
                break;

            case "SourceAudioSyncOffsetChanged":
                SourceAudioSyncOffsetChanged?.Invoke(this, (string)body["sourceName"], (int)body["syncOffset"]);
                break;

            case "SourceCreated":
                SourceCreated?.Invoke(this, new SourceSettings(body));
                break;

            case "SourceDestroyed":
                SourceDestroyed?.Invoke(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                break;

            case "SourceRenamed":
                SourceRenamed?.Invoke(this, (string)body["newName"], (string)body["previousName"]);
                break;

            case "SourceMuteStateChanged":
                SourceMuteStateChanged?.Invoke(this, (string)body["sourceName"], (bool)body["muted"]);
                break;

            case "SourceAudioDeactivated":
                SourceAudioDeactivated?.Invoke(this, (string)body["sourceName"]);
                break;

            case "SourceAudioActivated":
                SourceAudioActivated?.Invoke(this, (string)body["sourceName"]);
                break;

            case "SourceVolumeChanged":
                SourceVolumeChanged?.Invoke(this, new SourceVolume(body));
                break;

            case "SourceFilterAdded":
                SourceFilterAdded?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                break;

            case "SourceFilterRemoved":
                SourceFilterRemoved?.Invoke(this, (string)body["sourceName"], (string)body["filterName"]);
                break;

            case "SourceFiltersReordered":
                if (SourceFiltersReordered != null)
                {
                    List <FilterReorderItem> filters = new List <FilterReorderItem>();
                    JsonConvert.PopulateObject(body["filters"].ToString(), filters);

                    SourceFiltersReordered?.Invoke(this, (string)body["sourceName"], filters);
                }
                break;

            case "SourceFilterVisibilityChanged":
                SourceFilterVisibilityChanged?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (bool)body["filterEnabled"]);
                break;

            case "BroadcastCustomMessage":
                BroadcastCustomMessageReceived?.Invoke(this, (string)body["realm"], (JObject)body["data"]);
                break;

            case "MediaEnded":
                MediaEnded?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaStarted":
                MediaStarted?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPrevious":
                MediaPrevious?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaNext":
                MediaNext?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaStopped":
                MediaStopped?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaRestarted":
                MediaRestarted?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPaused":
                MediaPaused?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPlaying":
                MediaPlaying?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "VirtualCamStarted":
                VirtualCameraStarted?.Invoke(this, EventArgs.Empty);
                break;

            case "VirtualCamStopped":
                VirtualCameraStopped?.Invoke(this, EventArgs.Empty);
                break;

            default:
                var message = $"Unsupported Event: {eventType}\n{body}";
                Console.WriteLine(message);
                Debug.WriteLine(message);
                break;
            }
        }
Beispiel #7
0
        /**
         * @brief StartRecord Начать запись данных в файл
         * @param userName Имя респондента
         * @param filePath Путь к BDF файлу, в который нужно записывать данные
         * @return true если запись в файл началась успешно, false если запись не началась
         */
        public bool StartRecord(string userName, string filePath = "")
        {
            Debug.WriteLine("StartRecord");
            if (!m_Started || m_Recording || m_TranslationPaused || m_File != null)
            {
                Debug.WriteLine("StartRecord error 1");
                return(false);
            }
            else if (m_HeaderData.Count == 0)
            {
                Debug.WriteLine("StartRecord error 2");
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged.Invoke(this, (int)GARANT_EEG_DEVICE_RECORDING_STATE.DRS_HEADER_NOT_FOUND);
                }

                return(false);
            }

            if (filePath != "")
            {
                m_RecordFileName = filePath;
            }
            else
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "SaveData";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                m_RecordFileName = path + "/EegRecord_" + DateTime.Now.ToString("yyyy_MM_dd___HH_mm_ss") + ".bdf";
            }

            m_FileWriteBuffer = null;

            Debug.WriteLine("start recording in {0}", m_RecordFileName);

            m_File = new FileStream(m_RecordFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            if (m_File != null)
            {
                m_File.Write(m_HeaderData.ToArray(), 0, m_HeaderData.Count);

                string name     = FixEdfString(userName, 80);
                byte[] writeBuf = Encoding.ASCII.GetBytes(name);
                m_File.Seek(8, SeekOrigin.Begin);
                m_File.Write(writeBuf, 0, writeBuf.Length);

                for (int i = 0; i < (int)m_ChannelNames.Count; i++)
                {
                    string electrodeName     = FixEdfString(m_ChannelNames[i], 16);
                    byte[] writeElectrodeBuf = Encoding.ASCII.GetBytes(electrodeName);
                    m_File.Seek(256 + (16 * i), SeekOrigin.Begin);
                    m_File.Write(writeElectrodeBuf, 0, writeElectrodeBuf.Length);
                }

                m_File.Seek(m_HeaderData.Count, SeekOrigin.Begin);

                m_FileWriteBuffer  = new List <byte>();
                m_WrittenDataCount = 0;
                m_Recording        = true;
                m_RecordPaused     = false;

                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged.Invoke(this, (int)GARANT_EEG_DEVICE_RECORDING_STATE.DRS_NO_ERROR);
                }
            }
            else
            {
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged.Invoke(this, (int)GARANT_EEG_DEVICE_RECORDING_STATE.DRS_CREATE_FILE_ERROR);
                }
            }

            return(m_Recording);
        }
 private void Start_Clicked(object sender, EventArgs e)
 {
     recordingState = !recordingState;
     RecordingStateChanged?.Invoke(null, new EventArgs());
 }