Exemple #1
0
        public void SeveralNtFiles()
        {
            var StartAddresss = new ulong[] { expectedStartAddress, anotherExpectedStartAddress };
            var offsets       = new ulong[] { expectedOffset, expectedOffset };
            var EndAddresss   = new ulong[] { expectedEndAddress, anotherExpectedEndAddress };
            var names         = new string[] { expectedName, anotherExpectedName };

            var ntFiles   = TestData.GetNtFileSectionsBytes(StartAddresss, EndAddresss, offsets, names);
            var noteBytes =
                TestData.GetNoteSectionBytes(NoteSection.CoreName, NoteSection.NtFileType, ntFiles);

            var fileReader = new BinaryReader(new MemoryStream(noteBytes));
            var sections   = NoteSection.ReadModuleSections(fileReader, ntFiles.Length).ToArray();

            Assert.AreEqual(2, sections.Length);

            var first = sections.First();

            Assert.AreEqual(expectedEndAddress, first.EndAddress);
            Assert.AreEqual(expectedStartAddress, first.StartAddress);
            Assert.AreEqual(expectedName, first.Path);

            var last = sections.Last();

            Assert.AreEqual(anotherExpectedEndAddress, last.EndAddress);
            Assert.AreEqual(anotherExpectedStartAddress, last.StartAddress);
            Assert.AreEqual(anotherExpectedName, last.Path);
        }
Exemple #2
0
        public void AddSection(NoteSection section, int left)
        {
            var notesInSection = new List <NoteViewModel>();

            foreach (var note in section.AllNotes.OrderBy(x => x.Id))
            {
                var currentNoteY = NotesIndexInClef(note);
                var newNote      = CreateNoteAtIndex(note, left, currentNoteY);
                _createdNotes.Add(newNote);
                notesInSection.Add(newNote);
            }

            if (notesInSection.Count > 1)
            {
                var chord = new ChordSection(notesInSection);
                Sections.Add(chord);
                CorrectPositionsOfChordNotes(chord);
            }
            else
            {
                Sections.Add(new NoteSection(notesInSection));
            }

            AddLedgerLines(Sections.Last(), left);
            AddNoteStems(Sections.Last());
        }
Exemple #3
0
        public void EmptyStreamCoreFiles()
        {
            var emptyReader = new BinaryReader(new MemoryStream());
            var sections    = NoteSection.ReadModuleSections(emptyReader, 1).ToArray();

            Assert.AreEqual(0, sections.Length);
        }
Exemple #4
0
 public PlayingNoteViewModel(NoteSection x)
     : base()
 {
     this.x       = x;
     TopLedger    = x.TopLedger;
     BottomLedger = x.BottomLedger;
     AllNotes     = x.Notes.Select(theNote => theNote.Note).ToList();
 }
Exemple #5
0
        private Section <T> GetSectionFromSectionHeader(SectionHeader header)
        {
            Section <T> returned;

            switch (header.Type)
            {
            case SectionType.Null:
                goto default;

            case SectionType.ProgBits:
                returned = new ProgBitsSection <T>(header, readerSource);
                break;

            case SectionType.SymbolTable:
                returned = new SymbolTable <T>(
                    header,
                    readerSource,
                    objectsStringTable,
                    this
                    );
                break;

            case SectionType.StringTable:
                returned = new StringTable <T>(header, readerSource);
                break;

            case SectionType.RelocationAddends:
                goto default;

            case SectionType.HashTable:
                goto default;

            case SectionType.Dynamic:
                goto default;

            case SectionType.Note:
                returned = new NoteSection <T>(header, Class, readerSource);
                break;

            case SectionType.NoBits:
                goto default;

            case SectionType.Relocation:
                goto default;

            case SectionType.Shlib:
                goto default;

            case SectionType.DynamicSymbolTable:
                returned = new SymbolTable <T>(header, readerSource, objectsStringTable, this);
                break;

            default:
                returned = new Section <T>(header, readerSource);
                break;
            }
            return(returned);
        }
