Esempio n. 1
0
        public object ToJson()
        {
            var json = Platform.Platform.NewObject();

            var staveGroups = new FastList <StaveGroupBounds>();

            json.StaveGroups = staveGroups;

            foreach (var group in StaveGroups)
            {
                StaveGroupBounds g = Platform.Platform.NewObject();
                g.VisualBounds = BoundsToJson(group.VisualBounds);
                g.RealBounds   = BoundsToJson(group.RealBounds);
                g.Bars         = new FastList <MasterBarBounds>();

                foreach (var masterBar in group.Bars)
                {
                    MasterBarBounds mb = Platform.Platform.NewObject();
                    mb.LineAlignedBounds = BoundsToJson(masterBar.LineAlignedBounds);
                    mb.VisualBounds      = BoundsToJson(masterBar.VisualBounds);
                    mb.RealBounds        = BoundsToJson(masterBar.RealBounds);
                    mb.Index             = masterBar.Index;
                    mb.Bars = new FastList <BarBounds>();

                    foreach (var bar in masterBar.Bars)
                    {
                        BarBounds b = Platform.Platform.NewObject();
                        b.VisualBounds = BoundsToJson(bar.VisualBounds);
                        b.RealBounds   = BoundsToJson(bar.RealBounds);

                        b.Beats = new FastList <BeatBounds>();

                        foreach (var beat in bar.Beats)
                        {
                            var bb = Platform.Platform.NewObject();

                            bb.VisualBounds = BoundsToJson(beat.VisualBounds);
                            bb.RealBounds   = BoundsToJson(beat.RealBounds);
                            bb.BeatIndex    = beat.Beat.Index;
                            bb.VoiceIndex   = beat.Beat.Voice.Index;
                            bb.BarIndex     = beat.Beat.Voice.Bar.Index;
                            bb.StaffIndex   = beat.Beat.Voice.Bar.Staff.Index;
                            bb.TrackIndex   = beat.Beat.Voice.Bar.Staff.Track.Index;

                            b.Beats.Add(bb);
                        }

                        mb.Bars.Add(b);
                    }

                    g.Bars.Add(mb);
                }

                staveGroups.Add(g);
            }

            return(json);
        }
Esempio n. 2
0
        public static BoundsLookup FromJson(object json, Score score)
        {
            var lookup = new BoundsLookup();

            var staveGroups = json.Member <FastList <StaveGroupBounds> >("StaveGroups");

            foreach (var staveGroup in staveGroups)
            {
                var sg = new StaveGroupBounds();
                sg.VisualBounds = staveGroup.VisualBounds;
                sg.RealBounds   = staveGroup.RealBounds;
                lookup.AddStaveGroup(sg);

                foreach (var masterBar in staveGroup.Bars)
                {
                    var mb = new MasterBarBounds();
                    mb.Index             = masterBar.Index;
                    mb.IsFirstOfLine     = masterBar.IsFirstOfLine;
                    mb.LineAlignedBounds = masterBar.LineAlignedBounds;
                    mb.VisualBounds      = masterBar.VisualBounds;
                    mb.RealBounds        = masterBar.RealBounds;
                    sg.AddBar(mb);

                    foreach (var bar in masterBar.Bars)
                    {
                        var b = new BarBounds();
                        b.VisualBounds = bar.VisualBounds;
                        b.RealBounds   = bar.RealBounds;
                        mb.AddBar(b);

                        foreach (var beat in bar.Beats)
                        {
                            var bb = new BeatBounds();
                            bb.VisualBounds = beat.VisualBounds;
                            bb.RealBounds   = beat.RealBounds;
                            bb.Beat         = score
                                              .Tracks[beat.Member <int>("TrackIndex")]
                                              .Staves[beat.Member <int>("StaffIndex")]
                                              .Bars[beat.Member <int>("BarIndex")]
                                              .Voices[beat.Member <int>("VoiceIndex")]
                                              .Beats[beat.Member <int>("BeatIndex")];

                            b.AddBeat(bb);
                        }
                    }
                }
            }

            return(lookup);
        }
