Пример #1
0
        public NoteInfo CreateNote(ABC.Note note, ABC.Clef clef, IReadOnlyList <string> decorations, GameObject container)
        {
            int stepCount     = note.pitch - clefZero[clef];
            var noteDirection = stepCount > 3 ? NoteDirection.Down : NoteDirection.Up;

            return(CreateNote(note, clef, stepCount, null, noteDirection, decorations, container));
        }
Пример #2
0
 private GameObject CreateNoteStaffMarkers(NoteDirection noteDirection, ABC.Note note, ABC.Clef clef, float position, ref Bounds totalBounds)
 {
     if (noteDirection == NoteDirection.Up)
     {
         return(CreateNoteStaffMarkersUp(note, clef, position, ref totalBounds));
     }
     else
     {
         return(CreateNoteStaffMarkersDown(note, clef, position, ref totalBounds));
     }
 }
Пример #3
0
        public GameObject AppendNote(ABC.Note note, List <string> decorations, float pos)
        {
            GameObject noteContainer = new GameObject();

            noteContainer.transform.parent = container.transform;

            notes.CreateNote(note, this.clef, decorations, noteContainer);
            noteContainer.transform.localPosition = new Vector3(pos, 0.0f, 0.0f);
            noteContainer.transform.localScale    = Vector3.one; // clear any scaling set on the parent

            return(noteContainer);
        }
Пример #4
0
        private GameObject CreateNoteStaffMarkersDown(ABC.Note note, ABC.Clef clef, float position, ref Bounds totalBounds)
        {
            int stepCount = note.pitch - clefZero[clef];

            if (stepCount < 9)
            {
                return(null);
            }

            if (stepCount % 2 == 0)
            {
                stepCount -= 1;
            }

            var   staffMarkers    = new GameObject("Staff Markers");
            float staffMarkerSize = note.length < ABC.Length.Whole ? 1.0f : wholeNoteStaffMarkerSize;

            for (int step = stepCount; step >= 9; step -= 2)
            {
                totalBounds.Encapsulate(CreateStaffMark(step, staffMarkers, position, staffMarkerSize));
            }

            return(staffMarkers);
        }
Пример #5
0
 public GameObject AppendNote(ABC.Note note, float pos)
 {
     return(AppendNote(note, null, pos));
 }
Пример #6
0
        public NoteInfo CreateNote(ABC.Note note, Beam beam, IReadOnlyList <string> decorations, GameObject container)
        {
            int stepCount = note.pitch - clefZero[beam.clef];

            return(CreateNote(note, beam.clef, stepCount, beam, beam.noteDirection, decorations, container));
        }
Пример #7
0
        private NoteInfo CreateNote(ABC.Note note, ABC.Clef clef, int noteStepCount, Beam beam, NoteDirection noteDirection, IReadOnlyList <string> decorations, GameObject container)
        {
            var notePosition = new Vector3(0.0f, noteStep * noteStepCount, 0.0f);

            var totalBounds = new Bounds();

            totalBounds.SetMinMax(Vector3.zero, Vector3.zero);
            if (note.accidental != ABC.Accidental.Unspecified)
            {
                var accidental = spriteCache.GetSpriteObject($"Accidental_{note.accidental}");
                accidental.transform.parent        = container.transform;
                accidental.transform.localPosition = notePosition;

                totalBounds.Encapsulate(accidental.bounds);
                notePosition.x = totalBounds.size.x + accidentalOffset;
            }

            GameObject staffMarkers = null;

            if (NeedsStaffMarkers(noteStepCount))
            {
                staffMarkers  = CreateNoteStaffMarkers(noteDirection, note, clef, notePosition.x, ref totalBounds);
                notePosition += new Vector3(staffMarkerNoteOffset, 0.0f, 0.0f);
            }

            Bounds         rootItemBounds;
            SpriteRenderer rootItem = null;

            if (beam != null && beam.stemHeight != Beam.unspecifiedStemHeight)
            {
                var noteHead = spriteCache.GetSpriteObject("Chord_Quarter");
                noteHead.transform.parent        = container.transform;
                noteHead.transform.localPosition = notePosition;
                rootItemBounds = noteHead.bounds;

                rootItem = spriteCache.GetSpriteObject($"Note_Stem_{noteDirection}");
                rootItem.transform.parent = container.transform;

                var stemPos = notePosition + (noteDirection == NoteDirection.Up ? Beam.stemUpOffset : Beam.stemDownOffset);
                rootItem.transform.localPosition = stemPos;
                rootItem.transform.localScale    = new Vector3(1.0f, Mathf.Abs(beam.stemHeight - stemPos.y), 1.0f);
                rootItemBounds.Encapsulate(rootItem.bounds);
            }
            else
            {
                var spriteName = GetNoteSpriteName(note.length, note.beam != 0, noteDirection);
                rootItem = spriteCache.GetSpriteObject(spriteName);
                rootItem.transform.parent        = container.transform;
                rootItem.transform.localPosition = notePosition;

                rootItemBounds = rootItem.bounds;
            }

            totalBounds.Encapsulate(rootItemBounds);

            for (int i = 0; i < note.dotCount; i++)
            {
                float dotOffset = rootItemBounds.max.x + dotAdvance;
                var   dot       = CreateNoteDot(noteStepCount, container, dotOffset);
                totalBounds.Encapsulate(dot.bounds);
            }

            AddDecorations(note, decorations, rootItemBounds, container, ref totalBounds);

            if (staffMarkers != null)
            {
                staffMarkers.transform.parent = container.transform;
            }

            return(new NoteInfo(rootItemBounds, totalBounds));
        }