コード例 #1
0
        public void Test_VstParameterCollection_Index()
        {
            var paramInfo1 = new VstParameterInfo();

            paramInfo1.Name       = "Test1";
            paramInfo1.ShortLabel = "Tst1";
            paramInfo1.MaxInteger = 10;

            var col = new VstParameterCollection();

            var param1 = new VstParameter(paramInfo1);

            col.Add(param1);

            Assert.AreEqual(0, param1.Index, "Index of param1 is not as expected.");

            var paramInfo2 = new VstParameterInfo();

            paramInfo2.Name       = "Test2";
            paramInfo2.ShortLabel = "Tst2";
            paramInfo2.MaxInteger = 10;

            var param2 = new VstParameter(paramInfo2);

            col.Insert(0, param2);

            Assert.AreEqual(0, param2.Index, "Index of param2 is not as expected.");
            Assert.AreEqual(1, param1.Index, "Index of param1 is not as expected.");
        }
コード例 #2
0
 // create all parameters
 private void CreateParameters(VstParameterCollection desitnation, VstParameterInfoCollection parameterInfos)
 {
     foreach (VstParameterInfo paramInfo in parameterInfos)
     {
         desitnation.Add(CreateParameter(paramInfo));
     }
 }
コード例 #3
0
        /// <summary>
        /// Writes the Parameters in <paramref name="parameters"/> to the output stream.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        protected void Write(VstParameterCollection parameters)
        {
            WriteParameterHeader(parameters);

            foreach (VstParameter parameter in parameters)
                Write(parameter);
        }
コード例 #4
0
        public void Test_VstParameterCollection_Index()
        {
            var target = new VstParameterCollection();

            var paramInfo1 = new VstParameterInfo
            {
                Name       = "Test1",
                ShortLabel = "Tst1",
                MaxInteger = 10
            };

            var param1 = new VstParameter(paramInfo1);

            target.Add(param1);

            param1.Index.Should().Be(0);

            var paramInfo2 = new VstParameterInfo
            {
                Name       = "Test2",
                ShortLabel = "Tst2",
                MaxInteger = 10
            };

            var param2 = new VstParameter(paramInfo2);

            target.Insert(0, param2);

            param1.Index.Should().Be(1);
            param2.Index.Should().Be(0);
        }
コード例 #5
0
ファイル: VstProgramReader.cs プロジェクト: whinkloss/vst.net
        /// <summary>
        /// Reads the Parameter header from the stream.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        /// <returns>Returns the number of Parameters expected after the header.</returns>
        protected virtual int ReadParameterHeader(VstParameterCollection parameters)
        {
            string typeName = Reader.ReadString();
            int    count    = Reader.ReadInt32();

            return(count);
        }
コード例 #6
0
        /// <summary>
        /// Writes a header for the <paramref name="parameters"/> to the output stream.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        protected virtual void WriteParameterHeader(VstParameterCollection parameters)
        {
            var type = typeof(VstParameter);

            Writer.Write(type.FullName ?? type.Name);
            Writer.Write(parameters.Count);
        }
コード例 #7
0
 public void CreateParameters(VstParameterCollection parameters)
 {
     foreach (VstParameterInfo paramInfo in ParameterInfos)
     {
         VstParameter param = new VstParameter(paramInfo);
         parameters.Add(param);
     }
 }
コード例 #8
0
        /// <summary>
        /// Writes the Parameters in <paramref name="parameters"/> to the output stream.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        protected void Write(VstParameterCollection parameters)
        {
            WriteParameterHeader(parameters);

            foreach (VstParameter parameter in parameters)
            {
                Write(parameter);
            }
        }
コード例 #9
0
 /// <summary>
 /// Метод, используемый для записи значений параметров в файл.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="activeParameters"></param>
 public static void WriteParameters(Stream stream, VstParameterCollection activeParameters)
 {
     using (var writer = new BinaryWriter(stream, Encoding.Default, true))
     {
         foreach (var param in activeParameters)
         {
             writer.Write(param.Info.Name);
             writer.Write(param.NormalizedValue);
         }
     }
 }
コード例 #10
0
        /// <summary>
        /// Fills the <paramref name="parameters"/> collection with all parameters.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        /// <remarks>A <see cref="VstParameter"/> instance is created and linked up for each
        /// <see cref="VstParameterInfo"/> instance found in the <see cref="ParameterInfos"/> collection.</remarks>
        public void CreateParameters(VstParameterCollection parameters)
        {
            foreach (VstParameterInfo paramInfo in ParameterInfos)
            {
                if (Categories.Count > 0 && paramInfo.Category == null)
                {
                    paramInfo.Category = Categories[0];
                }

                var param = new VstParameter(paramInfo);
                parameters.Add(param);
            }
        }
コード例 #11
0
 /// <summary>
 /// Метод, используемый для считывания значений параметров из файла.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="activeParameters"></param>
 public static void ReadParameters(Stream stream, VstParameterCollection activeParameters)
 {
     using (var reader = new BinaryReader(stream, Encoding.Default, true))
     {
         foreach (var param in activeParameters)
         {
             var name = reader.ReadString();
             if (!activeParameters.Contains(name))
             {
                 throw new ArgumentException("File contains wrong values.");
             }
             var normalizedValue = reader.ReadSingle();
             if (normalizedValue < 0 || normalizedValue > 1)
             {
                 throw new ArgumentException("File contains wrong values.");
             }
             activeParameters[name].NormalizedValue = normalizedValue;
         }
     }
 }
