//you know what, Maybe I'll just not do these, you can still use attributes.Get.
        ///// <summary>
        ///// This field is deprecated, we did not bother to find out what it means.
        ///// </summary>
        //public int PBType;
        //
        ///// <summary>
        ///// This is for mode 1. (that means you may ignore it) (that means please do ignore it)
        ///// </summary>
        //public List<int> Pitches;

        /// <summary>
        ///     Create the note from raw text in format of ust files.
        /// </summary>
        /// <param name="list"></param>
        public USTNote(IEnumerable <string> list)
        {
            //this.TextRaw = list;
            _attributes = new DictionaryDataObject(list.Select(x => x.Split(new[] { '=' }, 2))
                                                   .ToDictionary(x => x[0], x => x[1]));

            Envelope = _attributes.ContainsKey(KeyEnvelope) ? new Envelope(_attributes[KeyEnvelope]) : new Envelope();
            _attributes.Remove(KeyEnvelope);

            if (!_attributes.ContainsKey(KeyPbw))
            {
                Portamento = null;
            }
            else
            {
                var pbw = _attributes[KeyPbw];
                var pbs = _attributes.ContainsKey(KeyPbs) ? _attributes[KeyPbs] : "0;"; //0 and invalid.
                var pby = _attributes.ContainsKey(KeyPby)
                    ? _attributes[KeyPby]
                    : ""; //pby and pbm will be fixed by Portamento upon construction.
                var pbm = _attributes.ContainsKey(KeyPbm) ? _attributes[KeyPbm] : "";
                Portamento = new Portamento(pbw, pbs, pby, pbm);
            }

            Vibrato = _attributes.ContainsKey(KeyVbr) ? new Vibrato(_attributes[KeyVbr]) : null;
            _attributes.Remove(KeyVbr);
        }
示例#2
0
 /// <summary>
 /// make a note with minimum data and default envelope.
 /// </summary>
 /// <param name="Length"></param>
 /// <param name="Lyric"></param>
 /// <param name="NoteNum"></param>
 public USTNote(int Length, string Lyric, int NoteNum)
 {
     this.attributes = new DictionaryDataObject();
     this.Length     = Length;
     this.Lyric      = Lyric;
     this.NoteNum    = NoteNum;
     this.Envelope   = new Envelope();
 }
 /// <summary>
 ///     make a note with minimum data and default envelope.
 /// </summary>
 /// <param name="length"></param>
 /// <param name="lyric"></param>
 /// <param name="noteNum"></param>
 public USTNote(int length, string lyric, int noteNum)
 {
     _attributes = new DictionaryDataObject();
     Length      = length;
     Lyric       = lyric;
     NoteNum     = noteNum;
     Envelope    = new Envelope();
 }
 /// <summary>
 ///     This is sort of a copy constructor. Yes, this will try to make deep copies of everything.
 /// </summary>
 /// <param name="version"></param>
 /// <param name="projectInfo"></param>
 /// <param name="trackData"></param>
 public USTFile(string version, IDictionary <string, string> projectInfo,
                IEnumerable <IEnumerable <USTNote> > trackData)
 {
     Version     = version;
     ProjectInfo = new DictionaryDataObject(projectInfo);
     TrackData   = new List <List <USTNote> >();
     foreach (var t in trackData)
     {
         var myTrack = t.Select(n => new USTNote(n)).ToList();
         TrackData.Add(myTrack);
     }
 }
示例#5
0
 /// <summary>
 /// This is sort of a copy constructor. Yes, this will try to make deep copies of everything.
 /// </summary>
 /// <param name="Version"></param>
 /// <param name="ProjectInfo"></param>
 /// <param name="TrackData"></param>
 public USTFile(string Version, IDictionary <string, string> ProjectInfo, List <List <USTNote> > TrackData)
 {
     this.Version     = Version;
     this.ProjectInfo = new DictionaryDataObject(ProjectInfo);
     this.TrackData   = new List <List <USTNote> >();
     foreach (var t in TrackData)
     {
         var myTrack = new List <USTNote>();
         foreach (var n in t)
         {
             myTrack.Add(new USTNote(n));
         }
         this.TrackData.Add(myTrack);
     }
 }
