Пример #1
0
 /// <summary>
 /// Initializes a new instance of the AudioFile class.
 /// Clone Constructor. Creates new <see cref="AudioFile"/> that is
 /// identical to the given <see cref="AudioFile"/>.
 /// </summary>
 /// <param name="audioFileToClone">The <see cref="AudioFile"/> to clone.</param>
 private AudioFile(AudioFile audioFileToClone)
 {
   this.Filename = audioFileToClone.Filename;
   this.Filepath = audioFileToClone.Filepath;
   this.Loop = audioFileToClone.Loop;
   this.ShouldPlay = audioFileToClone.ShouldPlay;
   this.ShowOnClick = audioFileToClone.ShowOnClick;
 }
    ///////////////////////////////////////////////////////////////////////////////
    // 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;
    }
Пример #3
0
 /// <summary>
 /// Constructor. Initializes fields.
 /// </summary>
 /// <param name="newAudioFile">New <see cref="AudioFile"/> that should be used.</param>
 public AudioPropertiesChangedEventArgs(AudioFile newAudioFile)
 {
   _audioFile = newAudioFile;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the VGElement class.
 /// </summary>
 /// <param name="newShapeDrawAction">Drawing action: Edge, Fill, Both</param>
 /// <param name="newPen">Pen for edges</param>
 /// <param name="newBrush">Brush for text and fills</param>
 /// <param name="newFont">Font for text</param>
 /// <param name="newFontColor">Color for text</param>
 /// <param name="newBounds">Bounds of element</param>
 /// <param name="newStyleGroup">Group Enumeration, <see cref="VGStyleGroup"/></param>
 /// <param name="newName">Name of Element</param>
 /// <param name="newElementGroup">Element group description</param>
 /// <param name="newSound">The <see cref="AudioFile"/> to play with this element.</param>
 public VGElement(
   ShapeDrawAction newShapeDrawAction,
   Pen newPen,
   Brush newBrush,
   Font newFont,
   Color newFontColor,
   RectangleF newBounds,
   VGStyleGroup newStyleGroup,
   string newName,
   string newElementGroup,
   AudioFile newSound)
 {
   this.InitStandards();
   this.pen = newPen == null ? null : (Pen)newPen.Clone();
   this.Brush = newBrush == null ? null : (Brush)newBrush.Clone();
   this.Bounds = newBounds;
   this.styleGroup = newStyleGroup;
   this.name = newName;
   this.elementGroup = newElementGroup;
   this.Font = newFont == null ? null : (Font)newFont.Clone();
   this.FontColor = newFontColor;
   this.shapeDrawAction = newShapeDrawAction;
   if (newSound != null)
   {
     this.Sound = (AudioFile)newSound.Clone();
   }
 }
Пример #5
0
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the VGText class.
    /// </summary>
    /// <param name="newShapeDrawAction">Drawing action: Edge, Fill, Both</param>
    /// <param name="newText">string to display</param>
    /// <param name="newFont">Font to use for the text</param>
    /// <param name="newFontColor">Color for the text</param>
    /// <param name="newAlignment">The <see cref="HorizontalAlignment"/> for the text.</param>
    /// <param name="newLineSpacing">The <see cref="float"/> with the new line spacing for the text.</param>
    /// <param name="newPadding">The <see cref="float"/> with the new text padding.</param>
    /// <param name="newPen">Pen for bounds</param>
    /// <param name="newBrush">Brush for fills</param>
    /// <param name="newNameFont">Font for name</param>
    /// <param name="newNameFontColor">Color for name</param>
    /// <param name="newBounds">Bounds of element</param>
    /// <param name="newStyleGroup">Group Enumeration, <see cref="VGStyleGroup"/></param>
    /// <param name="newName">Name of Element</param>
    /// <param name="newElementGroup">Element group description</param>
    /// <param name="newSound">Audio contents of Element</param>
    public VGText(
      ShapeDrawAction newShapeDrawAction,
      string newText,
      Font newFont,
      Color newFontColor,
      HorizontalAlignment newAlignment,
      float newLineSpacing,
      float newPadding,
      Pen newPen,
      Brush newBrush,
      Font newNameFont,
      Color newNameFontColor,
      RectangleF newBounds,
      VGStyleGroup newStyleGroup,
      string newName,
      string newElementGroup,
      AudioFile newSound)
      : base(
      newShapeDrawAction,
      newPen,
      newBrush,
      newNameFont,
      newNameFontColor,
      newBounds,
      newStyleGroup,
      newName,
      newElementGroup,
      newSound)
    {
      this.textFontColor = newFontColor;
      this.textAlignment = newAlignment;
      this.text = newText;
      this.textFont = newFont;
      this.LineSpacing = newLineSpacing != 0 ? newLineSpacing : 1.0f;
      this.Padding = newPadding;
    }
Пример #6
0
 /// <summary>
 /// <see cref="CheckBox.CheckedChanged"/> event handler for the
 /// <see cref="CheckBox"/> <see cref="chbPlaySound"/>.
 /// Raises the <see cref="AudioPropertiesChanged"/> event.
 /// </summary>
 /// <param name="sender">Source of the event.</param>
 /// <param name="e">An empty <see cref="EventArgs"/></param>
 private void chbPlaySound_CheckedChanged(object sender, EventArgs e)
 {
   if (this.audioFile == null)
   {
     this.audioFile = new AudioFile();
   }
   this.audioFile.ShouldPlay = chbPlaySound.Checked;
   chbLoop.Enabled = chbPlaySound.Checked;
   rdbOnAppearance.Enabled = chbPlaySound.Checked;
   rdbOnClick.Enabled = chbPlaySound.Checked;
   btnPreviewPlay.Enabled = chbPlaySound.Checked;
   btnPreviewStop.Enabled = chbPlaySound.Checked;
   this.RaiseEvent();
 }
Пример #7
0
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Constructor.
    /// </summary>
    public AudioControl()
    {
      InitializeComponent();
      this.pathToCopyTo = "";
      this.audioFile = new AudioFile();
      this.audioFile.Loop = false;
      this.audioFile.ShouldPlay = true;
      this.audioFile.ShowOnClick = false;
      this.player = new AudioPlayer();
    }