public SoundVisualizerVM(IValueHolderReadOnly<short[]> samples, IValueHolderReadOnly<int> samplingRate)
        {
            _color = new ValueHolder<Color>();
            _samplingRate = samplingRate;
            _samples = samples;
            _frequencies = new ValueHolder<IReadOnlyList<KeyValuePair<Frequency, double>>>();
            _amplitudes = new ValueHolder<IReadOnlyList<KeyValuePair<int, double>>>();
            _averageIntensity = new ValueHolder<double>();
            _averageAmplitudeFromLastSampling = new ValueHolder<double>();

            Sound2ColorMappings = new List<ISound2ColorMapping>{
                new LinearSound2ColorMapping{
                    Color = System.Windows.Media.Color.FromRgb(0,0,255),
                    IntensityMultiplier = 0.8,
                    SoundFrequencyMidpoint = new Frequency(250),
                    SoundFrequencySpanWidth = new Frequency(300)},
                new LinearSound2ColorMapping{
                    Color = System.Windows.Media.Color.FromRgb(0,255,0),
                    IntensityMultiplier = 1.1,
                    SoundFrequencyMidpoint = new Frequency(700),
                    SoundFrequencySpanWidth = new Frequency(450)},
                new LinearSound2ColorMapping{
                    Color = System.Windows.Media.Color.FromRgb(255,0,0),
                    IntensityMultiplier = 0.9,
                    SoundFrequencyMidpoint = new Frequency(1500),
                    SoundFrequencySpanWidth = new Frequency(1000)},
            new LinearSound2ColorMapping{
                    Color = System.Windows.Media.Color.FromRgb(255,0,0),
                    IntensityMultiplier = 0.4,
                    SoundFrequencyMidpoint = new Frequency(2600),
                    SoundFrequencySpanWidth = new Frequency(1400)}};

            _samples.PropertyChanged += HandleAmplitudesChanged;
            _samplingRate.PropertyChanged += HandleSamplingRateChanged;
        }
        public MainWindow()
        {
            InitializeComponent();

            _samples = new ValueHolder<short[]>();
            _samplingRate = new ValueHolder<int>();

            _soundManager = new SoundManager();
            _soundManager.NewSamples += HandleNewSamples;
            _soundManager.StartRecording(0, 30);

            _samplingRate.Value = _soundManager.SamplingRate;

            _soundVisualizerVM = new SoundVisualizerVM(_samples, _samplingRate);

            _soundVisualizer = new SoundVisualizerControl(_soundVisualizerVM);
            //MainGrid.Children.Add(_soundVisualizer);

            _scene = new WPF3DScene();
            MainGrid.Children.Add(_scene);
            _model = Create3DModel();
            _scene.AddModel(_model);
            AddUIP3DPlane();
            _soundVisualizerVM.AverageAmplitudeFromLastSampling.PropertyChanged += HandleAverageAmplitudeChanged;

            DeviceButton.Click += DeviceButton_Click;
            DeviceButton.Content = _soundManager.GetAvailableDevices().Keys.First().ProductName;
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string GetEnumName(this IValueHolder valueHolder, object key, bool uc, bool isMessage)
        ///
        /// \brief An IValueHolder extension method that gets enum name.
        ///
        /// \par Description.
        ///      When getting a key this method returns the enum name of the key
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 22/10/2017
        ///
        /// \param valueHolder The valueHolder to act on.
        /// \param key          (object) - The key.
        /// \param uc           (bool) - true to uc.
        /// \param isMessage    (bool) - true if this object is message.
        ///
        /// \return The enum name.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string GetEnumName(this IValueHolder valueHolder, object key, bool uc)
        {
            string enumName = "";

            if (key is NetworkElement.ElementDictionaries)
            {
                enumName = NetworkElement.ShortDictionariesNames[(int)((NetworkElement.ElementDictionaries)key)] + "k";
            }
            else
            {
                string keyString = TypesUtility.GetKeyToString(key);
                if (uc)
                {
                    enumName = char.ToUpper(keyString[0]) + keyString.Substring(1);
                }
                else
                {
                    enumName = char.ToLower(keyString[0]) + keyString.Substring(1);
                }
            }
            return(enumName);
        }
Beispiel #4
0
        private void FollowObjectReference(IValueHolder prop)
        {
            var refe = prop.Value as NdfObjectReference;

            if (refe == null)
            {
                return;
            }

            var vm = new NdfClassViewModel(refe.Class, ParentVm);

            var inst = vm.Instances.SingleOrDefault(x => x.Id == refe.InstanceId);

            if (inst == null)
            {
                return;
            }

            vm.InstancesCollectionView.MoveCurrentTo(inst);

            DialogProvider.ProvideView(vm, ParentVm);
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             IValueHolder ct = context.Instance as IValueHolder;
             if (ct != null)
             {
                 Keys ks = (Keys)ct.Value;
                 ControlSelectKeys csk = new ControlSelectKeys();
                 csk.SetEditorService(edSvc, ks);
                 edSvc.DropDownControl(csk);
                 if (csk.MadeSelection)
                 {
                     value = csk.Selection;
                 }
             }
         }
     }
     return(value);
 }
