예제 #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();
        }
예제 #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);
        }
예제 #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();
        }
예제 #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);
        }
예제 #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();
        }
예제 #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);
        }