Esempio n. 1
0
		public bool WriteFXP(string filePath) {

			FXP fxp = new FXP();
			fxp.ChunkMagic = "CcnK";
			fxp.ByteSize = 0; // will be set correctly by FXP class
			
			// Preset (Program) (.fxp) with chunk (magic = 'FPCh')
			fxp.FxMagic = "FPCh"; // FPCh = FXP (preset), FBCh = FXB (bank)
			fxp.Version = 1; // Format Version (should be 1)
			fxp.FxID = "J9AU";
			fxp.FxVersion = 1;
			fxp.ProgramCount = 36; // I.e. nummber of parameters
			fxp.Name = PresetName;
			
			byte[] chunkData = GetChunkData();
			fxp.ChunkSize = chunkData.Length;
			fxp.ChunkDataByteArray = chunkData;
			
			fxp.WriteFile(filePath);
			return true;
		}
Esempio n. 2
0
		public bool Read(string filePath)
		{
			// store filepath
			FilePath = filePath;
			
			FXP fxp = new FXP();
			fxp.ReadFile(filePath);
			
			if (!ReadFXP(fxp, filePath)) {
				return false;
			}
			return true;
		}
Esempio n. 3
0
		public bool ReadFXP(FXP fxp, string filePath="")
		{
			var bFile = new BinaryFile(fxp.ChunkDataByteArray, BinaryFile.ByteOrder.LittleEndian);

			// Read UAD Preset Header information
			PresetHeaderVar1 = bFile.ReadInt32();
			PresetHeaderVar2 = bFile.ReadInt32();
			PresetName = bFile.ReadString(32).Trim('\0');
			
			// Read Parameters
			Input = bFile.ReadSingle();
			Phase = bFile.ReadSingle();
			HPFreq = bFile.ReadSingle();
			LPFreq = bFile.ReadSingle();
			HP_LPDynSC = bFile.ReadSingle();
			CMPRatio = bFile.ReadSingle();
			CMPThresh = bFile.ReadSingle();
			CMPRelease = bFile.ReadSingle();
			CMPAttack = bFile.ReadSingle();
			StereoLink = bFile.ReadSingle();
			Select = bFile.ReadSingle();
			EXPThresh = bFile.ReadSingle();
			EXPRange = bFile.ReadSingle();
			EXPRelease = bFile.ReadSingle();
			EXPAttack = bFile.ReadSingle();
			DYNIn = bFile.ReadSingle();
			CompIn = bFile.ReadSingle();
			ExpIn = bFile.ReadSingle();
			LFGain = bFile.ReadSingle();
			LFFreq = bFile.ReadSingle();
			LFBell = bFile.ReadSingle();
			LMFGain = bFile.ReadSingle();
			LMFFreq = bFile.ReadSingle();
			LMFQ = bFile.ReadSingle();
			HMFQ = bFile.ReadSingle();
			HMFGain = bFile.ReadSingle();
			HMFFreq = bFile.ReadSingle();
			HFGain = bFile.ReadSingle();
			HFFreq = bFile.ReadSingle();
			HFBell = bFile.ReadSingle();
			EQIn = bFile.ReadSingle();
			EQDynSC = bFile.ReadSingle();
			PreDyn = bFile.ReadSingle();
			Output = bFile.ReadSingle();
			EQType = bFile.ReadSingle();
			Power = bFile.ReadSingle();
			
			return false;
		}