Beispiel #6
0
        public Number Calculate()
        {
            int steps = members.Count;
            var expr  = new Queue <IFunctor>(members);

            while (steps-- > 0)
            {
                var member = expr.Dequeue();

                if (member.Type == MemberType.Operand)
                {
                    machine.Push(member.Calculate());
                }
                else
                {
                    var args = new IValueHolder[member.ParamsCount];

                    for (int i = args.Length - 1; i >= 0; i--)
                    {
                        args[i] = machine.Pop();
                    }

                    try
                    {
                        machine.Push(member.SetInnerArgs(args).Calculate());
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException($"An exception occured during calculate an expression " +
                                                            $"\"{InitialExpressionString}\" in variable set \"{VariableSet}\".\n" +
                                                            $"Original exception is {ex}");
                    }
                }
            }

            return(machine.Pop().Value);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string MainDictionaryInitMethodName(this IValueHolder valueHolder)
        ///
        /// \brief An IValueHolder extension method that main dictionary init method name.
        ///
        /// \par Description.
        ///      -  The method name of the method that initializes a main dictionary
        ///      -  Example `InitPrivateAttribute`
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 22/10/2017
        ///
        /// \param valueHolder The valueHolder to act on.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string MainDictionaryInitMethodName(this IValueHolder valueHolder)
        {
            string dictionaryName = TypesUtility.GetKeyToString(valueHolder.Parent.GetChildKey(valueHolder));

            return("Init" + dictionaryName);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool CheckIfBelongsToBaseAlgorithmEnum(this IValueHolder valueHolder, NetworkElement networkElement, NetworkElement.ElementDictionaries mainDictionary)
        ///
        /// \brief An IValueHolder extension method that determine if belongs to base algorithm enum.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/10/2017
        ///
        /// \param valueHolder    The valueHolder to act on.
        /// \param networkElement  (NetworkElement) - The network element.
        /// \param mainDictionary  (ElementDictionaries) - Dictionary of mains.
        ///
        /// \return True if the value holder belongs to the base network element.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool BelongsToBaseAlgorithmEnum(this IValueHolder valueHolder, NetworkElement networkElement, NetworkElement.ElementDictionaries mainDictionary)
        {
            // If the value holder is not attribute get the attribute of the value holder
            Attribute attribute;

            if (!(valueHolder is Attribute))
            {
                attribute = (Attribute)valueHolder.Parent;
            }
            else
            {
                attribute = (Attribute)valueHolder;
            }

            // The condition is that the attribute which is the ancestor of our attribute
            // which is in the main dictionary belongs to the base class
            // Find the ancestor.
            // The parent sequence is ending in the following way
            // null <- networkElement <- Attribute <- mainDictionary <- Attribute
            // We have to find the last element in the chain described below
            // We do it with a loop that advances 2 parameters: The attribute and the chain end
            // The chain end is 4 times the parent of the attribute
            // Get the first chain end (If we cannot end the chain that means that the valueHolder is
            // one of the value holders at the middle of the chain hence they are not attributes in the
            // base classes main dictionary
            IValueHolder chainEnd = attribute;

            for (int idx = 0; idx < 4; idx++)
            {
                chainEnd = chainEnd.Parent;
                if (chainEnd == null && idx != 3)
                {
                    return(false);
                }
            }

            // Find the ancestor
            while (chainEnd != null)
            {
                chainEnd  = chainEnd.Parent.Parent;
                attribute = (Attribute)attribute.Parent.Parent;
            }

            // Decide if the attribute is part of the main dictionary
            if (!((AttributeDictionary)networkElement[mainDictionary]).Values.Any(a => a == attribute))
            {
                return(false);
            }

            // Get the key of the attribute
            dynamic key = attribute.Parent.GetChildKey(attribute);

            if (TypesUtility.CompareDynamics(key, bn.ork.SingleStepStatus))
            {
                int x = 1;
            }

            // Get the base NetworkElement
            Type           baseNetworkElementType = networkElement.GetType().BaseType;
            NetworkElement baseNetworkElement     = (NetworkElement)TypesUtility.CreateObjectFromTypeString(baseNetworkElementType.ToString());

            baseNetworkElement.Init(0);

            // Check if the key is found in the base network element's dictionary
            return(((AttributeDictionary)baseNetworkElement[mainDictionary]).Keys.Any(k => TypesUtility.CompareDynamics(k, key)));
        }
 private void GetValue(IValueHolder valueHolder, NdfObjectViewModel inst, List<NdfPropertyValue> result, NdfPropertyValue propertyValue)
 {
     switch (valueHolder.Value.Type)
     {
         case NdfType.ObjectReference:
             var ndfObjectReference = valueHolder.Value as NdfObjectReference;
             if (ndfObjectReference != null && ndfObjectReference.InstanceId == inst.Object.Id)
                 result.Add(propertyValue);
             break;
         case NdfType.List:
         case NdfType.MapList:
             var ndfCollection = valueHolder.Value as NdfCollection;
             if (ndfCollection != null)
                 foreach (var col in ndfCollection)
                     GetValue(col, inst, result, propertyValue);
             break;
         case NdfType.Map:
             var map = valueHolder.Value as NdfMap;
             if (map != null)
             {
                 GetValue(map.Key, inst, result, propertyValue);
                 GetValue(map.Value as IValueHolder, inst, result, propertyValue);
             }
             break;
     }
 }
Beispiel #10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public override void SetMembers(BaseNetwork network, NetworkElement element, Permissions permissions, IValueHolder parent, bool recursive = true)
        ///
        /// \brief Sets the members.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 30/05/2018
        ///
        /// \param network      (BaseNetwork) - The network.
        /// \param element      (NetworkElement) - The element.
        /// \param permissions  (Permissions) - The permissions.
        /// \param parent       (IValueHolder) - The parent.
        /// \param recursive   (Optional)  (bool) - true to process recursively, false to process locally only.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public override void SetMembers(BaseNetwork network, NetworkElement element, Permissions permissions, IValueHolder parent, bool recursive = true)
        {
            base.SetMembers(network, element, permissions, parent);
            process = (BaseProcess)Element;
        }
        private void FollowDetails(IValueHolder prop)
        {
            if (prop == null || prop.Value == null)
                return;

            switch (prop.Value.Type)
            {
                case NdfType.MapList:
                case NdfType.List:
                    FollowList(prop);
                    break;
                case NdfType.ObjectReference:
                    FollowObjectReference(prop);
                    break;
                case NdfType.Map:
                    var map = prop.Value as NdfMap;

                    if (map != null)
                    {
                        FollowDetails(map.Key);
                        FollowDetails(map.Value as IValueHolder);
                    }

                    break;
                default:
                    return;
            }
        }
        private void FollowObjectReference(IValueHolder prop)
        {
            var refe = prop.Value as NdfObjectReference;

            if (refe == null)
                return;

            var vm = new NdfClassViewModel(refe.Class, null);

            NdfObjectViewModel inst = vm.Instances.SingleOrDefault(x => x.Id == refe.InstanceId);

            if (inst == null)
                return;

            vm.InstancesCollectionView.MoveCurrentTo(inst);

            DialogProvider.ProvideView(vm);
        }
 public TestController(IValueHolder valueHolder)
 {
     _valueHolder = valueHolder;
 }
Beispiel #14
0
 public static IFunctor Wrap(IValueHolder valueHolder) =>
 new VoidFunctor().SetInnerArgs(new IValueHolder[] { valueHolder });
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static void GenerateCheckMessage(this IValueHolder valueHolder, int nestingLevel, string key, string message)
        ///
        /// \brief Generates a check message.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 25/07/2017
        ///
        /// \param valueHolder  The valueHolder to act on.
        /// \param nestingLevel  (int) - The nesting level.
        /// \param key           (string) - The key.
        /// \param message       (string) - The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void GenerateCheckMessage(this IValueHolder valueHolder, int nestingLevel, string key, string message)
        {
            MessageRouter.ReportMessage(new string('\t', nestingLevel) + "[" + key + "] (" + valueHolder.GetType().ToString().Replace("DistributedAlgorithms.", "") + ") ", "", message);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool EqualsTo(this IValueHolder valueHolder, int nestingLevel, object key, IValueHolder other, bool checkNotSameObject = false)
        ///
        /// \brief Equals to.
        ///
        /// \par Description.
        ///      -  This method recursively checks if the first IValueHolder is equal to the second
        ///      -  The compare is for the values and not the pointers of the IValueHolder
        ///      -  The parameter checkNotSameObject is for checking that there was a copy (means created
        ///         new objects) and not assignments.
        ///
        /// \par Algorithm.
        ///      -# Common checks for all the IValueHolder
        ///         -#  The type of the 2 IValueHolder is the same
        ///         -#  If checkNotSameObject check that the objects are not the same objects
        ///      -# Activate the recursive compare by calling the IValueHolder's EqualsTo method.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 25/07/2017
        ///
        /// \param valueHolder        The valueHolder to act on.
        /// \param nestingLevel        (int) - The nesting level.
        /// \param key                 (object) - The key.
        /// \param other               (IValueHolder) - The other.
        /// \param checkNotSameObject (Optional)  (bool) - true to check not same object.
        ///
        /// \return True if equals to, false if not.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool CheckEqual(this IValueHolder valueHolder,
                                      int nestingLevel,
                                      object key,
                                      IValueHolder other,
                                      bool print = false,
                                      bool checkNotSameObject = false)
        {
            string keyString = TypesUtility.GetKeyToString(key);

            if (print)
            {
                if (nestingLevel == 0)
                {
                    MessageRouter.ReportMessage("----- Start EqualsTo -----", "", "");
                }

                valueHolder.GenerateCheckMessage(nestingLevel, keyString, " Start");
            }
            if (!valueHolder.GetType().Equals(other.GetType()))
            {
                valueHolder.GenerateCheckMessage(nestingLevel, keyString, "The type of one is : " + valueHolder.GetType() +
                                                 " The type of two is : " + other.GetType());
                return(false);
            }

            if (checkNotSameObject)
            {
                if (valueHolder == other)
                {
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, "The pointer of one and two is equal and it should not");
                    return(false);
                }
            }

            string error = "";

            if (valueHolder.EqualsTo(nestingLevel, ref error, other, print, checkNotSameObject))
            {
                if (print)
                {
                    if (nestingLevel == 0)
                    {
                        MessageRouter.ReportMessage("----- Start EqualsTo -----", "", "");
                    }
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, " End - True");
                }
                return(true);
            }
            else
            {
                if (print)
                {
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, " " + error);
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, " End - False");
                    if (nestingLevel == 0)
                    {
                        MessageRouter.ReportMessage("----- End EqualsTo -----", "", "");
                    }
                }
                return(false);
            }
        }
