コード例 #1
0
        /// <summary>
        /// Do export to MusicXML file.
        /// </summary>
        /// <param name="sequence">A sequence to be exported.</param>
        /// <param name="file_path">A file path.</param>
        public void write(VsqFile sequence, string file_path)
        {
            var score = new scorepartwise();

            score.version = "2.0";

            score.identification          = new identification();
            score.identification.encoding = new encoding();
            score.identification.encoding.software.Add(this.GetType().FullName);

            score.partlist                          = new partlist();
            score.partlist.scorepart                = new scorepart();
            score.partlist.scorepart.id             = "P1";
            score.partlist.scorepart.partname       = new partname();
            score.partlist.scorepart.partname.Value = sequence.Track[1].getName();
            var partlist = new List <scorepart>();

            for (int i = 2; i < sequence.Track.Count; ++i)
            {
                var track     = sequence.Track[i];
                var scorepart = new scorepart();
                scorepart.id             = "P" + i;
                scorepart.partname       = new partname();
                scorepart.partname.Value = track.getName();
                partlist.Add(scorepart);
            }
            score.partlist.Items = partlist.ToArray();

            var quantized_tempo_table = quantizeTempoTable(sequence.TempoTable);

            score.part =
                sequence.Track.Skip(1).Select((track) => {
                var result = createScorePart(track, sequence.TimesigTable, quantized_tempo_table);
                quantized_tempo_table.Clear();
                return(result);
            }).ToArray();
            for (int i = 0; i < score.part.Length; i++)
            {
                score.part[i].id = "P" + (i + 1);
            }

            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(scorepartwise));

            using (var stream = new FileStream(file_path, FileMode.Create, FileAccess.Write)) {
                var writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);
                writer.Formatting = System.Xml.Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteDocType("score-partwise", "-//Recordare//DTD MusicXML 2.0 Partwise//EN", "http://www.musicxml.org/dtds/partwise.dtd", null);
                var ns = new System.Xml.Serialization.XmlSerializerNamespaces();
                ns.Add(string.Empty, string.Empty);
                serializer.Serialize(writer, score, ns);
            }
        }
コード例 #2
0
        // C2FORMAT.TXT line 197ff
        //STAFF_LAYOUT (Format einer Notenzeile)
        //  INT     Abstand nach oben
        //  INT     Abstand nach unten
        //  BYTE    keyByte
        //  BOOL    fSingleLine
        //  BOOL    irrelevant
        //  INT     baseSound
        //  INT     extSound
        //  INT     transp
        //  CHAR[3] brackets
        //  STRINGZ Beschreibung
        //  STRINGZ Bezeichnung
        //  STRINGZ Abkuerzung
        //end
        private void ReadSTAFFLAYOUT(byte[] buffer, ref uint position, int staffNumber, scorepart partDescription)
        {
            Read(buffer, ref position, out INT topMargin);
            Read(buffer, ref position, out INT bottomMargin);
            Read(buffer, ref position, out BYTE keyByte);

            // structure not explicitely described here
            // taken from section 5:
            //    +---+---+---+---+---+---+---+---+
            //    |3      |2          |1          |
            //    +---+---+---+---+---+---+---+---+
            //    BIT[3] Schluesselform (0=G, 1=C, 2=F, 3=Schlagz. 4=kein, 5=unveraendert)
            //    BIT[3] keyByte-Linie (0 = oberste Linie, ... , 4 = unterste Linie)
            //    BIT[2] keyByte-Oktavierung (0=nach oben, 1=keine, 2= nach unten)
            this.currentKeyForm[staffNumber]       = keyByte & 0x07;
            this.currentKeyLine[staffNumber]       = (keyByte & 0x38) >> 3;
            this.currentKeyOctavation[staffNumber] = (keyByte & 0xC0) >> 6;
            Read(buffer, ref position, out BOOL singleLine);
            Read(buffer, ref position, out BOOL irrelevant);
            Read(buffer, ref position, out INT baseSound);
            Read(buffer, ref position, out INT extSound);
            Read(buffer, ref position, out INT transp);
            var brackets = new CHAR[3];

            Read(buffer, ref position, out brackets[0]);
            Read(buffer, ref position, out brackets[1]);
            Read(buffer, ref position, out brackets[2]);

            // TODO kein DUMMY!
            this.ReadSTRINGZ(buffer, ref position, out string dummy);
            this.ReadSTRINGZ(buffer, ref position, out dummy);
            partDescription.partname = new partname {
                Value = dummy
            };
            this.ReadSTRINGZ(buffer, ref position, out dummy);
            partDescription.partabbreviation = new partname {
                Value = dummy
            };
        }