Esempio n. 4
0
        public static bool Convert2ReaEQ(REWEQFilters filters, string filePath)
        {
            List<ReaEQBand> ReaEqBands = new List<ReaEQBand>();
            foreach (REWEQBand filter in filters) {
                ReaEQBand band = new ReaEQBand();
                band.LogScaleAutoFreq = true;
                band.FilterFreq = filter.FilterFreq;
                band.FilterGain = filter.FilterGain;
                band.FilterBWOct = filter.FilterBWOct;
                band.Enabled = filter.Enabled;
                switch (filter.FilterType) {
                    case REWEQFilterType.PK:
                        band.FilterType = ReaEQFilterType.Band;
                        break;
                    case REWEQFilterType.LP:
                        band.FilterType = ReaEQFilterType.LowPass;
                        break;
                    case REWEQFilterType.HP:
                        band.FilterType = ReaEQFilterType.HighPass;
                        break;
                    case REWEQFilterType.LS:
                        band.FilterType = ReaEQFilterType.LowShelf;
                        break;
                    case REWEQFilterType.HS:
                        band.FilterType = ReaEQFilterType.HighShelf;
                        break;
                    default:
                        band.FilterType = ReaEQFilterType.Band;
                        break;
                }
                ReaEqBands.Add(band);
            }

            // store to file
            FXP fxp = new FXP();
            fxp.ChunkMagic = "CcnK";
            fxp.ByteSize = 0; // will be set correctly by FXP class
            fxp.FxMagic = "FPCh"; // FPCh = FXP (preset), FBCh = FXB (bank)
            fxp.Version = 1; // Format Version (should be 1)
            fxp.FxID = "reeq";
            fxp.FxVersion = 1100;
            fxp.ProgramCount = 1;
            fxp.Name = "";

            using(MemoryStream memStream = new MemoryStream(10))
            {
                BinaryFile binFile = new BinaryFile(memStream, BinaryFile.ByteOrder.LittleEndian);
                binFile.Write((int)33);
                binFile.Write((int)ReaEqBands.Count);
                foreach (ReaEQBand band in ReaEqBands) {
                    binFile.Write((int) band.FilterType);
                    binFile.Write((int) (band.Enabled ? 1 : 0) );
                    binFile.Write((double) band.FilterFreq);
                    binFile.Write((double) Decibel2AmplitudeRatio(band.FilterGain));
                    binFile.Write((double) band.FilterBWOct);
                    binFile.Write((byte) 1);
                }

                binFile.Write((int)1);
                binFile.Write((int)1);

                binFile.Write((double) Decibel2AmplitudeRatio(0.00));
                binFile.Write((int)0);

                memStream.Flush();
                byte[] chunkData = memStream.GetBuffer();
                fxp.ChunkSize = chunkData.Length;
                fxp.ChunkDataByteArray = chunkData;
            }
            fxp.WriteFile(filePath);
            return true;
        }