Beispiel #17
0
 public SynchronizedDecorator(IValueHolder <T> vh) => this.vh = vh;
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string MainDictionaryName(this IValueHolder valueHolder)
        ///
        /// \brief An IValueHolder extension method that main dictionary name.
        ///
        /// \par Description.
        ///      -  Get the name of the main dictionary.
        ///      -  The name of the main dictionary is the name of the enum for that dictionary without
        ///         the last letter (for example for PrivateAttribute dictionary the enum name is pak
        ///         and the dictionary name is pa)
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 22/10/2017
        ///
        /// \param valueHolder The valueHolder to act on.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string MainDictionaryName(this IValueHolder valueHolder)
        {
            string keyString = valueHolder.GetEnumName((object)valueHolder.Parent.GetChildKey(valueHolder), false);

            return(keyString.Substring(0, keyString.Length - 1));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string InitMethodName(this IValueHolder valueHolder)
        ///
        /// \brief An IValueHolder extension method that init method name.
        ///
        /// \par Description.
        ///      -  Method name for methods used in the init phase.
        ///      -  Example : `Init_EnumName`
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 22/10/2017
        ///
        /// \param valueHolder The valueHolder to act on.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string InitMethodName(this IValueHolder valueHolder)
        {
            return("Init_" + valueHolder.GetKeyString(true));
        }
Beispiel #20
0
 public SingleOptionControl(IValueHolder <string> optionRef, OptionsList list, string nameForLogging,
                            IWritingSystemDefinition preferredWritingSystem)
     : this(optionRef, list, nameForLogging, preferredWritingSystem, null)
 {
 }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string SendMethodName(this IValueHolder valueHolder, object key)
        ///
        /// \brief An IValueHolder extension method that sends a method name.
        ///
        /// \par Description.
        ///      -  Method name for sending a message method
        ///      -  Example : `SendMessageName`
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 22/10/2017
        ///
        /// \param valueHolder The valueHolder to act on.
        /// \param key          (object) - The key.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string SendMethodName(this IValueHolder valueHolder, object key)
        {
            return("Send" + valueHolder.GetEnumName(key, true));
        }
        private void FollowList(IValueHolder prop)
        {
            var refe = prop.Value as NdfCollection;

            if (refe == null)
                return;

            var editor = new ListEditorViewModel(refe, NdfbinManager);

            DialogProvider.ProvideView(editor, this);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string MessageMainDictionaryMethodName(this IValueHolder valueHolder, dynamic key)
        ///
        /// \brief An IValueHolder extension method that message main dictionary method name.
        ///
        /// \par Description.
        ///      Main dictionary method name (To be used in the generation of the Send... method
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 24/12/2017
        ///
        /// \param valueHolder The valueHolder to act on.
        /// \param key          (dynamic) - The key.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string MessageMainDictionaryMethodName(this IValueHolder valueHolder, object key)
        {
            return("MessageDataFor_" + valueHolder.GetEnumName(key, true));
        }
 public LogDecorator(IValueHolder<T> vh, TextWriter output)
 {
     this.vh = vh;
     this.output = output;
 }
        private NdfValueWrapper GetCopiedValue(IValueHolder toCopy)
        {
            NdfValueWrapper copiedValue = null;

            switch (toCopy.Value.Type)
            {
                case NdfType.ObjectReference:
                    var origInst = toCopy.Value as NdfObjectReference;

                    if (origInst != null && !origInst.Instance.IsTopObject)
                        copiedValue = new NdfObjectReference(origInst.Class, CopyInstance(origInst.Instance).Id);
                    else
                        copiedValue = NdfTypeManager.GetValue(toCopy.Value.GetBytes(), toCopy.Value.Type, toCopy.Manager);

                    break;
                case NdfType.List:
                case NdfType.MapList:
                    var copiedItems = new List<CollectionItemValueHolder>();
                    var collection = toCopy.Value as NdfCollection;
                    if (collection != null)
                        copiedItems.AddRange(collection.Select(entry => new CollectionItemValueHolder(GetCopiedValue(entry), toCopy.Manager)));
                    copiedValue = new NdfCollection(copiedItems);
                    break;

                case NdfType.Map:
                    var map = toCopy.Value as NdfMap;
                    if (map != null)
                        copiedValue = new NdfMap(new MapValueHolder(GetCopiedValue(map.Key), toCopy.Manager),
                            new MapValueHolder(GetCopiedValue(map.Value as IValueHolder), toCopy.Manager), toCopy.Manager);
                    break;

                default:
                    copiedValue = NdfTypeManager.GetValue(toCopy.Value.GetBytes(), toCopy.Value.Type, toCopy.Manager);
                    break;
            }

            return copiedValue;
        }