Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
 private IEnumerable <SnapPoint> GetActiveSnapPoints(SnapPointsGroup snapPointsGroup)
 {
     return(GetActiveSnapPoints().Where(p => p.SnapPointsGroup == snapPointsGroup));
 }
Ejemplo n.º 5
0
 internal SnapPoint GetPreviousSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetActiveSnapPoints(snapPointsGroup).TakeWhile(p => p.Time < time).LastOrDefault());
 }
Ejemplo n.º 6
0
 internal SnapPoint GetNextSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetActiveSnapPoints(snapPointsGroup).SkipWhile(p => p.Time <= time).FirstOrDefault());
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 9
0
 internal SnapPoint GetPreviousSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetPreviousSnapPoints(GetActiveSnapPoints(snapPointsGroup), time).LastOrDefault());
 }
Ejemplo n.º 10
0
 internal SnapPoint GetNextSnapPoint(TimeSpan time, SnapPointsGroup snapPointsGroup)
 {
     return(GetNextSnapPoints(GetActiveSnapPoints(snapPointsGroup), time).FirstOrDefault());
 }