예제 #1
0
 public static bool TryUpdate(this NoteTrack track, int noteIndex, Note note)
 {
     if (IsUpdateValid(track, noteIndex, note))
     {
         Update(track, noteIndex, note);
         return(true);
     }
     return(false);
 }
예제 #2
0
 public static int SubtrackCount(this NoteTrack track)
 {
     try
     {
         return(track.notes.Max(x => x.subTrack) + 1);
     }
     catch (InvalidOperationException)
     {
         return(0);
     }
 }
예제 #3
0
        public static List <List <Note> > BySubtrack(this NoteTrack track)
        {
            int count = track.SubtrackCount();

            var result = new List <List <Note> >();

            for (int i = 0; i < count; i++)
            {
                result.Add(NotesOnSubtrack(track, i));
            }
            return(result);
        }
예제 #4
0
        public static void AddNote(this NoteTrack track, Note note)
        {
            var pos = track.notes.FindIndex(x => x.End > note.End);

            if (pos == -1)
            {
                track.notes.Add(note);
            }
            else
            {
                track.notes.Insert(pos, note);
            }
        }
예제 #5
0
        public static void CalculateTriggersBetween(this NoteTrack track, float eventStart, float eventEnd, List <NoteEvent> result)
        {
            foreach (var note in track.notes)
            {
                float noteEnd = note.End;

                bool startsBefore = eventStart < note.start;
                bool startsAfter  = eventStart > noteEnd;
                bool startsInside = !startsBefore && !startsAfter;

                bool endsBefore = eventEnd < note.start;
                bool endsAfter  = eventEnd > noteEnd;
                bool endsInside = !endsBefore && !endsAfter;


                if (startsAfter)
                {
                    continue;
                }

                if (startsBefore)
                {
                    if (endsAfter)
                    {
                        result.Add(new NoteEvent(NoteEvent.Type.Start, note.subTrack, 0.0f));
                        result.Add(new NoteEvent(NoteEvent.Type.End, note.subTrack, 1.0f));
                    }
                    else if (endsInside)
                    {
                        result.Add(new NoteEvent(NoteEvent.Type.Start, note.subTrack, 0.0f));
                    }
                }
                else if (startsInside)
                {
                    if (endsAfter)
                    {
                        result.Add(new NoteEvent(NoteEvent.Type.End, note.subTrack, 1.0f));
                    }
                    else if (endsInside)
                    {
                        float noteProgressBeats = (eventEnd - note.start) / note.duration;
                        result.Add(new NoteEvent(NoteEvent.Type.Update, note.subTrack, noteProgressBeats));
                    }
                }
            }
        }
예제 #6
0
        public static bool TryAddNote(this NoteTrack track, int subtrackIndex, float pos, float duration)
        {
            var newNote = new Note()
            {
                subTrack = subtrackIndex, duration = duration, start = pos
            };
            var subtrack      = track.NotesOnSubtrack(subtrackIndex);
            var posInSubtrack = subtrack.FindIndex(x => x.End > pos);

            posInSubtrack = posInSubtrack == -1 ? subtrack.Count : posInSubtrack;

            if (subtrack.Skip(posInSubtrack).All(x => x.start >= newNote.End))
            {
                AddNote(track, newNote);
                return(true);
            }
            return(false);
        }
예제 #7
0
 public NoteTrackEditor(NoteTrack track, NoteSheetEditor owner)
 {
     this.noteTrack = track;
     this.owner     = owner;
 }
예제 #8
0
 private static List <Note> NotesOnSubtrack(this NoteTrack track, int i)
 {
     return(new List <Note>(track.notes.Where(x => x.subTrack == i)));
 }
예제 #9
0
 private static void Update(this NoteTrack track, int noteIndex, Note note)
 {
     track.notes.RemoveAt(noteIndex);
     track.AddNote(note);
 }
예제 #10
0
 public static bool IsUpdateValid(this NoteTrack track, int noteIndex, Note note)
 {
     return(!track.notes.SkipIndex(noteIndex).Any(x => x.subTrack == note.subTrack && x.TimeOverlaps(note)));
 }