public WPFMeasure(ScorePartwisePartMeasure measure, double fontSize)
 {
     FontSize                = fontSize;
     ScoreMeasure            = measure;
     MeasureFrameworkElement = WpfMeasureRendering.RenderMeasure(measure, 0, fontSize); //todo: staff properly
 }
Exemplo n.º 2
0
        /// <summary>
        /// Render a measure onto a canvas
        /// </summary>
        /// <param name="measure">The measure to render</param>
        /// <param name="staff">The staff being rendered for</param>
        /// <returns>A Framework Element with the measure rendered onto it</returns>
        public static Panel RenderMeasure(ScorePartwisePartMeasure measure, int staff, double fontSize) //todo: not return canvas
        {
            //todo: stack/queue for tie
            //todo: stack/queue for slur
            //todo: stack/queue for beam

            //todo: maybe approach this by doing all staves in render measure?

            double left = 0; //todo: padding/margin
            double top  = 0; //todo: padding/margin

            ICollection <object> itemList = measure.Items;
            FrameworkElement     element  = null;
            Panel grid = WPFRendering.CreateAutoSizingGrid();

            grid.Margin = new Thickness(50, 50, 0, 0); //todo: proper margin

            //todo: render each item
            for (int i = 0; i < itemList.Count; i++)
            {
                object obj  = itemList.ElementAt(i);
                Type   type = obj.GetType();


                if (type == typeof(Attributes))
                {
                    Attributes attributes = (Attributes)obj;
                    element = RenderAttributes(attributes, staff, fontSize);
                }
                else if (type == typeof(Note))
                {
                    //todo: may need to use attributes from previous measure to figure out where to render
                    Note note = (Note)obj;
                    element = RenderNoteOrRest(note, fontSize);
                }
                else if (type == typeof(Barline))
                {
                    Barline barline = (Barline)obj;
                    element = RenderBarline(barline, fontSize);
                }
                else if (type == typeof(Print))
                {
                    //todo: complete this section
                    element = new Label();
                }
                else if (type == typeof(Direction))
                {
                    //todo: complete this section
                    element = new Label();
                }

                if (element != null)
                {
                    element.Margin = new Thickness(left, top, 0, 0);
                    grid.Children.Add(element);
                    left += element.ActualWidth + 0; //todo: margin
                }
                else
                {
                    throw new NullMeasureElementException("Null element: " + obj.GetType() + "\n");
                }
            }

            //todo: render multiple staves for multi-part instruments etc
            //      This should be as simple as rendering a second staff then putting the note onto that staff as required
            //      Then joining those two staves via a wrapper container

            element = RenderStaff(Constants.Colors.DEFAULT_NOTE_COLOR, left, fontSize);
            grid.Children.Add(element);

            WPFRendering.RecalculateSize(grid);
            return(grid);
        }
        public string KeyboardTilesToMusicXML(List <KeyboardTile> keyboardTiles, int frameCount)
        {
            // Downloaded youtube videos always have a fps of 23.98
            int videoLength = frameCount / 24;

            int measureCount = videoLength / 2;

            ScorePartwisePartMeasure[] measures = new ScorePartwisePartMeasure[measureCount];
            for (int i = 0; i < measureCount; i++)
            {
                measures[i]        = new ScorePartwisePartMeasure();
                measures[i].Number = i.ToString();
            }

            Dictionary <Note, int> NoteFrameDict = new Dictionary <Note, int>();

            foreach (var keyboardTile in keyboardTiles)
            {
                foreach (var press in keyboardTile.TilePresses)
                {
                    var startFrame = press.Item1;
                    var endFrame   = press.Item2;

                    Pitch keyboardPitch = new Pitch();
                    keyboardPitch.Octave = keyboardTile.Octave.ToString();
                    keyboardPitch.Step   = NotesToMusicXMLStep[keyboardTile.Note];
                    keyboardPitch.Alter  = NoteToAlter(keyboardTile.Note);
                    double startSec     = startFrame / 24;
                    int    measureIndex = (int)(startSec / 2);
                    var    measure      = measures[measureIndex];
                    Note   pressNote    = new Note();
                    pressNote.Pitch = keyboardPitch;
                    pressNote.Type  = DurationToNodeType(press);
                    measure.Note.Add(pressNote);
                    NoteFrameDict.Add(pressNote, startFrame);
                }
            }

            for (int i = 0; i < measures.Length; i++)
            {
                var measure = measures[i];

                Note[] notes        = new Note[measure.Note.Count];
                var    notesOrdered = notes.OrderBy(x => NoteFrameDict[x]).Select(x => x);

                measure.Note.CopyTo(notes, 0);

                while (measure.Note.Count > 0)
                {
                    measure.Note.RemoveAt(0);
                }

                foreach (var note in notesOrdered)
                {
                    measure.Note.Add(note);
                }

                var lastFrame = 0;

                foreach (var note in measure.Note)
                {
                    var startFrame = NoteFrameDict[note];

                    if (lastFrame == startFrame)
                    {
                        note.Chord = new Empty();
                    }

                    lastFrame = startFrame;
                }
            }

            ScorePartwise spw       = new ScorePartwise();
            PartList      partList  = new PartList();
            ScorePart     scorePart = new ScorePart();
            PartName      partName  = new PartName();

            partName.Value     = "NotesheetR";
            scorePart.PartName = partName;
            scorePart.Id       = "1";
            partList.ScorePart = scorePart;
            ScorePartwisePart part = new ScorePartwisePart();

            part.Id = "1";

            foreach (var measure in measures)
            {
                part.Measure.Add(measure);
            }

            spw.Part.Add(part);
            spw.PartList = partList;
            return(ParseToXml(spw));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Wrapper for rendering a page. This is here so that passing in information that is not represented in
 /// MusicXML can be done.
 /// </summary>
 /// <param name="measure">The measure to render</param>
 /// <returns>Measure drawn on a canvas</returns>
 public Panel RenderMeasure(ScorePartwisePartMeasure measure)
 {
     //todo: render top staff measure and bottom then combine
     return(WpfMeasureRendering.RenderMeasure(measure, 0, FontSize));
 }
Exemplo n.º 5
0
 public Panel RenderMeasure(ScorePartwisePartMeasure measure, List <int> staves)
 {
     // todo: only render certain staves of a line of music
     return(WPFRendering.CreateAutoSizingGrid());
 }
        //todo: not return canvas
        /// <summary>
        /// Render a measure onto a canvas
        /// </summary>
        /// <param name="measure">The measure to render</param>
        /// <param name="staff">The staff being rendered for</param>
        /// <returns>A Framework Element with the measure rendered onto it</returns>
        public static Panel RenderMeasure(ScorePartwisePartMeasure measure, int staff, double fontSize)
        {
            //todo: stack/queue for tie
            //todo: stack/queue for slur
            //todo: stack/queue for beam

            //todo: maybe approach this by doing all staves in render measure?

            double left = 0; //todo: padding/margin
            double top = 0; //todo: padding/margin

            ICollection<object> itemList = measure.Items;
            FrameworkElement element = null;
            Panel grid = WPFRendering.CreateAutoSizingGrid();
            grid.Margin = new Thickness(50, 50, 0, 0); //todo: proper margin

            //todo: render each item
            for (int i = 0; i < itemList.Count; i++)
            {
                object obj = itemList.ElementAt(i);
                Type type = obj.GetType();

                if (type == typeof(Attributes))
                {
                    Attributes attributes = (Attributes) obj;
                    element = RenderAttributes(attributes, staff, fontSize);
                }
                else if (type == typeof(Note))
                {
                    //todo: may need to use attributes from previous measure to figure out where to render
                    Note note = (Note)obj;
                    element = RenderNoteOrRest(note, fontSize);
                }
                else if (type == typeof(Barline))
                {
                    Barline barline = (Barline)obj;
                    element = RenderBarline(barline, fontSize);
                }
                else if (type == typeof(Print))
                {
                    //todo: complete this section
                    element = new Label();
                }
                else if (type == typeof(Direction))
                {
                    //todo: complete this section
                    element = new Label();
                }

                if (element != null)
                {
                    element.Margin = new Thickness(left, top, 0, 0);
                    grid.Children.Add(element);
                    left += element.ActualWidth + 0; //todo: margin
                }
                else
                {
                    throw new NullMeasureElementException("Null element: " + obj.GetType() + "\n");
                }
            }

            //todo: render multiple staves for multi-part instruments etc
            //      This should be as simple as rendering a second staff then putting the note onto that staff as required
            //      Then joining those two staves via a wrapper container

            element = RenderStaff(Constants.Colors.DEFAULT_NOTE_COLOR, left, fontSize);
            grid.Children.Add(element);

            WPFRendering.RecalculateSize(grid);
            return grid;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Calculate the width of a measure
 /// </summary>
 /// <param name="measure">The measure to calculate the width of</param>
 /// <returns>The width of the measure inserted</returns>
 public double CalculateMeasureWidth(ScorePartwisePartMeasure measure)
 {
     return(RenderMeasure(measure).ActualWidth);
 }
 public WPFMeasure(ScorePartwisePartMeasure measure, double fontSize)
 {
     FontSize = fontSize;
     ScoreMeasure = measure;
     MeasureFrameworkElement = WpfMeasureRendering.RenderMeasure(measure, 0, fontSize); //todo: staff properly
 }
        public void ParseSimpleOneNoteStringTest()
        {
            String testString1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
                                "<!DOCTYPE score-partwise PUBLIC\n" +
                                "\"-//Recordare//DTD MusicXML 3.0 Partwise//EN\"\n" +
                                "\"http://www.musicxml.org/dtds/partwise.dtd\">\n" +
                                "<score-partwise version=\"3.0\">\n" +
                                "<part-list><score-part id=\"P1\"><part-name>Music</part-name></score-part></part-list>" +
                                "<part id=\"P1\"><measure number=\"1\"><attributes><divisions>1</divisions><key>" +
                                "<fifths>0</fifths></key><time><beats>4</beats><beat-type>4</beat-type></time>" +
                                "<clef><sign>G</sign><line>2</line></clef></attributes>" +
                                "<note><pitch><step>C</step><octave>4</octave></pitch><duration>4</duration>" +
                                "<type>whole</type><stem>up</stem></note></measure></part></score-partwise>";
            // create the expected structure
            Note n = new Note()
            {
                type = new NoteType { Value = NoteTypeValue.whole },
                stem = new Stem { Value = stemvalue.up },
                Items = new object[] { new Pitch { step = Step.C, octave = "4" }, new decimal(4) },
                ItemsElementName = new[] { ItemsChoiceType1.pitch, ItemsChoiceType1.duration }
            };

            ScorePartwisePartMeasure m = new ScorePartwisePartMeasure()
            {
                number = "1",
                Items = new object[]{
                    new Attributes()
                    {
                        divisions = 1,
                        key = new[]
                        {
                            new Key
                                {
                                Items = new object[]
                                {
                                    0
                                },
                                ItemsElementName = new[]
                                {
                                    ItemsChoiceType8.fifths
                                },
                            }
                        },
                        time = new[]
                        {
                            new Time { Beats = "4", BeatType = "4"}
                        },
                        clef = new[]
                        {
                            new Clef
                            {
                                sign = ClefSign.G,
                                line = "2"
                            }
                        }
                    },
                n
                }
            };

            // set expected
            ScorePartwise expected = new ScorePartwise { version = "3.0", part = new ScorePartwisePart[1] };

            // measure part and information
            expected.part[0] = new ScorePartwisePart { measure = new ScorePartwisePartMeasure[1] };
            expected.part[0].measure[0] = m;
            expected.part[0].id = "P1";

            // part list
            expected.partList = new PartList() { scorepart = new ScorePart() { id = "P1", partName = new PartName { Value = "Music" } } };

            ScorePartwise actual = ScorePartwise.Deserialize(testString1);
            CompareProperties(actual.GetType(), actual, expected);
        }
 public Panel RenderMeasure(ScorePartwisePartMeasure measure, List<int> staves)
 {
     // todo: only render certain staves of a line of music
     return WPFRendering.CreateAutoSizingGrid();
 }
 /// <summary>
 /// Wrapper for rendering a page. This is here so that passing in information that is not represented in 
 /// MusicXML can be done.
 /// </summary>
 /// <param name="measure">The measure to render</param>
 /// <returns>Measure drawn on a canvas</returns>
 public Panel RenderMeasure(ScorePartwisePartMeasure measure)
 {
     //todo: render top staff measure and bottom then combine
     return WpfMeasureRendering.RenderMeasure(measure, 0, FontSize);
 }
 /// <summary>
 /// Calculate the width of a measure
 /// </summary>
 /// <param name="measure">The measure to calculate the width of</param>
 /// <returns>The width of the measure inserted</returns>
 public double CalculateMeasureWidth(ScorePartwisePartMeasure measure)
 {
     return RenderMeasure(measure).ActualWidth;
 }