コード例 #12
0
ファイル: VstProgramReader.cs プロジェクト: whinkloss/vst.net
        /// <summary>
        /// Fills the <paramref name="parameters"/> collection with Parameters.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        protected virtual void ReadParameters(VstParameterCollection parameters)
        {
            int count = ReadParameterHeader(parameters);

            for (int i = 0; i < count; i++)
            {
                string name  = Reader.ReadString();
                float  value = Reader.ReadSingle();

                if (parameters.Contains(name))
                {
                    VstParameter parameter = parameters[name];
                    parameter.Value = value;
                }
                else
                {
                    OnParameterNotFound(parameters, name, value);
                }
            }
        }
コード例 #13
0
        private void Parameters_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            IEnumerable parameters = null;

            if (e.NewItems != null)
                parameters = e.NewItems;
            else
            {
                parameters = Parameters;

                // TODO: this will trigger a lot of CollectionChanged events...
                Categories.Clear();
            }

            foreach (VstParameter parameter in parameters)
                if (parameter.Info.Category != null)
                {
                    // add category to collection if not present yet
                    if (!Categories.Contains(parameter.Info.Category.Name))
                        Categories.Add(parameter.Info.Category);
                }
        }
コード例 #14
0
ファイル: VstProgramReader.cs プロジェクト: whinkloss/vst.net
 /// <summary>
 /// Called when a Parameter could not be found by name.
 /// </summary>
 /// <param name="parameters">The parameters that were discovered untill now. Can be used to add another Parameter.</param>
 /// <param name="name">The name of the parameter.</param>
 /// <param name="value">The value of the parameter.</param>
 protected virtual void OnParameterNotFound(VstParameterCollection parameters, string name, float value)
 {
     System.Diagnostics.Debug.WriteLine(
         String.Format("Parameter '{0}' was not found.", name), nameof(VstProgramReader));
 }
コード例 #15
0
        /// <summary>
        /// Reads the Parameter header from the stream.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        /// <returns>Returns the number of Parameters expected after the header.</returns>
        protected virtual int ReadParameterHeader(VstParameterCollection parameters)
        {
            string typeName = Reader.ReadString();
            int count = Reader.ReadInt32();

            return count;
        }
コード例 #16
0
        /// <summary>
        /// Fills the <paramref name="parameters"/> collection with Parameters.
        /// </summary>
        /// <param name="parameters">Must not be null.</param>
        protected virtual void ReadParameters(VstParameterCollection parameters)
        {
            int count = ReadParameterHeader(parameters);

            for (int i = 0; i < count; i++)
            {
                string name = Reader.ReadString();
                float value = Reader.ReadSingle();

                if (parameters.Contains(name))
                {
                    VstParameter parameter = parameters[name];
                    parameter.Value = value;
                }
                else
                    OnParameterNotFound(parameters, name, value);
            }
        }
コード例 #17
0
 /// <summary>
 /// Called when a Parameter could not be found by name.
 /// </summary>
 /// <param name="parameters">The parameters that were discovered untill now. Can be used to add another Parameter.</param>
 /// <param name="name">The name of the parameter.</param>
 /// <param name="value">The value of the parameter.</param>
 protected virtual void OnParameterNotFound(VstParameterCollection parameters, string name, float value)
 {
     Debug.WriteLine(String.Format("Parameter '{0}' was not found.", name), "VstProgramReaderBase");
 }
コード例 #18
0
ファイル: PluginPrograms.cs プロジェクト: kavun/VSTNETSynth
 // create all parameters
 private void CreateParameters(VstParameterCollection desitnation, VstParameterInfoCollection parameterInfos)
 {
     foreach (VstParameterInfo paramInfo in parameterInfos)
     {
         desitnation.Add(CreateParameter(paramInfo));
     }
 }
コード例 #19
0
 /// <summary>
 /// Writes a header for the <paramref name="parameters"/> to the output stream.
 /// </summary>
 /// <param name="parameters">Must not be null.</param>
 protected virtual void WriteParameterHeader(VstParameterCollection parameters)
 {
     Writer.Write(typeof(VstParameter).FullName);
     Writer.Write(parameters.Count);
 }
コード例 #20
0
 /// <summary>
 /// Override this method in derived classes to cleanup managed and/or
 /// unmanaged resources.
 /// </summary>
 /// <param name="disposing">When true dispose managed and unmanaged resources. 
 /// when false dispose only unmanaged resources.</param>
 /// <remarks>All references are cleared (null), also the callback handlers.</remarks>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // clear all references
         DisplayValue = null;
         Info = null;
         Parent = null;
     }
 }
コード例 #21
0
        /// <summary>
        /// Disposes a plugin program.
        /// </summary>
        /// <remarks>Also disposes all <see cref="VstParameter"/> instances in the <see cref="Parameters"/> collection.</remarks>
        public virtual void Dispose()
        {
            name = null;
            Categories = null;

            if (parameters != null)
            {
                parameters.Clear();    // disposes VstParameter instances
                parameters = null;
            }
        }