diff --git a/Release/Microsoft.Xna.Framework.Content.Pipeline.VideoImporters.dll b/Release/Microsoft.Xna.Framework.Content.Pipeline.VideoImporters.dll new file mode 100644 index 0000000..0b31c12 Binary files /dev/null and b/Release/Microsoft.Xna.Framework.Content.Pipeline.VideoImporters.dll differ diff --git a/Release/RF_Center_1.fsx b/Release/RF_Center_1.fsx new file mode 100644 index 0000000..2429088 --- /dev/null +++ b/Release/RF_Center_1.fsx @@ -0,0 +1,132 @@ +// F# Script File : RF_Center_1.fsx +// +// Mapping Receptive Field Center Location Use Drift Grating(one marker) +// +// Copyright (c) 2009-06-13 Zhang Li + +#r @"StiLib.dll" +#r @"Microsoft.Xna.Framework.dll" + +open System +open System.Windows.Forms +open Microsoft.Xna.Framework +open Microsoft.Xna.Framework.Graphics +open StiLib.Core +open StiLib.Vision + +// Our Custom Experiment is inherited from StiLib.Core.SLForm +type MyEx = class + inherit SLForm + + val mutable text: Text + val mutable ex: SLExperiment + val mutable grating: Grating + val mutable step: float32 + + new() as this = + { inherit SLForm(800, 600, 0, true, true); grating = null; text = null; ex = null; step = 0.0f } + then + this.text <- new Text(this.GraphicsDevice, this.Services, this.SLConfig.["content"], "Thames") + this.ex <- new SLExperiment() + this.ex.AddExType(ExType.RF) + + this.ex.Expara.trial <- 15 + this.ex.Expara.durT <- 0.05f + this.ex.Expara.bgcolor <- Color.Gray + + let mutable gpara = GratingPara.Default + gpara.tf <- 0.0f + gpara.sf <- 0.8f + gpara.sphase <- 0.0f + gpara.BasePara.diameter <- 2.0f + gpara.BasePara.movearea <- 4.0f + gpara.direction <- 45.0f + gpara.BasePara.center <- new Vector3(0.0f, 0.0f, 0.0f) + this.grating <- new Grating(this.GraphicsDevice, this.Services, this.SLConfig.["content"], gpara) + + this.step <- 0.3f + this.InitGrid() + + member this.InitGrid() = + let mutable row = int( Math.Floor(float( this.grating.Para.BasePara.movearea / this.step )) ) + if row % 2 = 0 then + row <- row + 1 + this.ex.AddCondition(ExPara.Location, row) + + override this.SetFlow() = + this.ex.Flow.TCount <- 0 + this.ex.Flow.SCount <- 0 + this.ex.Flow.IsPred <- false + + override this.MarkHead() = + this.DrawTip(ref this.text, this.ex.Expara.bgcolor, SLConstant.MarkHead) + + this.ex.Expara.stimuli.[0] <- this.ex.Cond.[0].VALUE.ValueN * this.ex.Cond.[0].VALUE.ValueN + this.ex.Rand.RandomizeSeed() + this.ex.Rand.RandomizeSequence(this.ex.Expara.stimuli.[0]) + + this.ex.PPort.MarkerEncode(this.ex.Extype.[0].Value) + this.ex.PPort.MarkerEncode(this.ex.Cond.[0].SKEY) + this.ex.PPort.MarkerEncode(this.ex.Cond.[0].VALUE.ValueN) + this.ex.PPort.MarkerEncode(this.ex.Rand.RSeed) + this.ex.PPort.MarkerEncode(this.ex.Expara.trial) + + this.ex.PPort.MarkerSeparatorEncode() + + this.grating.Para.Encode(this.ex.PPort) + this.ex.PPort.MarkerEncode(int( Math.Floor(float(this.step) * 100.0) )) + + this.ex.PPort.MarkerEndEncode() + this.ex.Flow.IsStiOn <- true + + override this.Update() = + if this.GO_OVER = true then + this.Update_fGrating() + override this.Draw() = + this.GraphicsDevice.Clear(this.ex.Expara.bgcolor) + if this.GO_OVER = true then + this.grating.Draw(this.GraphicsDevice) + this.ex.Flow.Info <- this.ex.Flow.TCount.ToString() + " / " + this.ex.Expara.trial.ToString() + " Trials\n" + + this.ex.Flow.SCount.ToString() + " / " + this.ex.Expara.stimuli.[0].ToString() + " Stimuli" + this.text.Draw(this.ex.Flow.Info) + else + this.text.Draw() + member this.Update_fGrating() = + if this.ex.Flow.IsStiOn = true then + this.ex.Flow.IsStiOn <- false + this.ex.PPort.timer.ReStart() + do this.ex.PPort.Trigger() + if this.ex.PPort.timer.ElapsedSeconds < float this.ex.Expara.durT + 0.001 then + if this.ex.Flow.IsPred = false then + this.ex.Flow.IsPred <- true + + let RCount = Math.Floor(float (this.ex.Rand.RSequence.[this.ex.Flow.SCount] / this.ex.Cond.[0].VALUE.ValueN)) + let CCount = this.ex.Rand.RSequence.[this.ex.Flow.SCount] % this.ex.Cond.[0].VALUE.ValueN + + let Xgrid = -float32(this.ex.Cond.[0].VALUE.ValueN - 1) * this.step / 2.0f + this.step * float32(CCount) + let Ygrid = float32(this.ex.Cond.[0].VALUE.ValueN - 1) * this.step / 2.0f - this.step * float32(RCount) + this.ex.Flow.Rotate <- Matrix.CreateRotationZ(this.grating.Para.direction * float32 SLConstant.RadpDeg) + this.ex.Flow.Translate <- Matrix.CreateTranslation(Xgrid, Ygrid, 0.0f) * this.ex.Flow.Rotate * Matrix.CreateTranslation(this.grating.Para.BasePara.center) + this.grating.SetWorld(this.ex.Flow.Translate) + + this.grating.SetTime(float32 this.ex.PPort.timer.ElapsedSeconds) + else + if this.ex.Flow.SCount - this.ex.Expara.stimuli.[0] < -1 then + this.ex.Flow.IsStiOn <- true + this.ex.Flow.IsPred <- false + this.ex.Flow.SCount <- this.ex.Flow.SCount + 1 + else + if this.ex.Flow.TCount - this.ex.Expara.trial < -1 then + this.ex.Rand.RandomizeSequence(this.ex.Expara.stimuli.[0]) + this.ex.Flow.IsStiOn <- true + this.ex.Flow.IsPred <- false + this.ex.Flow.TCount <- this.ex.Flow.TCount + 1 + this.ex.Flow.SCount <- 0 + else + this.GO_OVER <- false + this.Update() + +end + +let MyExperiment = new MyEx(Text = "F# Scripting RF_Center_1") +Application.Run(MyExperiment) \ No newline at end of file diff --git a/Release/RF_Center_2.fsx b/Release/RF_Center_2.fsx new file mode 100644 index 0000000..d71b805 --- /dev/null +++ b/Release/RF_Center_2.fsx @@ -0,0 +1,143 @@ +// F# Script File : RF_Center_2.fsx +// +// Mapping Receptive Field Center Location Use Drift Grating(two marker) +// +// Copyright (c) 2009-06-13 Zhang Li + +#r @"StiLib.dll" +#r @"Microsoft.Xna.Framework.dll" + +open System +open System.Windows.Forms +open Microsoft.Xna.Framework +open Microsoft.Xna.Framework.Graphics +open StiLib.Core +open StiLib.Vision + +// Our Custom Experiment is inherited from StiLib.Core.SLForm +type MyEx = class + inherit SLForm + + val mutable text: Text + val mutable ex: SLExperiment + val mutable grating: Grating + val mutable step: float32 + + new() as this = + { inherit SLForm(800, 600, 0, true, true); grating = null; text = null; ex = null; step = 0.0f } + then + this.text <- new Text(this.GraphicsDevice, this.Services, this.SLConfig.["content"], "Thames") + this.ex <- new SLExperiment() + this.ex.AddExType(ExType.RF) + + this.ex.Expara.trial <- 15 + this.ex.Expara.srestT <- 0.25f + this.ex.Expara.trestT <- 0.25f + this.ex.Expara.durT <- 0.5f + this.ex.Expara.bgcolor <- Color.Black + + let mutable gpara = GratingPara.Default + gpara.tf <- 4.0f + gpara.sf <- 0.8f + gpara.sphase <- 0.0f + gpara.BasePara.diameter <- 2.0f + gpara.BasePara.movearea <- 5.0f + gpara.direction <- 90.0f + gpara.BasePara.center <- new Vector3(0.0f, 0.0f, 0.0f) + this.grating <- new Grating(this.GraphicsDevice, this.Services, this.SLConfig.["content"], gpara) + + this.step <- 0.25f + this.InitGrid() + + member this.InitGrid() = + let mutable row = int( Math.Floor(float( this.grating.Para.BasePara.movearea / this.step )) ) + if row % 2 = 0 then + row <- row + 1 + this.ex.AddCondition(ExPara.Location, row) + + override this.SetFlow() = + this.ex.Flow.TCount <- 0 + this.ex.Flow.SCount <- 0 + this.ex.Flow.IsPred <- false + this.ex.Flow.IsRested <- false + + override this.MarkHead() = + this.DrawTip(ref this.text, this.ex.Expara.bgcolor, SLConstant.MarkHead) + + this.ex.Expara.stimuli.[0] <- this.ex.Cond.[0].VALUE.ValueN * this.ex.Cond.[0].VALUE.ValueN + this.ex.Rand.RandomizeSeed() + this.ex.Rand.RandomizeSequence(this.ex.Expara.stimuli.[0]) + + this.ex.PPort.MarkerEncode(this.ex.Extype.[0].Value) + this.ex.PPort.MarkerEncode(this.ex.Cond.[0].SKEY) + this.ex.PPort.MarkerEncode(this.ex.Cond.[0].VALUE.ValueN) + this.ex.PPort.MarkerEncode(this.ex.Rand.RSeed) + this.ex.PPort.MarkerEncode(this.ex.Expara.trial) + + this.ex.PPort.MarkerSeparatorEncode() + + this.grating.Para.Encode(this.ex.PPort) + this.ex.PPort.MarkerEncode(int( Math.Floor(float(this.step) * 100.0) )) + + this.ex.PPort.MarkerEndEncode() + this.ex.Flow.IsStiOn <- true + + override this.Update() = + if this.GO_OVER = true then + this.Update_fGrating() + override this.Draw() = + this.GraphicsDevice.Clear(this.ex.Expara.bgcolor) + if this.GO_OVER = true then + this.grating.Draw(this.GraphicsDevice) + this.ex.Flow.Info <- this.ex.Flow.TCount.ToString() + " / " + this.ex.Expara.trial.ToString() + " Trials\n" + + this.ex.Flow.SCount.ToString() + " / " + this.ex.Expara.stimuli.[0].ToString() + " Stimuli" + this.text.Draw(this.ex.Flow.Info) + else + this.text.Draw() + member this.Update_fGrating() = + if this.ex.Flow.IsStiOn = true then + this.ex.Flow.IsStiOn <- false + this.ex.PPort.timer.ReStart() + do this.ex.PPort.Trigger() + if this.ex.PPort.timer.ElapsedSeconds < float this.ex.Expara.durT then + if this.ex.Flow.IsPred = false then + this.ex.Flow.IsPred <- true + + let RCount = Math.Floor(float (this.ex.Rand.RSequence.[this.ex.Flow.SCount] / this.ex.Cond.[0].VALUE.ValueN)) + let CCount = this.ex.Rand.RSequence.[this.ex.Flow.SCount] % this.ex.Cond.[0].VALUE.ValueN + + let Xgrid = -float32(this.ex.Cond.[0].VALUE.ValueN - 1) * this.step / 2.0f + this.step * float32(CCount) + let Ygrid = float32(this.ex.Cond.[0].VALUE.ValueN - 1) * this.step / 2.0f - this.step * float32(RCount) + this.ex.Flow.Rotate <- Matrix.CreateRotationZ(this.grating.Para.direction * float32 SLConstant.RadpDeg) + this.ex.Flow.Translate <- Matrix.CreateTranslation(Xgrid, Ygrid, 0.0f) * this.ex.Flow.Rotate * Matrix.CreateTranslation(this.grating.Para.BasePara.center) + this.grating.SetWorld(this.ex.Flow.Translate) + this.grating.SetVisible(true) + + this.grating.SetTime(float32 this.ex.PPort.timer.ElapsedSeconds) + else + if this.ex.Flow.IsRested = false then + do this.ex.PPort.Trigger() + this.ex.Flow.IsRested <- true + this.grating.SetVisible(false) + if this.ex.Flow.SCount - this.ex.Expara.stimuli.[0] < -1 then + if this.ex.PPort.timer.ElapsedSeconds > float this.ex.Expara.durT + float this.ex.Expara.srestT then + this.ex.Flow.IsStiOn <- true + this.ex.Flow.IsPred <- false + this.ex.Flow.IsRested <- false + this.ex.Flow.SCount <- this.ex.Flow.SCount + 1 + else + if this.ex.Flow.TCount - this.ex.Expara.trial < -1 then + if this.ex.PPort.timer.ElapsedSeconds > float this.ex.Expara.durT + float this.ex.Expara.trestT then + this.ex.Rand.RandomizeSequence(this.ex.Expara.stimuli.[0]) + this.ex.Flow.IsStiOn <- true + this.ex.Flow.IsPred <- false + this.ex.Flow.IsRested <- false + this.ex.Flow.TCount <- this.ex.Flow.TCount + 1 + this.ex.Flow.SCount <- 0 + else + this.GO_OVER <- false + +end + +let MyExperiment = new MyEx(Text = "F# Scripting RF_Center_2") +Application.Run(MyExperiment) \ No newline at end of file diff --git a/StiLib/StiLib/Vision/SLVideo.cs b/StiLib/StiLib/Vision/SLVideo.cs new file mode 100644 index 0000000..8eb46ba --- /dev/null +++ b/StiLib/StiLib/Vision/SLVideo.cs @@ -0,0 +1,254 @@ +#region File Description +//----------------------------------------------------------------------------- +// SLVideo.cs +// +// StiLib Video +// Copyright (c) Zhang Li. 2009-06-19. +//----------------------------------------------------------------------------- +#endregion + +#region Using Statements +using System; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Media; +using System.Windows.Forms; +#endregion + +namespace StiLib.Vision +{ + /// + /// StiLib Video + /// + public class SLVideo : VisionStimulus + { + /// + /// Sprite Batch + /// + public SpriteBatch SpriteBatch; + /// + /// Basic Parameters + /// + public BasePara BasePara; + /// + /// Content Manager + /// + public ContentManager ContentManager; + /// + /// Video Texture + /// + public Texture2D Texture; + Video video; + VideoPlayer vplayer; + /// + /// Get the Video Player + /// + public VideoPlayer Player + { + get { return vplayer; } + } + + + /// + /// Set Video parameters to default, + /// before LoadContent() and Init() + /// + public SLVideo() + { + BasePara = BasePara.Default; + } + + /// + /// Init to default + /// + /// + /// + /// + /// + public SLVideo(GraphicsDevice gd, IServiceProvider service, string path, string videoname) + : this() + { + LoadContent(service, path, videoname); + Init(gd); + } + + /// + /// Init to custom base parameters + /// + /// + /// + /// + /// + /// + public SLVideo(GraphicsDevice gd, IServiceProvider service, string path, string videoname, BasePara bpara) + : base(gd) + { + LoadContent(service, path, videoname); + Init(gd, bpara); + } + + + /// + /// Load Compiled Video.xnb File using Content Manager + /// + /// + /// + /// + public void LoadContent(IServiceProvider service, string path, string videoname) + { + ContentManager = new ContentManager(service, path); + try + { + video = ContentManager.Load