コード例 #3
0
        // C2FORMAT.TXT line 85ff
        //LAYOUT (Beschreibung der Partitur-Formatvorlage)
        //  if Dateikennung >= V2.1
        //    BYTE    topDist
        //    CHAR    Ersatzzeichen fuer geschuetztes Leerzeichen ('\0' --> '$')
        //    BYTE    interDist
        //    CHAR    Ersatzzeichen fuer geschuetzten Bindestrich ('\0' --> '#')
        //  else
        //    INT     topDist
        //    INT     interDist
        //  endif
        //  BYTE    beamMode
        //  FONT    txtFont
        //  BYTE    txtAlign
        //  BOOL    allaBreve
        //  UINT    tempo
        //  INT     staves
        //  if Dateikennung >= V2.1
        //    BYTE[16] nSound  (Klang fuer Kanal 1 bis 16
        //                      im 1. Byte ist hoechstes Bit gesetzt!)
        //    BYTE[16] nVolume (Lautstaerke fuer Kanal 1 bis 16)
        //  else (Version 2.0)
        //    BYTE[9] nSound   (Klang fuer Kanal 1 bis 9)
        //    BYTE[9] nVolume  (Lautstaerke fuer Kanal 1 bis 9)
        //  endif
        //  STAFF_LAYOUT[staves]
        //end
        private void ReadLAYOUT(byte[] buffer, ref uint position)
        {
            if (this.version >= FileVersion.V21)
            {
                Read(buffer, ref position, out BYTE topDist);
                Read(buffer, ref position, out CHAR spaceReplacement);
                Read(buffer, ref position, out BYTE interDist);
                Read(buffer, ref position, out CHAR dashReplacement);
            }
            else
            {
                Read(buffer, ref position, out INT topDist);
                Read(buffer, ref position, out INT interDist);
            }

            Read(buffer, ref position, out BYTE beamMode);
            this.ReadFONT(buffer, ref position);
            Read(buffer, ref position, out BYTE txtAlign);
            Read(buffer, ref position, out BOOL allaBreve);
            Read(buffer, ref position, out UINT tempo);
            Read(buffer, ref position, out INT staveCount);
            if (this.version >= FileVersion.V21)
            {
                var soundValues  = new BYTE[16];
                var volumeValues = new BYTE[16];
                for (int i = 0; i < 16; i++)
                {
                    Read(buffer, ref position, out soundValues[i]);
                }

                for (int i = 0; i < 16; i++)
                {
                    Read(buffer, ref position, out volumeValues[i]);
                }
            }
            else
            {
                var soundValues  = new BYTE[9];
                var volumeValues = new BYTE[9];
                for (int i = 0; i < 9; i++)
                {
                    Read(buffer, ref position, out soundValues[i]);
                }

                for (int i = 0; i < 9; i++)
                {
                    Read(buffer, ref position, out volumeValues[i]);
                }
            }

            // TODO hier hatte ich zuerst ein partlist-Array. R# hat eine Co-Varianz-Warnung angezeigt. Daher nun object-Array.
            this.Document.partlist = new partlist {
                Items = new object[staveCount]
            };
            this.Document.part = new scorepartwisePart[staveCount];

            this.InitStaves(staveCount);

            for (int i = 0; i < staveCount; i++)
            {
                // initialite partDescription structures for current staff
                var partDescription = new scorepart();
                this.Document.partlist.Items[i] = partDescription;
                partDescription.id = "P" + (i + 1).ToString(CultureInfo.InvariantCulture);
                var partData = new scorepartwisePart {
                    id = partDescription.id
                };
                this.Document.part[i] = partData;

                var firstMeasure = new scorepartwisePartMeasure();
                this.measures[i].Add(firstMeasure);
                firstMeasure.number = "1";

                attributes att = firstMeasure.GetAttributes();

                // 32 corresponds with duration values in readSTAFF()
                att.divisions          = 32;
                att.divisionsSpecified = true;

                this.ReadSTAFFLAYOUT(buffer, ref position, i, partDescription);

                firstMeasure.AddClef(
                    this.currentKeyForm[i],
                    this.currentKeyLine[i],
                    this.currentKeyOctavation[i]);
            }
        }