public void AddNoteAtCursor()
        {
            Note newNote = new Note {
                Time = sequencer.CursorPosition
            };

            sequencer.ActionManager.RecordAdd(sequencer.GetModel().Notes, newNote);
        }
        private void OnCursorPositionChanged()
        {
            if (!IsEnabled)
            {
                return;
            }

            float        now             = sequencer.CursorPosition;
            List <Block> blockCandidates = ((IEnumerable <Block>)sequencer.GetModel().Blocks)
                                           .Where(b => b.IsTimeInOccupiedRange(now))
                                           .ToList();

            foreach (var vm in VisualizedTracks)
            {
                Block activeBlock = blockCandidates
                                    .Where(b => b.Tracks.Contains(vm.track))
                                    .LastOrDefault();

                if (activeBlock == null)
                {
                    vm.CurrentColor = Colors.Black;
                }
                else
                {
                    vm.CurrentColor = activeBlock.GetColorAtTime(now, vm.track).ToViewColor();
                }
            }
        }
        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));
        }
        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);
        }
Beispiel #5
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 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);
        }