Beispiel #1
0
        /// <summary>
        /// DPI1 chunk consists of:
        /// - DPN1  size x01D8
        /// - DPD1  size x1CCC contains drum pattern names + other (see documentation).
        /// - DPS1  size x4F4B8 containing
        ///   - multiple DPV1 0x17C00 probably containing the drum kit sequences
        /// </summary>
        private void ReadDpi1Chunk(int chunkSize)
        {
            CurrentPcgMemory.Chunks.Collection.Add(new Chunk("DPI1", Index, chunkSize));

            // Goto DPN1.
            Index += 12; // Skip DPI1 header.
            Debug.Assert(Util.GetChars(CurrentPcgMemory.Content, Index, 4) == "DPN1");

            Index += Util.GetInt(CurrentPcgMemory.Content, Index + 4, 4) + 12; // Skip DPN1

            Debug.Assert(Util.GetChars(CurrentPcgMemory.Content, Index, 4) == "DPD1");
            Index += 4;
            int dpd1ChunkSize = Util.GetInt(CurrentPcgMemory.Content, Index, 4);

            Index += 8; // Skip DPD1 header

            int sizeOfADrumPattern         = Util.GetInt(CurrentPcgMemory.Content, Index + 4, 4);
            int numberOfDrumPatternsInBank = dpd1ChunkSize / sizeOfADrumPattern;

            Debug.Assert(Util.GetInt(CurrentPcgMemory.Content, Index, 4) == numberOfDrumPatternsInBank);
            // ReSharper disable RedundantStringFormatCall
            Console.WriteLine($" Size of a drumpattern: {sizeOfADrumPattern}");
            // ReSharper restore RedundantStringFormatCall
            int bankId    = 1; // User bank
            int bankIndex = DrumPatternBankId2DrumPatternIndex(bankId);

            DrumPatternBank drumPatternBank = (DrumPatternBank)CurrentPcgMemory.DrumPatternBanks[bankIndex];

            drumPatternBank.ByteOffset = Index + 12;
            drumPatternBank.PatchSize  = sizeOfADrumPattern;
            drumPatternBank.IsWritable = true;
            drumPatternBank.IsLoaded   = true;

            Index += 12; // Goto first pattern data
            int index = 0;

            for (index = 0; index < numberOfDrumPatternsInBank; index++)
            {
                // Place in PcgMemory.
                DrumPattern drumPattern = (DrumPattern)drumPatternBank[index];
                drumPattern.ByteOffset = Index;
                drumPattern.ByteLength = sizeOfADrumPattern;
                drumPattern.IsLoaded   = true;

                Index += sizeOfADrumPattern;
            }

            // Clear all remaining (unexisting) patches.
            while (index < drumPatternBank.CountPatches)
            {
                drumPatternBank.Patches.RemoveAt(index);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="drumPatternBank"></param>
 /// <param name="index"></param>
 public MDrumPattern(DrumPatternBank drumPatternBank, int index)
     : base(drumPatternBank, index)
 {
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="drumPatternBank"></param>
 /// <param name="index"></param>
 public KronosDrumPattern(DrumPatternBank drumPatternBank, int index)
     : base(drumPatternBank, index)
 {
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="drumPatternBank"></param>
 /// <param name="index"></param>
 public NautilusDrumPattern(DrumPatternBank drumPatternBank, int index)
     : base(drumPatternBank, index)
 {
 }
        /// <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);
            }
        }