Esempio n. 3
0
        public static BoundsLookup FromJson(object json, Score score)
        {
            var lookup = new BoundsLookup();

            var staveGroups = json.Member("StaveGroups").As<FastList<StaveGroupBounds>>();
            foreach (var staveGroup in staveGroups)
            {
                var sg = new StaveGroupBounds();
                sg.VisualBounds = staveGroup.VisualBounds;
                sg.RealBounds = staveGroup.RealBounds;
                lookup.AddStaveGroup(sg);

                foreach (var masterBar in staveGroup.Bars)
                {
                    var mb = new MasterBarBounds();
                    mb.IsFirstOfLine = masterBar.IsFirstOfLine;
                    mb.VisualBounds = masterBar.VisualBounds;
                    mb.RealBounds = masterBar.RealBounds;
                    sg.AddBar(mb);

                    foreach (var bar in masterBar.Bars)
                    {
                        var b = new BarBounds();
                        b.VisualBounds = bar.VisualBounds;
                        b.RealBounds = bar.RealBounds;
                        mb.AddBar(b);

                        foreach (var beat in bar.Beats)
                        {
                            var bb = new BeatBounds();
                            bb.VisualBounds = beat.VisualBounds;
                            bb.RealBounds = beat.RealBounds;
                            bb.Beat = score
                                .Tracks[beat.Member("TrackIndex").As<int>()]
                                .Staves[beat.Member("StaffIndex").As<int>()]
                                .Bars[beat.Member("BarIndex").As<int>()]
                                .Voices[beat.Member("VoiceIndex").As<int>()]
                                .Beats[beat.Member("BeatIndex").As<int>()];

                            b.AddBeat(bb);
                        }
                    }
                }
            }

            return lookup;
        }
Esempio n. 4
0
 public void AddBar(BarBounds bounds)
 {
     bounds.MasterBarBounds = this;
     Bars.Add(bounds);
 }
Esempio n. 5
0
        public virtual void BuildBoundingsLookup(MasterBarBounds masterBarBounds, float cx, float cy)
        {
            var barBounds = new BarBounds();
            barBounds.Bar = Bar;
            barBounds.VisualBounds = new Bounds
            {
                X = cx + X,
                Y = cy + Y + TopPadding,
                W = Width,
                H = Height - TopPadding - BottomPadding
            };
            barBounds.RealBounds = new Bounds
            {
                X = cx + X,
                Y = cy + Y,
                W = Width,
                H = Height
            };
            masterBarBounds.AddBar(barBounds);

            foreach (var voice in _voiceContainers)
            {
                var c = _voiceContainers[voice];
                if (!c.Voice.IsEmpty)
                {
                    for (int i = 0, j = c.BeatGlyphs.Count; i < j; i++)
                    {
                        var bc = c.BeatGlyphs[i];

                        var beatBoundings = new BeatBounds();
                        beatBoundings.Beat = bc.Beat;
                        beatBoundings.VisualBounds = new Bounds
                        {
                            X = cx + X + c.X + bc.X + bc.OnNotes.X,
                            Y = barBounds.VisualBounds.Y,
                            W = bc.OnNotes.Width,
                            H = barBounds.VisualBounds.H
                        };
                        beatBoundings.RealBounds = new Bounds
                        {
                            X = cx + X + c.X + bc.X,
                            Y = barBounds.RealBounds.Y,
                            W = bc.Width,
                            H = barBounds.RealBounds.H
                        };
                        barBounds.AddBeat(beatBoundings);
                    }
                }
            }
        }
Esempio n. 6
0
 public void AddBar(BarBounds bounds)
 {
     bounds.MasterBarBounds = this;
     Bars.Add(bounds);
 }