Exemplo n.º 1
0
        void fill_tracks(XmlNodeList track_root)
        {
            XmlNode current = track_root[0];

            while (current != null)
            {
                track t = new track();
                foreach (XmlAttribute attr in current.Attributes)
                {
                    switch (attr.Name.ToLower())
                    {
                    case "name":
                        t.name = attr.Value;
                        break;

                    case "length":
                        t.length = int.Parse(attr.Value);
                        break;

                    case "beatsperminute":
                        t.bpm = int.Parse(attr.Value);
                        break;

                    default:
                        break;
                    }
                }
                for (int i = 0; i < t.length; i++)
                {
                    t.music.Add(new List <sequence>());
                }
                foreach (XmlNode subtrack in current.ChildNodes)
                {
                    int    start = 0;
                    int    end   = 0;
                    string name  = null;
                    string seq   = null;
                    string instr = null;
                    foreach (XmlAttribute attr in subtrack.Attributes)
                    {
                        switch (attr.Name.ToLower())
                        {
                        case "name":
                            name = attr.Value;
                            break;

                        case "start":
                            start = int.Parse(attr.Value);
                            break;

                        case "end":
                            end = int.Parse(attr.Value);
                            break;

                        case "sequence":
                            seq = attr.Value;
                            break;

                        case "beat":
                            instr = attr.Value;
                            break;

                        default:
                            break;
                        }
                    }
                    if (seq != null && instr != null)
                    {
                        for (int i = Math.Max(start, 0); i < Math.Min(t.length, end); i++)
                        {
                            sequence s = (sequence)(((beat)beats[instr]).sequence[seq]);
                            t.music[i].Add(s);
                        }
                    }
                }

                music.Add(t.name, t);
                current = current.NextSibling;
            }
        }
Exemplo n.º 2
0
        void fill_patterns(XmlNodeList patterns_root)
        {
            XmlNode current = patterns_root[0];

            while (current != null)
            {
                if (current.Name == "Beat")
                {
                    beat b = new beat();
                    foreach (XmlAttribute attr in current.Attributes)
                    {
                        string attribute_name = attr.Name.ToLower();
                        if (attribute_name == "name")
                        {
                            b.name = attr.Value;
                        }
                        else if (attribute_name == "img")
                        {
                            b.image_location = attr.Value;
                        }
                        else if (attribute_name == "followClave")
                        {
                            b.follows_clave = bool.Parse(attr.Value);
                        }
                        else if (attribute_name == "overlaps")
                        {
                            b.overlap = bool.Parse(attr.Value);
                        }
                    }
                    foreach (XmlNode sequence_node in current.ChildNodes)
                    {
                        sequence seq = new sequence();
                        foreach (XmlAttribute attr in sequence_node.Attributes)
                        {
                            string attribute_name = attr.Name.ToLower();
                            if (attribute_name == "name")
                            {
                                seq.name = attr.Value;
                            }
                        }
                        foreach (XmlNode sound_xml_in in sequence_node.ChildNodes)
                        {
                            sequence_note s     = new sequence_note();
                            string        instr = null;
                            string        note  = null;
                            foreach (XmlAttribute attr in sound_xml_in.Attributes)
                            {
                                string attribute_name = attr.Name.ToLower();

                                if (attribute_name == "time")
                                {
                                    s.time = (int.Parse(attr.Value));
                                }
                                else if (attribute_name == "instrument")
                                {
                                    instr = attr.Value;
                                }
                                else if (attribute_name == "note")
                                {
                                    note = attr.Value;
                                }
                                if (instr != null && note != null)
                                {
                                    s.note_ = ((note)((instrument)instruments[instr]).notes[note]);
                                }
                            }
                            seq.notes[s.time] = s;
                        }
                        b.sequence.Add(seq.name, seq);
                    }
                    beats.Add(b.name, b);
                }
                current = current.NextSibling;
            }
        }