protected virtual void PopulateFromXML(XElement element) { _startTime = (float)element.Element("start-time"); _duration = (float)element.Element("duration"); int segmentIndex = (int?)element.Element("segment-context") ?? 0; _segmentContext = timeline.MusicSegments[Math.Min(Math.Max(segmentIndex, 0), timeline.MusicSegments.Count - 1)]; }
public Timeline() { Blocks = new ObservableCollection <Block>(); Tracks = new ObservableCollection <Track>(); Notes = new ObservableCollection <Note>(); MusicSegments = new ObservableCollection <MusicSegment>(); MusicSegments.Add(MusicSegment.CreateStandard(this)); // this is ALWAYS here, even when loading from XML _defaultMusicSegment = MusicSegments[0]; }
public Block(Timeline timeline, params Track[] tracks) { this.timeline = timeline; foreach (var t in tracks) { _tracks.Add(t); } _tracks.CollectionChanged += (sender, e) => Notify(nameof(TrackNotificationPlaceholder)); _segmentContext = timeline.DefaultMusicSegment; }
public static Timeline FromXML(XElement element, string relativePathBase) { Timeline t = new Timeline(); t.MusicFileName = MusicFileFromXML(element.Element("music-file"), relativePathBase); foreach (var segment in element.ElementOrEmpty("segments").Elements("segment").Select(s => MusicSegment.FromXML(t, s))) { t.MusicSegments.Add(segment); } t.DefaultMusicSegment = t.MusicSegments[((int?)element.Element("default-segment")).GetValueOrDefault(0)]; foreach (var track in element.ElementOrEmpty("tracks").Elements("track").Select(g => Track.FromXML(t, g))) { t.Tracks.Add(track); } foreach (var block in element.ElementOrEmpty("blocks").Elements("block").Select(g => Block.FromXML(t, g))) { t.Blocks.Add(block); } foreach (var note in element.ElementOrEmpty("notes").Elements("note").Select(n => Note.FromXML(t, n))) { t.Notes.Add(note); } // TODO XML load validation return(t); }
public void SetupTestData() { // test data MusicSegments.Add(new MusicSegment(this) { Label = "Mah segment #1", Bpm = 128, BeatsPerBar = 4, TimeOrigin = 0 }); MusicSegments.Add(new MusicSegment(this) { Label = "Slow segment", Bpm = 96, BeatsPerBar = 3, TimeOrigin = 10 }); MusicSegments.Add(new MusicSegment(this) { Label = "D&B example", Bpm = 180, BeatsPerBar = 4, TimeOrigin = 20 }); DefaultMusicSegment = MusicSegments[1]; Tracks.Add(new Track(this, "Second track")); Tracks.Add(new Track(this, "Third track")); Blocks.Add(new ColorBlock(this, Tracks[0]) { StartTime = 0f, Duration = 0.5f, Color = GloColor.FromRGB(255, 0, 0), SegmentContext = MusicSegments[0] }); Blocks.Add(new ColorBlock(this, Tracks[0]) { StartTime = 1f, Duration = 0.5f, Color = GloColor.FromRGB(255, 127, 0), SegmentContext = MusicSegments[0] }); Blocks.Add(new RampBlock(this, Tracks[0]) { StartTime = 2f, Duration = 2f, StartColor = GloColor.FromRGB(255, 127, 0), EndColor = GloColor.White, SegmentContext = MusicSegments[0] }); Blocks.Add(new ColorBlock(this, Tracks[1], Tracks[2]) { StartTime = 0.5f, Duration = 2.5f, Color = GloColor.White }); Blocks.Add(new ColorBlock(this, Tracks[2]) { StartTime = 4f, Duration = 1f, Color = GloColor.FromRGB(0, 255, 120) }); Blocks.Add(new LoopBlock(this) { StartTime = 4.5f, Duration = 3f, SegmentContext = MusicSegments[0] } .AddChild(new ColorBlock(this, Tracks[0]) { StartTime = 0, Duration = 1.25f, Color = GloColor.FromRGB(0, 0, 255), SegmentContext = MusicSegments[0] }, false) .AddChild(new ColorBlock(this, Tracks[0]) { StartTime = 1.5f, Duration = 1.5f, Color = GloColor.FromRGB(0, 255, 255), SegmentContext = MusicSegments[0] }, false) ); Notes.Add(new Note { Label = "First marker", Time = 0.5f }); Notes.Add(new Note { Label = "Second marker", Time = 1.446f }); Notes.Add(new Note { Label = "Third marker", Time = 3.0f, Description = "This one is super fancy and has a description.\r\nThe possibilities are endless!" }); Notes.Add(new Note { Time = 4f }); }