Skip to content

Commit

Permalink
Add a command to play the first disc
Browse files Browse the repository at this point in the history
Mostly useful for albums with a bunch of bonus tracks on the second
disc, as is common with deluxe edition remasters.

Fixes GH-211.
  • Loading branch information
NattyNarwhal committed Jun 27, 2024
1 parent a5ba412 commit 34bd0d0
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ Doing so isn't fatal (it's not a secret), but it is annoying for other contribut
* You can now switch between now playing and current selection with a tab view.
* Playlist information can be viewed and edited.
* The playlist model has been corrected to handle multiple of the same track. (GH-192)
* Added a command to play the first disc from an album. (GH-211)
* Lower case artist names are properly sorted in the artist list.
* Favouriting items is available from the menu bar, or Cmd+E.
* Adding items to the tracklist now has a shortcut of Cmd+D.
* Fix parsing fractional dates returned by some servers.
* Fix the null cover being used for system now playing information.
* Upgrading from Submariner 1.x is no longer supported.
Expand Down
27 changes: 20 additions & 7 deletions Submariner/Music.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22690"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -66,7 +66,7 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="artistName" width="144" minWidth="40" maxWidth="1000" id="21">
<tableColumn identifier="artistName" width="124" minWidth="40" maxWidth="1000" id="21">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="artistName">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -174,11 +174,11 @@
<rect key="frame" x="-1" y="41" width="446" height="199"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="oeS-uH-lBG">
<rect key="frame" x="0.0" y="0.0" width="446" height="184"/>
<rect key="frame" x="0.0" y="0.0" width="446" height="199"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" autosaveName="LocalMusicTable" headerView="36" id="38" customClass="SBTableView">
<rect key="frame" x="0.0" y="0.0" width="692" height="156"/>
<rect key="frame" x="0.0" y="0.0" width="692" height="171"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -328,7 +328,7 @@
</subviews>
</clipView>
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="37">
<rect key="frame" x="0.0" y="184" width="446" height="15"/>
<rect key="frame" x="0.0" y="183" width="446" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="35">
Expand Down Expand Up @@ -406,7 +406,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="404" height="120"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1175"/>
<rect key="screenRect" x="0.0" y="0.0" width="1800" height="1125"/>
<view key="contentView" id="97">
<rect key="frame" x="0.0" y="0.0" width="404" height="120"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -538,6 +538,19 @@
<action selector="addAlbumToTracklist:" target="-2" id="G0o-Zq-P2Z"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="73S-05-gTS"/>
<menuItem title="Play First Disc" id="6Bo-Ls-nIg">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="playFirstDiscFromAlbum:" target="-2" id="iIp-fk-xty"/>
</connections>
</menuItem>
<menuItem title="Add First Disc to Tracklist" id="Pxi-7v-C0P">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="queueFirstDiscFromAlbum:" target="-1" id="xsa-zY-B1P"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="2oY-tZ-Yig"/>
<menuItem title="Delete" id="rvh-F0-V4Q">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
2 changes: 2 additions & 0 deletions Submariner/SBViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@
- (IBAction)trackDoubleClick:(id)sender;
- (IBAction)albumDoubleClick:(id)sender;
- (IBAction)playSelected:(id)sender;
- (IBAction)playFirstDiscFromAlbum:(id)sender;
- (IBAction)addArtistToTracklist:(id)sender;
- (IBAction)addAlbumToTracklist:(id)sender;
- (IBAction)addTrackToTracklist:(id)sender;
- (IBAction)addSelectedToTracklist:(id)sender;
- (IBAction)queueFirstDiscFromAlbum:(id)sender;
- (IBAction)createNewLocalPlaylistWithSelectedTracks:(id)sender;
- (IBAction)downloadTrack:(id)sender;
- (IBAction)downloadAlbum:(id)sender;
Expand Down
32 changes: 30 additions & 2 deletions Submariner/SBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ - (IBAction)playSelected:(id)sender {
}
}

- (IBAction)playFirstDiscFromAlbum:(id)sender {
NSArray<SBTrack*> *tracks = [self firstDiscTracksFor: self.selectedAlbums.firstObject];
[[SBPlayer sharedInstance] playTracks: tracks startingAt: 0];
}

#pragma mark Add to Tracklist

- (IBAction)addArtistToTracklist:(id)sender {
Expand Down Expand Up @@ -147,6 +152,12 @@ - (IBAction)addSelectedToTracklist:(id)sender {
}


- (IBAction)queueFirstDiscFromAlbum:(id)sender {
NSArray<SBTrack*> *tracks = [self firstDiscTracksFor: self.selectedAlbums.firstObject];
[[SBPlayer sharedInstance] addTrackArray: tracks replace: NO];
}


- (IBAction)addTrackToTracklist:(id)sender {
[[SBPlayer sharedInstance] addTrackArray: self.selectedTracks replace:NO];
}
Expand Down Expand Up @@ -374,6 +385,21 @@ - (void)createLocalPlaylistWithSelected:(NSArray<SBTrack*>*)trackList databaseCo
[playlistsSection addResourcesObject:newPlaylist];
}

