/// <summary>
        /// Converts a sequence to an array of animations.
        /// </summary>
        /// <param name="sequence">The sequence from which to gather animations information.</param>
        /// <returns>Returns a series of animations.</returns>
        protected ObjectAnimator[] PrepareNotesAnimations(Sequence sequence)
        {
            ObjectAnimator[] animations = new ObjectAnimator[sequence.Length];

            for (int i = 0; i < sequence.Length; i++)
            {
                //Get note from sequence.
                Note note = sequence[i];
                //Create a new visual representation of that note.
                NoteRepresentation noteRep = new NoteRepresentation(_activity, note);
                //Create the note's animation, and add that animation to the animations array.
                animations[i] = noteRep.CreateNoteAnimation();
				//Sign up for sound input window events.
				noteRep.OnNoteArraival += NotesPlayer_OnNoteArraival;
				noteRep.OnNoteGone += NotesPlayer_OnNoteGone;
            }

            return animations;
        }
Пример #2
0
 public void ReadSong()
 {
     string fileName = "TestSong"; //"TinyJonathan";
     _sequence = SequenceReader(fileName);
 }
        /// <summary>
        /// Reads a sequence from a *.vgts file.
        /// </summary>
        /// <param name="fileName">The file's name (no extension).</param>
        /// <returns>Returns the sequence of that file.</returns>
        protected Sequence SequenceReader(string fileName)
        {
            //string songsFolderPath = _activity.Resources.GetString(Resource.String.SongsFolderPath);

            string[] sequenceLines = GetFileLinesFromAssets(fileName + SONG_FILE_EXTENSION, _activity.Assets);

            DiscardCommentsAndEmptyLines(ref sequenceLines);

            Sequence sequence = new Sequence(sequenceLines.Length);
            string[] lineSegments;
            Notes notesReference = new Notes();

            for (int i = 0; i < sequenceLines.Length; i++)
            {
                string line = sequenceLines[i];
                lineSegments = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                NoteName noteName;
                double delay, duration;

                bool isNoteName = NoteName.TryParse(lineSegments[0], out noteName);
                bool isDouble1 = double.TryParse(lineSegments[1], out delay);
                bool isDouble2 = double.TryParse(lineSegments[2], out duration);
                
                if (!(isNoteName && isDouble1 && isDouble2))
                    throw new Exception("Parsing segments of song file failed. "
                        + "Only the following format is allowed: string double double. "
                        + "And make sure the string name is spelled correctly.");

                Note note = notesReference[noteName];

                if (i == 0)
                    note = new Note(noteName,
                    note.Positions[0],
                    delay,
                    duration);
                else
                    note = new Note(noteName,
                    CalculateClosestPositionFromPreviousNote(sequence[i - 1], note),
                    delay,
                    duration);

                sequence[i] = note;
            }
            return sequence;
        }