示例#1
0
        /// <summary>
        /// Adds snap points at times defined by the specified grid.
        /// </summary>
        /// <param name="grid">The grid that defines times to add snap points to.</param>
        /// <returns>An instance of the <see cref="SnapPointsGroup"/> added snap points belong to.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="grid"/> is <c>null</c>.</exception>
        public SnapPointsGroup SnapToGrid(IGrid grid)
        {
            ThrowIfArgument.IsNull(nameof(grid), grid);

            var snapPointsGroup = new SnapPointsGroup();

            foreach (var time in grid.GetTimes(_tempoMap))
            {
                TimeSpan metricTime = TimeConverter.ConvertTo <MetricTimeSpan>(time, _tempoMap);
                if (metricTime > _maxTime)
                {
                    break;
                }

                if (metricTime == TimeSpan.Zero)
                {
                    metricTime = new TimeSpan(1);
                }

                _snapPoints.Add(new SnapPoint(metricTime)
                {
                    SnapPointsGroup = snapPointsGroup
                });
            }

            return(snapPointsGroup);
        }
示例#2
0
        /// <summary>
        /// Sets playback position to the time of next snap point (relative to the current
        /// time of playback) that belongs to the specified <see cref="SnapPointsGroup"/>.
        /// </summary>
        /// <param name="snapPointsGroup"><see cref="SnapPointsGroup"/> that defines snap points to
        /// select the one from.</param>
        /// <returns><c>true</c> if playback position successfully changed to the time of a next snap point
        /// within <paramref name="snapPointsGroup"/>; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="snapPointsGroup"/> is <c>null</c>.</exception>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public bool MoveToNextSnapPoint(SnapPointsGroup snapPointsGroup)
        {
            ThrowIfArgument.IsNull(nameof(snapPointsGroup), snapPointsGroup);
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(_clock.CurrentTime, snapPointsGroup);

            return(TryToMoveToSnapPoint(snapPoint));
        }
示例#3
0
        /// <summary>
        /// Sets playback position to the time of the next snap point (relative to the current
        /// time of playback) that belongs to the specified <see cref="SnapPointsGroup"/>.
        /// </summary>
        /// <param name="snapPointsGroup"><see cref="SnapPointsGroup"/> that defines snap points to
        /// select the one from.</param>
        /// <exception cref="ArgumentNullException"><paramref name="snapPointsGroup"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void MoveToNextSnapPoint(SnapPointsGroup snapPointsGroup)
        {
            ThrowIfArgument.IsNull(nameof(snapPointsGroup), snapPointsGroup);
            EnsureIsNotDisposed();

            var snapPoint = Snapping.GetNextSnapPoint(_clock.CurrentTime, snapPointsGroup);

            if (snapPoint != null)
            {
                MoveToTime((MetricTimeSpan)snapPoint.Time);
            }
        }
示例#4
0
 private IEnumerable <SnapPoint> GetActiveSnapPoints(SnapPointsGroup snapPointsGroup)
 {
     return(GetActiveSnapPoints().Where(p => p.SnapPointsGroup == snapPointsGroup));
 }
示例#5
0
 internal SnapPoint GetPreviousSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetActiveSnapPoints(snapPointsGroup).TakeWhile(p => p.Time < time).LastOrDefault());
 }
示例#6
0
 internal SnapPoint GetNextSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetActiveSnapPoints(snapPointsGroup).SkipWhile(p => p.Time <= time).FirstOrDefault());
 }
示例#7
0
 /// <summary>
 /// Adds snap points at end times of notes.
 /// </summary>
 /// <returns>An instance of the <see cref="SnapPointsGroup"/> added snap points belong to.</returns>
 public SnapPointsGroup SnapToNotesEnds()
 {
     return(_noteEndSnapPointsGroup ?? (_noteEndSnapPointsGroup = SnapToNoteEvents(snapToNoteOn: false)));
 }
示例#8
0
 /// <summary>
 /// Adds snap points at start times of notes.
 /// </summary>
 /// <returns>An instance of the <see cref="SnapPointsGroup"/> added snap points belong to.</returns>
 public SnapPointsGroup SnapToNotesStarts()
 {
     return(_noteStartSnapPointsGroup ?? (_noteStartSnapPointsGroup = SnapToNoteEvents(snapToNoteOn: true)));
 }
示例#9
0
 internal SnapPoint GetPreviousSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetPreviousSnapPoints(GetActiveSnapPoints(snapPointsGroup), time).LastOrDefault());
 }
示例#10
0
 internal SnapPoint GetNextSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetNextSnapPoints(GetActiveSnapPoints(snapPointsGroup), time).FirstOrDefault());
 }