예제 #1
0
        static void Main(string[] args)
        {
            string    uri;
            ScoreType stype;

            //uri = @"E:\Pablo\xml sheet exports\dni-uhodyat-xop.xml";
            //stype = ScoreType.WordsSong;

            //uri = @"E:\Pablo\xml sheet exports\mozart-wolfgang-amadeus-marche-turque-508.xml";
            //stype = ScoreType.Classical;

            //uri = @"E:\Pablo\xml sheet exports\Violin\TheChopin.xml";
            //stype = ScoreType.Chopin;

            uri   = @"E:\Pablo\xml sheet exports\Violin\TheChopin.xml";
            stype = ScoreType.Violin;

            if (!File.Exists(uri))
            {
                Console.Write("File don't exist... ");
                Console.ReadLine();
                return;
            }

            string        xmlText  = File.ReadAllText(uri);
            Scorepartwise scoreObj = XMLDumping.FromXmlString(xmlText);
            string        notes    = XMLDumping.ScoreToNotes(scoreObj, stype);

            // Output to new file
            string fileName = Path.GetFileNameWithoutExtension(uri);

            notes = notes.Remove(notes.Length - 1); // Remove the last comma and newline
            File.WriteAllText(@"E:\Pablo\music for STEPITUP\" + fileName + ".txt", notes);

            Console.Write(notes);
            Console.ReadLine();
        }
예제 #2
0
        public static string ScoreToNotes(Scorepartwise scoreObj, ScoreType type)
        {
            StringBuilder sb = new StringBuilder();

            // Get the notes
            foreach (var part in scoreObj.Part)
            {
                foreach (var measure in part.Measure)
                {
                    foreach (var note in measure.Note)
                    {
                        if (note.Pitch != null)
                        {
                            if (type == ScoreType.WordsSong) // Only staff or first (treble) staff
                            {
                                if (note.Staff == null || note.Staff?.CompareTo("1") == 0)
                                {
                                    if (note.Stem?.Text.CompareTo("up") == 0) // Soprano
                                    {
                                        sb.Append(note.Pitch.Step);
                                        sb.Append(note.Pitch.Alter?.CompareTo("1") == 0 ? "b" : ""); // Sharp/Flat
                                        sb.Append(note.Pitch.Octave + ",");
                                        sb.Append(NoteTypeToNum(note.Type) + ",");                   // Note length
                                    }
                                }
                            }
                            else if (type == ScoreType.Classical) // Just the highest notes
                            {
                                // Different logic that I need help transcribing
                                if (note.Staff?.CompareTo("1") == 0)
                                {
                                    if (note.Voice?.CompareTo("1") == 0) // Top note
                                    {
                                        bool accidental = note.Pitch.Alter?.CompareTo("1") == 0;

                                        sb.Append(note.Pitch.Step);
                                        sb.Append(accidental ? "b" : "");          // Sharp/Flat
                                        sb.Append(note.Pitch.Octave + ",");
                                        sb.Append(NoteTypeToNum(note.Type) + ","); // Note length
                                    }
                                }
                            }
                            else if (type == ScoreType.Violin) // Violin sheet music
                            {
                                if (note.Staff?.CompareTo("1") == 0)
                                {
                                    string noteReal = string.Empty;
                                    noteReal += note.Pitch.Step;
                                    if (note.Accidental?.CompareTo("sharp") == 0 || note.Pitch.Alter?.CompareTo("1") == 0) // noteReal += note.Accidental.CompareTo("sharp") == 0 ? "s" : "";
                                    {
                                        noteReal += "s";
                                    }
                                    noteReal += note.Pitch.Octave;

                                    noteReal = ConvertToFlat(noteReal);

                                    sb.Append(noteReal + ",");
                                    float f = NoteTypeToNum(note.Type);
                                    if (note.Dot != null)
                                    {
                                        f = f * 1.5f;
                                    }
                                    sb.Append(f + ",");
                                }
                            }

                            else if (type == ScoreType.Chopin) // Violin sheet music
                            {
                                if (note.Staff?.CompareTo("1") == 0)
                                {
                                    string noteReal = string.Empty;
                                    noteReal += note.Pitch.Step;
                                    if (note.Accidental?.CompareTo("sharp") == 0 || note.Pitch.Alter?.CompareTo("1") == 0) // noteReal += note.Accidental.CompareTo("sharp") == 0 ? "s" : "";
                                    {
                                        noteReal += "s";
                                    }
                                    noteReal += note.Pitch.Octave;

                                    noteReal = ConvertToFlat(noteReal);

                                    sb.Append(noteReal + ",");
                                    float f = NoteTypeToNum(note.Type);
                                    if (note.Dot != null)
                                    {
                                        f = f * 1.5f;
                                    }
                                    sb.Append(f + ",");
                                }
                            }
                        }
                    }
                }
            }

            return(sb.ToString());
        }