Exemplo n.º 1
0
        /// <summary>
        /// Replaces the entire track queue with the contents of a track container. You should check the UserMutatedQueue property before performing a destructive replacement.
        /// </summary>
        /// <param name="a">The track container.</param>
        /// <param name="shuffle">Whether to shuffle the order in which the track container is added.</param>
        public void ReplaceAllWithTrackContainer(ITrackContainer a, bool shuffle)
        {
            Contract.Requires(a != null);
            Contract.Requires(a.TrackList != null);
            Contract.Requires(a.TrackList.Count != 0);

            _trackList.BatchChanges();

            Clear();

            if (shuffle)
            {
                var items = a.TrackList.AsParallel().Select(x => x.UniqueTrack()).OrderBy(x => x.UniqueId);
                _trackList.Enqueue(items);
                _trackList.Dequeue();
            }
            else
            {
                var items = a.TrackList.AsParallel().AsOrdered().Select(x => x.UniqueTrack());
                _trackList.Enqueue(items);
                _trackList.Dequeue();
            }

            _trackList.FlushChanges();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a track container to the queue.
        /// </summary>
        /// <param name="trackContainer">The track container to add.</param>
        /// <param name="play">Whether to immediately start playing.</param>
        public void Add(ITrackContainer trackContainer, bool play)
        {
            MutateQueue(() => _queue.Add(trackContainer.TrackList));

            if (Status == AudioControllerStatus.Inactive && play)
            {
                Play();
            }
        }
Exemplo n.º 3
0
        private static void CreateWatermark(ITrackContainer tracks, string imageName, double duration)
        {
            var videoTrack = tracks.AddTrack();
            var clip       = videoTrack.AddImage(imageName, 0, duration);

            clip.AddEffect(0, duration, StandardEffects.CreateAlphaSetterRamp(0.5));

            videoTrack.AddTransition(0, duration,
                                     StandardTransitions.CreateKey(KeyTransitionType.Rgb, null, null, null, 0x00FFFFFF, null),
                                     false);
        }
Exemplo n.º 4
0
        public Track(ITrackContainer container, IAMTimeline timeline, IAMTimelineTrack track, string name, int priority)
        {
            _container = container;
            _timeline = timeline;
            _track = track;
            _name = name;
            _priority = priority;

            int hr = timeline.GetDefaultFPS(out _fps);
            DESError.ThrowExceptionForHR(hr);
        }
Exemplo n.º 5
0
        public Track(ITrackContainer container, IAMTimeline timeline, IAMTimelineTrack track, string name, int priority)
        {
            _container = container;
            _timeline  = timeline;
            _track     = track;
            _name      = name;
            _priority  = priority;

            int hr = timeline.GetDefaultFPS(out _fps);

            DESError.ThrowExceptionForHR(hr);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a des track, wraps it into an ITrack, adds it to a collection and
        /// returns the new ITrack wrapper.
        /// </summary>
        /// <param name="desTimeline"></param>
        /// <param name="desComposition"></param>
        /// <param name="tracks"></param>
        /// <param name="name"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        internal static ITrack AddTrackToCollection(ITrackContainer container, IAMTimeline desTimeline,
                                                    IAMTimelineComp desComposition,
                                                    AddOnlyList <ITrack> tracks, string name, int priority)
        {
            priority = ReorderPriorities(tracks, priority);

            ITrack track = new Track(container, desTimeline, CreateTrack(desTimeline, desComposition, name, priority),
                                     name, priority);

            tracks.Add(track);

            return(track);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds the voice track
        /// </summary>
        /// <param name="tracks">The track container that will hold the new track</param>
        /// <param name="text">The text that will be converted to speech</param>
        /// <returns>The new text-to-speech track</returns>
        private ITrack AddVoiceTrack(ITrackContainer tracks, string text)
        {
            var audioTrack = tracks.AddTrack();

            var audioFileName = Path.Combine(workArea, "voice.wav");
            var voice         = CreateVoice();

            CreateAudioFile(audioFileName, voice, text);

            audioTrack.AddAudio(audioFileName);

            return(audioTrack);
        }
Exemplo n.º 8
0
        public async Task ValidateAsync(ITrackContainer trackContainer)
        {
            if (trackContainer == null)
            {
                throw new ArgumentNullException(nameof(trackContainer));
            }

            var album = await this.GetBy(trackContainer);

            if (trackContainer.TrackId.HasValue && album == null)
            {
                throw new InvalidOperationException($"Album not found by id {trackContainer.TrackId}");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Replaces the queue by a track container.
        /// </summary>
        /// <param name="trackContainer">The track container to add.</param>
        /// <param name="shuffle">Whether to shuffle the tracks when adding.</param>
        /// <param name="play">Whether to immediately start playing.</param>
        public void ReplaceAll(ITrackContainer trackContainer, bool shuffle, bool play)
        {
            Contract.Requires <ArgumentNullException>(trackContainer != null);
            Contract.Requires <ArgumentException>(trackContainer.TrackList.Count > 0);

            Stop();

            MutateQueue(() => _queue.ReplaceAllWithTrackContainer(trackContainer, shuffle));

            if (play)
            {
                Play();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds the sound files in a random order
        /// </summary>
        /// <param name="tracks">The track container that will hold the new track</param>
        /// <param name="soundFiles">The list of sound files to add</param>
        /// <param name="duration"></param>
        /// <returns>The new track</returns>
        private ITrack AddBackgroundMusic(ITrackContainer tracks, IList <string> soundFiles, double duration)
        {
            var audioTrack = tracks.AddTrack();

            if (soundFiles.Any())
            {
                var shuffled = shuffler.Shuffle(soundFiles);
                foreach (var soundFile in shuffled)
                {
                    audioTrack.AddAudio(soundFile, 0, duration);
                }
                audioTrack.AddEffect(0, audioTrack.Duration, StandardEffects.CreateAudioEnvelope(0.05));
            }

            return(audioTrack);
        }
Exemplo n.º 11
0
        private void AddWatermark(ITrackContainer tracks, string watermarkFile, double duration, int width, int height)
        {
            using (var img = Image.FromFile(watermarkFile))
            {
                var watermarkImage = new Bitmap(width, height);
                using (var g = Graphics.FromImage(watermarkImage))
                {
                    g.Clear(Color.Transparent);
                    g.DrawImage(img, 0, height - height / 5, width, height / 5);
                    g.Save();

                    var imageFileName = Path.Combine(workArea, "wm.gif");
                    watermarkImage.Save(imageFileName, ImageFormat.Gif);

                    CreateWatermark(tracks, imageFileName, duration);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Replaces the entire track queue with a single song, queuing up the other items in the same track container.
        /// You should check the UserMutatedQueue property before performing a destructive replacement.
        /// </summary>
        /// <param name="t">The song.</param>
        /// <param name="a">The track container that holds the song.</param>
        public void ReplaceAllWithSong(Track t, ITrackContainer a)
        {
            Contract.Requires(t != null);
            Contract.Requires(a != null);
            Contract.Requires(a.TrackList != null);
            Contract.Requires(a.TrackList.Count != 0);

            _trackList.BatchChanges();

            Clear();

            var items = a.TrackList.AsParallel().AsOrdered().Select(x => x.UniqueTrack());

            _trackList.Enqueue(items);

            int trackOffset = Math.Max(0, a.IndexOf(t));

            _trackList.Dequeue(trackOffset);

            _trackList.FlushChanges();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Replaces the entire track queue with a single song, queuing up the other items in the same track container.
        /// You should check the UserMutatedQueue property before performing a destructive replacement.
        /// </summary>
        /// <param name="t">The song.</param>
        /// <param name="a">The track container that holds the song.</param>
        public void ReplaceAllWithSong(Track t, ITrackContainer a)
        {
            Contract.Requires(t != null);
            Contract.Requires(a != null);
            Contract.Requires(a.TrackList != null);
            Contract.Requires(a.TrackList.Count != 0);

            _trackList.BatchChanges();

            Clear();

            var items = a.TrackList.AsParallel().AsOrdered().Select(x => x.UniqueTrack());
            _trackList.Enqueue(items);

            int trackOffset = Math.Max(0, a.IndexOf(t));
            _trackList.Dequeue(trackOffset);

            _trackList.FlushChanges();
        }
Exemplo n.º 14
0
 private Task <Track> GetBy(ITrackContainer departmentContainer)
 {
     return(this.TrackDataAccess.GetByAsync(departmentContainer));
 }
Exemplo n.º 15
0
 public async Task <Track> GetByAsync(ITrackContainer track)
 {
     return(track.TrackId.HasValue
         ? this.Mapper.Map <Track>(await this.Context.Track.FirstOrDefaultAsync(x => x.Id == track.TrackId))
         : null);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Like OnNavigatedTo(), but runs after the whole UI has already been prepared.
        /// Place any loading code here that requires the UI to be completely loaded.
        /// </summary>
        private async void page_Loaded(object sender, RoutedEventArgs e)
        {
            // Initialize the controller if necessary
            if (AudioController.Default.Status == AudioControllerStatus.NotReady)
            {
                DependencyObject rootGrid         = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(Window.Current.Content, 0);
                MediaElement     rootMediaElement = (MediaElement)Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(rootGrid, 0);
                AudioController.Default.Ready(rootMediaElement);
            }

            // Initialize animations
            VisualStateManager.GoToState(this, "NoOverlayAlbum", false);
            VisualStateManager.GoToState(this, "NoOverlayQueue", false);
            VisualStateManager.GoToState(this, "NoOverlayMessage", false);

            Type            pageMode            = typeof(Album);
            double          scroll              = 0d;
            ITrackContainer navigationContainer = null;
            Track           navigationItem      = null;

            if (_navigationParameter.HasValue && LibraryItemToken.VerifyToken(_navigationParameter.Value))
            {
                var navigationParameter = LibraryItemToken.GetItem(_navigationParameter.Value);

                // If there is a navigationParameter, use it, and ignore the pageState!
                if (navigationParameter is Album)
                {
                    pageMode            = typeof(Album);
                    navigationContainer = navigationParameter as ITrackContainer;
                }
                else if (navigationParameter is Playlist)
                {
                    pageMode            = typeof(Playlist);
                    navigationContainer = navigationParameter as ITrackContainer;
                }
                else if (navigationParameter is Track)
                {
                    pageMode       = typeof(Album);
                    navigationItem = navigationParameter as Track;
                    if (navigationItem != null)
                    {
                        navigationContainer = navigationItem.ContainingAlbum;
                    }
                }
            }
            else if (_pageState != null)
            {
                // If no navigationParameter but pageState available, modify UI according to pageState
                if (_pageState.ContainsKey("PageMode"))
                {
                    pageMode = Type.GetType((string)_pageState["PageMode"]);
                }

                if (_pageState.ContainsKey("AlbumScroll"))
                {
                    scroll = (double)_pageState["AlbumScroll"];
                }
            }

            PageMode             = pageMode;
            _pageState           = null;
            _navigationParameter = null;

            if (navigationContainer != null)
            {
                IsAlbumOverlayShown = true;

                // Delay scrolling after animation
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    CurrentSelection = navigationContainer;
                    albumGridView.ScrollIntoView(CurrentSelection);

                    if (navigationItem != null)
                    {
                        albumDetailListView.SelectedIndex = navigationContainer.IndexOf(navigationItem);
                        albumDetailListView.ScrollIntoView(albumDetailListView.SelectedItem);
                    }
                });
            }
            else if (scroll > double.Epsilon)             // Don't scroll if scroll is negative or less than Epsilon
            {
                // Delay scrolling after animation
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    FindVisualChild <ScrollViewer>(albumGridView).ScrollToHorizontalOffset(scroll);
                });
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Replaces the entire track queue with the contents of a track container. You should check the UserMutatedQueue property before performing a destructive replacement.
        /// </summary>
        /// <param name="a">The track container.</param>
        /// <param name="shuffle">Whether to shuffle the order in which the track container is added.</param>
        public void ReplaceAllWithTrackContainer(ITrackContainer a, bool shuffle)
        {
            Contract.Requires(a != null);
            Contract.Requires(a.TrackList != null);
            Contract.Requires(a.TrackList.Count != 0);

            _trackList.BatchChanges();

            Clear();

            if (shuffle)
            {
                var items = a.TrackList.AsParallel().Select(x => x.UniqueTrack()).OrderBy(x => x.UniqueId);
                _trackList.Enqueue(items);
                _trackList.Dequeue();
            }
            else
            {
                var items = a.TrackList.AsParallel().AsOrdered().Select(x => x.UniqueTrack());
                _trackList.Enqueue(items);
                _trackList.Dequeue();
            }

            _trackList.FlushChanges();
        }
Exemplo n.º 18
0
		/// <summary>
		/// Replaces the queue by a single track.
		/// </summary>
		/// <param name="t">The track to add.</param>
		/// <param name="trackContainer">A track container that contains the track <paramref name="t"/>.</param>
		/// <param name="play">Whether to immediately start playing.</param>
		public void ReplaceAll(Track t, ITrackContainer trackContainer, bool play)
		{
			Contract.Requires<ArgumentException>(t != null);
			Contract.Requires<ArgumentNullException>(trackContainer != null);
			Contract.Requires<ArgumentException>(trackContainer.TrackList.Count > 0);

			Stop();

			MutateQueue(() => _queue.ReplaceAllWithSong(t, trackContainer));

			if (play) Play();
		}
Exemplo n.º 19
0
		/// <summary>
		/// Adds a track container to the queue.
		/// </summary>
		/// <param name="trackContainer">The track container to add.</param>
		/// <param name="play">Whether to immediately start playing.</param>
		public void Add(ITrackContainer trackContainer, bool play)
		{
			MutateQueue(() => _queue.Add(trackContainer.TrackList));

			if (Status == AudioControllerStatus.Inactive && play) Play();
		}