private void Bar() { var master = new MasterBar(); _score.AddMasterBar(master); var bar = new Bar(); _track.AddBar(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); } }
private void ParseDirection(IXmlNode element, MasterBar masterBar) { element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "sound": var tempo = c.GetAttribute("tempo"); if (!string.IsNullOrEmpty(tempo)) { var tempoAutomation = new Automation(); tempoAutomation.IsLinear = true; tempoAutomation.Type = AutomationType.Tempo; tempoAutomation.Value = Std.ParseInt(tempo); masterBar.TempoAutomation = tempoAutomation; } break; case "direction-type": var directionType = c.FirstChild; switch (directionType.LocalName) { case "words": masterBar.Section = new Section(); masterBar.Section.Text = Std.GetNodeValue(directionType); break; } break; } } }); }
public void Generate() { // initialize tracks for (int i = 0, j = _score.Tracks.Count; i < j; i++) { GenerateTrack(_score.Tracks[i]); } var controller = new MidiPlaybackController(_score); MasterBar previousMasterBar = null; // store the previous played bar for repeats while (!controller.Finished) { var index = controller.Index; var bar = _score.MasterBars[index]; var currentTick = controller.CurrentTick; controller.ProcessCurrent(); if (controller.ShouldPlay) { GenerateMasterBar(bar, previousMasterBar, currentTick); for (int i = 0, j = _score.Tracks.Count; i < j; i++) { GenerateBar(_score.Tracks[i].Bars[index], currentTick); } } controller.MoveNext(); previousMasterBar = bar; } }
private void GenerateMasterBar(MasterBar masterBar, MasterBar previousMasterBar, int currentTick) { // time signature if (previousMasterBar == null || previousMasterBar.TimeSignatureDenominator != masterBar.TimeSignatureDenominator || previousMasterBar.TimeSignatureNumerator != masterBar.TimeSignatureNumerator) { _handler.AddTimeSignature(currentTick, masterBar.TimeSignatureNumerator, masterBar.TimeSignatureDenominator); } // tempo if (previousMasterBar == null) { _handler.AddTempo(currentTick, masterBar.Score.Tempo); _currentTempo = masterBar.Score.Tempo; } else if (masterBar.TempoAutomation != null) { _handler.AddTempo(currentTick, (int)masterBar.TempoAutomation.Value); _currentTempo = (int)(masterBar.TempoAutomation.Value); } // metronome if (GenerateMetronome) { var start = currentTick; var length = MidiUtils.ValueToTicks(masterBar.TimeSignatureDenominator); for (int i = 0; i < masterBar.TimeSignatureNumerator; i++) { _handler.AddMetronome(start, length); start += length; } } }
private void GenerateMasterBar(MasterBar masterBar, MasterBar previousMasterBar, int currentTick) { // time signature if (previousMasterBar == null || previousMasterBar.TimeSignatureDenominator != masterBar.TimeSignatureDenominator || previousMasterBar.TimeSignatureNumerator != masterBar.TimeSignatureNumerator) { _handler.AddTimeSignature(currentTick, masterBar.TimeSignatureNumerator, masterBar.TimeSignatureDenominator); } // tempo if (previousMasterBar == null) { _handler.AddTempo(currentTick, masterBar.Score.Tempo); _currentTempo = masterBar.Score.Tempo; } else if (masterBar.TempoAutomation != null) { _handler.AddTempo(currentTick, (int)masterBar.TempoAutomation.Value); _currentTempo = (int)(masterBar.TempoAutomation.Value); } var masterBarLookup = new MasterBarTickLookup(); masterBarLookup.MasterBar = masterBar; masterBarLookup.Start = currentTick; masterBarLookup.Tempo = _currentTempo; masterBarLookup.End = masterBarLookup.Start + masterBar.CalculateDuration(); TickLookup.AddMasterBar(masterBarLookup); }
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); } }
private MasterBar GetOrCreateMasterBar(int index) { if (index < _score.MasterBars.Count) { return(_score.MasterBars[index]); } for (int i = _score.MasterBars.Count; i <= index; i++) { var mb = new MasterBar(); if (_score.MasterBars.Count > 0) { var prev = _score.MasterBars[_score.MasterBars.Count - 1]; mb.TimeSignatureDenominator = prev.TimeSignatureDenominator; mb.TimeSignatureNumerator = prev.TimeSignatureNumerator; mb.KeySignature = prev.KeySignature; mb.KeySignatureType = prev.KeySignatureType; } _score.AddMasterBar(mb); } return(_score.MasterBars[index]); }
public int GetMasterBarStart(MasterBar bar) { if (!MasterBarLookup.ContainsKey(bar.Index)) { return(0); } return(MasterBarLookup[bar.Index].Start); }
private void ParseEnding(IXmlNode element, MasterBar masterBar) { var number = Std.ParseInt(element.GetAttribute("number")); if (number > 0) { --number; masterBar.AlternateEndings |= (byte)(0x01 << number); } }
public MasterBarBounds FindMasterBar(MasterBar bar) { var id = bar.Index; if (_masterBarLookup.ContainsKey(id)) { return(_masterBarLookup[id]); } return(null); }
private static void AddMasterBarToScore(Score score, string sessionText) { var masterBar = new MasterBar(); masterBar.timeSignatureDenominator = 4; masterBar.timeSignatureNumerator = 4; masterBar.section = new global::alphatab.model.Section() { text = sessionText }; score.addMasterBar(masterBar); }
private void ParseKey(IXmlNode element, MasterBar masterBar) { int fifths = int.MinValue; int keyStep = int.MinValue; int keyAlter = int.MinValue; string mode = null; element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "fifths": fifths = Std.ParseInt(Std.GetNodeValue(c)); break; case "key-step": keyStep = Std.ParseInt(Std.GetNodeValue(c)); break; case "key-alter": keyAlter = Std.ParseInt(Std.GetNodeValue(c)); break; case "mode": mode = Std.GetNodeValue(c); break; } } }); if (-7 <= fifths && fifths <= 7) { // TODO: check if this is conrrect masterBar.KeySignature = fifths; } else { masterBar.KeySignature = 0; // TODO: map keyStep/keyAlter to internal keysignature } if (mode == "minor") { masterBar.KeySignatureType = KeySignatureType.Minor; } else { masterBar.KeySignatureType = KeySignatureType.Major; } }
private void ParseAttributes(IXmlNode element, Bar[] bars, MasterBar masterBar) { int number; bool hasTime = false; element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "divisions": _divisionsPerQuarterNote = Std.ParseInt(Std.GetNodeValue(c)); break; case "key": ParseKey(c, masterBar); break; case "time": ParseTime(c, masterBar); hasTime = true; break; case "clef": number = Std.ParseInt(c.GetAttribute("number")); if (number == int.MinValue) { number = 1; } ParseClef(c, bars[number - 1]); break; case "staff-details": number = Std.ParseInt(c.GetAttribute("number")); if (number == int.MinValue) { number = 1; } ParseStaffDetails(c, bars[number - 1].Staff.Track); break; } } }); if (!hasTime) { masterBar.TimeSignatureCommon = true; } }
public MasterBarTickLookup GetMasterBar(MasterBar bar) { if (!MasterBarLookup.ContainsKey(bar.Index)) { return(new MasterBarTickLookup { Start = 0, End = 0, Beats = new FastList <BeatTickLookup>(), MasterBar = bar }); } return(MasterBarLookup[bar.Index]); }
private void ParseTime(IXmlNode element, MasterBar masterBar) { if (element.GetAttribute("symbol") == "common") { masterBar.TimeSignatureCommon = true; } bool beatsParsed = false; bool beatTypeParsed = false; element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { var v = Std.GetNodeValue(c); switch (c.LocalName) { case "beats": if (!beatsParsed) { if (!v.Contains("+")) // compound TS { masterBar.TimeSignatureNumerator = Std.ParseInt(v); } else { masterBar.TimeSignatureNumerator = 4; } beatsParsed = true; } break; case "beat-type": if (!beatTypeParsed) { if (!v.Contains("+")) // compound TS { masterBar.TimeSignatureDenominator = Std.ParseInt(v); } else { masterBar.TimeSignatureDenominator = 4; } beatTypeParsed = true; } break; } } }); }
private MasterBar GetOrCreateMasterBar(int index) { if (index < _score.MasterBars.Count) { return(_score.MasterBars[index]); } for (int i = _score.MasterBars.Count; i <= index; i++) { var mb = new MasterBar(); _score.AddMasterBar(mb); } return(_score.MasterBars[index]); }
protected void AreEqual(MasterBar expected, MasterBar actual) { AreEqual(expected, actual, t => t.AlternateEndings); AreEqual(expected, actual, t => t.Index); AreEqual(expected, actual, t => t.KeySignature); AreEqual(expected, actual, t => t.KeySignatureType); AreEqual(expected, actual, t => t.IsDoubleBar); AreEqual(expected, actual, t => t.IsRepeatStart); AreEqual(expected, actual, t => t.RepeatCount); AreEqual(expected, actual, t => t.TimeSignatureNumerator); AreEqual(expected, actual, t => t.TimeSignatureDenominator); AreEqual(expected, actual, t => t.TripletFeel); AreEqual(expected.Section, actual.Section); AreEqual(expected, actual, t => t.Start); }
protected void AreEqual(MasterBar expected, MasterBar actual) { Assert.AreEqual(expected.AlternateEndings, actual.AlternateEndings, "Mismatch on AlternateEndings"); Assert.AreEqual(expected.Index, actual.Index, "Mismatch on Index"); Assert.AreEqual(expected.KeySignature, actual.KeySignature, "Mismatch on KeySignature"); Assert.AreEqual(expected.KeySignatureType, actual.KeySignatureType, "Mismatch on KeySignatureType"); Assert.AreEqual(expected.IsDoubleBar, actual.IsDoubleBar, "Mismatch on IsDoubleBar"); Assert.AreEqual(expected.IsRepeatStart, actual.IsRepeatStart, "Mismatch on IsRepeatStart"); Assert.AreEqual(expected.RepeatCount, actual.RepeatCount, "Mismatch on RepeatCount"); Assert.AreEqual(expected.TimeSignatureNumerator, actual.TimeSignatureNumerator, "Mismatch on TimeSignatureNumerator"); Assert.AreEqual(expected.TimeSignatureDenominator, actual.TimeSignatureDenominator, "Mismatch on TimeSignatureDenominator"); Assert.AreEqual(expected.TripletFeel, actual.TripletFeel, "Mismatch on TripletFeel"); AreEqual(expected.Section, actual.Section); Assert.AreEqual(expected.Start, actual.Start, "Mismatch on Start"); }
/// <inheritdoc /> public void Generate() { // initialize tracks for (int i = 0, j = _score.Tracks.Count; i < j; i++) { GenerateTrack(_score.Tracks[i]); } Logger.Info("Midi", "Begin midi generation"); var controller = new MidiPlaybackController(_score); MasterBar previousMasterBar = null; // store the previous played bar for repeats while (!controller.Finished) { var index = controller.Index; var bar = _score.MasterBars[index]; var currentTick = controller.CurrentTick; controller.ProcessCurrent(); if (controller.ShouldPlay) { GenerateMasterBar(bar, previousMasterBar, currentTick); for (int i = 0, j = _score.Tracks.Count; i < j; i++) { var track = _score.Tracks[i]; for (int k = 0, l = track.Staves.Count; k < l; k++) { var staff = track.Staves[k]; if (index < staff.Bars.Count) { GenerateBar(staff.Bars[index], currentTick); } } } } controller.MoveNext(); previousMasterBar = bar; } for (int i = 0, j = _score.Tracks.Count; i < j; i++) { _handler.FinishTrack(_score.Tracks[i].Index, controller.CurrentTick); } TickLookup.Finish(); Logger.Info("Midi", "Midi generation done"); }
private void ParseDirection(IXmlNode element, MasterBar masterBar) { element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "sound": var tempoAutomation = new Automation(); tempoAutomation.IsLinear = true; tempoAutomation.Type = AutomationType.Tempo; tempoAutomation.Value = Std.ParseInt(c.GetAttribute("tempo")); masterBar.TempoAutomation = tempoAutomation; break; } } }); }
private void ParseRepeat(IXmlNode element, MasterBar masterBar) { var direction = element.GetAttribute("direction"); var times = Std.ParseInt(element.GetAttribute("times")); if (times < 0) { times = 2; } if (direction == "backward") { masterBar.RepeatCount = times; } else if (direction == "forward") { masterBar.IsRepeatStart = true; } }
private void ParseTime(IXmlNode element, MasterBar masterBar) { element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "beats": masterBar.TimeSignatureNumerator = Std.ParseInt(Std.GetNodeValue(c)); break; case "beats-type": masterBar.TimeSignatureDenominator = Std.ParseInt(Std.GetNodeValue(c)); break; } } }); }
private void ParseBarline(IXmlNode element, MasterBar masterBar) { element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "repeat": ParseRepeat(c, masterBar); break; case "ending": ParseEnding(c, masterBar); break; } } }); }
private void ParseAttributes(XmlElement element, Bar bar, MasterBar masterBar) { element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { var e = (XmlElement)c; switch (c.LocalName) { case "key": ParseKey(e, masterBar); break; case "time": ParseTime(e, masterBar); break; case "clef": ParseClef(e, bar); break; } } }); }
private static void AddMasterBarToScore(Score score, string sessionText, eBeatWrapper measureBeats) { var measureBeatsCount = measureBeats.MeasureSubBeats.Count + 1; var masterBar = new MasterBar(); if (measureBeatsCount == 2) { masterBar.TimeSignatureNumerator = 2; masterBar.TimeSignatureDenominator = 4; } else if (measureBeatsCount == 3) { masterBar.TimeSignatureNumerator = 3; masterBar.TimeSignatureDenominator = 4; } else if (measureBeatsCount == 6) { masterBar.TimeSignatureNumerator = 6; masterBar.TimeSignatureDenominator = 8; } else { masterBar.TimeSignatureNumerator = 4; masterBar.TimeSignatureDenominator = 4; if (measureBeatsCount != 4) { System.Diagnostics.Debug.WriteLine("Unknown timesignature (measureBeatsCount: {0}). Defaulting to 4/4.", measureBeatsCount); } } masterBar.Section = new global::AlphaTab.Model.Section() { Text = sessionText }; score.AddMasterBar(masterBar); }
private void ParseKey(IXmlNode element, MasterBar masterBar) { int fifths = int.MinValue; int keyStep = int.MinValue; int keyAlter = int.MinValue; element.IterateChildren(c => { if (c.NodeType == XmlNodeType.Element) { switch (c.LocalName) { case "fifths": fifths = Std.ParseInt(Std.GetNodeValue(c)); break; case "key-step": keyStep = Std.ParseInt(Std.GetNodeValue(c)); break; case "key-alter": keyAlter = Std.ParseInt(Std.GetNodeValue(c)); break; } } }); if (fifths != int.MinValue) { // TODO: check if this is conrrect masterBar.KeySignature = fifths; } else { // TODO: map keyStep/keyAlter to internal keysignature } }
public void ReadMasterBar() { MasterBar previousMasterBar = default(MasterBar); if (_score.MasterBars.Count > 0) { previousMasterBar = _score.MasterBars[_score.MasterBars.Count - 1]; } MasterBar newMasterBar = new MasterBar(); int flags = _data.ReadByte(); // time signature if ((flags & 0x01) != 0) { newMasterBar.TimeSignatureNumerator = _data.ReadByte(); } else if (previousMasterBar != null) { newMasterBar.TimeSignatureNumerator = previousMasterBar.TimeSignatureNumerator; } if ((flags & 0x02) != 0) { newMasterBar.TimeSignatureDenominator = _data.ReadByte(); } else if (previousMasterBar != null) { newMasterBar.TimeSignatureDenominator = previousMasterBar.TimeSignatureDenominator; } // repeatings newMasterBar.IsRepeatStart = (flags & 0x04) != 0; if ((flags & 0x08) != 0) { newMasterBar.RepeatCount = _versionNumber >= 500 ? _data.ReadByte() : 1; } // marker if ((flags & 0x20) != 0) { Section section = new Section(); section.Text = ReadStringIntByte(); section.Marker = ""; ReadColor(); newMasterBar.Section = section; } // alternate endings if ((flags & 0x10) != 0) { if (_versionNumber < 500) { MasterBar currentMasterBar = previousMasterBar; // get the already existing alternatives to ignore them int existentAlternatives = 0; while (currentMasterBar != null) { // found another repeat ending? if (currentMasterBar.IsRepeatEnd && currentMasterBar != previousMasterBar) { break; } // found the opening? if (currentMasterBar.IsRepeatStart) { break; } existentAlternatives |= currentMasterBar.AlternateEndings; } // now calculate the alternative for this bar var repeatAlternative = 0; var repeatMask = _data.ReadByte(); for (var i = 0; i < 8; i++) { // only add the repeating if it is not existing var repeating = (1 << i); if (repeatMask > i && (existentAlternatives & repeating) == 0) { repeatAlternative |= repeating; } } newMasterBar.AlternateEndings = (byte)repeatAlternative; } else { newMasterBar.AlternateEndings = (byte)_data.ReadByte(); } } // keysignature if ((flags & 0x40) != 0) { newMasterBar.KeySignature = _data.ReadSignedByte(); _data.ReadByte(); // keysignature type } else if (previousMasterBar != null) { newMasterBar.KeySignature = previousMasterBar.KeySignature; } if ((_versionNumber >= 500) && ((flags & 0x03) != 0)) { _data.Skip(4); } // better alternate ending mask in GP5 if ((_versionNumber >= 500) && ((flags & 0x10) == 0)) { newMasterBar.AlternateEndings = (byte)_data.ReadByte(); } // tripletfeel if (_versionNumber >= 500) { var tripletFeel = _data.ReadByte(); switch (tripletFeel) { case 1: newMasterBar.TripletFeel = TripletFeel.Triplet8th; break; case 2: newMasterBar.TripletFeel = TripletFeel.Triplet16th; break; } _data.ReadByte(); } else { newMasterBar.TripletFeel = _globalTripletFeel; } newMasterBar.IsDoubleBar = (flags & 0x80) != 0; _score.AddMasterBar(newMasterBar); }
void ExportBars(Track track) { int lastTempo = -1; prevChordId = -1; for (int i = 0; i < track.Bars.Count; ++i) { var bar = track.Bars[i]; if (gpif.MasterBars.Count <= i) { // this only has to be done for the first track, all other tracks // are assumed to have the same bar layout (which makes sense, if // they are supposed to fit together :) ). var masterBar = new MasterBar(); masterBar.Time = string.Format("{0}/{1}", bar.TimeNominator, bar.TimeDenominator); gpif.MasterBars.Add(masterBar); if (bar.BeatsPerMinute != lastTempo) { // set tempo for this bar var tempo = new Automation(); tempo.Bar = i; tempo.Position = 0; tempo.Linear = false; tempo.Value[0] = bar.BeatsPerMinute; tempo.Value[1] = 2; // no idea what this represents gpif.MasterTrack.Automations.Add(tempo); lastTempo = bar.BeatsPerMinute; } } // construct a voice for this bar var voice = new Voice(); voice.Id = gpif.Voices.Count; foreach (var chord in bar.Chords) { int id = ExportOrFindBeat(chord); voice.Beats.Add(id); } // see if this voice is already available, otherwise add var searchVoice = gpif.Voices.Find(x => x.Equals(voice)); if (searchVoice != null) { voice = searchVoice; } else { gpif.Voices.Add(voice); } // construct the bar var gpBar = new Gpif.Bar(); gpBar.Id = gpif.Bars.Count; if (track.Instrument == Track.InstrumentType.Bass) { gpBar.Clef = "F4"; } else { gpBar.Clef = "G2"; } gpBar.Voices[0] = voice.Id; // see if this bar is already available, otherwise add var searchBar = gpif.Bars.Find(x => x.Equals(gpBar)); if (searchBar != null) { gpBar = searchBar; } else { gpif.Bars.Add(gpBar); } // add to master bar gpif.MasterBars[i].Bars.Add(gpBar.Id); } }
void ExportBars(Track track) { int lastTempo = -1; prevChordId = -1; for (int i = 0; i < track.Bars.Count; ++i) { var bar = track.Bars[i]; if (gpif.MasterBars.Count <= i) { // this only has to be done for the first track, all other tracks // are assumed to have the same bar layout (which makes sense, if // they are supposed to fit together :) ). var masterBar = new MasterBar(); masterBar.Time = string.Format("{0}/{1}", bar.TimeNominator, bar.TimeDenominator); gpif.MasterBars.Add(masterBar); if (bar.BeatsPerMinute != lastTempo) { // set tempo for this bar var tempo = new Automation(); tempo.Bar = i; tempo.Position = 0; tempo.Linear = false; tempo.Value[0] = bar.BeatsPerMinute; tempo.Value[1] = 2; // no idea what this represents gpif.MasterTrack.Automations.Add(tempo); lastTempo = bar.BeatsPerMinute; } } // construct a voice for this bar var voice = new Voice(); voice.Id = gpif.Voices.Count; foreach (var chord in bar.Chords) { int id = ExportOrFindBeat(chord); voice.Beats.Add(id); } // see if this voice is already available, otherwise add var searchVoice = gpif.Voices.Find(x => x.Equals(voice)); if (searchVoice != null) voice = searchVoice; else gpif.Voices.Add(voice); // construct the bar var gpBar = new Gpif.Bar(); gpBar.Id = gpif.Bars.Count; if (track.Instrument == Track.InstrumentType.Bass) gpBar.Clef = "F4"; else gpBar.Clef = "G2"; gpBar.Voices[0] = voice.Id; // see if this bar is already available, otherwise add var searchBar = gpif.Bars.Find(x => x.Equals(gpBar)); if (searchBar != null) gpBar = searchBar; else gpif.Bars.Add(gpBar); // add to master bar gpif.MasterBars[i].Bars.Add(gpBar.Id); } }
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); }
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.Bars.Count; i <= barIndex; i++) { bar = new Bar(); masterBar = GetOrCreateMasterBar(barIndex); track.AddBar(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; } } }); }