public TrackAffiliationData(SelectionProperties context, TrackViewModel track) { this.context = context; _track = track; CollectionChangedEventManager.AddHandler(track.Blocks, (sender, e) => Notify(nameof(AffiliationState))); }
public SequencerViewModel(Timeline model) { this.model = model; ActionManager = new GuiLabs.Undo.ActionManager(); SelectedBlocks = new ObservableCollection <BlockViewModel>(); SelectionData = new SelectionProperties(this); Tracks = model.Tracks.Select(g => new TrackViewModel(this, g)); MusicSegments = model.MusicSegments.Select(seg => new MusicSegmentViewModel(this, seg)); AllBlocks = model.Blocks.Select(b => BlockViewModel.FromModel(this, b)); if (Tracks.Count > 0) { SelectedTrack = Tracks[0]; } ActiveMusicSegment = MusicSegments[model.DefaultMusicSegment.GetIndex()]; Playback = new PlaybackViewModel(this); Visualization = new VisualizationViewModel(this); Notes = new NotesViewModel(this); if (model.MusicFileName != null) { Playback.LoadFileAsync(model.MusicFileName).Forget(); } Action <BlockViewModel> fn_SubscribeToBlock = bvm => ForwardPropertyEvents(nameof(bvm.EndTimeOccupied), bvm, nameof(TimelineLength)); AllBlocks.ToList().ForEach(fn_SubscribeToBlock); AllBlocks.CollectionChanged += (_, e) => { if (e.NewItems != null) { e.NewItems.Cast <BlockViewModel>().ToList().ForEach(fn_SubscribeToBlock); } Notify(nameof(TimelineLength)); }; ForwardPropertyEvents(nameof(PipetteTarget), this, nameof(IsPipetteActive)); ForwardPropertyEvents(nameof(CursorPosition), this, nameof(CursorPixelPosition), nameof(CursorPixelPositionOnViewport)); ForwardPropertyEvents(nameof(TimePixelScale), this, nameof(CursorPixelPosition), nameof(CursorPixelPositionOnViewport), nameof(CurrentViewLeftPositionTime), nameof(CurrentViewRightPositionTime), nameof(TimelineWidth), nameof(GridInterval)); ForwardPropertyEvents(nameof(ActiveMusicSegment), this, nameof(GridInterval)); ForwardPropertyEvents(nameof(Playback.MusicDuration), Playback, nameof(TimelineLength)); ForwardPropertyEvents(nameof(TimelineLength), this, nameof(TimelineWidth)); ForwardCollectionEvents(SelectedBlocks, nameof(CanConvertToColor), nameof(CanConvertToRamp), nameof(CanConvertToAutoDeduced), nameof(ConvertAutoDeduceGestureText)); Tracks.CollectionChanged += (_, e) => { foreach (var b in AllBlocks) { b.OnTracksCollectionChanged(); } }; // Disable pipette whenever the selection is modified. SelectedBlocks.CollectionChanged += (_, __) => PipetteTarget = null; }