Esempio n. 1
0
        public static Mub ParseMidi(Midi mid)
        {
            Mub mub = new Mub();

            if (mid.Tracks.Count != 1)
            {
                throw new FormatException();
            }

            Midi.Track track = mid.Tracks[0];

            foreach (Midi.NoteEvent note in track.Notes)
            {
                float time     = GetBars(note.Time, mid) / mid.Division.TicksPerBeat;
                float duration = (GetBars(note.Time + note.Duration, mid) - GetBars(note.Time, mid)) / mid.Division.TicksPerBeat;

                mub.Nodes.Add(new Node()
                {
                    Time = time, Duration = duration, Type = (int)note.Note, Data = 0
                });
            }

            foreach (Midi.TextEvent comment in track.Comments)
            {
                float time = GetBars(comment.Time, mid) / mid.Division.TicksPerBeat;

                mub.Nodes.Add(new MarkerNode()
                {
                    Time = time, Duration = 0, Type = (int)0x0AFFFFFF, Text = comment.Text
                });
            }

            foreach (Midi.TextEvent comment in track.Markers)
            {
                float time = GetBars(comment.Time, mid) / mid.Division.TicksPerBeat;

                mub.Nodes.Add(new MarkerNode()
                {
                    Time = time, Duration = 0, Type = (int)0x09FFFFFF, Text = comment.Text
                });
            }

            return(mub);
        }
Esempio n. 2
0
        public static Mub Create(EndianReader reader)
        {
            Mub mub = new Mub();

            mub.Version = reader.ReadInt32();

            if (mub.Version != 1 && mub.Version != 2)
            {
                throw new FormatException();                 // Unknown version number
            }
            mub.Checksum = reader.ReadInt32();

            int nodes    = reader.ReadInt32();
            int datasize = reader.ReadInt32();

            long begin = reader.Position;

            for (int i = 0; i < nodes; i++)
            {
                Node node = Node.ParseNode(reader);

                mub.Nodes.Add(node);
            }

            foreach (Node node in mub.Nodes)
            {
                MarkerNode mark = node as MarkerNode;
                if (mark != null)
                {
                    reader.Position = begin + mark.Data;
                    mark.Text       = Util.ReadCString(reader.Base);
                }
            }

            return(mub);
        }