Contains options for playing a sound.
Esempio n. 1
0
        public EvaluatorStream(int BufferSize, Evaluator Evaluator, SoundOptions Options, bool Exporting)
        {
            this._Exporting = Exporting;
            this._Options = Options;
            this._Evaluator = Evaluator.GetBuffered(BufferSize);
            this._Offset = BufferSize;
            this._Parameter = Options.Offset;

            // Calculate shift and sample size
            int res = Options.Resolution;
            int sampsize = (res + 7) / 8;
            int shift = sampsize * 8 - res;
            this._SampleSize = sampsize;
            this._Shift = shift;

            this._Advance();
        }
Esempio n. 2
0
 /// <summary>
 /// Plays the given expression with the given options.
 /// </summary>
 private void _Play(Expression Expression, SoundOptions Options)
 {
     this._Sound.Stop(); // Just to make sure.
     if (this._Sound.Play(new EvaluatorStream(4096, Expression, Options, false)))
     {
         this._Update = false;
         this._PlayStop.Text = _StopText;
     }
     else
     {
         MessageBox.Show("Could not create sound output, check values of \"#rate\" and \"#resolution\".", MessageBoxCaption, MessageBoxButtons.OK);
         this._PlayStop.Text = _PlayText;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Tries parsing the selected contents of this form, displaying the appropriate messages on failure.
 /// </summary>
 private bool _ParseSelected(out Expression Expression, out SoundOptions Options)
 {
     Expression = null;
     Options = null;
     int targetindex = this._Text.SelectionStart;
     int targetlength = this._Text.SelectionLength;
     int errorindex = targetindex;
     if (targetlength > 0 && Parser.Parse(this._Text.Text, targetindex, targetlength, out Expression, out Options, out errorindex))
     {
         return true;
     }
     else
     {
         this._Text.Select(errorindex, 0);
         return false;
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Tries parsing the contents of this form, displaying the appropriate messages on failure.
 /// </summary>
 private bool _Parse(out Expression Expression, out SoundOptions Options)
 {
     int errorindex;
     if (Parser.Parse(this._Text.Text, out Expression, out Options, out errorindex))
     {
         if (Expression != null)
         {
             return true;
         }
         else
         {
             MessageBox.Show("The result variable \"" + Parser.Result + "\" must be defined", MessageBoxCaption, MessageBoxButtons.OK);
             return false;
         }
     }
     else
     {
         this._Text.Select(errorindex, 0);
         return false;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Parses the given text (or as much as possible of it) and returns the expression for the specified target string, or false with an error index.
 /// </summary>
 public static bool Parse(string Text, int TargetIndex, int TargetLength, out Expression Expression, out SoundOptions Options, out int ErrorIndex)
 {
     Expression = null;
     Options = new SoundOptions();
     Dictionary<string, Expression> variables = null;
     int index = 0;
     AcceptProgram(Text, ref index, ref variables, ref Options, out ErrorIndex);
     if (index >= TargetIndex)
     {
         index = 0;
         string target = Text.Substring(TargetIndex, TargetLength);
         AcceptExtendedWhitespace(target, ref index);
         if (AcceptExpression(variables, target, ref index, ref Expression, out ErrorIndex))
         {
             AcceptExtendedWhitespace(target, ref index);
             if (index == TargetLength)
             {
                 return true;
             }
         }
         ErrorIndex += TargetIndex;
         return false;
     }
     return false;
 }
Esempio n. 6
0
 /// <summary>
 /// Parses the given text and either returns true with an expression and sound options, or false with an error index.
 /// </summary>
 public static bool Parse(string Text, out Expression Expression, out SoundOptions Options, out int ErrorIndex)
 {
     Expression = null;
     Options = new SoundOptions();
     Dictionary<string, Expression> variables = null;
     int index = 0;
     AcceptProgram(Text, ref index, ref variables, ref Options, out ErrorIndex);
     if (index == Text.Length)
     {
         variables.TryGetValue(Result, out Expression);
         return true;
     }
     return false;
 }
Esempio n. 7
0
        /// <summary>
        /// Parses a program in the given text.
        /// </summary>
        public static void AcceptProgram(string Text, ref int Index, ref Dictionary<string, Expression> Variables, ref SoundOptions Options, out int ErrorIndex)
        {
            Variables = new Dictionary<string, Expression>();
            Variables[Parameter] = IdentityExpression.Instance;
            Variables[Resolution] = ResolutionExpression.Instance;

            while (true)
            {
                AcceptExtendedWhitespace(Text, ref Index);

                if (AcceptOption(Text, ref Index, Options, out ErrorIndex))
                {
                    continue;
                }

                string varname = null;
                Expression varvalue = null;
                if (AcceptAssignment(Variables, Text, ref Index, ref varname, ref varvalue, out ErrorIndex))
                {
                    Variables[varname] = varvalue;
                    continue;
                }

                break;
            }

            AcceptExtendedWhitespace(Text, ref Index);
        }
Esempio n. 8
0
 /// <summary>
 /// Tries parsing an option and applying it to the given sound options structure.
 /// </summary>
 public static bool AcceptOption(string Text, ref int Index, SoundOptions Options, out int ErrorIndex)
 {
     string optname = null;
     int optvalue = 0;
     if (AcceptOption(Text, ref Index, ref optname, ref optvalue, out ErrorIndex))
     {
         switch (optname)
         {
             case "rate":
                 Options.Rate = optvalue;
                 break;
             case "offset":
                 Options.Offset = optvalue;
                 break;
             case "length":
                 Options.Length = optvalue;
                 break;
             case "resolution":
                 Options.Resolution = optvalue;
                 break;
             default:
                 break;
         }
         return true;
     }
     return false;
 }
Esempio n. 9
0
 public EvaluatorStream(int BufferSize, Expression Expression, SoundOptions Options, bool Exporting)
     : this(BufferSize, Expression.GetEvaluator(new Dictionary<Expression,Evaluator>(), BufferSize, Options.Resolution), Options, Exporting)
 {
 }