public void HandleTrackChanged(TrackChangedEventArgs args) { TreeIter iter = new TreeIter(); CurrentTrack = args.NewTrack; bool exists = args.NewTrack != null && _trackIters.TryGetValue(args.NewTrack, out iter); if (exists) { EmitRowChanged(GetPath(iter), iter); } exists = args.OldTrack != null && _trackIters.TryGetValue(args.OldTrack, out iter); if (exists) { EmitRowChanged(GetPath(iter), iter); } }
public virtual void AddTrack(Track track) { track.Artists.Add(this); Tracks.Add(track); }
protected override void TrackListViewOnRowActivated(object o, RowActivatedArgs args) { TrackListView trackListView = o as TrackListView; if (trackListView == null) return; int numTracks = trackListView.Model.IterNChildren(); Track[] trackArray = new Track[numTracks]; TreeIter iter; int selectedTrackIndex = args.Path.Indices[0]; trackListView.Model.GetIterFirst(out iter); uint trackIndex = 0; bool valid = trackListView.Model.GetIterFirst(out iter); while (valid) { Track track = (Track)trackListView.Model.GetValue(iter, 0); trackArray[trackIndex++] = track; valid = trackListView.Model.IterNext(ref iter); } AudioPlayer.ReplacePlaylistAndPlay(trackArray, (uint)selectedTrackIndex); }
public virtual void AddTrack(Track track) { track.Genres.Add(this); Tracks.Add(track); }
private void UpdateTrackInDatabase(string filePath, TagLib.File file, ISession session, string tagLibHash, Track track) { Album trackAlbum = AddNonTrackEntitiesAndReturnAlbum(file, session); IEnumerable<Artist> newTrackArtists = GetTrackArtistsForTag(session, file.Tag); IEnumerable<Genre> newTrackGenres = GetTrackGenresForTag(session, file.Tag); track.Artists = new HashedSet<Artist>(newTrackArtists.ToArray()); track.Genres = new HashedSet<Genre>(newTrackGenres.ToArray()); track.Path = filePath; track.Title = file.Tag.Title; track.Album = trackAlbum; track.Duration = (ulong) file.Properties.Duration.TotalMilliseconds; track.Bitrate = (uint) file.Properties.AudioBitrate; track.ChannelCount = (uint) file.Properties.AudioChannels; track.SampleRate = (uint) file.Properties.AudioSampleRate; track.BitsPerSample = (uint) file.Properties.BitsPerSample; track.Codec = file.Properties.Codecs.First().Description; track.Size = (ulong) file.Length; track.TagLibHash = tagLibHash; track.TrackNumber = file.Tag.Track; track.Date = file.Tag.GetDate(); track.MusicBrainzId = file.Tag.MusicBrainzTrackId; track.Bpm = file.Tag.BeatsPerMinute == 0 ? (uint?)null : file.Tag.BeatsPerMinute; track.Rating = file.Tag.GetRatingNullableUInt32(); session.Update(track); }
private void AddTrackToDatabase(string filePath, TagLib.File file, ISession session, string tagLibHash) { Album trackAlbum = AddNonTrackEntitiesAndReturnAlbum(file, session); var trackArtists = GetTrackArtistsForTag(session, file.Tag); var trackGenres = GetTrackGenresForTag(session, file.Tag); FileInfo fileInfo = new FileInfo(filePath); Track newTrack = new Track { Album = trackAlbum, Artists = new HashedSet<Artist>(trackArtists.ToArray()), Bitrate = (uint) file.Properties.AudioBitrate, BitsPerSample = (uint) file.Properties.BitsPerSample, Bpm = file.Tag.BeatsPerMinute == 0 ? (uint?)null : file.Tag.BeatsPerMinute, ChannelCount = (uint) file.Properties.AudioChannels, Codec = file.Properties.Codecs.First().Description, Date = file.Tag.GetDate(), DateAdded = DateTime.Now, DiscNumber = file.Tag.Disc > 0 ? (uint?)file.Tag.Disc : null, Duration = (UInt64)file.Properties.Duration.TotalMilliseconds, Genres = new HashedSet<Genre>(trackGenres.ToArray()), MusicBrainzId = file.Tag.MusicBrainzTrackId, Path = filePath, Playcount = 0, Rating = file.Tag.GetRatingNullableUInt32(), SampleRate = (uint) file.Properties.AudioSampleRate, Size = (ulong) fileInfo.Length, TagLibHash = tagLibHash, Title = file.Tag.Title, TrackNumber = file.Tag.Track > 0 ? (uint?)file.Tag.Track : null, }; session.Save(newTrack); }
public void ReplacePlaylistAndPlay(Track[] trackArray, uint trackIndex) { if (trackIndex >= trackArray.Length) throw new ArgumentException("Index out of bounds", "trackIndex"); OnPlaylistChanged(new PlaylistChangedEventArgs {NewPlaylist = trackArray}); OnTrackChanged(new TrackChangedEventArgs { NewTrack = trackArray[trackIndex], OldTrack = _currentTrackIndex < _trackArray.Length ? _trackArray[_currentTrackIndex] : null }); _currentTrackIndex = trackIndex; _trackArray = trackArray; _playBin.SetState(State.Ready); _playBin.Uri = PathStringToUri(_trackArray[_currentTrackIndex].Path); _playBin.SetState(State.Playing); }
private void TrackSelectorOnSelectedTrack(object sender, SelectedTrackEventArgs args) { _selectedTrack = args.SelectedTrack; _selectedPixbuf = null; if (_selectedButton.Active) SetPictureAndQueueDraw(_selectedTrack, false); }
private void SetPictureAndQueueDraw(Track track, bool usePlayingTrack) { if (track == null) return; IPicture picture = track.GetPicture() ?? new Picture("Images/DefaultAlbumArt.png"); if (usePlayingTrack) { _playingPixbuf = _playingPixbuf ?? new Pixbuf(picture.Data.Data); _currentPixbuf = _playingPixbuf; } else { _selectedPixbuf = _selectedPixbuf ?? new Pixbuf(picture.Data.Data); _currentPixbuf = _selectedPixbuf; } _picture.Pixbuf = _currentPixbuf; _picture.QueueDraw(); }
private void AudioPlayerOnTrackChanged(object sender, TrackChangedEventArgs args) { _playingTrack = args.NewTrack; _playingPixbuf = null; if (_playingButton.Active) SetPictureAndQueueDraw(_playingTrack, true); }
public CoverArtPanel(AudioPlayer audioPlayer, params ITrackSelector[] trackSelectors) : base(false, 0) { ButtonBox buttonBox = new HButtonBox(); _selectedButton = new ToggleButton("Selected"); _playingButton = new ToggleButton("Playing"); buttonBox.Add(_playingButton); buttonBox.Add(_selectedButton); PackStart(buttonBox, false, false, 0); EventBox eventBox = new EventBox(); eventBox.Add(_picture); eventBox.ButtonPressEvent += (o, args) => { var window = new Gtk.Window(WindowType.Toplevel); var pixbuf = _currentPixbuf.Copy(); AutoScalingImage image = new AutoScalingImage(); window.Add(image); int left, top, right, bottom; window.GetFrameDimensions(out left, out top, out right, out bottom); int windowHeightWithFullImage = pixbuf.Height + top + bottom; if (windowHeightWithFullImage > Screen.Height) window.SetDefaultSize(((pixbuf.Width + left + right) * Screen.Height) / windowHeightWithFullImage, Screen.Height); else window.SetDefaultSize(pixbuf.Width + left + right, pixbuf.Height + top + bottom); window.AllowShrink = true; image.Pixbuf = pixbuf; Track track = _selectedButton.Active ? _selectedTrack : _playingTrack; window.Title = String.Format("{0} - {1}", string.Join("; ", track.Album.Artists.Select(a => a.Name)), track.Album.Title); window.ShowAll(); image.QueueResize(); window.SizeAllocated += (o1, allocatedArgs) => { Console.WriteLine("window: {0}", window.Allocation); Console.WriteLine("args: {0}", allocatedArgs.Allocation); if (window.Allocation.Width != allocatedArgs.Allocation.Width || window.Allocation.Height != allocatedArgs.Allocation.Height) { image.SizeAllocate(allocatedArgs.Allocation); image.QueueResize(); image.QueueDraw(); window.QueueDraw(); } }; }; PackStart(eventBox, true, true, 0); _selectedButton.Toggled += SelectedButtonOnToggled; _playingButton.Toggled += PlayingButtonOnToggled; foreach (var trackSelector in trackSelectors) { if (trackSelector.HasFocus) _selectedTrack = trackSelector.CurrentTrack; trackSelector.SelectedTrack += TrackSelectorOnSelectedTrack; } audioPlayer.TrackChanged += AudioPlayerOnTrackChanged; _selectedButton.Shown += (sender, args) => _selectedButton.Active = true; ShowAll(); }