/// <summary> /// Initializes a new instance of the VGSound class. /// Clone Constructor. Creates new sound that is /// identical to the given <see cref="VGSound"/> /// </summary> /// <param name="sound">AudioFile to clone</param> private VGSound(VGSound sound) : base( sound.ShapeDrawAction, sound.Pen, sound.Brush, sound.Font, sound.FontColor, sound.Bounds, sound.StyleGroup, sound.Name, sound.ElementGroup, sound.Sound) { }
/////////////////////////////////////////////////////////////////////////////// // Eventhandler for Custom Defined Events // /////////////////////////////////////////////////////////////////////////////// #region CUSTOMEVENTHANDLER #endregion //CUSTOMEVENTHANDLER #endregion //EVENTS /////////////////////////////////////////////////////////////////////////////// // Methods and Eventhandling for Background tasks // /////////////////////////////////////////////////////////////////////////////// #region BACKGROUNDWORKER #endregion //BACKGROUNDWORKER /////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// This method does the parsing of the given path and creates for each readable /// image or media file a trial with the defined conditions. /// </summary> /// <returns>A <see cref="List{Slide}"/> to be imported in the slideshow of /// the experiment.</returns> private List<Slide> GetSlides() { var newSlides = new List<Slide>(); var dirInfoStimuli = new DirectoryInfo(this.txbFolder.Text); if (dirInfoStimuli.Exists) { var files = dirInfoStimuli.GetFiles(); Array.Sort(files, new NumericComparer()); foreach (var file in files) { var extension = file.Extension.ToLower(); // Ignore files with unrecognized extensions switch (extension) { case ".bmp": case ".png": case ".jpg": case ".wmf": case ".mp3": case ".wav": case ".wma": break; default: continue; } // Ignore hidden and MAC files if (file.Name.StartsWith(".")) { continue; } var newSlide = new Slide { BackgroundColor = this.clbBackground.CurrentColor, Modified = true, MouseCursorVisible = this.chbShowMouseCursor.Checked, MouseInitialPosition = this.psbMouseCursor.CurrentPosition, Name = Path.GetFileNameWithoutExtension(file.Name), PresentationSize = Document.ActiveDocument.PresentationSize }; StopCondition stop = null; if (this.rdbTime.Checked) { stop = new TimeStopCondition((int)(this.nudTime.Value * 1000)); } else if (this.rdbKey.Checked) { string selectedItemKeys = (string)this.cbbKeys.SelectedItem; KeyStopCondition ksc = new KeyStopCondition(); if (selectedItemKeys == "Any") { ksc.CanBeAnyInputOfThisType = true; } else { ksc.StopKey = (Keys)Enum.Parse(typeof(Keys), selectedItemKeys); } stop = ksc; } else if (this.rdbMouse.Checked) { string selectedItemMouse = (string)this.cbbMouseButtons.SelectedItem; MouseStopCondition msc = new MouseStopCondition(); msc.CanBeAnyInputOfThisType = selectedItemMouse == "Any" ? true : false; if (!msc.CanBeAnyInputOfThisType) { msc.StopMouseButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), selectedItemMouse); } msc.Target = string.Empty; stop = msc; } else if (this.rdbDuration.Checked) { if (extension == ".mp3" || extension == ".wav" || extension == ".wma") { int duration = this.GetAudioFileLength(file.FullName); if (duration != 0) { stop = new TimeStopCondition(duration + (int)this.nudLatency.Value); } else { stop = new TimeStopCondition((int)(this.nudTime.Value * 1000)); } } else { stop = new TimeStopCondition((int)(this.nudTime.Value * 1000)); } } newSlide.StopConditions.Add(stop); foreach (VGElement element in this.lsbStandardItems.Items) { newSlide.VGStimuli.Add(element); } string destination = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, file.Name); switch (extension) { case ".bmp": case ".png": case ".jpg": case ".wmf": if (!File.Exists(destination)) { File.Copy(file.FullName, destination, true); } VGImage image = new VGImage( ShapeDrawAction.None, Pens.Red, Brushes.Red, SystemFonts.MenuFont, Color.Red, file.Name, Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, ImageLayout.Stretch, 1f, Document.ActiveDocument.PresentationSize, VGStyleGroup.None, file.Name, string.Empty, true); newSlide.VGStimuli.Add(image); newSlides.Add(newSlide); break; case ".mp3": case ".wav": case ".wma": File.Copy(file.FullName, destination, true); VGSound sound = new VGSound(ShapeDrawAction.None, Pens.Red, new Rectangle(0, 0, 200, 300)); sound.Center = newSlide.MouseInitialPosition; sound.Size = new SizeF(50, 50); AudioFile audioFile = new AudioFile(); audioFile.Filename = file.Name; audioFile.Filepath = Document.ActiveDocument.ExperimentSettings.SlideResourcesPath; audioFile.Loop = false; audioFile.ShouldPlay = true; audioFile.ShowOnClick = false; sound.Sound = audioFile; newSlide.VGStimuli.Add(sound); newSlides.Add(newSlide); break; } } } return newSlides; }