Ejemplo n.º 1
0
        /// <summary>
        ///     Changes the file that is being read, setting up the new reader
        /// </summary>
        /// <param name="newFile"></param>
        private void ChangeFile(string newFile)
        {
            ErrorStrings.Clear();

            // Dispose of the old reader as needed
            try
            {
                if (Reader != null)
                {
                    Reader.Dispose();
                }
            } catch { }
            Reader = null;

            // Create the new reader
            try
            {
                Reader = File.OpenText(newFile);
            }
            catch (Exception ex)
            {
                ErrorStrings.Add(ex.Message);
            }

            InvokeOnErrorStringsChanged();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Checks to see if this is functional
        /// </summary>
        /// <returns>True if the state is valid, False if not</returns>
        public override bool Validate()
        {
            ErrorStrings.Clear();
            if (Sampler != null)
            {
                return(true);
            }

            ErrorStrings.Add($"Select a valid audio file");
            InvokeOnErrorStringsChanged();
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Changes the file that is being read, setting up the new reader
        /// </summary>
        /// <param name="newFile"></param>
        private void ChangeFile(string newFile)
        {
            ErrorStrings.Clear();

            // Don't accept empty strings
            if (string.IsNullOrEmpty(newFile))
            {
                ErrorStrings.Add("Select a file to write to");
            }

            InvokeOnErrorStringsChanged();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Checks to see if this is functional
        /// </summary>
        /// <returns>True if the state is valid, False if not</returns>
        public override bool Validate()
        {
            ErrorStrings.Clear();
            if (!string.IsNullOrEmpty(Filename))
            {
                return(true);
            }

            ErrorStrings.Add($"Select a file to write to");
            InvokeOnErrorStringsChanged();
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Changes the file that is being read, setting up the new reader
        /// </summary>
        /// <param name="newFile"></param>
        private void ChangeFile(string newFile)
        {
            ErrorStrings.Clear();

            // Dispose of the old reader as needed
            try
            {
                if (Reader != null)
                {
                    Reader.Dispose();
                }
            } catch { }
            Reader  = null;
            Sampler = null;

            // Create the new reader
            var extension = Path.GetExtension(newFile).ToLower();

            switch (extension)
            {
            case ".wav":
                try
                {
                    Reader  = new WaveFileReader(newFile);
                    Sampler = Reader.ToSampleProvider();
                }
                catch (Exception ex)
                {
                    ErrorStrings.Add(ex.Message);
                }
                break;

            default:     // Unknown format
                ErrorStrings.Add($"The audio format {extension} is not supported.");
                break;
            }

            InvokeOnErrorStringsChanged();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Compiles this object for actual use
        /// </summary>
        public override void Compile()
        {
            NeedsCompile = false;
            ErrorStrings.Clear();

            // Create a new port with the user settings
            try
            {
                Port = new SerialPort(PortName, BaudRate, ParityBit, DataBits, StopBit);
                if (!Port.IsOpen)
                {
                    Port.Open();
                }
            }
            catch (Exception ex)
            {
                ErrorStrings.Add(ex.Message);
                Port = null;
            }

            // Update if this still needs compiled or not
            NeedsCompile = (Port == null || !Port.IsOpen);
        }