private static void AddBeatWithChordToVoice(Voice voice, SongChord2014 sourceChord, Duration duration, Single durationTime) { var beat = new Beat(); beat.Duration = duration; voice.AddBeat(beat); beat.ChordId = sourceChord.ChordId.ToString(); AlphaTab.Model.Chord chord = null; try { chord = beat.Chord; } catch (KeyNotFoundException) { } //Will be non-null if predefined chord exist (and predefined chord should exist if ChordId is present in ChordTemplates) if (chord == null) { beat.ChordId = null; //chord = new global::alphatab.model.Chord(); //voice.bar.track.chords.set(beat.chordId, chord); //Set notes in beat from this chord if (sourceChord.ChordNotes != null) { foreach (var sourceNote in sourceChord.ChordNotes) { var note1 = NoteFromNote(sourceNote, durationTime); beat.AddNote(note1); } } } else { //Set notes in beat from predefined chord for (int i = 0; i < chord.Strings.Count; i++) { var tmpstrFret = chord.Strings[i]; if (tmpstrFret > -1) { var note1 = new Note(); note1.Fret = tmpstrFret; note1.String = i + 1; beat.AddNote(note1); } } } }
private void ParseDiagramItem(Track track, IXmlNode node) { var chord = new Chord(); var chordId = node.Attributes.Get("id").Value; chord.Name = node.Attributes.Get("name").Value; track.Chords[chordId] = chord; }
public void ReadChord(Beat beat) { var chord = new Chord(); var chordId = Std.NewGuid(); if (_versionNumber >= 500) { Data.Skip(17); chord.Name = ReadStringByteLength(21); Data.Skip(4); chord.FirstFret = ReadInt32(); for (int i = 0; i < 7; i++) { var fret = ReadInt32(); if (i < chord.Strings.Count) { chord.Strings.Add(fret); } } Data.Skip(32); } else { if (Data.ReadByte() != 0) // mode1? { // gp4 if (_versionNumber >= 400) { // Sharp (1) // Unused (3) // Root (1) // Major/Minor (1) // Nin,Eleven or Thirteen (1) // Bass (4) // Diminished/Augmented (4) // Add (1) Data.Skip(16); chord.Name = (ReadStringByteLength(21)); // Unused (2) // Fifth (1) // Ninth (1) // Eleventh (1) Data.Skip(4); chord.FirstFret = (ReadInt32()); for (int i = 0; i < 7; i++) { var fret = ReadInt32(); if (i < chord.Strings.Count) { chord.Strings.Add(fret); } } // number of barres (1) // Fret of the barre (5) // Barree end (5) // Omission1,3,5,7,9,11,13 (7) // Unused (1) // Fingering (7) // Show Diagram Fingering (1) // ?? Data.Skip(32); } else { // unknown Data.Skip(25); chord.Name = ReadStringByteLength(34); chord.FirstFret = ReadInt32(); for (int i = 0; i < 6; i++) { var fret = ReadInt32(); chord.Strings.Add(fret); } // unknown Data.Skip(36); } } else { int strings = _versionNumber >= 406 ? 7 : 6; chord.Name = ReadStringIntByte(); chord.FirstFret = ReadInt32(); if (chord.FirstFret > 0) { for (int i = 0; i < strings; i++) { var fret = ReadInt32(); if (i < chord.Strings.Count) { chord.Strings.Add(fret); } } } } } if (!string.IsNullOrEmpty(chord.Name)) { beat.ChordId = chordId; beat.Voice.Bar.Staff.Track.Chords[beat.ChordId] = chord; } }
public Score JsObjectToScore(Score score) { var score2 = new Score(); Score.CopyTo(score, score2); #region MasterBars for (var i = 0;i < score.MasterBars.Count; i++) { var masterBar = score.MasterBars[i]; var masterBar2 = new MasterBar(); MasterBar.CopyTo(masterBar, masterBar2); if (masterBar.TempoAutomation != null) { masterBar2.TempoAutomation = new Automation(); Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation); } if (masterBar.VolumeAutomation != null) { masterBar2.VolumeAutomation = new Automation(); Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation); } if (masterBar.Section != null) { masterBar2.Section = new Section(); Section.CopyTo(masterBar.Section, masterBar2.Section); } score2.AddMasterBar(masterBar2); } #endregion #region Tracks for (int t = 0; t < score.Tracks.Count; t++) { var track = score.Tracks[t]; var track2 = new Track(); Track.CopyTo(track, track2); score2.AddTrack(track2); PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo); foreach (var key in track.Chords.Keys) { var chord = track.Chords[key]; var chord2 = new Chord(); Chord.CopyTo(chord, chord2); track2.Chords[key] = chord2; } #region Bars for (int b = 0; b < track.Bars.Count; b++) { var bar = track.Bars[b]; var bar2 = new Bar(); Bar.CopyTo(bar, bar2); track2.AddBar(bar2); #region Voices for (int v = 0; v < bar.Voices.Count; v++) { var voice = bar.Voices[v]; var voice2 = new Voice(); Voice.CopyTo(voice, voice2); bar2.AddVoice(voice2); #region Beats for (int bb = 0; bb < voice.Beats.Count; bb++) { var beat = voice.Beats[bb]; var beat2 = new Beat(); Beat.CopyTo(beat, beat2); voice2.AddBeat(beat2); for (int a = 0; a < beat.Automations.Count; a++) { var automation = new Automation(); Automation.CopyTo(beat.Automations[a], automation); beat2.Automations.Add(automation); } for (int i = 0; i < beat.WhammyBarPoints.Count; i++) { var point = new BendPoint(); BendPoint.CopyTo(beat.WhammyBarPoints[i], point); beat2.WhammyBarPoints.Add(point); } #region Notes for (int n = 0; n < beat.Notes.Count; n++) { var note = beat.Notes[n]; var note2 = new Note(); Note.CopyTo(note, note2); beat2.AddNote(note2); for (int i = 0; i < note.BendPoints.Count; i++) { var point = new BendPoint(); BendPoint.CopyTo(note.BendPoints[i], point); note2.AddBendPoint(point); } } #endregion } #endregion } #endregion } #endregion } #endregion score2.Finish(); return score2; }
private void ParseDiagramItem(Track track, XmlElement node) { var chord = new Chord(); var chordId = node.Attributes["id"].Value; chord.Name = node.Attributes["name"].Value; track.Chords[chordId] = chord; }
internal static void CopyTo(Chord src, Chord dst) { dst.FirstFret = src.FirstFret; dst.Name = src.Name; dst.Strings = src.Strings.Clone(); }
/// <summary> /// Converts the score into a JavaScript object without circular dependencies. /// </summary> /// <param name="score">The score object to serialize</param> /// <returns>A serialized score object without ciruclar dependencies that can be used for further serializations.</returns> public static object ScoreToJsObject(Score score) { Score score2 = Platform.Platform.NewObject(); Score.CopyTo(score, score2); score2.MasterBars = new FastList <MasterBar>(); score2.Tracks = new FastList <Track>(); score2.Stylesheet = Platform.Platform.NewObject(); RenderStylesheet.CopyTo(score.Stylesheet, score2.Stylesheet); #region MasterBars for (var i = 0; i < score.MasterBars.Count; i++) { MasterBar masterBar = score.MasterBars[i]; MasterBar masterBar2 = Platform.Platform.NewObject(); MasterBar.CopyTo(masterBar, masterBar2); if (masterBar.TempoAutomation != null) { masterBar2.TempoAutomation = Platform.Platform.NewObject(); Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation); } if (masterBar.Section != null) { masterBar2.Section = Platform.Platform.NewObject(); Section.CopyTo(masterBar.Section, masterBar2.Section); } masterBar2.Fermata = Platform.Platform.NewObject(); foreach (var offset in masterBar.Fermata) { var fermata = masterBar.Fermata[offset]; var fermata2 = masterBar2.Fermata[offset] = Platform.Platform.NewObject(); Fermata.CopyTo(fermata, fermata2); } score2.MasterBars.Add(masterBar2); } #endregion #region Tracks for (int t = 0; t < score.Tracks.Count; t++) { var track = score.Tracks[t]; Track track2 = Platform.Platform.NewObject(); track2.Color = Platform.Platform.NewObject(); Track.CopyTo(track, track2); track2.PlaybackInfo = Platform.Platform.NewObject(); PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo); #region Staves track2.Staves = new FastList <Staff>(); for (int s = 0; s < track.Staves.Count; s++) { var staff = track.Staves[s]; Staff staff2 = Platform.Platform.NewObject(); Staff.CopyTo(staff, staff2); staff2.Chords = new FastDictionary <string, Chord>(); foreach (var key in staff.Chords) { var chord = staff.Chords[key]; Chord chord2 = Platform.Platform.NewObject(); Chord.CopyTo(chord, chord2); staff2.Chords[key] = chord; } #region Bars staff2.Bars = new FastList <Bar>(); for (int b = 0; b < staff.Bars.Count; b++) { var bar = staff.Bars[b]; Bar bar2 = Platform.Platform.NewObject(); Bar.CopyTo(bar, bar2); #region Voices bar2.Voices = new FastList <Voice>(); for (int v = 0; v < bar.Voices.Count; v++) { var voice = bar.Voices[v]; Voice voice2 = Platform.Platform.NewObject(); Voice.CopyTo(voice, voice2); #region Beats voice2.Beats = new FastList <Beat>(); for (int bb = 0; bb < voice.Beats.Count; bb++) { var beat = voice.Beats[bb]; Beat beat2 = Platform.Platform.NewObject(); Beat.CopyTo(beat, beat2); beat2.Automations = new FastList <Automation>(); for (int a = 0; a < beat.Automations.Count; a++) { Automation automation = Platform.Platform.NewObject(); Automation.CopyTo(beat.Automations[a], automation); beat2.Automations.Add(automation); } beat2.WhammyBarPoints = new FastList <BendPoint>(); for (int i = 0; i < beat.WhammyBarPoints.Count; i++) { BendPoint point = Platform.Platform.NewObject(); BendPoint.CopyTo(beat.WhammyBarPoints[i], point); beat2.WhammyBarPoints.Add(point); } #region Notes beat2.Notes = new FastList <Note>(); for (int n = 0; n < beat.Notes.Count; n++) { var note = beat.Notes[n]; Note note2 = Platform.Platform.NewObject(); Note.CopyTo(note, note2); note2.BendPoints = new FastList <BendPoint>(); for (int i = 0; i < note.BendPoints.Count; i++) { BendPoint point = Platform.Platform.NewObject(); BendPoint.CopyTo(note.BendPoints[i], point); note2.BendPoints.Add(point); } beat2.Notes.Add(note2); } #endregion voice2.Beats.Add(beat2); } #endregion bar2.Voices.Add(voice2); } #endregion staff2.Bars.Add(bar2); } #endregion track2.Staves.Add(staff2); } #endregion score2.Tracks.Add(track2); } #endregion return(score2); }
/// <summary> /// Converts the given JavaScript object into a score object. /// </summary> /// <param name="jsObject">The javascript object created via <see cref="ScoreToJsObject"/></param> /// <param name="settings">The settings to use during conversion.</param> /// <returns>The converted score object.</returns> public static Score JsObjectToScore(object jsObject, Settings settings = null) { Score score = jsObject.As <Score>(); var score2 = new Score(); Score.CopyTo(score, score2); RenderStylesheet.CopyTo(score.Stylesheet, score2.Stylesheet); #region MasterBars for (var i = 0; i < score.MasterBars.Count; i++) { var masterBar = score.MasterBars[i]; var masterBar2 = new MasterBar(); MasterBar.CopyTo(masterBar, masterBar2); if (masterBar.TempoAutomation != null) { masterBar2.TempoAutomation = new Automation(); Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation); } if (masterBar.Section != null) { masterBar2.Section = new Section(); Section.CopyTo(masterBar.Section, masterBar2.Section); } foreach (var offset in masterBar.Fermata) { var fermata = masterBar.Fermata[offset]; var fermata2 = new Fermata(); Fermata.CopyTo(fermata, fermata2); masterBar2.AddFermata(offset, fermata2); } score2.AddMasterBar(masterBar2); } #endregion #region Tracks for (int t = 0; t < score.Tracks.Count; t++) { var track = score.Tracks[t]; var track2 = new Track(track.Staves.Count); Track.CopyTo(track, track2); score2.AddTrack(track2); PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo); #region Staves for (var s = 0; s < track.Staves.Count; s++) { var staff = track.Staves[s]; var staff2 = track2.Staves[s]; Staff.CopyTo(staff, staff2); foreach (var key in staff.Chords) { var chord = staff.Chords[key]; var chord2 = new Chord(); Chord.CopyTo(chord, chord2); staff2.Chords[key] = chord2; } #region Bars for (int b = 0; b < staff.Bars.Count; b++) { var bar = staff.Bars[b]; var bar2 = new Bar(); Bar.CopyTo(bar, bar2); staff2.AddBar(bar2); #region Voices for (int v = 0; v < bar.Voices.Count; v++) { var voice = bar.Voices[v]; var voice2 = new Voice(); Voice.CopyTo(voice, voice2); bar2.AddVoice(voice2); #region Beats for (int bb = 0; bb < voice.Beats.Count; bb++) { var beat = voice.Beats[bb]; var beat2 = new Beat(); Beat.CopyTo(beat, beat2); voice2.AddBeat(beat2); for (int a = 0; a < beat.Automations.Count; a++) { var automation = new Automation(); Automation.CopyTo(beat.Automations[a], automation); beat2.Automations.Add(automation); } for (int i = 0; i < beat.WhammyBarPoints.Count; i++) { var point = new BendPoint(); BendPoint.CopyTo(beat.WhammyBarPoints[i], point); beat2.AddWhammyBarPoint(point); } #region Notes for (int n = 0; n < beat.Notes.Count; n++) { var note = beat.Notes[n]; var note2 = new Note(); Note.CopyTo(note, note2); beat2.AddNote(note2); for (int i = 0; i < note.BendPoints.Count; i++) { var point = new BendPoint(); BendPoint.CopyTo(note.BendPoints[i], point); note2.AddBendPoint(point); } } #endregion } #endregion } #endregion } #endregion } #endregion } #endregion score2.Finish(settings); return(score2); }
public Score JsObjectToScore(Score score) { var score2 = new Score(); Score.CopyTo(score, score2); #region MasterBars for (var i = 0; i < score.MasterBars.Count; i++) { var masterBar = score.MasterBars[i]; var masterBar2 = new MasterBar(); MasterBar.CopyTo(masterBar, masterBar2); if (masterBar.TempoAutomation != null) { masterBar2.TempoAutomation = new Automation(); Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation); } if (masterBar.VolumeAutomation != null) { masterBar2.VolumeAutomation = new Automation(); Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation); } if (masterBar.Section != null) { masterBar2.Section = new Section(); Section.CopyTo(masterBar.Section, masterBar2.Section); } score2.AddMasterBar(masterBar2); } #endregion #region Tracks for (int t = 0; t < score.Tracks.Count; t++) { var track = score.Tracks[t]; var track2 = new Track(); Track.CopyTo(track, track2); score2.AddTrack(track2); PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo); foreach (var key in track.Chords.Keys) { var chord = track.Chords[key]; var chord2 = new Chord(); Chord.CopyTo(chord, chord2); track2.Chords[key] = chord2; } #region Bars for (int b = 0; b < track.Bars.Count; b++) { var bar = track.Bars[b]; var bar2 = new Bar(); Bar.CopyTo(bar, bar2); track2.AddBar(bar2); #region Voices for (int v = 0; v < bar.Voices.Count; v++) { var voice = bar.Voices[v]; var voice2 = new Voice(); Voice.CopyTo(voice, voice2); bar2.AddVoice(voice2); #region Beats for (int bb = 0; bb < voice.Beats.Count; bb++) { var beat = voice.Beats[bb]; var beat2 = new Beat(); Beat.CopyTo(beat, beat2); voice2.AddBeat(beat2); for (int a = 0; a < beat.Automations.Count; a++) { var automation = new Automation(); Automation.CopyTo(beat.Automations[a], automation); beat2.Automations.Add(automation); } for (int i = 0; i < beat.WhammyBarPoints.Count; i++) { var point = new BendPoint(); BendPoint.CopyTo(beat.WhammyBarPoints[i], point); beat2.WhammyBarPoints.Add(point); } #region Notes for (int n = 0; n < beat.Notes.Count; n++) { var note = beat.Notes[n]; var note2 = new Note(); Note.CopyTo(note, note2); beat2.AddNote(note2); for (int i = 0; i < note.BendPoints.Count; i++) { var point = new BendPoint(); BendPoint.CopyTo(note.BendPoints[i], point); note2.BendPoints.Add(point); } } #endregion } #endregion } #endregion } #endregion } #endregion score2.Finish(); return(score2); }
public Score ScoreToJsObject(Score score) { Score score2 = NewObject(); Score.CopyTo(score, score2); score2.MasterBars = new FastList <MasterBar>(); score2.Tracks = new FastList <Track>(); #region MasterBars for (var i = 0; i < score.MasterBars.Count; i++) { MasterBar masterBar = score.MasterBars[i]; MasterBar masterBar2 = NewObject(); MasterBar.CopyTo(masterBar, masterBar2); if (masterBar.TempoAutomation != null) { masterBar2.TempoAutomation = NewObject(); Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation); } if (masterBar.VolumeAutomation != null) { masterBar2.VolumeAutomation = NewObject(); Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation); } if (masterBar.Section != null) { masterBar2.Section = NewObject(); Section.CopyTo(masterBar.Section, masterBar2.Section); } score2.MasterBars.Add(masterBar2); } #endregion #region Tracks for (int t = 0; t < score.Tracks.Count; t++) { var track = score.Tracks[t]; Track track2 = NewObject(); track2.Color = NewObject(); Track.CopyTo(track, track2); track2.PlaybackInfo = NewObject(); PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo); track2.Chords = new FastDictionary <string, Chord>(); foreach (var key in track.Chords.Keys) { var chord = track.Chords[key]; Chord chord2 = NewObject(); Chord.CopyTo(chord, chord2); track2.Chords[key] = chord; } #region Bars track2.Bars = new FastList <Bar>(); for (int b = 0; b < track.Bars.Count; b++) { var bar = track.Bars[b]; Bar bar2 = NewObject(); Bar.CopyTo(bar, bar2); #region Voices bar2.Voices = new FastList <Voice>(); for (int v = 0; v < bar.Voices.Count; v++) { var voice = bar.Voices[v]; Voice voice2 = NewObject(); Voice.CopyTo(voice, voice2); #region Beats voice2.Beats = new FastList <Beat>(); for (int bb = 0; bb < voice.Beats.Count; bb++) { var beat = voice.Beats[bb]; Beat beat2 = NewObject(); Beat.CopyTo(beat, beat2); beat2.Automations = new FastList <Automation>(); for (int a = 0; a < beat.Automations.Count; a++) { Automation automation = NewObject(); Automation.CopyTo(beat.Automations[a], automation); beat2.Automations.Add(automation); } beat2.WhammyBarPoints = new FastList <BendPoint>(); for (int i = 0; i < beat.WhammyBarPoints.Count; i++) { BendPoint point = NewObject(); BendPoint.CopyTo(beat.WhammyBarPoints[i], point); beat2.WhammyBarPoints.Add(point); } #region Notes beat2.Notes = new FastList <Note>(); for (int n = 0; n < beat.Notes.Count; n++) { var note = beat.Notes[n]; Note note2 = NewObject(); Note.CopyTo(note, note2); note2.BendPoints = new FastList <BendPoint>(); for (int i = 0; i < note.BendPoints.Count; i++) { BendPoint point = NewObject(); BendPoint.CopyTo(note.BendPoints[i], point); note2.BendPoints.Add(point); } beat2.Notes.Add(note2); } #endregion voice2.Beats.Add(beat2); } #endregion bar2.Voices.Add(voice2); } #endregion track2.Bars.Add(bar2); } #endregion score2.Tracks.Add(track2); } #endregion return(score2); }
public static void CopyTo(Chord src, Chord dst) { dst.FirstFret = src.FirstFret; dst.Name = src.Name; dst.Strings = src.Strings.Clone(); }