/// <summary>
        ///
        /// </summary>
        /// <param name="bankIndex"></param>
        /// <param name="nrOfPatches"></param>
        private void ReadAllCombis(int bankIndex, int nrOfPatches)
        {
            if ((ContentType == PcgMemory.ContentType.All) ||
                (ContentType == PcgMemory.ContentType.AllCombis))
            {
                // Read combi data.
                CombiBank bank = (CombiBank)(CurrentPcgMemory.CombiBanks[bankIndex]);
                bank.ByteOffset = Index;
                bank.PatchSize  = 124;
                bank.IsWritable = true;
                bank.IsLoaded   = true;

                for (int index = 0; index < nrOfPatches; index++)
                {
                    // Place in PcgMemory.
                    Combi combi = (Combi)bank[index];
                    combi.ByteOffset = Index;
                    combi.ByteLength = bank.PatchSize;
                    combi.IsLoaded   = true;

                    // Skip to next.
                    Index += bank.PatchSize;
                }

                // When virtual banks are used, here needs to be checked to stop reading combi banks.
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="banks"></param>
        private void ReadCombiBanks(int banks)
        {
            for (int index = 0; index < banks; index++)
            {
                // Normally the bank index should be 2 bytes, however, PRELOAD1.PCG's second bank at 0x2F3B4 has
                // value 0x0500.
                int unusedMsbBankIndex = Util.GetInt(CurrentPcgMemory.Content, _index, 1);
                Debug.Assert((unusedMsbBankIndex == 0x00) || (unusedMsbBankIndex == 0x05));
                _index += 1;

                int bankIndex = Util.GetInt(CurrentPcgMemory.Content, _index, 1);
                _index += 1;

                CombiBank bank = (CombiBank)CurrentPcgMemory.CombiBanks[bankIndex];
                // combiBank.PcgId =
                bank.ByteOffset = _index;
                bank.PatchSize  = CombiSize;
                bank.IsWritable = true;
                bank.IsLoaded   = true;

                for (int patchIndex = 0; patchIndex < 128; patchIndex++)
                {
                    // Place in PcgMemory.
                    Combi combi = (Combi)bank[patchIndex];
                    combi.ByteOffset = _index;
                    combi.ByteLength = bank.PatchSize;
                    combi.IsLoaded   = true;

                    _index += bank.PatchSize;
                }
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="combiPatchSize"></param>
        /// <param name="startCombiBank"></param>
        private void ReadCombis(int combiPatchSize, int startCombiBank)
        {
            if ((ContentType == PcgMemory.ContentType.All) ||
                (ContentType == PcgMemory.ContentType.AllCombis))
            {
                // Read combi data.
                CombiBank combiBank = (CombiBank)CurrentPcgMemory.CombiBanks[0];

                for (int bankIndex = startCombiBank; bankIndex < CurrentPcgMemory.CombiBanks.BankCollection.Count;
                     bankIndex++)
                {
                    ICombiBank bank = (ICombiBank)(CurrentPcgMemory.CombiBanks[bankIndex]);
                    if (bank.Type != BankType.EType.Virtual)
                    {
                        bank.ByteOffset = Index;
                        bank.ByteLength = combiPatchSize;
                        bank.IsWritable = true;
                        bank.IsLoaded   = true;

                        foreach (IPatch combi in bank.Patches)
                        {
                            combi.ByteOffset = Index;
                            combi.ByteLength = combiBank.PatchSize;
                            combi.IsLoaded   = true;

                            // Skip to next.
                            Index += bank.ByteLength;
                        }
                    }

                    // When virtual banks are used, here needs to be checked to stop reading combi banks.
                }
            }
        }
示例#4
0
        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);
        }
示例#5
0
        /// <summary>
        /// Returns bank index.
        /// </summary>
        /// <returns></returns>
        private void ReadCbk1Chunk()
        {
            int chunkSize = Util.GetInt(CurrentPcgMemory.Content, Index + 4, 4);

            CurrentPcgMemory.Chunks.Collection.Add(new Chunk("CBK1", Index, chunkSize));

            int startIndex = Index;

            Index += Cbk1NumberOfCombisOffset;
            int numberOfCombisInBank = Util.GetInt(CurrentPcgMemory.Content, Index, 4);

            Index += 4;
            int sizeOfACombi = Util.GetInt(CurrentPcgMemory.Content, Index, 4);

// ReSharper disable RedundantStringFormatCall
            Console.WriteLine($" Size of a combi: {sizeOfACombi}");
// ReSharper restore RedundantStringFormatCall
            Index += 4;
            int bankId    = Util.GetInt(CurrentPcgMemory.Content, Index, 4);
            int bankIndex = CombiBankId2CombiIndex(bankId);

            Index += 4;

            CombiBank combiBank = (CombiBank)CurrentPcgMemory.CombiBanks[bankIndex];

            combiBank.ByteOffset = startIndex;
            combiBank.PatchSize  = sizeOfACombi;
            combiBank.IsWritable = true;
            combiBank.IsLoaded   = true;

            for (int index = 0; index < numberOfCombisInBank; index++)
            {
                // Place in PcgMemory.
                Combi combi = (Combi)combiBank[index];
                combi.ByteOffset = Index;
                combi.ByteLength = sizeOfACombi;
                combi.IsLoaded   = true;

                combi.Timbres.ByteOffset = combi.ByteOffset + TimbresByteOffset;

                foreach (ITimbre timbre in combi.Timbres.TimbresCollection)
                {
                    timbre.ByteOffset = combi.Timbres.ByteOffset + timbre.Index * timbre.TimbresSize;
                }

                // Skip to next.
                //for (int timbre = 0; timbre < 8; timbre++)
                //    Console.WriteLine(String.Format("Combi id {0}, timbre index  {1} bank {2} program {3}, offset {4:x}",
                //        combi.Id, combi.Timbres[timbre].Index,
                //        combi.Timbres[timbre].UsedProgramBank.Id, combi.Timbres[timbre].UsedProgram.Id,
                //        combi.ByteOffset));
                Index += sizeOfACombi;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="combiBank"></param>
        /// <param name="bank"></param>
        private void ReadCombi(CombiBank combiBank, CombiBank bank)
        {
            foreach (IPatch combi in bank.Patches)
            {
                combi.ByteOffset = Index;
                combi.ByteLength = combiBank.PatchSize;
                combi.IsLoaded   = true;

                // Skip to next.
                Index += bank.PatchSize;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="combiPatchSize"></param>
        /// <param name="bankIndex"></param>
        /// <param name="combiBank"></param>
        private void ReadCombiBank(int combiPatchSize, int bankIndex, CombiBank combiBank)
        {
            CombiBank bank = (CombiBank)(CurrentPcgMemory.CombiBanks[bankIndex]);

            if (bank.Type != BankType.EType.Virtual)
            {
                bank.ByteOffset = Index;
                bank.PatchSize  = combiPatchSize;
                bank.IsLoaded   = true;
                bank.IsWritable = true;

                ReadCombi(combiBank, bank);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="offset"></param>
        private void ReadSingleCombi(int offset)
        {
            CombiBank bank = (CombiBank)(CurrentPcgMemory.CombiBanks[0]);

            bank.ByteOffset = 0;
            bank.PatchSize  = 124;
            bank.IsWritable = true;
            bank.IsLoaded   = true;

            Combi combi = (Combi)bank[0];

            combi.ByteOffset = offset;
            combi.ByteLength = bank.PatchSize;
            combi.IsLoaded   = true;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="combiPatchSize"></param>
        /// <param name="startCombiBank"></param>
        private void ReadCombis(int combiPatchSize, int startCombiBank)
        {
            if ((ContentType == PcgMemory.ContentType.All) ||
                (ContentType == PcgMemory.ContentType.AllCombis))
            {
                // Read combi data.
                CombiBank combiBank = (CombiBank)CurrentPcgMemory.CombiBanks[0];

                for (int bankIndex = startCombiBank; bankIndex < CurrentPcgMemory.CombiBanks.BankCollection.Count; bankIndex++)
                {
                    ReadCombiBank(combiPatchSize, bankIndex, combiBank);

                    // When virtual banks are used, here needs to be checked to stop reading combi banks.
                }
            }
        }
示例#10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="combiBank"></param>
 /// <param name="index"></param>
 public NautilusCombi(CombiBank combiBank, int index)
     : base(combiBank, index)
 {
     Timbres = new NautilusTimbres(this);
 }
示例#11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="combiBank"></param>
 /// <param name="index"></param>
 public KronosCombi(CombiBank combiBank, int index)
     : base(combiBank, index)
 {
     Timbres = new KronosTimbres(this);
 }
示例#12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="combiBank"></param>
 /// <param name="index"></param>
 public M1Combi(CombiBank combiBank, int index)
     : base(combiBank, index)
 {
     Id      = $"{combiBank.Id}{(index).ToString("00")}";
     Timbres = new M1Timbres(this);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="lines"></param>
        private void ParseItems(TextWriter writer, List <string> lines)
        {
            foreach (IBank bank in _list)
            {
                string        bankType        = string.Empty;
                string        contentType     = string.Empty;
                string        bankId          = string.Empty;
                int           writablePatches = 0;
                int           filledPatches   = 0;
                int           emptyPatches    = 0;
                List <IPatch> filledPatchList = new List <IPatch>();

                ProgramBank bank1 = bank as ProgramBank;
                if (bank1 != null)
                {
                    ProgramBank 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
                {
                    CombiBank combiBank1 = bank as CombiBank;
                    if (combiBank1 != null)
                    {
                        CombiBank combiBank = combiBank1;

                        bankType        = "CombiBank";
                        bankId          = combiBank.Id;
                        contentType     = "Combis";
                        writablePatches = combiBank.Patches.Count(combi => combiBank.IsWritable);
                        filledPatches   = combiBank.CountFilledPatches;
                        emptyPatches    = writablePatches - filledPatches;

                        IEnumerable <IPatch> filledCombis = combiBank.Patches.Where(combi => combiBank.IsLoaded && !combi.IsEmptyOrInit);
                        filledPatchList.AddRange(filledCombis);
                    }
                    else
                    {
                        SetList list = bank as SetList;
                        if (list != null)
                        {
                            SetList 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
                        {
                            WaveSequenceBank seqBank = bank as WaveSequenceBank;
                            if (seqBank != null)
                            {
                                WaveSequenceBank 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
                            {
                                DrumKitBank kitBank = bank as DrumKitBank;
                                if (kitBank != null)
                                {
                                    DrumKitBank 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
                                {
                                    DrumPatternBank patternBank = bank as DrumPatternBank;
                                    if (patternBank != null)
                                    {
                                        DrumPatternBank 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);
            }
        }