public SWD(string path) { using (var reader = new EndianBinaryReader(new MemoryStream(File.ReadAllBytes(path)))) { Type = reader.ReadString(4); Unknown = reader.ReadBytes(4); Length = reader.ReadUInt32(); Version = reader.ReadUInt16(); switch (Version) { case 0x402: { Header_V402 header = reader.ReadObject <Header_V402>(); Header = header; Programs = ReadPrograms <ProgramInfo_V402>(reader, header.NumPRGISlots); Samples = ReadSamples <WavInfo_V402>(reader, header.NumWAVISlots); break; } case 0x415: { Header_V415 header = reader.ReadObject <Header_V415>(); Header = header; Programs = ReadPrograms <ProgramInfo_V415>(reader, header.NumPRGISlots); if (header.PCMDLength != 0 && (header.PCMDLength & 0xFFFF0000) != 0xAAAA0000) { Samples = ReadSamples <WavInfo_V415>(reader, header.NumWAVISlots); } break; } default: throw new InvalidDataException(); } } }
/// <summary> /// /// </summary> /// <param name="filetype"></param> /// <param name="modelType"></param> public override void ReadContent(Memory.FileType filetype, Models.EModelType modelType) { Index = 0x60; ProgramBank programBank = (ProgramBank)CurrentPcgMemory.ProgramBanks[0]; const int numberOfProgramsInBank = 64; for (int bankIndex = 0; bankIndex < CurrentPcgMemory.ProgramBanks.BankCollection.Count; bankIndex++) { ProgramBank bank = (ProgramBank)(CurrentPcgMemory.ProgramBanks[bankIndex]); bank.ByteOffset = Index; bank.BankSynthesisType = ProgramBank.SynthesisType.Mmt; bank.PatchSize = 496; bank.IsWritable = true; bank.IsLoaded = true; for (int index = 0; index < numberOfProgramsInBank; index++) { // Place in PcgMemory. Program program = (Program)bank[index]; program.ByteOffset = Index; program.ByteLength = programBank.PatchSize; program.IsLoaded = true; // Skip to next. Index += 0x210; } } }
/// <summary> /// /// </summary> /// <param name="bankIndex"></param> /// <param name="nrOfPatches"></param> private void ReadAllPrograms(int bankIndex, int nrOfPatches) { if ((ContentType == PcgMemory.ContentType.All) || (ContentType == PcgMemory.ContentType.AllPrograms)) { // Read program data. ProgramBank bank = (ProgramBank)(CurrentPcgMemory.ProgramBanks[bankIndex]); bank.ByteOffset = Index; bank.BankSynthesisType = ProgramBank.SynthesisType.Ai; bank.PatchSize = 143; bank.IsWritable = true; bank.IsLoaded = true; for (int index = 0; index < nrOfPatches; index++) { // Place in PcgMemory. Program program = (Program)bank[index]; program.ByteOffset = Index; program.ByteLength = bank.PatchSize; program.IsLoaded = true; // Skip to next. Index += bank.PatchSize; } } }
protected void TestAll(string path) { KorgFileReader korgFileReader = new KorgFileReader(); _pcgMemory = (PcgMemory)korgFileReader.Read(DefaultDirectory + path); Debug.Assert(_pcgMemory != null); // Test set list generator. TestDefaultPatchList(); TestProgramUsageList(); TestDefaultCombiContentList(); TestDefaultFileContentList(); // Swap program (if there is more than one program). IProgramBanks programBanks = _pcgMemory.ProgramBanks; if (programBanks != null) { ProgramBank programBank = (ProgramBank)programBanks[0]; if (programBank.IsFilled && programBank.IsWritable && (programBank.CountPatches > 1)) { _pcgMemory.SwapPatch(programBank[0], programBank[1]); } } // Swap combi (if there is more than one combi). ICombiBanks combiBanks = _pcgMemory.CombiBanks; if (combiBanks != null) { CombiBank combiBank = (CombiBank)combiBanks[0]; if (combiBank.IsFilled && combiBank.IsWritable && (combiBank.CountPatches > 1)) { _pcgMemory.SwapPatch(combiBank[0], combiBank[1]); } } // Swap set list slot. ISetLists setLists = _pcgMemory.SetLists; if (setLists != null) { SetList setList0 = (SetList)setLists[0]; if (setList0.IsFilled && setList0.IsWritable) { _pcgMemory.SwapPatch((SetListSlot)(setList0[0]), (SetListSlot)(setList0[1])); } } // Test save. _pcgMemory.FileName = "E:\\test.pcg"; _pcgMemory.SaveFile(false, false); }
private void RunTest(CopyPaste.PatchDuplication patchNameSetting, string ignoreFragments, int sourceIndex, int destinationCompareIndex, bool patchNamesEqual, int destinationIndex, bool pasted) { SetUp(); Settings.Default.CopyPaste_OverwriteFilledPrograms = true; Settings.Default.CopyPaste_PatchDuplicationName = (int)patchNameSetting; Settings.Default.CopyPaste_IgnoreCharactersForPatchDuplication = ignoreFragments; IPatch program2 = ((ProgramBank)_pcgOs2.ProgramBanks["I-A"])[sourceIndex]; // I-A000 Kronos grand. CopyPasteCommands commands2 = new CopyPasteCommands(); ObservableCollectionEx <IPatch> patches = new ObservableCollectionEx <IPatch> { program2 }; PcgClipBoard clipBoard = new PcgClipBoard(); program2.IsSelected = true; commands2.CopyPasteCopy(clipBoard, _pcgOs2, PcgViewModel.ScopeSet.Patches, true, false, false, false, false, false, false, null, patches, false); ProgramBank icBank = (ProgramBank)_pcgOs3.ProgramBanks["I-C"]; if (patchNamesEqual) { Assert.AreEqual(program2.Name, icBank[destinationCompareIndex].Name); } IPatch program3 = icBank[destinationIndex]; ObservableCollectionEx <IPatch> patches3 = new ObservableCollectionEx <IPatch> { program3 }; program3.Clear(); program3.IsSelected = true; Assert.AreNotEqual(program2.Name, program3.Name); commands2.CopyPastePaste(clipBoard, _pcgOs3, PcgViewModel.ScopeSet.Patches, true, false, false, false, false, false, false, null, patches3); if (pasted) { Assert.AreEqual(program2.Name, program3.Name); } else { Assert.AreNotEqual(program2.Name, program3.Name); } }
/// <summary> /// /// </summary> /// <param name="programPatchSize"></param> /// <param name="bankIndex"></param> private void ReadProgramBank(int programPatchSize, int bankIndex) { ProgramBank bank = (ProgramBank)(CurrentPcgMemory.ProgramBanks[bankIndex]); if ((bank.Type != BankType.EType.Virtual) && (bank.Type != BankType.EType.Gm)) { bank.ByteOffset = Index; bank.PatchSize = programPatchSize; bank.IsLoaded = true; bank.IsWritable = true; ReadProgram(bank); } }
/// <summary> /// /// </summary> /// <param name="offset"></param> private void ReadSingleProgram(int offset) { ProgramBank bank = (ProgramBank)(CurrentPcgMemory.ProgramBanks[0]); bank.ByteOffset = 0; bank.BankSynthesisType = ProgramBank.SynthesisType.AnalogModeling; bank.PatchSize = 143; bank.IsWritable = true; bank.IsLoaded = true; Program program = (Program)bank[0]; program.ByteOffset = offset; program.ByteLength = bank.PatchSize; program.IsLoaded = true; }
/// <summary> /// /// </summary> /// <param name="filetype"></param> /// <param name="modelType"></param> public override void ReadContent(Memory.FileType filetype, Models.EModelType modelType) { ProgramBank bank = (ProgramBank)CurrentPcgMemory.ProgramBanks[0]; bank.ByteOffset = Index; bank.BankSynthesisType = ProgramBank.SynthesisType.Mmt; bank.PatchSize = 496; bank.IsWritable = true; bank.IsLoaded = true; // Place in PcgMemory. Program program = (Program)bank[0]; program.ByteOffset = 32; // Fixed program.ByteLength = bank.PatchSize; program.IsLoaded = true; }
/// <summary> /// For 'normal' EDS, HD1 like programs. /// Returns the bank index. /// </summary> private void ReadPbk1Chunk() { int chunkSize = Util.GetInt(CurrentPcgMemory.Content, Index + 4, 4); CurrentPcgMemory.Chunks.Collection.Add(new Chunk("PBK1", Index, chunkSize)); int startIndex = Index; Index += Pbk1NumberOfProgramsOffset; int numberOfProgramsInBank = Util.GetInt(CurrentPcgMemory.Content, Index, 4); Index += 4; int sizeOfAProgram = Util.GetInt(CurrentPcgMemory.Content, Index, 4); // ReSharper disable RedundantStringFormatCall Console.WriteLine($" Size of a program: {sizeOfAProgram}"); // ReSharper restore RedundantStringFormatCall Index += 4; int bankId = Util.GetInt(CurrentPcgMemory.Content, Index, 4); int bankIndex = ProgramBankId2ProgramIndex(bankId); Index += 4; ProgramBank programBank = (ProgramBank)CurrentPcgMemory.ProgramBanks[bankIndex]; programBank.ByteOffset = startIndex; programBank.PatchSize = sizeOfAProgram; programBank.BankSynthesisType = programBank.DefaultSampledSynthesisType; programBank.IsWritable = true; programBank.IsLoaded = true; for (int index = 0; index < numberOfProgramsInBank; index++) { // Place in PcgMemory. Program program = (Program)programBank[index]; program.ByteOffset = Index; program.ByteLength = sizeOfAProgram; program.IsLoaded = true; // Skip to next. Index += sizeOfAProgram; } }
/// <summary> /// /// </summary> /// <param name="programBank"></param> /// <param name="index"></param> public M3RProgram(ProgramBank programBank, int index) : base(programBank, index) { Id = $"{programBank.Id}{(index).ToString("00")}"; }
/// <summary> /// /// </summary> /// <param name="programBank"></param> /// <param name="index"></param> /// <param name="name"></param> public NautilusGmProgram(ProgramBank programBank, int index, string name) : base(programBank, index) { _name = name; Id = $"{programBank.Id}{UserIndex:000}"; }
/// <summary> /// /// </summary> /// <param name="filetype"></param> /// <param name="modelType"></param> public override void ReadContent(Memory.FileType filetype, Models.EModelType modelType) // Continue parsing. { KrossPcgMemory memory = (KrossPcgMemory)CurrentPcgMemory; const int headerSize = 32; // bytes switch (_contentType) { case PcgMemory.ContentType.All: { ReadAllCombis(memory, 0x20); ReadAllPrograms(memory, 0xf7a20); ReadAllDrumKits(memory, 0x246020); } break; case PcgMemory.ContentType.CurrentProgram: ReadSingleProgram(headerSize); // Is starting index memory.SynchronizeProgramName(); break; case PcgMemory.ContentType.ProgramBank: { ProgramBank firstBank = (ProgramBank)(memory.ProgramBanks[0]); int offset = headerSize; foreach (IPatch program in firstBank.Patches) { ReadSingleProgram(offset); offset += firstBank.PatchSize; } } break; case PcgMemory.ContentType.AllPrograms: ReadAllPrograms(memory, headerSize); break; case PcgMemory.ContentType.CurrentCombi: ReadSingleCombi(headerSize); // Is starting index memory.SynchronizeCombiName(); break; case PcgMemory.ContentType.CombiBank: { IBank firstBank = memory.CombiBanks[0]; int offset = headerSize; foreach (IPatch combi in firstBank.Patches) { ReadSingleCombi(offset); offset += firstBank.ByteLength; } } break; case PcgMemory.ContentType.AllCombis: ReadAllCombis(memory, headerSize); break; case PcgMemory.ContentType.AllDrumSound: case PcgMemory.ContentType.Drums: case PcgMemory.ContentType.ArpeggioPattern: case PcgMemory.ContentType.CurrentArpeggioPattern: case PcgMemory.ContentType.MultiSound: case PcgMemory.ContentType.Global: case PcgMemory.ContentType.AllSequence: case PcgMemory.ContentType.CurrentSequence: // Do not read anything. break; default: throw new NotSupportedException("Unsupported SysEx function"); } // Read global. if (_contentType == PcgMemory.ContentType.All) { memory.Global.ByteOffset = 0x338680 - 334; // 334 bytes before categories start. } else { memory.Global = null; } }
/// <summary> /// /// </summary> /// <param name="writer"></param> /// <param name="lines"></param> private void ParseItems(TextWriter writer, List <string> lines) { foreach (var bank in _list) { var bankType = string.Empty; var contentType = string.Empty; var bankId = string.Empty; var writablePatches = 0; var filledPatches = 0; var emptyPatches = 0; var filledPatchList = new List <IPatch>(); var bank1 = bank as ProgramBank; if (bank1 != null) { var programBank = bank1; bankType = "ProgramBank"; bankId = programBank.Id; contentType = $"{ProgramBank.SynthesisTypeAsString(programBank.BankSynthesisType)} {Strings.Programs}"; writablePatches = programBank.Patches.Count(program => programBank.IsWritable); filledPatches = programBank.CountFilledAndNonEmptyPatches; emptyPatches = writablePatches - filledPatches; filledPatchList.AddRange( programBank.Patches.Where(program => programBank.IsLoaded && !program.IsEmptyOrInit)); } else { var combiBank1 = bank as CombiBank; if (combiBank1 != null) { var combiBank = combiBank1; bankType = "CombiBank"; bankId = combiBank.Id; contentType = "Combis"; writablePatches = combiBank.Patches.Count(combi => combiBank.IsWritable); filledPatches = combiBank.CountFilledPatches; emptyPatches = writablePatches - filledPatches; var filledCombis = combiBank.Patches.Where(combi => combiBank.IsLoaded && !combi.IsEmptyOrInit); filledPatchList.AddRange(filledCombis); } else { var list = bank as SetList; if (list != null) { var setList = list; bankType = "SetList"; bankId = setList.Id; contentType = "SetListSlots"; writablePatches = setList.Patches.Count(setListSlot => setList.IsWritable); filledPatches = setList.CountFilledPatches; emptyPatches = writablePatches - filledPatches; filledPatchList.AddRange(setList.Patches.Where( setListSlot => setList.IsLoaded && !setListSlot.IsEmptyOrInit)); } else { var seqBank = bank as WaveSequenceBank; if (seqBank != null) { var waveSeqBank = seqBank; bankType = "WaveSeqBank"; bankId = waveSeqBank.Id; contentType = "WaveSequences"; writablePatches = waveSeqBank.Patches.Count(waveSeq => waveSeqBank.IsWritable); filledPatches = waveSeqBank.CountFilledPatches; emptyPatches = writablePatches - filledPatches; filledPatchList.AddRange(waveSeqBank.Patches.Where( waveSeq => waveSeqBank.IsLoaded && !waveSeq.IsEmptyOrInit)); } else { var kitBank = bank as DrumKitBank; if (kitBank != null) { var drumKitBank = kitBank; bankType = "DrumKitBank"; bankId = drumKitBank.Id; contentType = "DrumKits"; writablePatches = drumKitBank.Patches.Count(drumKit => drumKitBank.IsWritable); filledPatches = drumKitBank.CountFilledPatches; emptyPatches = writablePatches - filledPatches; filledPatchList.AddRange(drumKitBank.Patches.Where( drumKit => drumKitBank.IsLoaded && !drumKit.IsEmptyOrInit)); } else { var patternBank = bank as DrumPatternBank; if (patternBank != null) { var drumPatternBank = patternBank; bankType = "DrumPatternBank"; bankId = drumPatternBank.Id; contentType = "DrumPatterns"; writablePatches = drumPatternBank.Patches.Count( drumPattern => drumPatternBank.IsWritable); filledPatches = drumPatternBank.CountFilledPatches; emptyPatches = writablePatches - filledPatches; filledPatchList.AddRange(drumPatternBank.Patches.Where( drumPattern => drumPatternBank.IsLoaded && !drumPattern.IsEmptyOrInit)); } else { Debug.Fail("Error in switch"); } } } } } } WriteItem(writer, lines, bankType, contentType, bankId, writablePatches, filledPatches, emptyPatches, filledPatchList); } }
/// <summary> /// /// </summary> /// <param name="programBank"></param> /// <param name="index"></param> public KromeExProgram(ProgramBank programBank, int index) : base(programBank, index) { }
/// <summary> /// /// </summary> /// <param name="programBank"></param> /// <param name="index"></param> public M3RProgram(ProgramBank programBank, int index) : base(programBank, index) { Id = string.Format("{0}{1}", programBank.Id, (index).ToString("00")); }