示例#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);
            }
        }
        /// <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);
            }
        }