Ejemplo n.º 1
0
        /// <summary>
        /// Restore plugin state
        /// </summary>
        /// <param name="stateData">Byte array of data to restore</param>
        public override void RestoreState(byte[] stateData)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(VstProgramParameters));

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(stateData))
                {
                    VstProgramParameters programParameters = serializer.Deserialize(memoryStream) as VstProgramParameters;

                    if (string.IsNullOrEmpty(programParameters.SchematicPath))
                    {
                        haveSimulationError = false;

                        SimulationProcessor.ClearSchematic();
                    }
                    else
                    {
                        LoadSchematic(programParameters.SchematicPath);
                    }

                    SimulationProcessor.Oversample = programParameters.OverSample;
                    SimulationProcessor.Iterations = programParameters.Iterations;

                    foreach (VSTProgramControlParameter controlParameter in programParameters.ControlParameters)
                    {
                        var wrapper = SimulationProcessor.InteractiveComponents.Where(i => i.Name == controlParameter.Name).SingleOrDefault();

                        if (wrapper != null)
                        {
                            switch (wrapper)
                            {
                            case PotWrapper potWrapper:
                                potWrapper.PotValue = controlParameter.Value;
                                break;

                            case DoubleThrowWrapper doubleThrowWrapper:
                                doubleThrowWrapper.Engaged = (controlParameter.Value == 1);
                                break;

                            case MultiThrowWrapper multiThrowWrapper:
                                multiThrowWrapper.Position = (int)controlParameter.Value;
                                break;
                            }
                        }
                    }

                    if (EditorView != null)
                    {
                        EditorView.UpdateSchematic();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Load state failed: " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set plugin state from program data
        /// </summary>
        /// <param name="program">The program data</param>
        /// <param name="index">The index of the program</param>
        public void SetProgramData(Program program, int index)
        {
            Logging.Log("Load program: " + index);

            XmlSerializer serializer = new XmlSerializer(typeof(VstProgramParameters));

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(program.Data))
                {
                    VstProgramParameters programParameters = serializer.Deserialize(memoryStream) as VstProgramParameters;

                    if (string.IsNullOrEmpty(programParameters.SchematicPath))
                    {
                        haveSimulationError = false;

                        SimulationProcessor.ClearSchematic();
                    }
                    else
                    {
                        LoadSchematic(programParameters.SchematicPath);
                    }

                    SimulationProcessor.Oversample = programParameters.OverSample;
                    SimulationProcessor.Iterations = programParameters.Iterations;

                    foreach (VSTProgramControlParameter controlParameter in programParameters.ControlParameters)
                    {
                        ComponentWrapper wrapper = SimulationProcessor.InteractiveComponents.Where(i => i.Name == controlParameter.Name).SingleOrDefault();

                        if (wrapper != null)
                        {
                            if (wrapper.Name == controlParameter.Name)
                            {
                                if (wrapper is PotWrapper)
                                {
                                    (wrapper as PotWrapper).PotValue = controlParameter.Value;
                                }
                                else if (wrapper is ButtonWrapper)
                                {
                                    (wrapper as ButtonWrapper).Engaged = (controlParameter.Value == 1);
                                }
                            }
                        }
                    }

                    if (EditorView != null)
                    {
                        EditorView.UpdateSchematic();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Log("Load program failed: " + ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Save our current plugin state
        /// </summary>
        /// <returns>A byte array of data</returns>
        public override byte[] SaveState()
        {
            byte[] stateData = null;

            VstProgramParameters programParameters = new VstProgramParameters
            {
                SchematicPath = SimulationProcessor.SchematicPath,
                OverSample    = SimulationProcessor.Oversample,
                Iterations    = SimulationProcessor.Iterations
            };

            foreach (var wrapper in SimulationProcessor.InteractiveComponents)
            {
                switch (wrapper)
                {
                case PotWrapper potWrapper:
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = potWrapper.PotValue
                    });
                    break;

                case DoubleThrowWrapper doubleThrowWrapper:
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = doubleThrowWrapper.Engaged ? 1 : 0
                    });
                    break;

                case MultiThrowWrapper multiThrowWrapper:
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = multiThrowWrapper.Position
                    });
                    break;
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(VstProgramParameters));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                serializer.Serialize(memoryStream, programParameters);

                stateData = memoryStream.ToArray();
            }

            return(stateData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Save our current plugin state
        /// </summary>
        /// <param name="index">Program index</param>
        /// <returns></returns>
        public Program GetProgramData(int index)
        {
            Logging.Log("Save program: " + index);

            // We only have one program

            var program = new Program();

            program.Name = null; // "Program 1";
            program.Data = null;

            VstProgramParameters programParameters = new VstProgramParameters
            {
                SchematicPath = SimulationProcessor.SchematicPath,
                OverSample    = SimulationProcessor.Oversample,
                Iterations    = SimulationProcessor.Iterations
            };

            foreach (ComponentWrapper wrapper in SimulationProcessor.InteractiveComponents)
            {
                if (wrapper is PotWrapper)
                {
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = (wrapper as PotWrapper).PotValue
                    });
                }
                else if (wrapper is ButtonWrapper)
                {
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = (wrapper as ButtonWrapper).Engaged ? 1 : 0
                    });
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(VstProgramParameters));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                serializer.Serialize(memoryStream, programParameters);

                program.Data = memoryStream.ToArray();
            }

            return(program);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Save our current plugin state
        /// </summary>
        /// <returns>A byte array of data</returns>
        public override byte[] SaveState()
        {
            byte[] stateData = null;

            VstProgramParameters programParameters = new VstProgramParameters
            {
                SchematicPath = SimulationProcessor.SchematicPath,
                OverSample    = SimulationProcessor.Oversample,
                Iterations    = SimulationProcessor.Iterations
            };

            foreach (ComponentWrapper wrapper in SimulationProcessor.InteractiveComponents)
            {
                if (wrapper is PotWrapper)
                {
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = (wrapper as PotWrapper).PotValue
                    });
                }
                else if (wrapper is ButtonWrapper)
                {
                    programParameters.ControlParameters.Add(new VSTProgramControlParameter {
                        Name = wrapper.Name, Value = (wrapper as ButtonWrapper).Engaged ? 1 : 0
                    });
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(VstProgramParameters));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                serializer.Serialize(memoryStream, programParameters);

                stateData = memoryStream.ToArray();
            }

            return(stateData);
        }