Exemplo n.º 1
0
 public Cancion(string ruta)
 {
     XmlReader reader = XmlReader.Create(ruta);
     List<Nota> notas = new List<Nota>();
     while (reader.Read())
     {
         if (reader.HasAttributes && reader.Name == "bar")
         {
             Compas comp = new Compas((reader.GetAttribute("loop")), (reader.GetAttribute("tempo")), (reader.GetAttribute("length")));
             compases.Add(comp);
         }
         if (reader.HasAttributes && reader.Name == "note")
         {
             Nota n = new Nota(reader.GetAttribute("i"), reader.GetAttribute("pos"), reader.GetAttribute("num"), reader.GetAttribute("type"));
             compases.Last().agregarNota(n);
         }
     }
     foreach (Compas c in compases)
     {
         duracion += c.duracion;
     }
 }
Exemplo n.º 2
0
        public void crearXML(string ruta, bool silencio = false)
        {
            Cancion song = new Cancion();
            for (int i = 0; i < compases; i++)
            {
                Compas c = new Compas("1", this.tempo.ToString(), this.tiempos.ToString());
                for (int j = 0; j < 16*this.tiempos; j++)
                {
                    if (TL[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), TL[i * 16 * tiempos + j].ToString(), "tom_low");
                        c.agregarNota(n);
                    }
                    if (TH[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), TH[i * 16 * tiempos + j].ToString(), "tom_high");
                        c.agregarNota(n);
                    }
                    if (TF[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), TF[i * 16 * tiempos + j].ToString(), "tom_floor");
                        c.agregarNota(n);
                    }
                    if (S[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), S[i * 16 * tiempos + j].ToString(), "snare");
                        c.agregarNota(n);
                    }
                    if (R[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), R[i * 16 * tiempos + j].ToString(), "ride");
                        c.agregarNota(n);
                    }
                    if (K[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), K[i * 16 * tiempos + j].ToString(), "kick");
                        c.agregarNota(n);
                    }
                    if (HHO[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), HHO[i * 16 * tiempos + j].ToString(), "hihat_open");
                        c.agregarNota(n);
                    }
                    if (HHC[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), HHC[i * 16 * tiempos + j].ToString(), "hihat_closed");
                        c.agregarNota(n);
                    }
                    if (CL[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), CL[i * 16 * tiempos + j].ToString(), "crash_low");
                        c.agregarNota(n);
                    }
                    if (CH[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), CH[i * 16 * tiempos + j].ToString(), "crash_high");
                        c.agregarNota(n);
                    }
                    if (C[i * 16 * tiempos + j] != 0)
                    {
                        Nota n = new Nota("100", (j / 16.0).ToString(), C[i * 16 * tiempos + j].ToString(), "cowbell");
                        c.agregarNota(n);
                    }
                }
                song.compases.Add(c);
            }

            using (XmlWriter writer = XmlWriter.Create(ruta))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("barList");

                foreach (Compas c in song.compases)
                {
                    writer.WriteStartElement("bar");
                    writer.WriteAttributeString("loop", c.loop.ToString());
                    writer.WriteAttributeString("tempo", c.tempo.ToString());
                    writer.WriteAttributeString("length", c.length.ToString());
                        writer.WriteStartElement("notelist");
                        foreach (Nota n in c.notas)
                        {
                            writer.WriteStartElement("note");
                            writer.WriteAttributeString("i", n.i.ToString());
                            writer.WriteAttributeString("pos", n.pos.ToString());
                            writer.WriteAttributeString("num", n.num.ToString());
                            writer.WriteAttributeString("type", n.typeCompleto);
                            writer.WriteEndElement();
                        }

                        writer.WriteEndElement();

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
                if (!silencio)
                {
                    Console.WriteLine("XML creado correctamente!");
                    Console.WriteLine(ruta);
                    System.Threading.Thread.Sleep(1500);
                }

            }
        }