示例#6
0
        /// <summary>
        /// Creates a ust from string array.
        /// </summary>
        /// <param name="data">lines of a file</param>
        public USTFile(string[] data)
        {
            TrackData = new List <List <USTNote> >();

            //Split by tracks first.
            //This split version and project info into the first track, so we'll deal with that first
            //TODO: Refactor this
            List <List <string> > tracks = zusp.ListSplit(data.ToList(), @"\[#TRACKEND\]");
            //Split lines into segments.
            List <List <string> > ls = zusp.ListSplit(tracks[0], @"\[#.*\]");

            //The first segment is ust format version, we only handled the newest.
            Version = ls[0][0];
            //The next segment is project info
            ProjectInfo = new DictionaryDataObject(zusp.ListToDictionary(ls[1], "="));

            TrackData.Add(new List <USTNote>());
            //The remaining segments are notes
            for (int i = 2; i < ls.Count; i++)
            {
                int notenum = i - 2; //LI:when i is 2, it's note 0
                TrackData[0].Add(new USTNote(ls[i]));
            }
            if (tracks.Count > 1) //Handle the other tracks
            {
                foreach (var t in tracks.Skip(1))
                {
                    TrackData.Add(zusp.ListSplit(t, @"\[*\]").Select((n) => new USTNote(n)).ToList());
                }
            }

            //TODO: deal with this
            //now we need to fix portamentos if any.
            foreach (var track in TrackData)
            {
                for (int i = 1; i < track.Count; i++)                                       //sliding window of i-1, i
                {
                    if (track[i].Portamento != null && !track[i].Portamento.HasValidPBS1()) //note this is [i-1] - [i] because it's relative to [i]
                    {
                        track[i].Portamento.PBS[1] = track[i - 1].NoteNum - track[i].NoteNum;
                    }
                }
            }
        }
        /// <summary>
        ///     Creates a ust from string array.
        /// </summary>
        /// <param name="data"></param>
        public USTFile(IEnumerable <string> data)
        {
            TrackData = new List <List <USTNote> >();

            //split by tracks first. yes, that exists.
            //thank you c# for providing @.. escaping more escape character is just...
            var tracks = zusp.ListSplit(data.ToList(), @"\[#TRACKEND\]");
            var ls     = zusp.ListSplit(tracks[0], @"\[#.*\]");

            //ls[0] is ust version, we only handled the newest.
            Version = ls[0][0];
            //ls[1] is other project info
            ProjectInfo = new DictionaryDataObject(zusp.ListToDictionary(ls[1], "="));

            TrackData.Add(new List <USTNote>());
            //rest of it is notes of this ust.
            for (var i = 2; i < ls.Count; i++)
            {
                var noteNum = i - 2; //LI:when i is 2, it's note 0
                TrackData[0].Add(new USTNote(ls[i]));
            }

            if (tracks.Count > 1)                 //yes there can be more than 1 tracks. not on windows versions though!
            {
                foreach (var t in tracks.Skip(1)) //much better code after those special cases are gone now...
                {
                    TrackData.Add(zusp.ListSplit(t, @"\[*\]").Select(n => new USTNote(n)).ToList());
                }
            }

            //now we need to fix portamentos if any.
            foreach (var track in TrackData)
            {
                for (var i = 1; i < track.Count; i++) //sliding window of i-1, i
                {
                    if (track[i].Portamento != null && !track[i].Portamento.HasValidPbs1()
                        ) //note this is [i-1] - [i] because it's relative to [i]
                    {
                        track[i].Portamento.Pbs[1] = track[i - 1].NoteNum - track[i].NoteNum;
                    }
                }
            }
        }
示例#8
0
        //you know what, Maybe I'll just not do these, you can still use attributes.Get.
        ///// <summary>
        ///// This field is deprecated, we did not bother to find out what it means.
        ///// </summary>
        //public int PBType;
        //
        ///// <summary>
        ///// This is for mode 1. (that means you may ignore it) (that means please do ignore it)
        ///// </summary>
        //public List<int> Pitches;

        /// <summary>
        /// Create the note from raw text in format of ust files.
        /// </summary>
        /// <param name="list"></param>
        public USTNote(List <string> list)
        {
            //this.TextRaw = list;
            this.attributes = new DictionaryDataObject(zusp.ListToDictionary(list, "="));

            this.Envelope = attributes.ContainsKey(KEY_ENVELOPE) ? new Envelope(attributes[KEY_ENVELOPE]):new Envelope();
            attributes.Remove(KEY_ENVELOPE);

            if (!attributes.ContainsKey(KEY_PBW))
            {
                this.Portamento = null;
            }
            else
            {
                string pbw = attributes[KEY_PBW];
                string pbs = attributes.ContainsKey(KEY_PBS) ? attributes[KEY_PBS] : "0;"; //0 and invalid.
                string pby = attributes.ContainsKey(KEY_PBY) ? attributes[KEY_PBY] : "";   //pby and pbm will be fixed by Portamento upon construction.
                string pbm = attributes.ContainsKey(KEY_PBM) ? attributes[KEY_PBM] : "";
                this.Portamento = new Portamento(pbw, pbs, pby, pbm);
            }

            this.Vibrato = attributes.ContainsKey(KEY_VBR) ?  new Vibrato(attributes[KEY_VBR]): null;
            attributes.Remove(KEY_VBR);
        }