Exemple #6
0
        public void ShortNoteStream()
        {
            var minNote        = TestData.GetNoteSectionBytes("", 0, new byte[0]);
            var notEnoughBytes = minNote.Skip(1).ToArray();
            var emptyReader    = new BinaryReader(new MemoryStream(notEnoughBytes));
            var sections       = NoteSection.ReadModuleSections(emptyReader, minNote.Length).ToArray();

            Assert.AreEqual(0, sections.Length);
        }
Exemple #7
0
        public static List <NoteSection> CreateEmpty(int len)
        {
            var section = new NoteSection();
            var notes   = new List <Note>();

            notes.AddRange(Enumerable.Repeat(new Note(), Notes.BassNotes.Count));

            return(Enumerable.Repeat(section, len).ToList());
        }
Exemple #8
0
        public void WrongIdNoteType()
        {
            var noteBytes = TestData.GetNoteSectionBytes(
                NoteSection.GnuName, NoteSection.NtFileType, TestData.expectedId.Bytes.ToArray());

            var reader  = new BinaryReader(new MemoryStream(noteBytes));
            var buildId = NoteSection.ReadBuildId(reader, noteBytes.Length);

            Assert.AreEqual(BuildId.Empty, buildId);
        }
Exemple #9
0
        public void WrongNtFileType()
        {
            var ntFile    = GetExpectedNtFileBytes();
            var noteBytes = TestData.GetNoteSectionBytes(NoteSection.CoreName, 0, ntFile);

            var fileReader = new BinaryReader(new MemoryStream(noteBytes));
            var sections   = NoteSection.ReadModuleSections(fileReader, ntFile.Length).ToArray();

            Assert.AreEqual(0, sections.Length);
        }
Exemple #10
0
 private void AddLedgerLines(NoteSection section, int xoffset)
 {
     CreateTrailingLinesForSection(section)
     .ForEach(note => NotesInLedger.Add(
                  new NoteViewModel(note.Note)
     {
         X = xoffset,
         Y = NoteHeight * NotesIndexInClef(note.Note)
     })
              );
 }
Exemple #11
0
 public static NoteSectionDTO ConvertToDTO(this NoteSection noteSection)
 {
     return(new NoteSectionDTO
     {
         Id = noteSection.Id,
         SectionColor = noteSection.SectionColor,
         SectionName = noteSection.SectionName,
         EntityStateDTO = ConvertState(noteSection.EntityState),
         IsActive = noteSection.IsActive,
     });
 }
Exemple #12
0
        private int CalculateWidth(NoteSection x)
        {
            int noteDist = (int)(NoteWidth * 1.5);

            if (x.Notes == null)
            {
                return(noteDist);
            }

            return(x.Notes.Any(note => note.Note.IsSharp || note.Note.IsFlat) ||
                   x as ChordSection != null && (x as ChordSection).HasInterval(ChordSection.Interval.Second, ActiveClef) ? noteDist * 2 : noteDist);
        }
Exemple #13
0
        private List <NoteViewModel> CreateTrailingLinesForSection(NoteSection noteSection)
        {
            if (noteSection.Notes.Count <= 0)
            {
                return(new List <NoteViewModel>());
            }

            var linesToFill = new List <NoteViewModel>();

            linesToFill.AddRange(Notes.GetNotesInLedger(noteSection.HighestNote, ActiveClef).Select(x => new NoteViewModel(x)));
            linesToFill.AddRange(Notes.GetNotesInLedger(noteSection.LowestNote, ActiveClef).Select(x => new NoteViewModel(x)));

            return(linesToFill);
        }
Exemple #14
0
        public void CorrectNtFileNote()
        {
            var ntFile    = GetExpectedNtFileBytes();
            var noteBytes =
                TestData.GetNoteSectionBytes(NoteSection.CoreName, NoteSection.NtFileType, ntFile);

            var fileReader = new BinaryReader(new MemoryStream(noteBytes));
            var sections   = NoteSection.ReadModuleSections(fileReader, ntFile.Length).ToArray();

            Assert.AreEqual(1, sections.Length);

            var section = sections.First();

            Assert.AreEqual(expectedEndAddress, section.EndAddress);
            Assert.AreEqual(expectedStartAddress, section.StartAddress);
            Assert.AreEqual(expectedName, section.Path);
        }
