public LoopBlockViewModel(SequencerViewModel sequencer, Model.LoopBlock model)
     : base(sequencer, model, "Loop")
 {
     this.model = model;
     ForwardPropertyEvents(nameof(model.Repetitions), model,
         nameof(Repetitions), nameof(ChildrenRepetitions), nameof(EndTimeOccupied));
 }
 public RampBlockViewModel(SequencerViewModel sequencer, Model.RampBlock model)
     : base(sequencer, model, "Ramp")
 {
     this.model = model;
     ForwardPropertyEvents(nameof(model.StartColor), model, nameof(StartColor));
     ForwardPropertyEvents(nameof(model.EndColor), model, nameof(EndColor));
 }
        public VisualizationViewModel(SequencerViewModel sequencer)
        {
            this.sequencer   = sequencer;
            VisualizedTracks = sequencer.GetModel().Tracks.Select(t => new VisualizedTrackViewModel(t));

            ForwardPropertyEvents(nameof(sequencer.CursorPosition), sequencer, OnCursorPositionChanged, true);
            ForwardPropertyEvents(nameof(IsEnabled), this, OnIsEnabledChanged);
        }
        public NotesViewModel(SequencerViewModel sequencer)
        {
            this.sequencer = sequencer;
            Notes          = sequencer.GetModel().Notes.Select(note => new NoteViewModel(sequencer, note));
            NotesSorted    = Notes.OrderBy(note => note.TimeSeconds);

            ForwardCollectionEvents(Notes, nameof(HasNotes));
        }
Beispiel #5
0
 public ColorBlockViewModel(SequencerViewModel sequencer, Model.ColorBlock model)
     : base(sequencer, model, "Color")
 {
     this.model = model;
     ForwardPropertyEvents(nameof(model.Color), model, nameof(Color));
     ForwardPropertyEvents(nameof(model.RenderedColor1), model, nameof(RenderedColor1));
     ForwardPropertyEvents(nameof(model.RenderedColor2), model, nameof(RenderedColor2));
 }
        public TrackViewModel(SequencerViewModel sequencer, Model.Track model)
        {
            this.sequencer = sequencer;
            this.model     = model;

            ForwardPropertyEvents(nameof(model.Label), model, nameof(Label));
            ForwardPropertyEvents(nameof(sequencer.SelectedTrack), sequencer, nameof(IsSelected));

            Blocks = model.Blocks.Select(b => BlockViewModel.FromModel(sequencer, b));
        }
        public NoteViewModel(SequencerViewModel sequencer, Note model)
        {
            this.sequencer = sequencer;
            this.model     = model;

            ForwardPropertyEvents(nameof(model.Label), model, nameof(Label), nameof(FormattedTimeAndLabel));
            ForwardPropertyEvents(nameof(model.Description), model, nameof(Description));
            ForwardPropertyEvents(nameof(model.Time), model, nameof(TimeSeconds), nameof(DisplayOffset), nameof(FormattedTimeAndLabel));
            ForwardPropertyEvents(nameof(sequencer.TimePixelScale), sequencer, nameof(DisplayOffset));
        }
        private SequencerViewModel MakeSequencerViewModel(Timeline timeline)
        {
            // Hack: Extract view state from old view model and inject into new one,
            // so it can work with it without before the view is updated.
            double viewportLeftOffsetPx = CurrentDocument?.GetViewportLeftOffsetPx() ?? 0.0;
            double viewportWidthPx      = CurrentDocument?.GetViewportWidth() ?? 1000.0;

            var newDocument = new SequencerViewModel(timeline);

            newDocument.SetViewportState(viewportLeftOffsetPx, viewportWidthPx);
            return(newDocument);
        }
        public ReplaceColorViewModel(SequencerViewModel sequencer)
        {
            this.sequencer = sequencer;

            var colorItems = from color in _ColorsFromBlocks(GetConsideredBlocks())
                             group color by color into g
                             //orderby g.Key.R + g.Key.G + g.Key.B descending
                             select new Xceed.Wpf.Toolkit.ColorItem(g.Key, string.Format("R: {0}; G: {1}; B: {2} - Usages: {3}", g.Key.R, g.Key.G, g.Key.B, g.Count()));

            ColorChoices   = new ObservableCollection <Xceed.Wpf.Toolkit.ColorItem>(colorItems);
            ColorToSearch  = (ColorChoices.Any() ? ColorChoices.First().Color.Value : Colors.White);
            ColorToReplace = Colors.White;
        }
        public VisualizationViewModel()
        {
            sequencer = null;
            var tl = new Timeline();

            VisualizedTracks = new ObservableCollection <Track> {
                new Track(tl, "Track 01"),
                new Track(tl, "Track 02"),
                new Track(tl, "Track 03"),
                new Track(tl, "Track 04"),
                new Track(tl, "Track 05"),
                new Track(tl, "Track 06"),
            }.Select(t => new VisualizedTrackViewModel(t));
        }
