Exemplo n.º 1
0
        private void Bar()
        {
            var master = new MasterBar();

            _score.AddMasterBar(master);

            var bar = new Bar();

            _track.AddBarToStaff(0, bar);

            if (master.Index > 0)
            {
                master.KeySignature             = master.PreviousMasterBar.KeySignature;
                master.TimeSignatureDenominator = master.PreviousMasterBar.TimeSignatureDenominator;
                master.TimeSignatureNumerator   = master.PreviousMasterBar.TimeSignatureNumerator;
                bar.Clef = bar.PreviousBar.Clef;
            }
            BarMeta(bar);

            var voice = new Voice();

            bar.AddVoice(voice);

            while (_sy != AlphaTexSymbols.Pipe && _sy != AlphaTexSymbols.Eof)
            {
                Beat(voice);
            }

            if (voice.Beats.Count == 0)
            {
                var emptyBeat = new Beat();
                emptyBeat.IsEmpty = true;
                voice.AddBeat(emptyBeat);
            }
        }
Exemplo n.º 2
0
        public void ReadBar(Track track)
        {
            var newBar = new Bar();

            if (track.IsPercussion)
            {
                newBar.Clef = Clef.Neutral;
            }
            track.AddBarToStaff(0, newBar);

            var voiceCount = 1;

            if (_versionNumber >= 500)
            {
                Data.ReadByte();
                voiceCount = 2;
            }

            for (int v = 0; v < voiceCount; v++)
            {
                ReadVoice(track, newBar);
            }
        }
Exemplo n.º 3
0
        private void ParseMeasure(IXmlNode element, Track track, bool isFirstMeasure)
        {
            var barIndex = 0;

            if (isFirstMeasure)
            {
                _trackFirstMeasureNumber = Std.ParseInt(element.GetAttribute("number"));
                barIndex = 0;
            }
            else
            {
                barIndex = Std.ParseInt(element.GetAttribute("number")) - _trackFirstMeasureNumber;
            }

            // create empty bars to the current index
            Bar       bar       = null;
            MasterBar masterBar = null;

            for (int i = track.Staves[0].Bars.Count; i <= barIndex; i++)
            {
                bar       = new Bar();
                masterBar = GetOrCreateMasterBar(barIndex);
                track.AddBarToStaff(0, bar);

                for (int j = 0; j < _maxVoices; j++)
                {
                    var emptyVoice = new Voice();
                    bar.AddVoice(emptyVoice);
                    var emptyBeat = new Beat {
                        IsEmpty = true
                    };
                    emptyVoice.AddBeat(emptyBeat);
                }
            }

            bool chord       = false;
            bool isFirstBeat = true;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "note":
                        chord       = ParseNoteBeat(c, track, bar, chord, isFirstBeat);
                        isFirstBeat = false;
                        break;

                    case "forward":
                        break;

                    case "direction":
                        ParseDirection(c, masterBar);
                        break;

                    case "attributes":
                        ParseAttributes(c, bar, masterBar);
                        break;

                    case "harmony":
                        // TODO
                        break;

                    case "sound":
                        // TODO
                        break;

                    case "barline":
                        // TODO
                        break;
                    }
                }
            });
        }
Exemplo n.º 4
0
        private bool ParseMeasure(IXmlNode element, Track track, bool isFirstMeasure)
        {
            if (element.GetAttribute("implicit") == "yes" && element.GetElementsByTagName("note").Length == 0)
            {
                return(false);
            }

            var barIndex = 0;

            if (isFirstMeasure)
            {
                _divisionsPerQuarterNote = 0;
                _trackFirstMeasureNumber = Std.ParseInt(element.GetAttribute("number"));
                if (_trackFirstMeasureNumber == int.MinValue)
                {
                    _trackFirstMeasureNumber = 0;
                }
                barIndex = 0;
            }
            else
            {
                barIndex = Std.ParseInt(element.GetAttribute("number"));
                if (barIndex == int.MinValue)
                {
                    return(false);
                }
                barIndex -= _trackFirstMeasureNumber;
            }

            // try to find out the number of staffs required
            if (isFirstMeasure)
            {
                var attributes = element.GetElementsByTagName("attributes");
                if (attributes.Length > 0)
                {
                    var stavesElements = attributes[0].GetElementsByTagName("staves");
                    if (stavesElements.Length > 0)
                    {
                        var staves = Std.ParseInt(Std.GetNodeValue(stavesElements[0]));
                        track.EnsureStaveCount(staves);
                    }
                }
            }


            // create empty bars to the current index
            Bar[]     bars      = new Bar[track.Staves.Count];
            MasterBar masterBar = null;

            for (int b = track.Staves[0].Bars.Count; b <= barIndex; b++)
            {
                for (int s = 0; s < track.Staves.Count; s++)
                {
                    var bar = bars[s] = new Bar();
                    if (track.Staves[s].Bars.Count > 0)
                    {
                        var previousBar = track.Staves[s].Bars[track.Staves[s].Bars.Count - 1];
                        bar.Clef = previousBar.Clef;
                    }
                    masterBar = GetOrCreateMasterBar(barIndex);
                    track.AddBarToStaff(s, bar);

                    for (int v = 0; v < _maxVoices; v++)
                    {
                        var emptyVoice = new Voice();
                        bar.AddVoice(emptyVoice);
                        var emptyBeat = new Beat {
                            IsEmpty = true
                        };
                        emptyVoice.AddBeat(emptyBeat);
                    }
                }
            }

            var attributesParsed = false;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                    case "note":
                        ParseNoteBeat(c, bars);
                        break;

                    case "forward":
                        ParseForward(c, bars);
                        break;

                    case "direction":
                        ParseDirection(c, masterBar);
                        break;

                    case "attributes":
                        if (!attributesParsed)
                        {
                            ParseAttributes(c, bars, masterBar);
                            attributesParsed = true;
                        }
                        break;

                    case "harmony":
                        ParseHarmony(c, track);
                        break;

                    case "sound":
                        // TODO
                        break;

                    case "barline":
                        ParseBarline(c, masterBar);
                        break;
                    }
                }
            });

            return(true);
        }