Exemple #15
0
        public void NtFileWithSeveralLocations()
        {
            var StartAddresss = new ulong[] { expectedStartAddress + 1, expectedStartAddress };
            var offsets       = new ulong[] { expectedOffset + 1, expectedOffset };
            var EndAddresss   = new ulong[] { expectedEndAddress + 1, expectedEndAddress };
            var names         = new string[] { expectedName, expectedName };

            var ntFile = TestData.GetNtFileSectionsBytes(StartAddresss, EndAddresss, offsets,
                                                         names);
            var noteBytes =
                TestData.GetNoteSectionBytes(NoteSection.CoreName, NoteSection.NtFileType, ntFile);

            var fileReader = new BinaryReader(new MemoryStream(noteBytes));
            var sections   = NoteSection.ReadModuleSections(fileReader, ntFile.Length).ToArray();

            Assert.AreEqual(1, sections.Length);

            var section = sections.First();

            Assert.AreEqual(expectedEndAddress, section.EndAddress);
            Assert.AreEqual(expectedStartAddress, section.StartAddress);
            Assert.AreEqual(expectedName, section.Path);
        }
Exemple #16
0
        private void AddNoteStems(NoteSection section)
        {
            if (section is ChordSection)
            {
                AddNoteStems(section as ChordSection);
                return;
            }

            foreach (var note in section.Notes)
            {
                var octave   = note.Note;
                var relation = note.Note.RelationToMidpoint(ActiveClef);
                octave = relation != Relation.Lower ? note.Note.OctaveDown(ActiveClef) :
                         note.Note.OctaveUp(ActiveClef);

                if (Notes.IsOuterLedger(note.Note, ActiveClef))
                {
                    octave = Notes.Midpoint(ActiveClef);
                }

                var offsets = relation != Relation.Lower ?
                              new { x = 3, y = 3, noteIndexCorrection = 0 } :
                new { x = 14, y = NoteHeight, noteIndexCorrection = -2 };

                //Adds correction when mid
                if (octave == Notes.Midpoint(ActiveClef))
                {
                    offsets = new { offsets.x, offsets.y, noteIndexCorrection = -1 }
                }
                ;

                var ocUp = (NotesIndexInClef(octave) - offsets.noteIndexCorrection) * NoteHeight;
                note.StemEnd = ocUp;
                note.StemY   = note.Y + offsets.y;
                note.StemX   = note.X + offsets.x;
            }
        }
Exemple #17
0
        public void SeveralNtFilesNotes()
        {
            var firstNtFilesSection = GetExpectedNtFileBytes();
            var firstNoteBytes      = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, firstNtFilesSection);

            var wrongNtFilesSection = GetExpectedNtFileBytes();
            var wrongNoteBytes      = TestData.GetNoteSectionBytes(
                NoteSection.GnuName, NoteSection.NtFileType, wrongNtFilesSection);

            var secondNtFileSection = TestData.GetNtFileSectionBytes(
                anotherExpectedStartAddress, anotherExpectedEndAddress, expectedOffset,
                anotherExpectedName);
            var secondNoteBytes = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, secondNtFileSection);

            var fullNoteBytes = firstNoteBytes.Concat(wrongNoteBytes).Concat(secondNoteBytes)
                                .ToArray();

            var fileReader = new BinaryReader(new MemoryStream(fullNoteBytes));
            var sections   = NoteSection.ReadModuleSections(fileReader, fullNoteBytes.Length).ToArray();

            Assert.AreEqual(2, sections.Length);

            var first = sections.First();

            Assert.AreEqual(expectedEndAddress, first.EndAddress);
            Assert.AreEqual(expectedStartAddress, first.StartAddress);
            Assert.AreEqual(expectedName, first.Path);

            var last = sections.Last();

            Assert.AreEqual(anotherExpectedEndAddress, last.EndAddress);
            Assert.AreEqual(anotherExpectedStartAddress, last.StartAddress);
            Assert.AreEqual(anotherExpectedName, last.Path);
        }