Esempio n. 5
0
        private static FXP ReadFXP(BinaryFile bf)
        {
            string ChunkMagic = bf.ReadString(4);

            if (ChunkMagic != "CcnK")
            {
                throw new FormatException(string.Format("Error reading file. Missing preset header information {0}", ChunkMagic));
            }

            var    fxp      = new FXP();
            int    ByteSize = bf.ReadInt32();
            string FxMagic  = bf.ReadString(4);

            if (FxMagic == "FBCh")
            {
                // Bank (.fxb) with chunk (magic = 'FBCh')
                var chunkSet = new FxChunkSet();
                chunkSet.ChunkMagic = ChunkMagic;
                chunkSet.ByteSize   = ByteSize;
                chunkSet.FxMagic    = FxMagic;

                chunkSet.Version   = bf.ReadInt32();
                chunkSet.FxID      = bf.ReadString(4);
                chunkSet.FxVersion = bf.ReadInt32();

                chunkSet.NumPrograms = bf.ReadInt32();
                chunkSet.Future      = bf.ReadString(128).TrimEnd('\0');
                chunkSet.ChunkSize   = bf.ReadInt32();

                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                chunkSet.ChunkData = bf.ReadBytes(0, chunkSet.ChunkSize, BinaryFile.ByteOrder.LittleEndian);

                // read the xml chunk into memory
                try
                {
                    if (chunkSet.ChunkData != null)
                    {
                        var xmlDocument   = new XmlDocument();
                        var chunkAsString = Encoding.UTF8.GetString(chunkSet.ChunkData);
                        xmlDocument.LoadXml(chunkAsString);
                        fxp.XmlDocument = xmlDocument;
                    }
                }
                catch (XmlException)
                {
                }

                fxp.Content = chunkSet;
            }
            else if (FxMagic == "FPCh")
            {
                // Preset (Program) (.fxp) with chunk (magic = 'FPCh')
                var programSet = new FxProgramSet();
                programSet.ChunkMagic = ChunkMagic;
                programSet.ByteSize   = ByteSize;
                programSet.FxMagic    = FxMagic;

                programSet.Version   = bf.ReadInt32();
                programSet.FxID      = bf.ReadString(4);
                programSet.FxVersion = bf.ReadInt32();

                programSet.NumPrograms = bf.ReadInt32();
                programSet.Name        = bf.ReadString(28).TrimEnd('\0');
                programSet.ChunkSize   = bf.ReadInt32();

                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                programSet.ChunkData = bf.ReadBytes(0, programSet.ChunkSize, BinaryFile.ByteOrder.LittleEndian);

                // read the xml chunk into memory
                try
                {
                    if (programSet.ChunkData != null)
                    {
                        var xmlDocument   = new XmlDocument();
                        var chunkAsString = Encoding.UTF8.GetString(programSet.ChunkData);
                        xmlDocument.LoadXml(chunkAsString);
                        fxp.XmlDocument = xmlDocument;
                    }
                }
                catch (XmlException)
                {
                }

                fxp.Content = programSet;
            }
            else if (FxMagic == "FxCk")
            {
                // For Preset (Program) (.fxp) without chunk (magic = 'FxCk')
                var program = new FxProgram();
                program.ChunkMagic = ChunkMagic;
                program.ByteSize   = ByteSize;
                program.FxMagic    = FxMagic;

                program.Version   = bf.ReadInt32();
                program.FxID      = bf.ReadString(4);
                program.FxVersion = bf.ReadInt32();

                program.NumParameters = bf.ReadInt32();
                program.ProgramName   = bf.ReadString(28).TrimEnd('\0');

                // variable no. of parameters
                program.Parameters = new float[program.NumParameters];
                for (int i = 0; i < program.NumParameters; i++)
                {
                    program.Parameters[i] = bf.ReadSingle();
                }

                fxp.Content = program;
            }
            else if (FxMagic == "FxBk")
            {
                // For bank (.fxb) without chunk (magic = 'FxBk')
                var set = new FxSet();
                set.ChunkMagic = ChunkMagic;
                set.ByteSize   = ByteSize;
                set.FxMagic    = FxMagic;

                set.Version   = bf.ReadInt32();
                set.FxID      = bf.ReadString(4);
                set.FxVersion = bf.ReadInt32();

                set.NumPrograms = bf.ReadInt32();
                set.Future      = bf.ReadString(128).TrimEnd('\0');

                // variable no. of programs
                set.Programs = new FxProgram[set.NumPrograms];
                for (int p = 0; p < set.NumPrograms; p++)
                {
                    var content = ReadFXP(bf).Content;
                    if (content is FxProgram)
                    {
                        set.Programs[p] = (FxProgram)content;
                    }
                }

                fxp.Content = set;
            }

            return(fxp);
        }
Esempio n. 6
0
        public void SaveFXP(string filePath)
        {
            bool UseChunk = false;
            if ((PluginContext.PluginInfo.Flags & VstPluginFlags.ProgramChunks) == 0) {
                // Chunks not supported.
                UseChunk = false;
            } else {
                // Chunks supported.
                UseChunk = true;
            }

            FXP fxp = new FXP();
            fxp.ChunkMagic = "CcnK";
            fxp.ByteSize = 0; // will be set correctly by FXP class

            if (UseChunk) {
                // Preset (Program) (.fxp) with chunk (magic = 'FPCh')
                fxp.FxMagic = "FPCh"; // FPCh = FXP (preset), FBCh = FXB (bank)
                fxp.Version = 1; // Format Version (should be 1)
                fxp.FxID = PluginIDNumberToIDString(PluginContext.PluginInfo.PluginID);
                fxp.FxVersion = PluginContext.PluginInfo.PluginVersion;
                fxp.ProgramCount = PluginContext.PluginInfo.ProgramCount;
                fxp.Name = PluginContext.PluginCommandStub.GetProgramName();

                byte[] chunkData = PluginContext.PluginCommandStub.GetChunk(true);
                fxp.ChunkSize = chunkData.Length;
                fxp.ChunkDataByteArray = chunkData;
            } else {
                // Preset (Program) (.fxp) without chunk (magic = 'FxCk')
                fxp.FxMagic = "FxCk"; // FxCk = FXP (preset), FxBk = FXB (bank)
                fxp.Version = 1; // Format Version (should be 1)
                fxp.FxID = PluginIDNumberToIDString(PluginContext.PluginInfo.PluginID);
                fxp.FxVersion = PluginContext.PluginInfo.PluginVersion;
                fxp.ParameterCount = PluginContext.PluginInfo.ParameterCount;
                fxp.Name = PluginContext.PluginCommandStub.GetProgramName();

                // variable no. of parameters
                float[] parameters = new float[fxp.ParameterCount];
                for (int i = 0; i < fxp.ParameterCount; i++) {
                    parameters[i] = PluginContext.PluginCommandStub.GetParameter(i);
                }
                fxp.Parameters = parameters;
            }
            fxp.WriteFile(filePath);
        }
