Click here to Skip to main content
15,891,828 members
Articles / Programming Languages / C# 4.0

Grandiose projects 5. Audio support

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
3 Feb 2012CPOL8 min read 23.2K   2K   8  
Audio support for grandiose projects
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.IO;


using CategoryTheory;

using BaseTypes.Interfaces;
using BaseTypes;


using DiagramUI;
using DiagramUI.Labels;

using DataPerformer.Interfaces;

namespace DataPerformer
{
    /// <summary>
    /// Table of three parameters
    /// This table uses linear interpolation
    /// </summary>
    [Serializable()]
    public class Table3D : DataPerformer.Basic.Table3D, ICategoryObject, IDataConsumer, IMeasurements, IObjectOperation,
       IPowered, IPostSetArrow
    {

        #region Fields

        /// <summary>
        /// Change input event
        /// </summary>
        private event Action onChangeInput = () => { };
        
        /// <summary>
        /// Associated object
        /// </summary>
        private object obj;

        /// <summary>
        /// Output measurements
        /// </summary>
        private IMeasure[] output = null;

        /// <summary>
        /// Arguments
        /// </summary>
        private string[] arguments;

        /// <summary>
        /// Input measurements
        /// </summary>
        private IMeasure[] input = new IMeasure[2];

        /// <summary>
        /// The x, y - arguments
        /// </summary>
        private readonly string[] xy = new string[] { "x", "y" };

        /// <summary>
        /// Measurements
        /// </summary>
        private List<IMeasurements> measurements = new List<IMeasurements>();

        /// <summary>
        /// The "is updated" sign
        /// </summary>
        private bool isUpdated;

        /// <summary>
        /// The "has derivation" sign
        /// </summary>
        private bool hasDerivation = true;

        private const double type = 0;

        private readonly object[] types = new object[] { new ArrayReturnType((double)0, new int[] { 2 }, false) };


        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public Table3D()
        {
        }

        /// <summary>
        /// Deserilaization constructor
        /// </summary>
        /// <param name="info">Serialization Info</param>
        /// <param name="context">Streaming Context</param>
        protected Table3D(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            Func<object> fn = () => { return this; };
            output = new IMeasure[]{ new Measure(this, fn, "Function")};
            
            /*arguments = (string[])info.GetValue("Arguments", typeof(string[]));
            Double a = 0;
            output[0] = new MeasureDerivation(a, new Func<object>(GetFunction), new Measure(GetDerivation, "Der_Value"), "Value");
            Func<object> fn = () => { return this; };
            output[1] = new Measure(this, fn, "Function");
            try
            {
                throwsOutOfRangeException =
                    info.GetBoolean("ThrowsOutOfRangeException");
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
            }*/
        }


        #endregion

        #region ICategoryObject Members

        ICategory ICategoryObject.Category
        {
            get { return null; }
        }

        ICategoryArrow ICategoryObject.Id
        {
            get { return null; }
        }

        #endregion

        #region IAssociatedObject Members

        object IAssociatedObject.Object
        {
            get
            {
                return obj;
            }
            set
            {
                obj = value;
            }
        }

        #endregion

        #region IDataConsumer Members

        void IDataConsumer.Add(IMeasurements measurements)
        {
            this.measurements.Add(measurements);
        }

        void IDataConsumer.Remove(IMeasurements measurements)
        {
            this.measurements.Remove(measurements);
        }

        void IDataConsumer.UpdateChildrenData()
        {
            measurements.UpdateChildrenData();
        }

        int IDataConsumer.Count
        {
            get { return measurements.Count; }
        }

        IMeasurements IDataConsumer.this[int n]
        {
            get { return measurements[n]; }
        }

        void IDataConsumer.Reset()
        {
            this.FullReset();
        }

        event Action IDataConsumer.OnChangeInput
        {
            add { onChangeInput += value; }
            remove { onChangeInput -= value; }
        }

        #endregion

        #region IMeasurements Members

        int IMeasurements.Count
        {
            get { return 1; }
        }

        IMeasure IMeasurements.this[int n]
        {
            get { return output[n]; }
        }

        void IMeasurements.UpdateMeasurements()
        {
            /*
            if (input[0] == null)
            {
                return;
            }
            if (isUpdated)
            {
                return;
            }
            try
            {
                IDataConsumer c = this;
                c.UpdateChildrenData();
                Calculate((double)input[0].Parameter(), (double)input[1].Parameter());
                if (hasDerivation)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        IDerivation der = input[i] as IDerivation;
                        result[1] += dx[i] * (double)der.Derivation.Parameter();
                    }
                }
                isUpdated = true;
            }
            catch (Exception e)
            {
                e.ShowError(10);
                this.Throw(e);
            }*/
        }

        bool IMeasurements.IsUpdated
        {
            get
            {
                return isUpdated;
            }
            set
            {
                isUpdated = value;
            }
        }

        #endregion

        #region IObjectOperation Members

        object[] IObjectOperation.InputTypes
        {
            get { return types; }
        }

        object IObjectOperation.this[object[] x]
        {
            get
            {
                object[] o = x[0] as object[];
                return Calculate((double)o[0], (double)o[1], (double)o[2]);
            }
        }

        object IObjectOperation.ReturnType
        {
            get { return type; }
        }

        bool IPowered.IsPowered
        {
            get { return false; }
        }

        #endregion

        #region IPostSetArrow Members

        void IPostSetArrow.PostSetArrow()
        {
            try
            {
                AcceptArguments();
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
            }
        }

        #endregion

        #region Specific Members

        /// <summary>
        /// Comments
        /// </summary>
        public ICollection Comments
        {
            get
            {
                return PureDesktopPeer.Deserialize(comments) as ICollection;
            }
            set
            {
                comments = PureDesktopPeer.Serialize(value);
            }
        }



        /// <summary>
        /// Arguments
        /// </summary>
        public string[] Arguments
        {
            get
            {
                return arguments;
            }
        }

        /// <summary>
        /// Pre initialization
        /// </summary>
        protected override void PreInit()
        {
            arguments = new string[] { "", "" };
        }


        /// <summary>
        /// Accepts arguments
        /// </summary>
        private void AcceptArguments()
        {
            foreach (IMeasurements measurements in this.measurements)
            {
                IAssociatedObject cont = measurements as IAssociatedObject;
                INamedComponent c = cont.Object as INamedComponent;
                string name = c.Name;
                for (int i = 0; i < measurements.Count; i++)
                {
                    IMeasure measure = measurements[i];
                    string p = name + "." + measure.Name;
                    for (int j = 0; j < 2; j++)
                    {
                        if (arguments[j].Equals(p))
                        {
                            input[j] = measure;
                            break;
                        }
                    }
                }
            }
            for (int i = 0; i < 2; i++)
            {
                if (arguments[i].Equals("Time"))
                {
                    input[i] = DataPerformer.StaticExtensionDataPerformerBase.Factory.TimeProvider.TimeMeasure;
                }
            }
            hasDerivation = true;
            for (int i = 0; i < input.Length; i++)
            {
                IDerivation der = input[i] as IDerivation;
                if (der == null)
                {
                    hasDerivation = false;
                    break;
                }
            }
        }


        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions