Ejemplo n.º 1
0
        private void UpdateMeasureAttributes(MeasureAttributes attributes, List <Staff> staffs, double noteTime)
        {
            //For each staff, refresh timings/clefs etc.
            for (int i = 0; i < staffs.Count; i++)
            {
                Staff staff   = staffs[i];
                Clef  xmlClef = attributes.Clef(i + 1); //xml attrubutes are base 1, not base 0...

                //Check the Clefs not been updated
                if (xmlClef != null && !staff.ClefEquivalentToCurrent(xmlClef))
                {
                    staff.StaffClef.Line = xmlClef.Line;
                    staff.StaffClef.Sign = xmlClef.Sign;
                    staff.AddCleffChange(noteTime);
                }

                Time xmlTime = attributes.Time;
                //Check the timing signature hasn't chagned.
                if (xmlTime != null)
                {
                    if (xmlTime.Beats != staff.Timing.Numerator || xmlTime.Mode != staff.Timing.Denominator)
                    {
                        staff.Timing.Numerator   = xmlTime.Beats;
                        staff.Timing.Denominator = xmlTime.Mode;
                        staff.AddTimingChange(noteTime);
                    }
                }

                Key key = attributes.Key;
                if (key != null)
                {
                    staff.AddKey(noteTime, key);
                }
            }
        }
Ejemplo n.º 2
0
        public Song Parse()
        {
            var song = new Song();

            int?tempo = _score.Parts.First().Measures.First().Directions.Where(x => x.Placement == DirectionPlacement.Above).First().Tempo;

            if (tempo == null)
            {
                song.Tempo = 100;
            }
            else
            {
                song.Tempo = (int)tempo;
            }

            double currentNoteTime  = 0;
            double currentDevisions = 4;

            //foreach (Part part in _score.Parts)
            Part part = MusicXmlHelpers.SelectPianoPart(_score);

            foreach (Measure measure in part.Measures)
            {
                MeasureAttributes attributes = measure.Attributes;
                if (attributes != null)
                {
                    if (attributes.Divisions != -1)
                    {
                        currentDevisions = attributes.Divisions;
                    }
                }

                double lastXmlNoteDuration = 0;

                foreach (Note note in measure.Notes)
                {
                    double noteDuration = note.Duration / currentDevisions;
                    //If the current note is part of a chord, we need to revert to the previous NoteTime
                    if (note.IsChord)
                    {
                        currentNoteTime -= lastXmlNoteDuration;
                    }

                    //After current note drawn, handle keeping track of noteTime in the piece
                    switch (note.NoteType)
                    {
                    case Note.NoteTypes.Note:
                        if (note.TieType == TieType.Stop)
                        {
                            ExtendSongNote(currentNoteTime, song, note, noteDuration);
                        }
                        else
                        {
                            AddSongNoteToSong(currentNoteTime, song, note, noteDuration);
                        }
                        currentNoteTime += noteDuration;
                        break;

                    case Note.NoteTypes.Backup:
                        currentNoteTime -= noteDuration;
                        break;

                    case Note.NoteTypes.Forward:
                        currentNoteTime += noteDuration;
                        break;

                    default:
                        currentNoteTime += noteDuration;
                        break;
                    }
                    lastXmlNoteDuration = noteDuration;
                }
            }

            song = BuildKeyReleases(song);

            return(song);
        }