Beispiel #11
0
        public MusicSegmentViewModel(SequencerViewModel sequencer, Model.MusicSegment model)
        {
            this.sequencer = sequencer;
            this.model     = model;

            ReferringBlocksDummies = sequencer.GetModel().Blocks.Where(b => b.SegmentContext == model).Select(b => (object)null);

            ForwardPropertyEvents(nameof(model.Label), model, nameof(Label));
            ForwardPropertyEvents(nameof(model.Bpm), model, nameof(Bpm));
            ForwardPropertyEvents(nameof(model.BeatsPerBar), model, nameof(BeatsPerBar));
            ForwardPropertyEvents(nameof(model.TimeOrigin), model, nameof(TimeOrigin), nameof(TimeOriginSeconds));
            ForwardPropertyEvents(nameof(model.IsReadOnly), model, nameof(IsReadOnly));
            ForwardPropertyEvents(nameof(model.IsDefault), model, nameof(IsDefault));

            ForwardPropertyEvents(nameof(Bpm), this, () => sequencer.NotifyGridInterval());
        }
        public bool OpenDocument(string file)
        {
            Timeline timeline = FileSerializer.LoadFromFile(file);

            if (timeline == null)
            {
                OpenNewDocument();
                return(false);
            }

            FilePath        = file;
            CurrentDocument = MakeSequencerViewModel(timeline);

            IsDirty = false;
            CurrentDocument.ActionManager.CollectionChanged += (_, __) => IsDirty = true;

            return(true);
        }
        public void OpenNewDocument()
        {
            FilePath = null;

            Timeline timeline = new Timeline();

            timeline.SetupNew();
            CurrentDocument?.OnClose();
            CurrentDocument = MakeSequencerViewModel(timeline);

            IsDirty = false;
            CurrentDocument.ActionManager.CollectionChanged += (_, __) => IsDirty = true;

#if DEBUG
            timeline.SetupTestData();
            CurrentDocument.SelectBlock(CurrentDocument.AllBlocks[0], CompositionMode.None);
#endif
        }
        public SelectionProperties(SequencerViewModel sequencer)
        {
            this.sequencer = sequencer;

            selectedBlocks = sequencer.SelectedBlocks;
            selectedBlocks.CollectionChanged += selectedBlocks_CollectionChanged;

            ForwardPropertyEvents(nameof(SegmentContext), this, () =>
            {
                if (!sequencer.SynchronizeActiveWithSelection || !IsMusicSegmentModifiable)
                {
                    return;
                }
                var context = SegmentContext;
                if (context != null)
                {
                    sequencer.ActiveMusicSegment = SegmentContext;
                }
            });
        }
        public PlaybackViewModel(SequencerViewModel sequencer)
        {
            this.sequencer     = sequencer;
            this.timelineModel = sequencer.GetModel();

            cursorUpdateTimer = new System.Windows.Threading.DispatcherTimer()
            {
                Interval = CURSOR_UPDATE_INTERVAL
            };
            cursorUpdateTimer.Tick += (_, __) => UpdateCursorPosition();

            ForwardPropertyEvents(nameof(MusicVolume), this, () => audioPlayback.Volume = LoudnessHelper.LoudnessFromVolume(MusicVolume));
            ForwardPropertyEvents(nameof(sequencer.CurrentViewLeftPositionTime), sequencer, InvalidateWaveform);
            // Note: Because CurrentViewLeftPositionTime depends on TimePixelScale and is always changed together with the right position,
            // it is enough to only depend on this one to reduce callback duplication.
            //ForwardPropertyEvents(nameof(sequencer.TimePixelScale), sequencer, InvalidateWaveform);
            //ForwardPropertyEvents(nameof(sequencer.CurrentViewRightPositionTime), sequencer, InvalidateWaveform);
            ForwardPropertyEvents(nameof(sequencer.CursorPosition), sequencer, OnCursorPositionChanged);
            audioPlayback.PlaybackStopped += OnPlaybackStopped;

            audioPlayback.Init(EmptySampleProvider.Singleton);
        }
        protected BlockViewModel(SequencerViewModel sequencer, Model.Block model, string typeLabel)
        {
            this.sequencer  = sequencer;
            this.model      = model;
            this._typeLabel = typeLabel;

            ForwardPropertyEvents(nameof(model.StartTime), model, nameof(StartTime), nameof(EndTime), nameof(EndTimeOccupied), nameof(DisplayOffset));
            ForwardPropertyEvents(nameof(model.Duration), model, nameof(Duration), nameof(EndTime), nameof(EndTimeOccupied), nameof(DisplayWidth));

            ForwardPropertyEvents(nameof(model.SegmentContext), model, nameof(SegmentContext), nameof(IsSegmentActive));
            // track affiliation
            ForwardCollectionEvents(model.Tracks, nameof(DisplayTopOffset), nameof(DisplayHeight), nameof(DisplayClip));
            // tracks in general
            // moved to OnTracksCollectionChanged(), called by the sequencer, because when this view model is constructed, the "Tracks" collection may still be under construction
            //CollectionChangedEventManager.AddHandler(sequencer.Tracks, (sender, e) => { Notify(nameof(DisplayTopOffset)); Notify(nameof(DisplayHeight)); Notify(nameof(DisplayClip)); });

            // subscribe to sequencer
            ForwardPropertyEvents(nameof(sequencer.ActiveMusicSegment), sequencer, nameof(IsSegmentActive));
            ForwardPropertyEvents(nameof(sequencer.TimePixelScale), sequencer, nameof(DisplayOffset), nameof(DisplayWidth));
            ForwardCollectionEvents(sequencer.SelectedBlocks, (sender, e) =>
            {
                if ((e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Contains(this)) ||
                    (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems.Contains(this)) ||
                    e.Action == NotifyCollectionChangedAction.Replace ||
                    e.Action == NotifyCollectionChangedAction.Reset)
                {
                    Notify(nameof(IsSelected));
                }
            });

            // subscribe to track height changes
            if (globalParams != null)
            {
                ForwardPropertyEvents(nameof(globalParams.TrackDisplayHeight), globalParams, NotifyTrackRelatedProperties);
            }
        }
        public static BlockViewModel FromModel(SequencerViewModel sequencer, Model.Block model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            BlockViewModel vm;

            if (!s_viewModelCache.TryGetValue(model, out vm))
            {
                if (model is Model.ColorBlock)
                {
                    vm = new ColorBlockViewModel(sequencer, (Model.ColorBlock)model);
                }
                else if (model is Model.RampBlock)
                {
                    vm = new RampBlockViewModel(sequencer, (Model.RampBlock)model);
                }
                else if (model is Model.LoopBlock)
                {
                    vm = new LoopBlockViewModel(sequencer, (Model.LoopBlock)model);
                }
                //else if (model is Model.GroupBlock)
                //    vm = new GroupBlockViewModel(sequencer, (Model.GroupBlock)model);

                else
                {
                    throw new NotImplementedException("unknown block type: " + model.GetType().Name);
                }

                s_viewModelCache[model] = vm;
            }

            return(vm);
        }
 protected GroupBlockViewModel(SequencerViewModel sequencer, Model.GroupBlock model, string typeLabel)
     : base(sequencer, model, typeLabel)
 {
     this.model = model;
     _children  = model.Children.Select(b => BlockViewModel.FromModel(sequencer, b));
 }
 public GroupBlockViewModel(SequencerViewModel sequencer, Model.GroupBlock model)
     : this(sequencer, model, "Group")
 {
 }
Beispiel #20
0
 public BrightModeViewModel(SequencerViewModel sequencer)
 {
     this.sequencer = sequencer;
 }