Esempio n. 7
0
        public void LoadFXP(string filePath)
        {
            if (filePath == null || filePath == "") {
                return;
            }
            // How does the GetChunk/SetChunk interface work? What information should be in those chunks?
            // How does the BeginLoadProgram and BeginLoadBank work?
            // There doesn't seem to be any restriction on what data is put in the chunks.
            // The beginLoadBank/Program methods are also part of the persistence call sequence.
            // GetChunk returns a buffer with program information of either the current/active program
            // or all programs.
            // SetChunk should read this information back in and initialize either the current/active program
            // or all programs.
            // Before SetChunk is called, the beginLoadBank/Program method is called
            // passing information on the version of the plugin that wrote the data.
            // This will allow you to support older data versions of your plugin's data or
            // even support reading other plugin's data.
            // Some hosts will call GetChunk before calling beginLoadBakn/Program and SetChunk.
            // This is an optimazation of the host to determine if the information to load is
            // actually different than the state your plugin program(s) (are) in.

            bool UseChunk = false;
            if ((PluginContext.PluginInfo.Flags & VstPluginFlags.ProgramChunks) == 0) {
                // Chunks not supported.
                UseChunk = false;
            } else {
                // Chunks supported.
                UseChunk = true;
            }

            FXP fxp = new FXP();
            fxp.ReadFile(filePath);
            if (fxp.ChunkMagic != "CcnK") {
                // not a fxp or fxb file
                Console.Out.WriteLine("Error - Cannot Load. Loaded preset is not a fxp or fxb file");
                return;
            }

            int pluginUniqueID = PluginIDStringToIDNumber(fxp.FxID);
            int currentPluginID = PluginContext.PluginInfo.PluginID;
            if (pluginUniqueID != currentPluginID) {
                Console.Out.WriteLine("Error - Cannot Load. Loaded preset has another ID!");
            } else {
                // Preset (Program) (.fxp) with chunk (magic = 'FPCh')
                // Bank (.fxb) with chunk (magic = 'FBCh')
                if (fxp.FxMagic == "FPCh" || fxp.FxMagic == "FBCh") {
                    UseChunk = true;
                } else {
                    UseChunk = false;
                }
                if (UseChunk) {
                    // If your plug-in is configured to use chunks
                    // the Host will ask for a block of memory describing the current
                    // plug-in state for saving.
                    // To restore the state at a later stage, the same data is passed
                    // back to setChunk.
                    byte[] chunkData = fxp.ChunkDataByteArray;
                    bool beginSetProgramResult = PluginContext.PluginCommandStub.BeginSetProgram();
                    int iResult = PluginContext.PluginCommandStub.SetChunk(chunkData, true);
                    bool endSetProgramResult = PluginContext.PluginCommandStub.EndSetProgram();
                } else {
                    // Alternatively, when not using chunk, the Host will simply
                    // save all parameter values.
                    float[] parameters = fxp.Parameters;
                    bool beginSetProgramResult = PluginContext.PluginCommandStub.BeginSetProgram();
                    for (int i = 0; i < parameters.Length; i++) {
                        PluginContext.PluginCommandStub.SetParameter(i, parameters[i]);
                    }
                    bool endSetProgramResult = PluginContext.PluginCommandStub.EndSetProgram();
                }
            }
        }