public void XMLtoWav(string ruta, bool silencio = false) { Cancion song = new Cancion(ruta); int y = (Int32)Math.Round(song.duracion); int o = (Int32)Math.Ceiling( y * (44100 / 1000.0) + 6 * 44100.0); Canales main = new Canales(o); int Samplepos = 0; //Se agregan todas las notas al main foreach (Compas c in song.compases) { for (int i = 0; i < c.loop; i++) { foreach (Nota n in c.notas) { var npos = Math.Round(((n.pos * 60 * (44100.0 / c.tempo)) + Samplepos)); main = incluirNota(main, n, (int)npos); } Samplepos += (int)Math.Round(c.duracion * (44100 / 1000.0)); } } //Se normalizan los canales main.normalizar(silencio); List<short> leftSamples = new List<short>(); List<short> rightSamples = new List<short>(); for (int i = 0; i < main.left.Count; i++) { leftSamples.Add(Convert.ToInt16(main.left[i])); rightSamples.Add(Convert.ToInt16(main.right[i])); } SaveToWave(leftSamples, rightSamples, ruta.Slice(0,-3) + "wav", silencio); }
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); } } }