Ejemplo n.º 1
0
        public static TapFile ReadTapFile(Stream inputStream, string fileName)
        {
            TapFile resultFile = new TapFile(fileName);

            using (BinaryReader fileReader = new BinaryReader(inputStream, Encoding.GetEncoding("ISO-8859-1")))
            {
                while (fileReader.PeekChar() >= 0)
                {
                    TapDataBlock dataBlock = ReadTapDataBlock(fileReader);
                    resultFile.DataBlocks.Add(dataBlock);

                    TapeSection section = new TapeSection(dataBlock);
                    resultFile.Sections.Add(section);
                }
            }
            TapeSection       lastSection       = resultFile.Sections[resultFile.Sections.Count - 1];
            TapeSoundSequence lastSoundSequence = lastSection.SoundSequences[lastSection.SoundSequences.Count - 1];

            if (lastSoundSequence.GetType() != typeof(PauseSequence))
            {
                lastSection.SoundSequences.Add(new PauseSequence("End of tape", 1));
            }

            foreach (TapeSection section in resultFile.Sections)
            {
                resultFile.Duration += section.Duration;
            }
            resultFile.Description = ""; // Tap file do not contain metadata

            return(resultFile);
        }
        public void Eject()
        {
            Stop();

            Tape = null;
            PlayingTime = 0;
            nextStateChangeCountdown = 0;
            currentSectionIndex = 0;
            currentSection = null;
            currentSoundSequenceIndex = 0;
            currentSoundSequence = null;
        }
        private void SetCurrentSoundSequence(int targetSoundSequenceIndex)
        {
            currentSoundSequenceIndex = targetSoundSequenceIndex;
            currentSoundSequence = currentSection.SoundSequences[currentSoundSequenceIndex];

            currentSoundSequence.ResetPosition();
            currentSoundSequence.GetNextState(ref SoundSignal.Level, out nextStateChangeCountdown);
        }
Ejemplo n.º 4
0
        public static TzxFile ReadTzxFile(Stream inputStream, string fileName)
        {
            TzxFile resultFile = new TzxFile(fileName);

            using (BinaryReader fileReader = new BinaryReader(inputStream, Encoding.GetEncoding("ISO-8859-1")))
            {
                string signature = Encoding.GetEncoding("ISO-8859-1").GetString(fileReader.ReadBytes(7));
                if (signature != "ZXTape!")
                {
                    throw new InvalidDataException("The signature of the file does not match the standard TZX file format");
                }
                else
                {
                    resultFile.Signature = signature;
                }

                resultFile.EndOfTextFileMarker = fileReader.ReadByte();
                resultFile.MajorRevisionNumber = fileReader.ReadByte();
                resultFile.MinorRevisionNumber = fileReader.ReadByte();

                TapeSection currentGroupSection = null;

                while (fileReader.PeekChar() >= 0)
                {
                    TzxDataBlock tzxBlock = ReadTzxDataBlock(fileReader);
                    resultFile.DataBlocks.Add(tzxBlock);

                    switch (tzxBlock.Type)
                    {
                    case TzxDataBlockType.StandardSpeedDataBlock:
                    case TzxDataBlockType.TurboSpeedDataBlock:
                    case TzxDataBlockType.PureTone:
                    case TzxDataBlockType.PulseSequence:
                    case TzxDataBlockType.PureDataBlock:
                    case TzxDataBlockType.DirectRecording:
                        TapeSection section = new TapeSection(tzxBlock);
                        if (currentGroupSection == null)
                        {
                            resultFile.Sections.Add(section);
                        }
                        else
                        {
                            foreach (TapeSoundSequence soundSequence in section.SoundSequences)
                            {
                                currentGroupSection.SoundSequences.Add(soundSequence);
                            }
                        }
                        break;

                    case TzxDataBlockType.PauseOrStopTheTape:
                        PauseOrStopTheTape pauseBlock = (PauseOrStopTheTape)tzxBlock;
                        if (pauseBlock.PauseInMs > 0)
                        {
                            section = new TapeSection(tzxBlock);
                            if (currentGroupSection == null)
                            {
                                resultFile.Sections.Add(section);
                            }
                            else
                            {
                                foreach (TapeSoundSequence soundSequence in section.SoundSequences)
                                {
                                    currentGroupSection.SoundSequences.Add(soundSequence);
                                }
                            }
                        }
                        break;

                    case TzxDataBlockType.TextDescription:
                        TextDescription descriptionBlock = (TextDescription)tzxBlock;
                        resultFile.Description += descriptionBlock.Text;
                        break;

                    case TzxDataBlockType.ArchiveInfo:
                        ArchiveInfo archiveInfo = (ArchiveInfo)tzxBlock;
                        resultFile.Description += archiveInfo.ToString();
                        break;

                    case TzxDataBlockType.GroupStart:
                        currentGroupSection = new TapeSection(tzxBlock);
                        break;

                    case TzxDataBlockType.GroupEnd:
                        foreach (TapeSoundSequence soundSequence in currentGroupSection.SoundSequences)
                        {
                            currentGroupSection.Duration += soundSequence.Duration;
                        }
                        resultFile.Sections.Add(currentGroupSection);
                        currentGroupSection = null;
                        break;
                    }
                }
            }
            TapeSection       lastSection       = resultFile.Sections[resultFile.Sections.Count - 1];
            TapeSoundSequence lastSoundSequence = lastSection.SoundSequences[lastSection.SoundSequences.Count - 1];

            if (lastSoundSequence.GetType() != typeof(PauseSequence))
            {
                lastSection.SoundSequences.Add(new PauseSequence("End of tape", 1));
            }

            foreach (TapeSection section in resultFile.Sections)
            {
                resultFile.Duration += section.Duration;
            }

            return(resultFile);
        }