protected async Task GetPresetsUsingFullBank(PresetBank bank, int start, int numPresets, string sourceFile) { if (start < 0) { Logger.Error("GetPresets start index is less than 0, ignoring. This is probably a bug or a " + "misconfiguration. Please report this including the full log file."); return; } var endIndex = start + numPresets; if (endIndex > PluginInstance.Plugin.PluginInfo.ProgramCount) { Logger.Error( $"Tried to retrieve presets between the index {start} and {endIndex}, but this would exceed maximum " + $"program count of {PluginInstance.Plugin.PluginInfo.ProgramCount}, ignoring. You might wish to " + "report this as a bug."); return; } for (var index = start; index < endIndex; index++) { PluginInstance.SetProgram(index); var preset = new PresetParserMetadata { PresetName = PluginInstance.GetCurrentProgramName(), BankPath = bank.BankPath, SourceFile = sourceFile + ":" + index, Plugin = PluginInstance.Plugin }; await DataPersistence.PersistPreset(preset, PluginInstance.GetChunk(false)); } }
public void RefreshChunks() { var bankChunk = PluginInstance.GetChunk(false); if (!(bankChunk is null)) { ChunkBankMemoryStream.SetLength(0); ChunkBankMemoryStream.Write(bankChunk, 0, bankChunk.Length); ChunkBankHash = HashUtils.getIxxHash(bankChunk); BankChunkChanged?.Invoke(this, EventArgs.Empty); } var presetChunk = PluginInstance.GetChunk(true); if (!(presetChunk is null)) { ChunkPresetMemoryStream.SetLength(0); ChunkPresetMemoryStream.Write(presetChunk, 0, presetChunk.Length); ChunkPresetHash = HashUtils.getIxxHash(presetChunk); PresetChunkChanged?.Invoke(this, EventArgs.Empty); } }
/** * Checks if the chunks are null */ public bool AreChunksNull(bool isPreset) { Logger.Debug(isPreset ? $"{PluginInstance.Plugin.PluginName}: checking if bank chunks are null" : $"{PluginInstance.Plugin.PluginName}: checking if program chunks are null"); PluginInstance.SetProgram(0); var chunk = PluginInstance.GetChunk(isPreset); return(chunk == null); }
/** * Checks if the current program number is stored in the bank chunk. Some VSTs do it (like V-Station), * others don't (which should be the norm). * * Interpret the return value "true" as "uncertain" */ public bool IsCurrentProgramStoredInBankChunk() { PluginInstance.SetProgram(0); var firstHash = HashUtils.getIxxHash(PluginInstance.GetChunk(false)); PluginInstance.SetProgram(1); var secondHash = HashUtils.getIxxHash(PluginInstance.GetChunk(false)); if (firstHash != secondHash) { return(true); } return(false); }
protected override byte[] ProcessFile(string fileName, PresetParserMetadata preset) { var xmlPreset = XDocument.Load(fileName); var chunk = PluginInstance.GetChunk(false); var chunkXml = Encoding.UTF8.GetString(chunk); var actualPresetDocument = XDocument.Parse(chunkXml); RetrievePresetData(xmlPreset, preset); MigrateData(xmlPreset, actualPresetDocument, preset); var builder = new StringBuilder(); using (TextWriter writer = new StringWriter(builder)) { actualPresetDocument.Save(writer); return(Encoding.UTF8.GetBytes(builder.ToString())); } }
/** * Checks if the full bank presets are consistent. The full bank chunk should not change for the same program. * * We check it 10 times to see if the hashes are consistent. If they're not, the plugin most likely stores some * runtime data (like LFO state). * */ public bool AreChunksConsistent(bool isPreset) { Logger.Debug(isPreset ? $"{PluginInstance.Plugin.PluginName}: checking if bank chunks are consistent" : $"{PluginInstance.Plugin.PluginName}: checking if program chunks are consistent"); PluginInstance.SetProgram(0); var chunk = PluginInstance.GetChunk(isPreset); if (chunk == null) { return(false); } var firstPresetHash = HashUtils.getIxxHash(chunk); Logger.Debug(PluginInstance.Plugin.PluginName + ": hash for program 0 is " + firstPresetHash); for (var i = 0; i < 10; i++) { PluginInstance.SetProgram(0); chunk = PluginInstance.GetChunk(isPreset); if (chunk == null) { return(false); } if (firstPresetHash != HashUtils.getIxxHash(chunk)) { return(false); } } return(true); }
protected async Task GetPresetsUsingBankTrickery(PresetBank bank, int start, int numPresets, string sourceFile) { if (start < 0) { Logger.Error("GetPresets start index is less than 0, ignoring. This is probably a bug or a " + "misconfiguration. Please report this including the full log file."); return; } var endIndex = start + numPresets; if (endIndex > PluginInstance.Plugin.PluginInfo.ProgramCount) { Logger.Error( $"Tried to retrieve presets between the index {start} and {endIndex}, but this would exceed maximum " + $"program count of {PluginInstance.Plugin.PluginInfo.ProgramCount}, ignoring. You might wish to " + "report this as a bug."); return; } for (var index = start; index < endIndex; index++) { PluginInstance.SetProgram(0); PluginInstance.PerformIdleLoop(10); var programBackup = PluginInstance.GetChunk(true); PluginInstance.SetProgram(index); PluginInstance.PerformIdleLoop(10); var programName = PluginInstance.GetCurrentProgramName(); var fullSourceFile = sourceFile + ":" + index; var vstPreset = new PresetParserMetadata { SourceFile = fullSourceFile, BankPath = bank.BankPath, PresetName = programName, Plugin = PluginInstance.Plugin }; var realProgram = PluginInstance.GetChunk(true); PluginInstance.SetProgram(0); PluginInstance.PerformIdleLoop(10); PluginInstance.SetChunk(realProgram, true); PluginInstance.PerformIdleLoop(10); var presetData = PluginInstance.GetChunk(false); // Restore original program 0 PluginInstance.SetChunk(programBackup, true); PluginInstance.PerformIdleLoop(10); var hash = HashUtils.getIxxHash(presetData); if (PresetHashes.ContainsKey(hash)) { Logger.Warning( $"Skipping program {index} with name {programName} because a program with the same data " + $"was already added ({PresetHashes[hash]}. Please report this if you think if it's a bug."); } else { PresetHashes.Add(hash, fullSourceFile + " " + programName); await DataPersistence.PersistPreset(vstPreset, presetData); } } }