public void TestPauseResume() { var stopwatch = new Stopwatch(); var stageProvider = new StageProvider(new Stage { Duration = 2000 }, new Stage { Duration = 2000 }); var program = new StageProgram(Clock.SystemTicksClock, stageProvider); program.Started += (sender, e) => stopwatch.Restart(); var evt = new ManualResetEvent(false); program.Stopped += (sender, e) => { stopwatch.Stop(); evt.Set(); }; program.Start(); Thread.Sleep(2500); Assert.IsTrue(program.Pause()); Thread.Sleep(2500); Assert.IsTrue(program.Resume()); evt.WaitOne(); const double estimatedSeconds = 6.5; var elapsedTime = stopwatch.Elapsed; Assert.IsTrue(Math.Abs(elapsedTime.TotalSeconds - estimatedSeconds) < 1); }
public MidasTouchWindow(Session session) { // ReSharper disable once LocalizableElement Text = "Midas Touch"; SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); Load += Window_OnLoaded; KeyUp += Window_OnKeyUp; Resize += Window_OnResize; this.HideCursorInside(); _session = session; _paradigm = (MidasTouchParadigm)session.Paradigm; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); _stageProgram = _paradigm.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; /* Type conversion */ _backgroundColor = _paradigm.Config.Gui.ColorScheme[ColorKeys.Background].ToSdColor().ToSdx(); _foregroundColor = _paradigm.Config.Gui.ColorScheme[ColorKeys.Foreground].ToSdColor().ToSdx(); _blockBorderColor = _paradigm.Config.Gui.ButtonBorder.Color.ToSdColor().ToSdx(); _blockNormalColor = _paradigm.Config.Gui.ButtonNormalColor.ToSdColor().ToSdx(); }
public MavepTestWindow(Session session) { // ReSharper disable once LocalizableElement Text = "VEP"; SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); Load += Window_OnLoaded; KeyUp += Window_OnKeyUp; this.HideCursorInside(); _session = session; _experiment = (MavepExperiment)session.Experiment; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); _stageProgram = _experiment.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; _stimulusPoints = new D2D1.Ellipse[_experiment.Config.Gui.Stimulus.Count]; /* Type conversion */ _backgroundColor = _experiment.Config.Gui.BackgroundColor.ToSdColor().ToSdx(); _fontColor = _experiment.Config.Gui.BackgroundColor.ToSdColor().Inverted().ToSdx(); _fixationColor = _experiment.Config.Gui.FixationPoint.Color.ToSdColor().ToSdx(); }
public void TestPauseResume2() { var stopwatch = new Stopwatch(); var stageProvider = new StageProvider(new Stage { Duration = 1000 }, new Stage { Marker = 1 }, new Stage { Duration = 1000 }); var program = new StageProgram(Clock.SystemTicksClock, stageProvider); program.Started += (sender, e) => stopwatch.Restart(); program.StageChanged += (sender, e) => e.Action = (e.Stage?.Marker ?? 0) == 1 ? StageAction.Pause : e.Action; var evt = new ManualResetEvent(false); program.Stopped += (sender, e) => { stopwatch.Stop(); evt.Set(); }; program.Start(); Thread.Sleep(5000); Assert.IsTrue(program.Resume()); evt.WaitOne(); const int estimatedSeconds = 6; var elapsedTime = stopwatch.Elapsed; Assert.IsTrue(Math.Abs(elapsedTime.TotalSeconds - estimatedSeconds) < 1); }
public EyeTrackingSpellerWindow(Session session, SpellerController spellerController) : base(session, spellerController) { SuspendLayout(); ControlBox = false; IsFullscreen = false; // ReSharper disable once VirtualMemberCallInConstructor DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); _detector = new EyeTrackingDetector(); GazePointHandler.Point += (sender, e) => { if (e != null) { _detector.Accept(e.Value); } }; SpellerController.CancellingTrial += (sender, e) => { if (_trial != null) { StageProgram.Skip(); TrialCancelled = true; } }; }
/* D3D Resources */ public P300SpellerWindow(Session session, SpellerController spellerController) : base(session, spellerController) { SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); SpellerController.CancellingTrial += (sender, e) => { if (_trial != null) { StageProgram.Skip(); TrialCancelled = true; } }; if (session.StreamerCollection.TryFindFirst <BiosignalStreamer>(out var biosignalStreamer)) { biosignalStreamer.Attach(_p300Detector = new P300Detector( Experiment.Config.Test.Channels.Enumerate(1, biosignalStreamer.BiosignalSampler.ChannelNum).Select(i => (uint)(i - 1)).ToArray(), biosignalStreamer.BiosignalSampler.Frequency, (uint)biosignalStreamer.BiosignalSampler.Frequency, 0.5F)); } }
public SsvepSpellerWindow(Session session, SpellerController spellerController) : base(session, spellerController) { SuspendLayout(); ControlBox = false; IsFullscreen = true; // ReSharper disable once VirtualMemberCallInConstructor DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); SpellerController.CancellingTrial += (sender, e) => { if (_trial != null) { StageProgram.Skip(); TrialCancelled = true; } }; _stimulationPatterns = Paradigm.Config.Test.StimulationPatterns; if (session.StreamerCollection.TryFindFirst(out _biosignalStreamer)) { _hybridSsvepIdentifier = new HybridSsvepIdentifier(session.Clock, Paradigm.Config.Test.ComputeParallelLevel, _stimulationPatterns, Paradigm.Config.Test.FilterBank, Paradigm.Config.Test.SubBandMixingParams, Paradigm.Config.Test.HarmonicsCount, Paradigm.Config.Test.CcaThreshold, Paradigm.Config.Test.Channels.Enumerate(1, _biosignalStreamer.BiosignalSource.ChannelNum).Select(i => (uint)(i - 1)).ToArray(), _biosignalStreamer.BiosignalSource.Frequency, Paradigm.Config.Test.Trial.Duration, Paradigm.Config.Test.SsvepDelay); _biosignalStreamer.AttachConsumer(_hybridSsvepIdentifier); } }
public P300ExperimentWindow(Session session) { // ReSharper disable once LocalizableElement Text = "P300"; SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); Load += Window_OnLoaded; KeyUp += Window_OnKeyUp; Resize += Window_OnResize; this.HideCursorInside(); _session = session; _paradigm = (P300Paradigm)session.Paradigm; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); _result = new P300Paradigm.Result { Trials = new LinkedList <P300Paradigm.Result.Trial>() }; _stageProgram = _paradigm.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; /* Initialize blocks */ _blocks = new Block[(int)_paradigm.Config.Test.Layout]; for (var i = 0; i < _blocks.Length; i++) { var block = new Block { Target = _blocks.Length / 2 == i, Random = _paradigm.Config.Test.TargetRate .CreateRandomBoolSequence((int)(DateTimeUtils.CurrentTimeTicks << 1 + i)), Size = new RawVector2(_paradigm.Config.Gui.BlockLayout.Width, _paradigm.Config.Gui.BlockLayout.Height), BorderWidth = (float)_paradigm.Config.Gui.BlockBorder.Width }; block.UpdateGeometries(); _blocks[i] = block; } /* Type conversion */ _backgroundColor = _paradigm.Config.Gui.BackgroundColor.ToSdColor().ToSdx(); _fontColor = _paradigm.Config.Gui.BackgroundColor.ToSdColor().Inverted().ToSdx(); _blockBorderColor = _paradigm.Config.Gui.BlockBorder.Color.ToSdColor().ToSdx(); _blockNormalColor = _paradigm.Config.Gui.BlockNormalColor.ToSdColor().ToSdx(); _blockActivedColor = _paradigm.Config.Gui.BlockActivedColor.ToSdColor().ToSdx(); }
public SsvepTestWindow(Session session) { // ReSharper disable once LocalizableElement Text = "SSVEP"; SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); Load += Window_OnLoaded; KeyUp += Window_OnKeyUp; Resize += Window_OnResize; this.HideCursorInside(); _session = session; _experiment = (SsvepExperiment)session.Experiment; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); _paradigm = _experiment.Config.Test.Paradigm; _blocks = new Block[(int)_experiment.Config.Gui.BlockLayout.Volume]; var patternMultiplier = _paradigm.GetParadigmPatternMultiplier(); for (var i = 0; i < _blocks.Length; i++) { _blocks[i].Size = new RawVector2(_experiment.Config.Gui.BlockSize.Width, _experiment.Config.Gui.BlockSize.Height); _blocks[i].BorderWidth = (float)_experiment.Config.Gui.BlockBorder.Width * (float)GraphicsUtils.Scale; _blocks[i].FixationPointSize = _experiment.Config.Gui.BlockFixationPoint.Size * (float)GraphicsUtils.Scale; var patterns = new ITemporalPattern[patternMultiplier]; for (var j = 0; j < patternMultiplier; j++) { patterns[j] = _experiment.Config.Test.Patterns[i * patternMultiplier + j]; } _blocks[i].Patterns = patterns.All(Functions.IsNull) ? null : patterns; _blocks[i].UpdateGeometries(); } _stageProgram = _experiment.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; /* Type conversion */ _backgroundColor = _experiment.Config.Gui.BackgroundColor.ToSdColor().ToSdx(); _fontColor = _experiment.Config.Gui.BackgroundColor.ToSdColor().Inverted().ToSdx(); _blockBorderColor = _experiment.Config.Gui.BlockBorder.Color.ToSdColor().ToSdx(); _blockNormalColor = _experiment.Config.Gui.BlockColors[0].ToSdColor().ToSdx(); _blockFlashingColor = _experiment.Config.Gui.BlockColors[1].ToSdColor().ToSdx(); _blockFixationPointColor = _experiment.Config.Gui.BlockFixationPoint.Color.ToSdColor().ToSdx(); }
public TestWindow(Session session) { InitializeComponent(); _session = session; this.HideCursorInside(); var experiment = (RestExperiment)session.Experiment; Background = new SolidColorBrush(experiment.Config.Gui.BackgroundColor.ToSwmColor()); CueText.Foreground = new SolidColorBrush(experiment.Config.Gui.ForegroundColor.ToSwmColor()); CueText.FontSize = experiment.Config.Gui.FontSize; _stageProgram = experiment.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; }
public TestWindow(Session session) { InitializeComponent(); _session = session; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); this.HideCursorInside(); var experiment = (CountdownExperiment)session.Experiment; Background = new SolidColorBrush(experiment.Config.Gui.BackgroundColor.ToSwmColor()); CueText.Foreground = new SolidColorBrush(experiment.Config.Gui.ForegroundColor.ToSwmColor()); CueText.FontSize = experiment.Config.Gui.FontSize; _stageProgram = experiment.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; }
public TextDisplayExperimentWindow(Session session) { InitializeComponent(); _session = session; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); this.HideCursorInside(); var paradigm = (TextDisplayParadigm)session.Paradigm; Background = new SolidColorBrush(paradigm.Config.Gui.BackgroundColor.ToSwmColor()); CueText.Foreground = new SolidColorBrush(paradigm.Config.Gui.ForegroundColor.ToSwmColor()); CueText.FontSize = paradigm.Config.Gui.FontSize; _stageProgram = paradigm.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; }
public TestWindow(Session session) { InitializeComponent(); _session = session; _experiment = (MrcpExperiment)session.Experiment; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); this.HideCursorInside(); _stageProgram = _experiment.CreateStagedProgram(session); _stageProgram.StageChanged += StageProgram_StageChanged; _defaultLineStyle = (Style)FindResource("DefaultLineStyle"); _highlightedLineStyle = (Style)FindResource("HighlightedLineStyle"); _relaxCueImage = (BitmapImage)FindResource("RelaxCueImage"); _liftCueImage = (BitmapImage)FindResource("LiftCueImage"); }
protected AbstractSpellerWindow(Session session, SpellerController spellerController) { // ReSharper disable once LocalizableElement Text = "Speller"; SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); Load += Window_OnLoaded; KeyUp += Window_OnKeyUp; Resize += Window_OnResize; Session = session; SpellerController = spellerController; Paradigm = (SpellerParadigm)session.Paradigm; Markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); LayoutSize = Paradigm.Config.Test.Layout.GetLayoutSize(Paradigm.Config.Gui.ColumnsOverridden); var maxButtonNum = LayoutSize[0] * LayoutSize[1]; Buttons = new UIButton[maxButtonNum]; var index = 0; var scaleFactor = (float)GraphicsUtils.Scale; foreach (var key in Paradigm.Config.Test.Layout.Keys) { if (index > maxButtonNum) { break; } var button = new UIButton(index, index / LayoutSize[1], index % LayoutSize[1], key, (float)Paradigm.Config.Gui.ButtonBorder.Width * scaleFactor, Paradigm.Config.Gui.ButtonFixationPoint.Size * scaleFactor, Paradigm.Config.Gui.ButtonFlashingMargins * (Paradigm.Config.Gui.ButtonFlashingMargins.Relative ? 1 : scaleFactor)) { State = -1 }; var size = Paradigm.Config.Gui.ButtonSize * scaleFactor; button.UpdateGeometries(new RawVector2(), new RawVector2(size, size)); Buttons[index++] = button; } ButtonMatrix = Buttons.Reshape(LayoutSize[0], LayoutSize[1], MatrixOrder.CRowMajor); ButtonCenterMatrix = new RawVector2[LayoutSize[0], LayoutSize[1]]; Char2ButtonDict = new Dictionary <char, UIButton>(); foreach (var button in Buttons) { if (button?.Key?.InputChar != null) { var ch = button.Key.InputChar.Value; if (Char2ButtonDict.ContainsKey(ch)) { throw new Exception($"duplicated char: '{ch}'"); } Char2ButtonDict[button.Key.InputChar.Value] = button; } } StageProgram = Paradigm.CreateStagedProgram(session, spellerController); StageProgram.StageChanged += (sender, e) => { if (e.IsEndReached) { this.ControlInvoke(self => Stop()); } else { OnNextStage(e); } }; GazePointHandler = new GazePointHandler(); if (session.StreamerCollection.TryFindFirst <GazePointStreamer>(out var gazePointStreamer)) { gazePointStreamer.AttachConsumer(GazePointHandler); // if (_paradigm.Config.Test.TrialCancellable) TODO: blink to cancel if (gazePointStreamer.EyeTracker.GetType() != typeof(CursorTracker)) { this.HideCursorInside(); } } else { throw new StateException("gaze point streamer not found for GazePointController"); } if (Paradigm.Config.Test.DynamicInterval) { if (Paradigm.Config.Test.ActivationMode == SpellerActivationMode.Single) { TrialTrigger = new ButtonInsideTrialTrigger(session.Clock, SpellerController, GazePointHandler, Paradigm.Config.Test, FindButtonAt); } else { TrialTrigger = new DwellTrialTrigger(session.Clock, SpellerController, GazePointHandler, Paradigm.Config.Test); } } HintText = Paradigm.Config.Test.HintText; /* Type conversion */ BackgroundColor = Paradigm.Config.Gui.BackgroundColor.ToSdColor().ToSdx(); ForegroundColor = Paradigm.Config.Gui.ForegroundColor.ToSdColor().ToSdx(); CorrectTextColor = Paradigm.Config.Gui.CorrectTextColor.ToSdColor().ToSdx(); WrongTextColor = Paradigm.Config.Gui.WrongTextColor.ToSdColor().ToSdx(); ButtonBorderColor = Paradigm.Config.Gui.ButtonBorder.Color.ToSdColor().ToSdx(); ButtonNormalColor = Paradigm.Config.Gui.ButtonNormalColor.ToSdColor().ToSdx(); ButtonFlashingColor = Paradigm.Config.Gui.ButtonFlashingColor.ToSdColor().ToSdx(); ButtonHintColor = Paradigm.Config.Gui.ButtonHintColor.ToSdColor().ToSdx(); ButtonFixationPointColor = Paradigm.Config.Gui.ButtonFixationPoint.Color.ToSdColor().ToSdx(); }
public SsvepExperimentWindow(Session session) { // ReSharper disable once LocalizableElement Text = "SSVEP"; SuspendLayout(); ControlBox = false; IsFullscreen = true; DoubleBuffered = false; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; ResumeLayout(true); Load += Window_OnLoaded; KeyUp += Window_OnKeyUp; this.HideCursorInside(); _session = session; _paradigm = (SsvepParadigm)session.Paradigm; _trialStartEvent = _paradigm.Config.Test.PressKeyToStartBlock.HasValue ? new AutoResetEvent(false) : null; _markable = session.StreamerCollection.FindFirstOrDefault <IMarkable>(); _stageProgram = _paradigm.CreateStagedProgram(session, _trialStartEvent); _stageProgram.StageChanged += StageProgram_StageChanged; _blocks = new Block[(int)_paradigm.Config.Gui.BlockLayout.Volume]; for (var i = 0; i < _blocks.Length; i++) { var block = _blocks[i] = new Block(); block.Size = new RawVector2(_paradigm.Config.Gui.BlockSize.Width, _paradigm.Config.Gui.BlockSize.Height); block.Pattern = _paradigm.Config.Test.Patterns[i]; block.Text = _paradigm.Config.Gui.GetBlockText(i); } /* Type conversion */ _backgroundColor = _paradigm.Config.Gui.BackgroundColor.ToSdColor().ToSdx(); _fontColor = _paradigm.Config.Gui.BackgroundColor.ToSdColor().Inverted().ToSdx(); _blockBorderColor = _paradigm.Config.Gui.BlockBorder.Color.ToSdColor().ToSdx(); _blockNormalColor = _paradigm.Config.Gui.BlockColors[0].ToSdColor().ToSdx(); _blockFlashingColor = _paradigm.Config.Gui.BlockColors[1].ToSdColor().ToSdx(); _blockFontColor = _paradigm.Config.Gui.BlockFontColor.ToSdColor().ToSdx(); _blockFixationPointColor = _paradigm.Config.Gui.BlockFixationPoint.Color.ToSdColor().ToSdx(); /* Initialize presenter */ switch (_paradigm.Config.Test.StimulationType) { case SsvepStimulationType.Square01: _presenter = new Square01StimulationPresenter(_blockNormalColor, _blockFlashingColor); break; case SsvepStimulationType.SineGradient: _presenter = new SineGradientStimulationPresenter(_blockNormalColor, _blockFlashingColor); break; case SsvepStimulationType.SquareCheckerboard: _presenter = new SquareCheckerboardStimulationPresenter(_blockNormalColor, _blockFlashingColor); break; case SsvepStimulationType.SquareCheckerboardRadical: _presenter = new SquareCheckerboardRadicalStimulationPresenter(_blockNormalColor, _blockFlashingColor); break; default: throw new NotSupportedException(_paradigm.Config.Test.StimulationType.ToString()); } }