Ejemplo n.º 3
0
        public void Render()
        {
            _renderHelper = new RenderHelper(_scorePanel);

            double currentNoteTime  = 0;
            int    currentDivisions = 0;

            var staffs = new Staffs(_renderHelper);

            staffs.Add(new Staff(_renderHelper, ScoreLayoutDetails.LineSpacing_Y, ScoreLayoutDetails.Staff1_FristLineY));

            if (_score == null)
            {
                throw new Exception("Score is empty, doh..");
            }

            Part part = MusicXmlHelpers.SelectPianoPart(_score);

            double numberOfStaves = MusicXmlHelpers.GetNumberOfStaves(part);

            //Only add a second stave if nec.
            if (numberOfStaves == 2)
            {
                staffs.Add(new Staff(_renderHelper, ScoreLayoutDetails.LineSpacing_Y, ScoreLayoutDetails.Staff2_FristLineY));
            }

            staffs.AddBarLine(currentNoteTime);

            //foreach (Part part in _score.Parts)
            foreach (Measure measure in part.Measures)
            {
                MeasureAttributes attributes = measure.Attributes;
                if (attributes != null)
                {
                    if (attributes.Divisions != -1)
                    {
                        currentDivisions = attributes.Divisions;
                    }

                    UpdateMeasureAttributes(attributes, staffs, currentNoteTime);
                }

                double lastNoteDuration = 0;

                foreach (Note note in measure.Notes)
                {
                    //If the current note is part of a chord, we need to revert to the previous NoteTime
                    if (note.IsChord)
                    {
                        currentNoteTime -= 1.0 * lastNoteDuration / currentDivisions;
                    }

                    Staff staff = GetStaffFromNote(staffs, note);
                    if (staff != null && note.IsDrawableEntity)
                    {
                        staff.AddNote(note, currentDivisions, currentNoteTime);
                    }

                    //After current note drawn, handle keeping track of noteTime in the piece
                    switch (note.NoteType)
                    {
                    case Note.NoteTypes.Backup: currentNoteTime -= 1.0 * note.Duration / currentDivisions;
                        break;

                    case Note.NoteTypes.Forward: currentNoteTime += 1.0 * note.Duration / currentDivisions;
                        break;

                    default: currentNoteTime += 1.0 * note.Duration / currentDivisions;
                        break;
                    }

                    lastNoteDuration = note.Duration;
                }

                staffs.AddBarLine(currentNoteTime);
            }

            double finalX = _renderHelper.RenderItems(ScoreLayoutDetails.DefaultMargin_X);

            foreach (var staff in staffs)
            {
                staff.DrawStaffLines(ScoreLayoutDetails.DefaultMargin_X, finalX);
            }
        }
Ejemplo n.º 4
0
        public Song Parse()
        {
            var song = new Song();

            int?tempo = _score.Parts.First().Measures.First().Directions.Where(x => x.Placement == DirectionPlacement.Above).First().Tempo;

            if (tempo == null)
            {
                song.Tempo = 100;
            }
            else
            {
                song.Tempo = (int)tempo;
            }


            double currentNoteTime  = 0;
            double currentDevisions = 4;

            foreach (Part part in _score.Parts)
            {
                foreach (Measure measure in part.Measures)
                {
                    MeasureAttributes attributes = measure.Attributes;
                    if (attributes != null)
                    {
                        if (attributes.Divisions != -1)
                        {
                            currentDevisions = attributes.Divisions;
                        }
                    }

                    double lastNoteDuration = 0;

                    foreach (Note note in measure.Notes)
                    {
                        //If the current note is part of a chord, we need to revert to the previous NoteTime
                        if (note.IsChord)
                        {
                            currentNoteTime -= lastNoteDuration / currentDevisions;
                        }

                        //After current note drawn, handle keeping track of noteTime in the piece
                        switch (note.NoteType)
                        {
                        case Note.NoteTypes.Note:
                            song.Add(ConvertXmlNoteToSongNote(currentNoteTime, note));
                            currentNoteTime += note.Duration / currentDevisions;
                            break;

                        case Note.NoteTypes.Backup:
                            currentNoteTime -= note.Duration / currentDevisions;
                            break;

                        case Note.NoteTypes.Forward:
                            currentNoteTime += note.Duration / currentDevisions;
                            break;

                        default:
                            currentNoteTime += note.Duration / currentDevisions;
                            break;
                        }
                        lastNoteDuration = note.Duration;
                    }
                }
            }

            return(song);
        }