private MusicalSymbol getSymbol(ISymbol symbol)
 {
     if (symbol is MaatStreepSymbol)
     {
         return(new Barline());
     }
     else if (symbol is TimeSignatureSymbol)
     {
         TimeSignatureSymbol timeSignatureObject = (TimeSignatureSymbol)symbol;
         return(new TimeSignature(TimeSignatureType.Numbers, (uint)timeSignatureObject.timeSignature[0], (uint)timeSignatureObject.timeSignature[1]));
     }
     else if (symbol is RestSymbol)
     {
         RestSymbol restObject = (RestSymbol)symbol;
         return(new Rest(noteLengthToMusicalSymbolDuration((int)restObject.lengte))
         {
             NumberOfDots = restObject.punt
         });
     }
     else if (symbol is TempoSymbol)
     {
         return(null);
     }
     else
     {
         NoteSymbol noteObject = (NoteSymbol)symbol;
         return(new Note(noteObject.toonHoogte, noteObject.kruisMol, noteObject.octaaf - 1, noteLengthToMusicalSymbolDuration((int)noteObject.lengte), NoteStemDirection.Up, NoteTieType.None, new List <NoteBeamType>()
         {
             NoteBeamType.Single
         })
         {
             NumberOfDots = noteObject.punt
         });
     }
 }
Exemple #2
0
        private ISymbol createNote(string note)
        {
            string toonhoogte = note.Substring(0, 1);       // a, b, c etc..

            if (toonhoogte == "r")
            {
                RestSymbol newNote = new RestSymbol();
                newNote.octaaf = latestNoteOctaaf;

                newNote.kruisMol = addKruisMol(note);

                if (note.Substring(note.Length - 1, 1) == ".")
                {
                    newNote.punt = 1;
                }
                try
                {
                    newNote.lengte = Int32.Parse(Regex.Match(note, @"\d+").Value);
                }
                catch
                {
                    newNote.lengte = 1;
                }
                latestNoteOctaaf     = newNote.octaaf;
                latestNoteToonhoogte = newNote.toonHoogte;
                return(newNote);
            }
            else
            {
                NoteSymbol newNote = new NoteSymbol();
                newNote.toonHoogte = toonhoogte.ToUpper();
                newNote.octaaf     = setCurrentOctaaf(note);
                newNote.kruisMol   = addKruisMol(note);

                if (note.Substring(note.Length - 1, 1) == ".")
                {
                    newNote.punt = 1;
                }
                try
                {
                    newNote.lengte = Int32.Parse(Regex.Match(note, @"\d+").Value);
                }
                catch
                {
                    newNote.lengte = 1;
                }
                latestNoteOctaaf     = newNote.octaaf;
                latestNoteToonhoogte = newNote.toonHoogte;
                return(newNote);
            }
        }
        public void draw(ScrollViewer scrollViewer, TrackObject track)
        {
            createStaff();

            staff.ClearMusicalIncipit();
            staff.Width = 500;
            staff.AddMusicalSymbol(new Clef(ClefType.GClef, 2));

            double maatvol = 0;
            int    a       = 0;

            if (track.notes.Count > 2)
            {
                foreach (ISymbol symbol in track.notes)
                {
                    if (symbol is NoteSymbol)
                    {
                        NoteSymbol note = (NoteSymbol)symbol;
                        a = note.absoluteTicks >= 16128 && track.timeSignature.Count > 1 ? 1 : 0;
                        if (track.timeSignature.Count > 0)
                        {
                            if (maatvol >= track.timeSignature[a][1])
                            {
                                staff.AddMusicalSymbol(new Barline());
                                maatvol = 0;
                            }
                        }

                        maatvol += note.nootduur;
                    }

                    MusicalSymbol musicalSymbol = getSymbol(symbol);

                    if (musicalSymbol != null)
                    {
                        staff.AddMusicalSymbol(musicalSymbol);
                    }
                    staff.Width += 30;
                }
            }

            scrollViewer.Content = staff;
        }
        public string convert(TrackObject track)
        {
            string lilyPond = "\\relative c' { \n \\clef treble \n";

            for (int i = 0; i < track.notes.Count; i++)
            {
                if (track.notes[i] is NoteSymbol)
                {
                    NoteSymbol note = (NoteSymbol)track.notes[i];
                    lilyPond += note.toonHoogte.ToLower();
                    if (note.kruisMol > 0)
                    {
                        lilyPond += "is";
                    }
                    if (note.kruisMol < 0)
                    {
                        lilyPond += "es";
                    }
                    for (int o = prevOctaaf; o < note.octaaf; o++)
                    {
                        lilyPond += "'";
                    }
                    for (int o = prevOctaaf; o > note.octaaf; o--)
                    {
                        lilyPond += ",";
                    }
                    lilyPond += note.lengte;
                    if (note.punt == 1)
                    {
                        lilyPond += ".";
                    }
                    prevOctaaf = note.octaaf;
                    lilyPond  += " ";
                }
                if (track.notes[i] is RestSymbol)
                {
                    RestSymbol rest = (RestSymbol)track.notes[i];
                    lilyPond += "r" + rest.lengte;
                    if (rest.punt == 1)
                    {
                        lilyPond += ".";
                    }
                    lilyPond += " ";
                }
                if (track.notes[i] is MaatStreepSymbol)
                {
                    lilyPond += "|\n";
                }
                if (track.notes[i] is TimeSignatureSymbol)
                {
                    TimeSignatureSymbol ts = (TimeSignatureSymbol)track.notes[i];
                    lilyPond += "\\time " + ts.timeSignature[0] + "/" + ts.timeSignature[1] + " \n";
                }
                if (track.notes[i] is TempoSymbol)
                {
                    TempoSymbol tempoSymbol = (TempoSymbol)track.notes[i];
                    lilyPond += "\\tempo " + tempoSymbol.tempo[0] + "=" + tempoSymbol.tempo[1] + " \n";
                }
                // lilyPond += (i % 5) == 0 ? "\n" : string.Empty;
            }
            lilyPond += "\n}";
            return(lilyPond);
        }