- (NSArray<SBTrack*>*)firstDiscTracksFor:(SBAlbum*)album {
NSArray<SBTrack*> *sortedTracks = [album.tracks sortedArrayUsingDescriptors: self.trackSortDescriptor];
NSIndexSet *trackIndices = [sortedTracks indexesOfObjectsPassingTest: ^BOOL(SBTrack * _Nonnull track, NSUInteger index, BOOL * _Nonnull stop) {
// Albums almost always start 1 indexed
return track.discNumber.intValue == 1;
}];
// Fallback if we just don't have numbered discs
if (trackIndices.count == 0) {
trackIndices = [sortedTracks indexesOfObjectsPassingTest: ^BOOL(SBTrack * _Nonnull track, NSUInteger index, BOOL * _Nonnull stop) {
return track.discNumber.intValue == 0;
}];
}
return [sortedTracks objectsAtIndexes: trackIndices];
}

- (SBSelectedItemType) selectedItemType {
NSObject<SBStarrable> *first = self.selectedMusicItems.firstObject;
if ([first isKindOfClass: SBArtist.class]) {
Expand Down Expand Up @@ -438,8 +464,10 @@ - (BOOL)validateUserInterfaceItem: (id<NSValidatedUserInterfaceItem>) item {
// for context menus
if (action == @selector(albumDoubleClick:)
|| action == @selector(downloadAlbum:)
|| action == @selector(addAlbumToTracklist:)) {
return albumSelected > 0;
|| action == @selector(addAlbumToTracklist:)
|| action == @selector(playFirstDiscFromAlbum:)
|| action == @selector(queueFirstDiscFromAlbum:)) {
return albumSelected > 0 && albumsActive;
}

if (action == @selector(addArtistToTracklist:)) {
Expand Down
23 changes: 18 additions & 5 deletions Submariner/ServerHome.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22690"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -72,11 +72,11 @@
<rect key="frame" x="-2" y="41" width="622" height="158"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="SWK-O6-Z3Q">
<rect key="frame" x="0.0" y="0.0" width="622" height="143"/>
<rect key="frame" x="0.0" y="0.0" width="622" height="158"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" autosaveName="ServerAlbumsTable" headerView="15" id="13" customClass="SBTableView">
<rect key="frame" x="0.0" y="0.0" width="707" height="115"/>
<rect key="frame" x="0.0" y="0.0" width="707" height="130"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -237,7 +237,7 @@
</subviews>
</clipView>
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="14">
<rect key="frame" x="0.0" y="143" width="622" height="15"/>
<rect key="frame" x="0.0" y="142" width="622" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="16">
Expand Down Expand Up @@ -312,6 +312,19 @@
<action selector="addAlbumToTracklist:" target="-2" id="zDA-gm-oDK"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="4sd-vx-bix"/>
<menuItem title="Play First Disc" id="k5I-2Y-c7J">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="playFirstDiscFromAlbum:" target="-2" id="ru9-Xh-94m"/>
</connections>
</menuItem>
<menuItem title="Add First Disc to Tracklist" id="rXg-2R-jU0">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="queueFirstDiscFromAlbum:" target="-2" id="FvQ-zB-R9x"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="8z0-m8-feZ"/>
<menuItem title="Download" id="Mkc-gS-tbg">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
25 changes: 19 additions & 6 deletions Submariner/ServerLibrary.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22690"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -66,7 +66,7 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="itemName" width="144" minWidth="40" maxWidth="1000" id="184">
<tableColumn identifier="itemName" width="124" minWidth="40" maxWidth="1000" id="184">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -167,11 +167,11 @@
<rect key="frame" x="-2" y="41" width="446" height="199"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="uNg-bD-Z0H">
<rect key="frame" x="0.0" y="0.0" width="446" height="184"/>
<rect key="frame" x="0.0" y="0.0" width="446" height="199"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" autosaveName="ServerMusicTable" headerView="110" id="108" customClass="SBTableView">
<rect key="frame" x="0.0" y="0.0" width="711" height="156"/>
<rect key="frame" x="0.0" y="0.0" width="711" height="171"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -336,7 +336,7 @@
</subviews>
</clipView>
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="109">
<rect key="frame" x="0.0" y="184" width="446" height="15"/>
<rect key="frame" x="0.0" y="183" width="446" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="111">
Expand Down Expand Up @@ -434,6 +434,19 @@
<action selector="addAlbumToTracklist:" target="-2" id="O6Y-vp-Tih"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="6zf-07-KHp"/>
<menuItem title="Play First Disc" id="h7O-R5-T2O">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="playFirstDiscFromAlbum:" target="-2" id="Yfw-ZW-kJH"/>
</connections>
</menuItem>
<menuItem title="Add First Disc to Tracklist" id="4G6-ZO-KD9">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="queueFirstDiscFromAlbum:" target="-2" id="4om-Gh-tC7"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="vpg-ew-I1e"/>
<menuItem title="Download" id="0xt-vi-X6m">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
Loading

0 comments on commit 34bd0d0

Please sign in to comment.