Beispiel #1
0
        public void SaveTrack(string path)
        {
            XmlDocument    document    = new XmlDocument();
            XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement     root        = document.DocumentElement;

            document.InsertBefore(declaration, root);

            XmlElement TrackRoot = document.CreateElement("Track");

            #region CreateTrackAttrubutes
            XmlElement   TrackAttrubutes = document.CreateElement(_XmlAttr);
            XmlAttribute TrackName       = document.CreateAttribute(_XmlAttrName);
            TrackName.Value = this.TrackName;
            XmlAttribute TrackTime = document.CreateAttribute(_XmlAttrTime);
            TrackTime.Value = this.TrackLength.ToString();
            XmlAttribute TrackLevel = document.CreateAttribute(_XmlAttrLevel);
            TrackLevel.Value = this.TrackLevel.ToString();
            XmlAttribute TrackBPM = document.CreateAttribute(_XmlAttrBPM);
            TrackBPM.Value = this.TrackBPM.ToString();
            XmlAttribute TrackNPS = document.CreateAttribute(_XmlAttrNPB);
            TrackNPS.Value = this.TrackNPB.ToString();
            TrackAttrubutes.Attributes.Append(TrackNPS);
            TrackAttrubutes.Attributes.Append(TrackBPM);
            TrackAttrubutes.Attributes.Append(TrackLevel);
            TrackAttrubutes.Attributes.Append(TrackTime);
            TrackAttrubutes.Attributes.Append(TrackName);
            #endregion

            XmlElement NoteLine = document.CreateElement("NoteLine");
            foreach (ObservableCollection <Note> notes in NoteList.GetNoteListRef(Direction.UP))
            {
                foreach (Note note in notes)
                {
                    AppendNoteXml(note, ref document, ref NoteLine);
                }
            }
            foreach (ObservableCollection <Note> notes in NoteList.GetNoteListRef(Direction.DOWN))
            {
                foreach (Note note in notes)
                {
                    AppendNoteXml(note, ref document, ref NoteLine);
                }
            }

            XmlElement MusicData = document.CreateElement("MusicData");


            TrackRoot.AppendChild(TrackAttrubutes);
            TrackRoot.AppendChild(NoteLine);
            TrackRoot.AppendChild(MusicData);
            document.AppendChild(TrackRoot);
            document.Save(path);
        }
Beispiel #2
0
        private static void ReadNote(ref NoteList notes, ref XmlReader reader)
        {
            Direction dir       = Direction.UP;
            Keys      key       = Keys.NotAKey;
            int       _Position = 0;

            try
            {
                if (reader.MoveToFirstAttribute())
                {
                    do
                    {
                        string attrbName = reader.Name;
                        if (attrbName.CompareTo(_XmlNoteKey) == 0)
                        {
                            Enum.TryParse <Keys>(reader.Value, out key);
                        }
                        else if (attrbName.CompareTo(_XmlNotePosition) == 0)
                        {
                            _Position = int.Parse(reader.Value);
                        }
                        else if (attrbName.CompareTo(_XmlNoteLocation) == 0)
                        {
                            if (reader.Value.Equals(_XmlNoteLocationUP))
                            {
                                dir = Direction.UP;
                            }
                            else
                            {
                                dir = Direction.DOWN;
                            }
                        }
                    } while (reader.MoveToNextAttribute());
                }
            }
            catch (System.Exception e)
            {
                Console.Write(e.Message);
                return;
            }


            Note note = new Note(key, dir)
            {
                Position = _Position,
                isActive = true
            };
            int _last = notes.GetNotes(key, dir).Count;

            if (_Position > _last)
            {
                int _resrvPos = _Position + (NoteList.DefaultNoteReserveLength -
                                             (_Position % NoteList.DefaultNoteReserveLength));
                NoteList.ReserveFrom(ref notes.GetNoteListRef(dir), _last, _resrvPos);
            }
            notes.GetNotesRef(note.Key, dir)[_Position] = note;
        }