Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c87b19085 | ||
|
|
ac363ea0f7 | ||
|
|
b10528d69c | ||
|
|
42f5eddb36 | ||
|
|
7f4a07d846 | ||
|
|
29cc9a03d4 | ||
|
|
592f623bc2 | ||
|
|
3ec9b043e3 |
No files matched your search
@@ -219,11 +219,19 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
|
|||||||
@ObservationIgnored private var stationGen = 0
|
@ObservationIgnored private var stationGen = 0
|
||||||
@ObservationIgnored private var stationBusy = false
|
@ObservationIgnored private var stationBusy = false
|
||||||
private static let radioAlbumsAhead = 8
|
private static let radioAlbumsAhead = 8
|
||||||
private static let radioAlbumsLow = 3
|
/// Each new song adds an album, up to this many ahead (keeps the queue from growing without end).
|
||||||
|
private static let radioAlbumsMax = 40
|
||||||
|
/// Album radio: the song the last top-up saw, and songs started since that haven't added their album yet.
|
||||||
|
@ObservationIgnored private var radioSeenUid: Int64?
|
||||||
|
@ObservationIgnored private var radioOwed = 0
|
||||||
private static let radioSongsBatch = 100
|
private static let radioSongsBatch = 100
|
||||||
private static let radioSongsLow = 25
|
private static let radioSongsLow = 25
|
||||||
|
|
||||||
private func setStation(_ s: Station?) { station = s; stationGen += 1; stationBusy = false }
|
private func setStation(_ s: Station?) {
|
||||||
|
station = s; stationGen += 1; stationBusy = false
|
||||||
|
radioSeenUid = queue.indices.contains(index) ? queue[index].uid : nil
|
||||||
|
radioOwed = 0
|
||||||
|
}
|
||||||
|
|
||||||
private func albumDeck() async throws -> [String] {
|
private func albumDeck() async throws -> [String] {
|
||||||
var deck = (try? await plex.albums().map(\.ratingKey)) ?? []
|
var deck = (try? await plex.albums().map(\.ratingKey)) ?? []
|
||||||
@@ -268,18 +276,28 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
|
|||||||
let gen = stationGen
|
let gen = stationGen
|
||||||
switch st {
|
switch st {
|
||||||
case .albums(let saved):
|
case .albums(let saved):
|
||||||
|
// Every song that starts (the next track, a skip, a jump to another album) owes one more album,
|
||||||
|
// so the queue always runs on past what's playing.
|
||||||
|
let uid = queue[index].uid
|
||||||
|
if uid != radioSeenUid { radioSeenUid = uid; radioOwed += 1 }
|
||||||
let ahead = Set(queue[index...].map { $0.track.albumKey ?? $0.track.album }).count
|
let ahead = Set(queue[index...].map { $0.track.albumKey ?? $0.track.album }).count
|
||||||
guard ahead <= Self.radioAlbumsLow else { return }
|
let want = min(max(Self.radioAlbumsAhead + 1 - ahead, radioOwed), Self.radioAlbumsMax - ahead)
|
||||||
|
guard want > 0 else { radioOwed = 0; return }
|
||||||
stationBusy = true
|
stationBusy = true
|
||||||
|
let owed = radioOwed
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
defer { if gen == stationGen { stationBusy = false } }
|
var got = false
|
||||||
|
// Checks again once the albums are in, unless nothing came back (server down: don't spin).
|
||||||
|
defer { if gen == stationGen { stationBusy = false; if got { topUpStation() } } }
|
||||||
var deck = saved
|
var deck = saved
|
||||||
if deck.isEmpty { deck = (try? await albumDeck()) ?? [] }
|
if deck.count < want { deck += (try? await albumDeck()) ?? [] }
|
||||||
let take = Array(deck.prefix(Self.radioAlbumsAhead + 1 - ahead))
|
let take = Array(deck.prefix(want))
|
||||||
deck.removeFirst(take.count)
|
deck.removeFirst(take.count)
|
||||||
let tracks = await albumTracks(take)
|
let tracks = await albumTracks(take)
|
||||||
guard gen == stationGen else { return }
|
guard gen == stationGen else { return }
|
||||||
station = .albums(deck)
|
station = .albums(deck)
|
||||||
|
radioOwed = max(radioOwed - owed, 0)
|
||||||
|
got = !tracks.isEmpty
|
||||||
addToQueue(tracks)
|
addToQueue(tracks)
|
||||||
}
|
}
|
||||||
case .songs:
|
case .songs:
|
||||||
@@ -563,14 +581,16 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
|
|||||||
|
|
||||||
var karaokeVocals: KaraokeVocals { KaraokeVocals(rawValue: settings.karaokeVocals) ?? .Off }
|
var karaokeVocals: KaraokeVocals { KaraokeVocals(rawValue: settings.karaokeVocals) ?? .Off }
|
||||||
|
|
||||||
func setKaraokeVocals(_ v: KaraokeVocals) {
|
/// [engage] (from the lyrics panel) turns karaoke on, so the choice is heard even if lyrics were opened without it.
|
||||||
|
func setKaraokeVocals(_ v: KaraokeVocals, engage: Bool = false) {
|
||||||
settings.karaokeVocals = v.rawValue
|
settings.karaokeVocals = v.rawValue
|
||||||
if karaoke { applyMix(karaokeMix) }
|
if karaoke { applyMix(karaokeMix) } else if engage { setKaraoke(true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func setKaraokeSoftDb(_ db: Int) {
|
func setKaraokeSoftDb(_ db: Int, engage: Bool = false) {
|
||||||
settings.karaokeSoftDb = db
|
settings.karaokeSoftDb = db
|
||||||
if karaoke && karaokeVocals == .Soft { applyMix(karaokeMix) }
|
guard karaokeVocals == .Soft else { return }
|
||||||
|
if karaoke { applyMix(karaokeMix) } else if engage { setKaraoke(true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turning it off puts back the song's saved mix, or the one from before, unless the mix was changed meanwhile.
|
/// Turning it off puts back the song's saved mix, or the one from before, unless the mix was changed meanwhile.
|
||||||
|
|||||||
@@ -88,15 +88,21 @@ final class StemPlaylists {
|
|||||||
/// Saves [data] (any image format Photos hands over) as the list's cover, scaled to 1200 px.
|
/// Saves [data] (any image format Photos hands over) as the list's cover, scaled to 1200 px.
|
||||||
/// Each pick gets a new file name so cached art doesn't show the old one.
|
/// Each pick gets a new file name so cached art doesn't show the old one.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func setPhotoArt(_ id: String, _ data: Data) -> Bool {
|
/// A picked photo as a JPEG no bigger than 2000 px a side. The cropper's JPEGs pass through as they are.
|
||||||
guard let img = UIImage(data: data) else { return false }
|
static func coverJpeg(_ data: Data) -> Data? {
|
||||||
let side: CGFloat = 1200
|
guard let img = UIImage(data: data) else { return nil }
|
||||||
|
let side: CGFloat = 2000
|
||||||
|
if data.starts(with: [0xFF, 0xD8]), max(img.size.width, img.size.height) <= side { return data }
|
||||||
let scale = min(1, side / max(img.size.width, img.size.height, 1))
|
let scale = min(1, side / max(img.size.width, img.size.height, 1))
|
||||||
let size = CGSize(width: (img.size.width * scale).rounded(), height: (img.size.height * scale).rounded())
|
let size = CGSize(width: (img.size.width * scale).rounded(), height: (img.size.height * scale).rounded())
|
||||||
let fmt = UIGraphicsImageRendererFormat.default(); fmt.scale = 1
|
let fmt = UIGraphicsImageRendererFormat.default(); fmt.scale = 1
|
||||||
let jpeg = UIGraphicsImageRenderer(size: size, format: fmt).jpegData(withCompressionQuality: 0.85) { _ in
|
return UIGraphicsImageRenderer(size: size, format: fmt).jpegData(withCompressionQuality: 0.85) { _ in
|
||||||
img.draw(in: CGRect(origin: .zero, size: size))
|
img.draw(in: CGRect(origin: .zero, size: size))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setPhotoArt(_ id: String, _ data: Data) -> Bool {
|
||||||
|
guard let jpeg = Self.coverJpeg(data) else { return false }
|
||||||
let name = "\(id)-\(UUID().uuidString.prefix(8).lowercased()).jpg"
|
let name = "\(id)-\(UUID().uuidString.prefix(8).lowercased()).jpg"
|
||||||
do {
|
do {
|
||||||
try FileManager.default.createDirectory(at: Self.artDir, withIntermediateDirectories: true)
|
try FileManager.default.createDirectory(at: Self.artDir, withIntermediateDirectories: true)
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ struct JItem: Decodable {
|
|||||||
func toArtist() -> Artist { Artist(ratingKey: id, title: name, sortTitle: sortName ?? name, thumb: thumb) }
|
func toArtist() -> Artist { Artist(ratingKey: id, title: name, sortTitle: sortName ?? name, thumb: thumb) }
|
||||||
|
|
||||||
func toPlaylist() -> Playlist {
|
func toPlaylist() -> Playlist {
|
||||||
Playlist(ratingKey: id, title: name, thumb: thumb, trackCount: childCount ?? 0, durationMs: durationMs)
|
// "id|tag": a new cover changes the tag, so the art cache doesn't keep the old one.
|
||||||
|
Playlist(ratingKey: id, title: name, thumb: primaryTag.map { "\(id)|\($0)" } ?? thumb, trackCount: childCount ?? 0, durationMs: durationMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,6 +415,15 @@ final class JellyfinClient: MediaSource, @unchecked Sendable {
|
|||||||
try await send("DELETE", "/Items/\(key)")
|
try await send("DELETE", "/Items/\(key)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Jellyfin wants the image base64 encoded in the body.
|
||||||
|
func setPlaylistArt(_ key: String, jpeg: Data) async throws {
|
||||||
|
guard server.signedIn else { throw NotSignedIn() }
|
||||||
|
var req = request(try url("/Items/\(key)/Images/Primary"), method: "POST")
|
||||||
|
req.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")
|
||||||
|
req.httpBody = jpeg.base64EncodedData()
|
||||||
|
_ = try await http.data(req)
|
||||||
|
}
|
||||||
|
|
||||||
// ---- playback reporting ----------------------------------------------------------------
|
// ---- playback reporting ----------------------------------------------------------------
|
||||||
|
|
||||||
func scrobble(_ trackKey: String) async {
|
func scrobble(_ trackKey: String) async {
|
||||||
@@ -431,8 +441,9 @@ final class JellyfinClient: MediaSource, @unchecked Sendable {
|
|||||||
// ---- URLs ---------------------------------------------------------------------------
|
// ---- URLs ---------------------------------------------------------------------------
|
||||||
|
|
||||||
func artUrl(_ thumb: String?, px: Int) -> URL? {
|
func artUrl(_ thumb: String?, px: Int) -> URL? {
|
||||||
guard let thumb, !thumb.isEmpty, server.signedIn, let u = URL(string: base + "/Items/\(thumb)/Images/Primary") else { return nil }
|
let parts = thumb?.split(separator: "|", maxSplits: 1).map(String.init) ?? []
|
||||||
return u.with([("fillWidth", px), ("fillHeight", px), ("quality", 90), ("api_key", server.token)])
|
guard let id = parts.first, !id.isEmpty, server.signedIn, let u = URL(string: base + "/Items/\(id)/Images/Primary") else { return nil }
|
||||||
|
return u.with([("fillWidth", px), ("fillHeight", px), ("quality", 90), ("tag", parts.count > 1 ? parts[1] : nil), ("api_key", server.token)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The original file, untouched, like Plex's part URL.
|
/// The original file, untouched, like Plex's part URL.
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ protocol MediaSource: AnyObject, Sendable {
|
|||||||
func removeFromPlaylist(_ key: String, playlistItemId: Int64) async throws
|
func removeFromPlaylist(_ key: String, playlistItemId: Int64) async throws
|
||||||
func movePlaylistItem(_ key: String, playlistItemId: Int64, afterItemId: Int64?) async throws
|
func movePlaylistItem(_ key: String, playlistItemId: Int64, afterItemId: Int64?) async throws
|
||||||
func renamePlaylist(_ key: String, title: String) async throws
|
func renamePlaylist(_ key: String, title: String) async throws
|
||||||
|
/// Uploads [jpeg] as the playlist's cover.
|
||||||
|
func setPlaylistArt(_ key: String, jpeg: Data) async throws
|
||||||
func deletePlaylist(_ key: String) async throws
|
func deletePlaylist(_ key: String) async throws
|
||||||
func scrobble(_ trackKey: String) async
|
func scrobble(_ trackKey: String) async
|
||||||
func timeline(_ track: Track, state: String, positionMs: Int64) async
|
func timeline(_ track: Track, state: String, positionMs: Int64) async
|
||||||
|
|||||||
@@ -201,6 +201,16 @@ final class PlexClient: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Made on the server of the first song; songs from other servers are left out.
|
/// Made on the server of the first song; songs from other servers are left out.
|
||||||
|
/// Servers a new playlist can live on, as (id, name).
|
||||||
|
var playlistServers: [(String, String)] { sources.map { ($0.server.id, $0.server.name) } }
|
||||||
|
|
||||||
|
/// An empty playlist on one server (the only one when [serverId] is nil).
|
||||||
|
func createEmptyPlaylist(_ title: String, serverId: String?) async throws -> Playlist? {
|
||||||
|
let list = sources
|
||||||
|
guard let s = list.first(where: { $0.server.id == serverId }) ?? list.first else { throw NotSignedIn() }
|
||||||
|
return try await s.createPlaylist(title, trackKeys: [])?.tagged(s.server.id)
|
||||||
|
}
|
||||||
|
|
||||||
func createPlaylist(_ title: String, trackKeys: [String]) async throws -> Playlist? {
|
func createPlaylist(_ title: String, trackKeys: [String]) async throws -> Playlist? {
|
||||||
guard let first = trackKeys.first else { return nil }
|
guard let first = trackKeys.first else { return nil }
|
||||||
let (s, _) = try routed(first)
|
let (s, _) = try routed(first)
|
||||||
@@ -235,6 +245,13 @@ final class PlexClient: @unchecked Sendable {
|
|||||||
try await s.deletePlaylist(k)
|
try await s.deletePlaylist(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Uploads the cover, then returns the playlist's new thumb.
|
||||||
|
func setPlaylistArt(_ key: String, jpeg: Data) async throws -> String? {
|
||||||
|
let (s, k) = try routed(key)
|
||||||
|
try await s.setPlaylistArt(k, jpeg: jpeg)
|
||||||
|
return try await s.playlists(sort: "titleSort").first { $0.ratingKey == k }?.thumb.tagged(s.server.id)
|
||||||
|
}
|
||||||
|
|
||||||
// ---- playback reporting ---------------------------------------------------------
|
// ---- playback reporting ---------------------------------------------------------
|
||||||
|
|
||||||
func scrobble(_ trackKey: String) async {
|
func scrobble(_ trackKey: String) async {
|
||||||
|
|||||||
@@ -266,7 +266,9 @@ final class PlexServer: MediaSource, @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createPlaylist(_ title: String, trackKeys: [String]) async throws -> Playlist? {
|
func createPlaylist(_ title: String, trackKeys: [String]) async throws -> Playlist? {
|
||||||
let uri = try await libraryUri(trackKeys)
|
// No songs: a bare library uri makes an empty playlist (newer Plex servers allow it).
|
||||||
|
if trackKeys.isEmpty, machine.isEmpty { machine = try await machineId() }
|
||||||
|
let uri = trackKeys.isEmpty ? "server://\(machine)/com.plexapp.plugins.library" : try await libraryUri(trackKeys)
|
||||||
return try await send("POST", "/playlists", [("type", "audio"), ("title", title), ("smart", 0), ("uri", uri)])
|
return try await send("POST", "/playlists", [("type", "audio"), ("title", title), ("smart", 0), ("uri", uri)])
|
||||||
.metadata.first?.toPlaylist()
|
.metadata.first?.toPlaylist()
|
||||||
}
|
}
|
||||||
@@ -293,6 +295,15 @@ final class PlexServer: MediaSource, @unchecked Sendable {
|
|||||||
try await send("DELETE", "/playlists/\(key)")
|
try await send("DELETE", "/playlists/\(key)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Plex takes the image as the raw body and selects it as the poster.
|
||||||
|
func setPlaylistArt(_ key: String, jpeg: Data) async throws {
|
||||||
|
guard signedIn else { throw NotSignedIn() }
|
||||||
|
var req = request(try url("/library/metadata/\(key)/posters"), method: "POST")
|
||||||
|
req.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")
|
||||||
|
req.httpBody = jpeg
|
||||||
|
_ = try await http.data(req)
|
||||||
|
}
|
||||||
|
|
||||||
// ---- playback reporting ---------------------------------------------------------
|
// ---- playback reporting ---------------------------------------------------------
|
||||||
|
|
||||||
func scrobble(_ trackKey: String) async {
|
func scrobble(_ trackKey: String) async {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 228 KiB After Width: | Height: | Size: 173 KiB |
|
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 192 KiB |
@@ -315,11 +315,14 @@ struct HingeEdge: ViewModifier {
|
|||||||
struct Page<Content: View>: View {
|
struct Page<Content: View>: View {
|
||||||
let title: String
|
let title: String
|
||||||
var large = true
|
var large = true
|
||||||
|
/// Moves the content up into an empty nav bar.
|
||||||
|
var pullUp: CGFloat = 0
|
||||||
@ViewBuilder let content: () -> Content
|
@ViewBuilder let content: () -> Content
|
||||||
@Environment(\.palette) private var p
|
@Environment(\.palette) private var p
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
LazyVStack(alignment: .leading, spacing: 0) { content() }
|
LazyVStack(alignment: .leading, spacing: 0) { content() }
|
||||||
|
.padding(.top, -pullUp)
|
||||||
.padding(.bottom, 24)
|
.padding(.bottom, 24)
|
||||||
}
|
}
|
||||||
.modifier(HingeEdge())
|
.modifier(HingeEdge())
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
/// Square crop for a playlist cover: pinch or slide to zoom, drag to place, pick the saved size.
|
||||||
|
struct CoverCropper: View {
|
||||||
|
let image: UIImage
|
||||||
|
let done: (Data?) -> Void
|
||||||
|
|
||||||
|
@State private var zoom: CGFloat = 1
|
||||||
|
@State private var offset: CGSize = .zero
|
||||||
|
@State private var dragStart: CGSize?
|
||||||
|
@State private var zoomStart: CGFloat?
|
||||||
|
@State private var side: CGFloat = 1
|
||||||
|
@State private var saving = false
|
||||||
|
@AppStorage("coverCropSize") private var outSize = 1200
|
||||||
|
|
||||||
|
private static let sizes = [(600, "Small"), (1200, "Medium"), (2000, "Large")]
|
||||||
|
private let maxZoom: CGFloat = 6
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
GeometryReader { geo in
|
||||||
|
let s = max(1, min(geo.size.width, geo.size.height) - 32)
|
||||||
|
ZStack {
|
||||||
|
Color.black
|
||||||
|
Image(uiImage: image)
|
||||||
|
.resizable()
|
||||||
|
.frame(width: shown(s).width, height: shown(s).height)
|
||||||
|
.offset(offset)
|
||||||
|
CropMask(side: s).allowsHitTesting(false)
|
||||||
|
}
|
||||||
|
.frame(width: geo.size.width, height: geo.size.height)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.gesture(drag(s).simultaneously(with: pinch(s)))
|
||||||
|
.onAppear { side = s }
|
||||||
|
.onChange(of: s) { _, v in side = v; clamp(v) }
|
||||||
|
}
|
||||||
|
.clipped()
|
||||||
|
controls
|
||||||
|
}
|
||||||
|
.background(Color.black)
|
||||||
|
.navigationTitle("Crop Cover")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.toolbarColorScheme(.dark, for: .navigationBar)
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .cancellationAction) { Button("Cancel") { done(nil) } }
|
||||||
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
|
if saving { ProgressView() } else { Button("Apply") { apply() }.bold() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var controls: some View {
|
||||||
|
VStack(spacing: 14) {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
Image(systemName: "minus.magnifyingglass").foregroundStyle(.secondary)
|
||||||
|
Slider(value: Binding(get: { zoom }, set: { zoom = $0; clamp(side) }), in: 1...maxZoom)
|
||||||
|
Image(systemName: "plus.magnifyingglass").foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Picker("Size", selection: $outSize) {
|
||||||
|
ForEach(Self.sizes, id: \.0) { Text($0.1).tag($0.0) }
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
Text("\(outSize) × \(outSize) px").font(.caption).monospacedDigit().foregroundStyle(.secondary)
|
||||||
|
Button("Reset") { withAnimation(.snappy(duration: 0.2)) { zoom = 1; offset = .zero } }
|
||||||
|
.font(.subheadline)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 24).padding(.top, 12).padding(.bottom, 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The image's on-screen size: filling the square at zoom 1.
|
||||||
|
private func shown(_ s: CGFloat) -> CGSize {
|
||||||
|
let w = max(image.size.width, 1), h = max(image.size.height, 1)
|
||||||
|
let k = s / min(w, h) * zoom
|
||||||
|
return CGSize(width: w * k, height: h * k)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keeps the square covered by the image.
|
||||||
|
private func clamp(_ s: CGFloat) {
|
||||||
|
let d = shown(s)
|
||||||
|
let mx = max(0, (d.width - s) / 2), my = max(0, (d.height - s) / 2)
|
||||||
|
offset = CGSize(width: min(max(offset.width, -mx), mx), height: min(max(offset.height, -my), my))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func drag(_ s: CGFloat) -> some Gesture {
|
||||||
|
DragGesture(minimumDistance: 0)
|
||||||
|
.onChanged { v in
|
||||||
|
let start = dragStart ?? offset
|
||||||
|
if dragStart == nil { dragStart = start }
|
||||||
|
offset = CGSize(width: start.width + v.translation.width, height: start.height + v.translation.height)
|
||||||
|
clamp(s)
|
||||||
|
}
|
||||||
|
.onEnded { _ in dragStart = nil }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func pinch(_ s: CGFloat) -> some Gesture {
|
||||||
|
MagnifyGesture()
|
||||||
|
.onChanged { v in
|
||||||
|
let start = zoomStart ?? zoom
|
||||||
|
if zoomStart == nil { zoomStart = start }
|
||||||
|
zoom = min(max(start * v.magnification, 1), maxZoom)
|
||||||
|
clamp(s)
|
||||||
|
}
|
||||||
|
.onEnded { _ in zoomStart = nil }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func apply() {
|
||||||
|
let s = side
|
||||||
|
let d = shown(s)
|
||||||
|
let k = d.width / max(image.size.width, 1) // screen points per image point
|
||||||
|
// The square's top-left and side, in image points.
|
||||||
|
let x0 = (d.width / 2 - s / 2 - offset.width) / k
|
||||||
|
let y0 = (d.height / 2 - s / 2 - offset.height) / k
|
||||||
|
let crop = CGRect(x: x0, y: y0, width: s / k, height: s / k)
|
||||||
|
let img = image
|
||||||
|
let out = CGFloat(outSize)
|
||||||
|
saving = true
|
||||||
|
Task {
|
||||||
|
let data = await Task.detached(priority: .userInitiated) { CoverCropper.render(img, crop, out) }.value
|
||||||
|
saving = false
|
||||||
|
done(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nonisolated static func render(_ img: UIImage, _ crop: CGRect, _ out: CGFloat) -> Data? {
|
||||||
|
let f = out / max(crop.width, 1)
|
||||||
|
let fmt = UIGraphicsImageRendererFormat.default(); fmt.scale = 1; fmt.opaque = true
|
||||||
|
return UIGraphicsImageRenderer(size: CGSize(width: out, height: out), format: fmt).jpegData(withCompressionQuality: 0.85) { _ in
|
||||||
|
img.draw(in: CGRect(x: -crop.minX * f, y: -crop.minY * f, width: img.size.width * f, height: img.size.height * f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dims everything outside the centered square and outlines it.
|
||||||
|
private struct CropMask: View {
|
||||||
|
let side: CGFloat
|
||||||
|
var body: some View {
|
||||||
|
GeometryReader { geo in
|
||||||
|
let r = CGRect(x: (geo.size.width - side) / 2, y: (geo.size.height - side) / 2, width: side, height: side)
|
||||||
|
Path { p in p.addRect(CGRect(origin: .zero, size: geo.size)); p.addRect(r) }
|
||||||
|
.fill(Color.black.opacity(0.55), style: FillStyle(eoFill: true))
|
||||||
|
Rectangle().stroke(Color.white.opacity(0.9), lineWidth: 1)
|
||||||
|
.frame(width: side, height: side).position(x: r.midX, y: r.midY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,14 +54,68 @@ struct MediaMenu {
|
|||||||
playlistKey: nil, extra: [], confirmDownload: true, stemmed: stemmed(cov))
|
playlistKey: nil, extra: [], confirmDownload: true, stemmed: stemmed(cov))
|
||||||
}
|
}
|
||||||
|
|
||||||
func playlist(_ pl: Playlist, extra: [SheetAction] = []) -> [SheetAction] {
|
/// [changed] hears the playlist after a rename or a new cover, so an open page can follow; [deleted] after a delete.
|
||||||
|
func playlist(_ pl: Playlist, extra: [SheetAction] = [], changed: ((Playlist) -> Void)? = nil, deleted: (() -> Void)? = nil) -> [SheetAction] {
|
||||||
let plex = g.plex
|
let plex = g.plex
|
||||||
let copy = SheetAction("Copy to Stem Playlist…", icon: "doc.on.doc") { copyToStems(pl) }
|
let copy = SheetAction("Copy to Stem Playlist…", icon: "doc.on.doc") { copyToStems(pl) }
|
||||||
let gr = DownloadGroup(kind: .playlist, key: pl.ratingKey, title: pl.title, subtitle: "Playlist", thumb: pl.thumb)
|
let gr = DownloadGroup(kind: .playlist, key: pl.ratingKey, title: pl.title, subtitle: "Playlist", thumb: pl.thumb)
|
||||||
return collection(pl.title, gr, { try await plex.playlistTracks(pl.ratingKey) }, playlistKey: pl.ratingKey, extra: [copy] + extra,
|
return collection(pl.title, gr, { try await plex.playlistTracks(pl.ratingKey) }, playlistKey: pl.ratingKey,
|
||||||
|
extra: [copy] + (pl.smart ? [] : playlistEdits(pl, changed)) + extra + [delete(pl, deleted)],
|
||||||
confirmDownload: pl.trackCount > 50)
|
confirmDownload: pl.trackCount > 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rename and Change Cover, saved on the playlist's own server (Plex or Jellyfin).
|
||||||
|
private func playlistEdits(_ pl: Playlist, _ changed: ((Playlist) -> Void)?) -> [SheetAction] {
|
||||||
|
let plex = g.plex
|
||||||
|
let overlays = overlays
|
||||||
|
let ui = ui
|
||||||
|
let rename = SheetAction("Rename…", icon: "pencil") {
|
||||||
|
overlays.prompt("Rename Playlist", nil, initial: pl.title, "Save") { name in
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await plex.renamePlaylist(pl.ratingKey, title: name)
|
||||||
|
var p = pl; p.title = name
|
||||||
|
ui.playlistEdits += 1
|
||||||
|
changed?(p)
|
||||||
|
} catch { overlays.hud("Couldn't rename: \(error.localizedDescription)", "exclamationmark.triangle") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let cover = SheetAction("Change Cover…", icon: "photo") {
|
||||||
|
overlays.pickPhoto { data in
|
||||||
|
guard let jpeg = StemPlaylists.coverJpeg(data) else { overlays.hud("Couldn't use that photo", "exclamationmark.triangle"); return }
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let thumb = try await plex.setPlaylistArt(pl.ratingKey, jpeg: jpeg)
|
||||||
|
var p = pl; p.thumb = thumb ?? pl.thumb
|
||||||
|
ui.playlistEdits += 1
|
||||||
|
changed?(p)
|
||||||
|
overlays.hud("Cover updated")
|
||||||
|
} catch { overlays.hud("Couldn't upload: \(error.localizedDescription)", "exclamationmark.triangle") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [rename, cover]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func delete(_ pl: Playlist, _ deleted: (() -> Void)?) -> SheetAction {
|
||||||
|
let plex = g.plex
|
||||||
|
let overlays = overlays
|
||||||
|
let ui = ui
|
||||||
|
return SheetAction("Delete Playlist…", icon: "trash", destructive: true) {
|
||||||
|
overlays.confirm("Delete “\(pl.title)”?", "This removes it from the server for every app.", "Delete") {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await plex.deletePlaylist(pl.ratingKey)
|
||||||
|
ui.playlistEdits += 1
|
||||||
|
overlays.hud("Deleted “\(pl.title)”", "trash")
|
||||||
|
deleted?()
|
||||||
|
} catch { overlays.hud("Couldn't delete: \(error.localizedDescription)", "exclamationmark.triangle") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func stemPlaylist(_ pl: StemPlaylist, extra: [SheetAction] = [], onPage: Bool = false) -> [SheetAction] {
|
func stemPlaylist(_ pl: StemPlaylist, extra: [SheetAction] = [], onPage: Bool = false) -> [SheetAction] {
|
||||||
var a = [
|
var a = [
|
||||||
SheetAction("Play Next", icon: "text.line.first.and.arrowtriangle.forward") {
|
SheetAction("Play Next", icon: "text.line.first.and.arrowtriangle.forward") {
|
||||||
@@ -75,23 +129,30 @@ struct MediaMenu {
|
|||||||
{ pl.tracks }, confirm: false)
|
{ pl.tracks }, confirm: false)
|
||||||
if pl.items.isEmpty { a = [] }
|
if pl.items.isEmpty { a = [] }
|
||||||
let lists = g.stemPlaylists
|
let lists = g.stemPlaylists
|
||||||
|
a.append(SheetAction("Rename…", icon: "pencil") {
|
||||||
|
overlays.prompt("Rename Stem Playlist", nil, initial: pl.title, "Save") { lists.rename(pl.id, $0) }
|
||||||
|
})
|
||||||
|
a.append(SheetAction("Change Cover…", icon: "photo") {
|
||||||
|
var seen = Set<String>()
|
||||||
|
var acts: [SheetAction] = [
|
||||||
|
SheetAction("Choose from Photos…", icon: "photo.on.rectangle") {
|
||||||
|
overlays.pickPhoto { data in
|
||||||
|
if !lists.setPhotoArt(pl.id, data) { overlays.hud("Couldn't use that photo", "exclamationmark.triangle") }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SheetAction("Automatic", icon: "wand.and.stars") { lists.setArt(pl.id, nil) },
|
||||||
|
]
|
||||||
|
for t in pl.tracks {
|
||||||
|
guard let th = t.thumb, seen.insert(th).inserted, seen.count <= 20 else { continue }
|
||||||
|
acts.append(SheetAction(t.album, icon: th == pl.artThumb ? "checkmark" : "photo") { lists.setArt(pl.id, th) })
|
||||||
|
}
|
||||||
|
overlays.actions("Choose a Cover", acts)
|
||||||
|
})
|
||||||
if !pl.items.isEmpty {
|
if !pl.items.isEmpty {
|
||||||
a.append(SheetAction("Change Cover…", icon: "photo") {
|
a.append(SheetAction("Set Mix for All Songs…", icon: "slider.horizontal.3") {
|
||||||
var seen = Set<String>()
|
chooseMix(pl.tracks) { m in lists.setItems(pl.id, pl.items.map { var it = $0; it.mix = MixPresets.normalized(m); return it }) }
|
||||||
var acts: [SheetAction] = [
|
|
||||||
SheetAction("Choose from Photos…", icon: "photo.on.rectangle") {
|
|
||||||
overlays.pickPhoto { data in
|
|
||||||
if !lists.setPhotoArt(pl.id, data) { overlays.hud("Couldn't use that photo", "exclamationmark.triangle") }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
SheetAction("Automatic", icon: "wand.and.stars") { lists.setArt(pl.id, nil) },
|
|
||||||
]
|
|
||||||
for t in pl.tracks {
|
|
||||||
guard let th = t.thumb, seen.insert(th).inserted, seen.count <= 20 else { continue }
|
|
||||||
acts.append(SheetAction(t.album, icon: th == pl.artThumb ? "checkmark" : "photo") { lists.setArt(pl.id, th) })
|
|
||||||
}
|
|
||||||
overlays.actions("Choose a Cover", acts)
|
|
||||||
})
|
})
|
||||||
|
a.append(SheetAction("Copy to Plex Playlist…", icon: "doc.on.doc") { newPlaylist(pl.tracks) { ui.playlistEdits += 1 } })
|
||||||
}
|
}
|
||||||
a.append(SheetAction("Delete Stem Playlist", icon: "trash", destructive: true) {
|
a.append(SheetAction("Delete Stem Playlist", icon: "trash", destructive: true) {
|
||||||
overlays.confirm("Delete “\(pl.title)”?", "Stem playlists are only on this device.", "Delete") { lists.delete(pl.id); if onPage { ui.pop() } }
|
overlays.confirm("Delete “\(pl.title)”?", "Stem playlists are only on this device.", "Delete") { lists.delete(pl.id); if onPage { ui.pop() } }
|
||||||
@@ -260,6 +321,29 @@ struct MediaMenu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Empty playlist; asks which server first when more than one is signed in.
|
||||||
|
func newEmptyPlaylist(onCreated: @escaping () -> Void = {}) {
|
||||||
|
let plex = g.plex
|
||||||
|
let servers = plex.playlistServers
|
||||||
|
let make: (String?) -> Void = { id in
|
||||||
|
overlays.prompt("New Playlist", "Add songs later with “Add to Playlist”.", "Create", placeholder: "Playlist name") { name in
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
_ = try await plex.createEmptyPlaylist(name, serverId: id)
|
||||||
|
overlays.hud("Created “\(name)”")
|
||||||
|
ui.playlistEdits += 1
|
||||||
|
onCreated()
|
||||||
|
} catch {
|
||||||
|
overlays.hud("Couldn't create: \(error.localizedDescription)", "exclamationmark.triangle")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if servers.count > 1 {
|
||||||
|
overlays.actions("Which Server?", servers.map { s in SheetAction(s.1.isEmpty ? "Server" : s.1) { make(s.0) } })
|
||||||
|
} else { make(servers.first?.0) }
|
||||||
|
}
|
||||||
|
|
||||||
func newPlaylist(_ tracks: [Track], onCreated: @escaping () -> Void = {}) {
|
func newPlaylist(_ tracks: [Track], onCreated: @escaping () -> Void = {}) {
|
||||||
let plex = g.plex
|
let plex = g.plex
|
||||||
overlays.prompt("New Playlist", "Name it; you can add more songs later.", "Create", placeholder: "Playlist name") { name in
|
overlays.prompt("New Playlist", "Name it; you can add more songs later.", "Create", placeholder: "Playlist name") { name in
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ final class Overlays {
|
|||||||
/// Set while the Photos picker is up; gets the picked image's data.
|
/// Set while the Photos picker is up; gets the picked image's data.
|
||||||
var photoPick: ((Data) -> Void)?
|
var photoPick: ((Data) -> Void)?
|
||||||
var photoShown = false
|
var photoShown = false
|
||||||
|
/// A picked cover waiting in the cropper.
|
||||||
|
var crop: Crop?
|
||||||
|
struct Crop: Identifiable { let id = UUID(); var image: UIImage; var run: (Data) -> Void }
|
||||||
/// 1 while the Now Playing sheet is up, so its host shows overlays instead of the root's.
|
/// 1 while the Now Playing sheet is up, so its host shows overlays instead of the root's.
|
||||||
var level = 0
|
var level = 0
|
||||||
|
|
||||||
@@ -95,7 +98,7 @@ struct OverlayHost: ViewModifier {
|
|||||||
private var mine: Bool { overlays.level == level }
|
private var mine: Bool { overlays.level == level }
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
content
|
content.modifier(CropHost(overlays: overlays, mine: mine))
|
||||||
.overlay {
|
.overlay {
|
||||||
if mine, let h = overlays.hud {
|
if mine, let h = overlays.hud {
|
||||||
HudView(hud: h).transition(.opacity.combined(with: .scale(scale: 0.9))).allowsHitTesting(false)
|
HudView(hud: h).transition(.opacity.combined(with: .scale(scale: 0.9))).allowsHitTesting(false)
|
||||||
@@ -132,8 +135,9 @@ struct OverlayHost: ViewModifier {
|
|||||||
photo = nil
|
photo = nil
|
||||||
overlays.photoPick = nil
|
overlays.photoPick = nil
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
if let data = try? await item.loadTransferable(type: Data.self) { run(data) }
|
if let data = try? await item.loadTransferable(type: Data.self), let img = UIImage(data: data) {
|
||||||
else { overlays.hud("Couldn't load that photo", "exclamationmark.triangle") }
|
overlays.crop = Overlays.Crop(image: img, run: run)
|
||||||
|
} else { overlays.hud("Couldn't load that photo", "exclamationmark.triangle") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(item: Binding(get: { mine ? overlays.addToPlaylist : nil }, set: { overlays.addToPlaylist = $0 })) { r in
|
.sheet(item: Binding(get: { mine ? overlays.addToPlaylist : nil }, set: { overlays.addToPlaylist = $0 })) { r in
|
||||||
@@ -146,6 +150,20 @@ struct OverlayHost: ViewModifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The cover cropper, split out to keep OverlayHost's chain small enough to type-check.
|
||||||
|
private struct CropHost: ViewModifier {
|
||||||
|
let overlays: Overlays
|
||||||
|
let mine: Bool
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
content.fullScreenCover(item: Binding(get: { mine ? overlays.crop : nil }, set: { overlays.crop = $0 })) { c in
|
||||||
|
CoverCropper(image: c.image) { data in
|
||||||
|
overlays.crop = nil
|
||||||
|
if let data { c.run(data) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private struct HudView: View {
|
private struct HudView: View {
|
||||||
let hud: Overlays.Hud
|
let hud: Overlays.Hud
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ final class Ui {
|
|||||||
/// Split only: which of the deck's pages is showing.
|
/// Split only: which of the deck's pages is showing.
|
||||||
var deckPage: DeckPage = .Stems
|
var deckPage: DeckPage = .Stems
|
||||||
let overlays: Overlays
|
let overlays: Overlays
|
||||||
|
/// Bumped when a playlist is renamed or gets a new cover, so the lists reload.
|
||||||
|
var playlistEdits = 0
|
||||||
|
|
||||||
init(overlays: Overlays) { self.overlays = overlays }
|
init(overlays: Overlays) { self.overlays = overlays }
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,36 @@ enum NpPanel { case Art, Mixer, Queue, Lyrics }
|
|||||||
/// The close drag's offset. Only DropOffset reads it, so dragging re-renders just the offset.
|
/// The close drag's offset. Only DropOffset reads it, so dragging re-renders just the offset.
|
||||||
@Observable final class DropState { var y: CGFloat = 0 }
|
@Observable final class DropState { var y: CGFloat = 0 }
|
||||||
|
|
||||||
|
/// ProMotion only runs as fast as someone asks. A plain drag asks nothing, and the 30 fps meters and
|
||||||
|
/// bars then set the pace, so the close drag crawled. This display link asks for 120 Hz while held.
|
||||||
|
@MainActor final class FrameBoost: NSObject {
|
||||||
|
static let shared = FrameBoost()
|
||||||
|
private var link: CADisplayLink?
|
||||||
|
private var stopGen = 0
|
||||||
|
|
||||||
|
func start() {
|
||||||
|
stopGen += 1
|
||||||
|
guard link == nil else { return }
|
||||||
|
let l = CADisplayLink(target: self, selector: #selector(tick))
|
||||||
|
l.preferredFrameRateRange = CAFrameRateRange(minimum: 80, maximum: 120, preferred: 120)
|
||||||
|
l.add(to: .main, forMode: .common)
|
||||||
|
link = l
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keeps the boost through the spring back or the cover's slide down.
|
||||||
|
func stop(after: Double = 0.6) {
|
||||||
|
stopGen += 1
|
||||||
|
let gen = stopGen
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + after) { [weak self] in
|
||||||
|
guard let self, gen == self.stopGen else { return }
|
||||||
|
self.link?.invalidate()
|
||||||
|
self.link = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func tick() {}
|
||||||
|
}
|
||||||
|
|
||||||
private struct DropOffset: ViewModifier {
|
private struct DropOffset: ViewModifier {
|
||||||
let state: DropState
|
let state: DropState
|
||||||
func body(content: Content) -> some View { content.offset(y: state.y) }
|
func body(content: Content) -> some View { content.offset(y: state.y) }
|
||||||
@@ -310,9 +340,12 @@ struct NowPlayingScreen: View {
|
|||||||
.onChanged { v in
|
.onChanged { v in
|
||||||
let dy = v.translation.height
|
let dy = v.translation.height
|
||||||
let top = fromTop(v, header: header)
|
let top = fromTop(v, header: header)
|
||||||
drop.y = !docked && top && dy > 0 && dy > abs(v.translation.width) ? dy : 0
|
let y = !docked && top && dy > 0 && dy > abs(v.translation.width) ? dy : 0
|
||||||
|
if y > 0 { FrameBoost.shared.start() }
|
||||||
|
if y != drop.y { drop.y = y }
|
||||||
}
|
}
|
||||||
.onEnded { v in
|
.onEnded { v in
|
||||||
|
FrameBoost.shared.stop()
|
||||||
let dy = v.translation.height
|
let dy = v.translation.height
|
||||||
let vertical = abs(dy) > abs(v.translation.width)
|
let vertical = abs(dy) > abs(v.translation.width)
|
||||||
let top = fromTop(v, header: header)
|
let top = fromTop(v, header: header)
|
||||||
@@ -1303,7 +1336,7 @@ private struct LyricsPanel: View {
|
|||||||
if g.playback.source == .Stems && g.playback.stemNames.contains("vocals") {
|
if g.playback.source == .Stems && g.playback.stemNames.contains("vocals") {
|
||||||
HStack(spacing: 12) {
|
HStack(spacing: 12) {
|
||||||
Text("Vocals").font(.subheadline.weight(.semibold)).foregroundStyle(p.label2)
|
Text("Vocals").font(.subheadline.weight(.semibold)).foregroundStyle(p.label2)
|
||||||
Picker("Vocals", selection: Binding(get: { g.playback.karaokeVocals }, set: { g.playback.setKaraokeVocals($0) })) {
|
Picker("Vocals", selection: Binding(get: { g.playback.karaokeVocals }, set: { g.playback.setKaraokeVocals($0, engage: true) })) {
|
||||||
ForEach(KaraokeVocals.allCases, id: \.self) { Text(String(describing: $0)).tag($0) }
|
ForEach(KaraokeVocals.allCases, id: \.self) { Text(String(describing: $0)).tag($0) }
|
||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
.pickerStyle(.segmented)
|
||||||
@@ -1313,7 +1346,7 @@ private struct LyricsPanel: View {
|
|||||||
let db = g.settings.karaokeSoftDb
|
let db = g.settings.karaokeSoftDb
|
||||||
HStack(spacing: 12) {
|
HStack(spacing: 12) {
|
||||||
Text("Softness").font(.subheadline.weight(.semibold)).foregroundStyle(p.label2)
|
Text("Softness").font(.subheadline.weight(.semibold)).foregroundStyle(p.label2)
|
||||||
Slider(value: Binding(get: { Double(db) }, set: { g.playback.setKaraokeSoftDb(Int($0.rounded())) }), in: -30...(-3), step: 1)
|
Slider(value: Binding(get: { Double(db) }, set: { g.playback.setKaraokeSoftDb(Int($0.rounded()), engage: true) }), in: -30...(-3), step: 1)
|
||||||
Text("\(db) dB").font(.caption).monospacedDigit().foregroundStyle(p.label2).frame(width: 46, alignment: .trailing)
|
Text("\(db) dB").font(.caption).monospacedDigit().foregroundStyle(p.label2).frame(width: 46, alignment: .trailing)
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 28).padding(.top, 8)
|
.padding(.horizontal, 28).padding(.top, 8)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ struct PlaylistsScreen: View {
|
|||||||
@State private var reload = 0
|
@State private var reload = 0
|
||||||
@AppStorage("playlistKind") private var kind = PlaylistKind.Plex
|
@AppStorage("playlistKind") private var kind = PlaylistKind.Plex
|
||||||
private let sort = SortState("playlists", PLAYLIST_SORTS)
|
private let sort = SortState("playlists", PLAYLIST_SORTS)
|
||||||
|
private let stemSort = SortState("stemPlaylists", STEM_PLAYLIST_SORTS)
|
||||||
|
@State private var shuffleSeed = 0
|
||||||
private var g: AppGraph { .shared }
|
private var g: AppGraph { .shared }
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -31,7 +33,7 @@ struct PlaylistsScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let stems = g.stemPlaylists.lists
|
let stems = g.stemPlaylists.lists.sorted(stemSort, seed: shuffleSeed)
|
||||||
if stems.isEmpty {
|
if stems.isEmpty {
|
||||||
EmptyState(icon: "slider.horizontal.3", title: "No Stem Playlists",
|
EmptyState(icon: "slider.horizontal.3", title: "No Stem Playlists",
|
||||||
message: "Each song plays with its own mix, like an instrumental or a cappella. Hold any song and choose “Add to Stem Playlist”, or copy a Plex playlist with +.")
|
message: "Each song plays with its own mix, like an instrumental or a cappella. Hold any song and choose “Add to Stem Playlist”, or copy a Plex playlist with +.")
|
||||||
@@ -42,30 +44,29 @@ struct PlaylistsScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
if kind == .Plex { ToolbarItem(placement: .topBarTrailing) { SortMenu(sort: sort) } }
|
ToolbarItem(placement: .topBarTrailing) { SortMenu(sort: kind == .Plex ? sort : stemSort) }
|
||||||
ToolbarItem(placement: .topBarTrailing) {
|
ToolbarItem(placement: .topBarTrailing) {
|
||||||
Button { kind == .Plex ? newPlaylist() : newStemPlaylist() } label: { Image(systemName: "plus") }
|
Button { kind == .Plex ? newPlaylist() : newStemPlaylist() } label: { Image(systemName: "plus") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.task(id: "\(g.settings.libraryKey)|\(sort.token)|\(reload)") {
|
.onChange(of: stemSort.token) { shuffleSeed += 1 }
|
||||||
|
.task(id: "\(g.settings.libraryKey)|\(sort.token)|\(reload)|\(ui.playlistEdits)") {
|
||||||
// /playlists may not take sort=random, so Random shuffles here.
|
// /playlists may not take sort=random, so Random shuffles here.
|
||||||
let random = sort.option.random
|
let random = sort.option.random
|
||||||
await LoadState.load($lists) { try await random ? g.plex.playlists().shuffled() : g.plex.playlists(sort: sort.param) }
|
await LoadState.load($lists) { try await random ? g.plex.playlists().shuffled() : g.plex.playlists(sort: sort.param) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Plex can't hold an empty playlist, so new ones start from songs you have.
|
|
||||||
private func newPlaylist() {
|
private func newPlaylist() {
|
||||||
let queue = g.playback.queue
|
let queue = g.playback.queue
|
||||||
var acts: [SheetAction] = []
|
var acts: [SheetAction] = [SheetAction("Empty Playlist…", icon: "plus") { ui.menu.newEmptyPlaylist { reload += 1 } }]
|
||||||
if !queue.isEmpty {
|
if !queue.isEmpty {
|
||||||
acts.append(SheetAction("New Playlist from Queue (\(queue.count))") { ui.menu.newPlaylist(queue.map(\.track)) { reload += 1 } })
|
acts.append(SheetAction("New Playlist from Queue (\(queue.count))") { ui.menu.newPlaylist(queue.map(\.track)) { reload += 1 } })
|
||||||
}
|
}
|
||||||
if let now = g.playback.current?.track {
|
if let now = g.playback.current?.track {
|
||||||
acts.append(SheetAction("New Playlist with “\(now.title)”") { ui.menu.newPlaylist([now]) { reload += 1 } })
|
acts.append(SheetAction("New Playlist with “\(now.title)”") { ui.menu.newPlaylist([now]) { reload += 1 } })
|
||||||
}
|
}
|
||||||
if acts.isEmpty { ui.overlays.hud("Play something first, or use “Add to Playlist” on any song.", "info.circle") }
|
ui.overlays.actions("New Playlist", acts)
|
||||||
else { ui.overlays.actions("New Playlist", acts) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func newStemPlaylist() {
|
private func newStemPlaylist() {
|
||||||
@@ -142,7 +143,7 @@ struct StemPlaylistScreen: View {
|
|||||||
.navigationTitle(pl.title)
|
.navigationTitle(pl.title)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
} else {
|
} else {
|
||||||
Page(title: pl.title, large: false) {
|
Page(title: pl.title, large: false, pullUp: BAR_PULL) {
|
||||||
header(pl)
|
header(pl)
|
||||||
if pl.items.isEmpty {
|
if pl.items.isEmpty {
|
||||||
EmptyState(icon: "slider.horizontal.3", title: "No Songs",
|
EmptyState(icon: "slider.horizontal.3", title: "No Songs",
|
||||||
@@ -159,12 +160,11 @@ struct StemPlaylistScreen: View {
|
|||||||
}
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||||
if !editing { MoreMenu(items: moreItems(pl)) }
|
|
||||||
if editing { Button("Done") { g.stemPlaylists.setItems(pl.id, items); editing = false }.bold() }
|
if editing { Button("Done") { g.stemPlaylists.setItems(pl.id, items); editing = false }.bold() }
|
||||||
else if !pl.items.isEmpty { Button("Edit") { items = pl.items; editing = true } }
|
else { MoreMenu(items: moreItems(pl)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.modifier(SplitHidesTitle())
|
.modifier(SplitHidesTitle(bare: !editing))
|
||||||
}
|
}
|
||||||
|
|
||||||
private func header(_ pl: StemPlaylist) -> some View {
|
private func header(_ pl: StemPlaylist) -> some View {
|
||||||
@@ -179,18 +179,40 @@ struct StemPlaylistScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
.padding(.top, 8).padding(.bottom, 16)
|
.padding(.bottom, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func moreItems(_ pl: StemPlaylist) -> [SheetAction] {
|
private func moreItems(_ pl: StemPlaylist) -> [SheetAction] {
|
||||||
let lists = g.stemPlaylists
|
let edit = pl.items.isEmpty ? [] : [SheetAction("Edit Songs", icon: "list.bullet") { items = pl.items; editing = true }]
|
||||||
let rename = SheetAction("Rename…", icon: "pencil") {
|
return ui.menu.stemPlaylist(pl, extra: edit, onPage: true)
|
||||||
ui.overlays.prompt("Rename Stem Playlist", nil, initial: pl.title, "Save") { lists.rename(pl.id, $0) }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stem playlists live on the device, so they sort here.
|
||||||
|
let STEM_PLAYLIST_SORTS = [
|
||||||
|
SortOption(title: "Title", key: "title", up: "A to Z", down: "Z to A"),
|
||||||
|
SortOption(title: "Date Added", key: "created", desc: true, up: "Oldest First", down: "Newest First"),
|
||||||
|
SortOption(title: "Last Updated", key: "updated", desc: true, up: "Oldest First", down: "Newest First"),
|
||||||
|
SortOption(title: "Songs", key: "count", desc: true, up: "Fewest First", down: "Most First"),
|
||||||
|
SortOption(title: "Duration", key: "duration", desc: true, up: "Shortest First", down: "Longest First"),
|
||||||
|
SortOption(title: "Random", key: "random", up: "Shuffled", down: "Shuffled"),
|
||||||
|
]
|
||||||
|
|
||||||
|
extension [StemPlaylist] {
|
||||||
|
func sorted(_ sort: SortState, seed: Int) -> [StemPlaylist] {
|
||||||
|
let o = sort.option
|
||||||
|
if o.random {
|
||||||
|
return map { ($0, ($0.id + "\(seed)").hashValue) }.sorted { $0.1 < $1.1 }.map(\.0)
|
||||||
}
|
}
|
||||||
let mixAll = SheetAction("Set Mix for All Songs…", icon: "slider.horizontal.3") {
|
let asc: [StemPlaylist]
|
||||||
ui.menu.chooseMix(pl.tracks) { m in lists.setItems(pl.id, pl.items.map { var it = $0; it.mix = MixPresets.normalized(m); return it }) }
|
switch o.key {
|
||||||
|
case "created": asc = sorted { $0.created < $1.created }
|
||||||
|
case "updated": asc = sorted { $0.updated < $1.updated }
|
||||||
|
case "count": asc = sorted { $0.items.count < $1.items.count }
|
||||||
|
case "duration": asc = sorted { $0.durationMs < $1.durationMs }
|
||||||
|
default: asc = sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending }
|
||||||
}
|
}
|
||||||
return ui.menu.stemPlaylist(pl, extra: pl.items.isEmpty ? [rename] : [rename, mixAll], onPage: true)
|
return sort.descending ? asc.reversed() : asc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,6 +243,7 @@ struct PlaylistScreen: View {
|
|||||||
@State private var tracks: LoadState<[Track]> = .loading
|
@State private var tracks: LoadState<[Track]> = .loading
|
||||||
@State private var reload = 0
|
@State private var reload = 0
|
||||||
@State private var title: String
|
@State private var title: String
|
||||||
|
@State private var thumb: String?
|
||||||
@State private var editing = false
|
@State private var editing = false
|
||||||
@State private var items: [Track] = []
|
@State private var items: [Track] = []
|
||||||
@State private var removed: [Track] = []
|
@State private var removed: [Track] = []
|
||||||
@@ -230,6 +253,7 @@ struct PlaylistScreen: View {
|
|||||||
init(playlist: Playlist) {
|
init(playlist: Playlist) {
|
||||||
self.playlist = playlist
|
self.playlist = playlist
|
||||||
_title = State(initialValue: playlist.title)
|
_title = State(initialValue: playlist.title)
|
||||||
|
_thumb = State(initialValue: playlist.thumb)
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -255,7 +279,7 @@ struct PlaylistScreen: View {
|
|||||||
.navigationTitle(title)
|
.navigationTitle(title)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
} else {
|
} else {
|
||||||
Page(title: title, large: false) {
|
Page(title: title, large: false, pullUp: BAR_PULL) {
|
||||||
header(list)
|
header(list)
|
||||||
Loaded(state: tracks, retry: { reload += 1 }) { list in
|
Loaded(state: tracks, retry: { reload += 1 }) { list in
|
||||||
ForEach(Array(list.enumerated()), id: \.element.id) { i, t in
|
ForEach(Array(list.enumerated()), id: \.element.id) { i, t in
|
||||||
@@ -268,15 +292,12 @@ struct PlaylistScreen: View {
|
|||||||
}
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||||
if !editing { MoreMenu(items: moreItems(list)) }
|
if saving { ProgressView() }
|
||||||
if !playlist.smart && !list.isEmpty {
|
else if editing { Button("Done") { commit(list) }.bold() }
|
||||||
if saving { ProgressView() }
|
else { MoreMenu(items: moreItems(list)) }
|
||||||
else if editing { Button("Done") { commit(list) }.bold() }
|
|
||||||
else { Button("Edit") { items = list; removed = []; editing = true } }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.modifier(SplitHidesTitle())
|
.modifier(SplitHidesTitle(bare: !editing))
|
||||||
.task(id: reload) {
|
.task(id: reload) {
|
||||||
await LoadState.load($tracks) { try await g.plex.playlistTracks(playlist.ratingKey) }
|
await LoadState.load($tracks) { try await g.plex.playlistTracks(playlist.ratingKey) }
|
||||||
}
|
}
|
||||||
@@ -284,7 +305,7 @@ struct PlaylistScreen: View {
|
|||||||
|
|
||||||
private func header(_ list: [Track]) -> some View {
|
private func header(_ list: [Track]) -> some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
Artwork(thumb: playlist.thumb, size: 230, corner: 10, placeholder: "music.note.list")
|
Artwork(thumb: thumb, size: 230, corner: 10, placeholder: "music.note.list")
|
||||||
Text(title).font(.title2.bold()).foregroundStyle(p.label).multilineTextAlignment(.center).lineLimit(2)
|
Text(title).font(.title2.bold()).foregroundStyle(p.label).multilineTextAlignment(.center).lineLimit(2)
|
||||||
.padding(.horizontal, 32).padding(.top, 14)
|
.padding(.horizontal, 32).padding(.top, 14)
|
||||||
if !list.isEmpty {
|
if !list.isEmpty {
|
||||||
@@ -295,7 +316,7 @@ struct PlaylistScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
.padding(.top, 8).padding(.bottom, 16)
|
.padding(.bottom, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func removeAction(_ t: Track) -> [SheetAction] {
|
private func removeAction(_ t: Track) -> [SheetAction] {
|
||||||
@@ -309,25 +330,13 @@ struct PlaylistScreen: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func moreItems(_ list: [Track]) -> [SheetAction] {
|
private func moreItems(_ list: [Track]) -> [SheetAction] {
|
||||||
var extra: [SheetAction] = []
|
let extra = playlist.smart || list.isEmpty ? [] :
|
||||||
let plex = g.plex
|
[SheetAction("Edit Songs", icon: "list.bullet") { items = list; removed = []; editing = true }]
|
||||||
let key = playlist.ratingKey
|
|
||||||
if !playlist.smart {
|
|
||||||
extra.append(SheetAction("Rename…", icon: "pencil") {
|
|
||||||
ui.overlays.prompt("Rename Playlist", nil, initial: title, "Save") { name in
|
|
||||||
Task { if (try? await plex.renamePlaylist(key, title: name)) != nil { title = name } }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
extra.append(SheetAction("Delete Playlist", icon: "trash", destructive: true) {
|
|
||||||
ui.overlays.confirm("Delete “\(title)”?", "This removes it from Plex for every app.", "Delete") {
|
|
||||||
Task { if (try? await plex.deletePlaylist(key)) != nil { ui.pop() } }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
var pl = playlist
|
var pl = playlist
|
||||||
pl.title = title
|
pl.title = title
|
||||||
|
pl.thumb = thumb
|
||||||
pl.trackCount = list.count
|
pl.trackCount = list.count
|
||||||
return ui.menu.playlist(pl, extra: extra)
|
return ui.menu.playlist(pl, extra: extra, changed: { title = $0.title; thumb = $0.thumb }, deleted: { ui.pop() })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends removals, then replays the new order as "move after" calls against a simulated server list.
|
/// Sends removals, then replays the new order as "move after" calls against a simulated server list.
|
||||||
@@ -417,11 +426,16 @@ struct SearchScreen: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Split at the Duo's hinge the pane's own header already names the playlist, so the bar drops the title.
|
/// Split at the Duo's hinge the pane's own header already names the playlist, so the bar drops the title.
|
||||||
|
/// How far a playlist page's header rides up into the empty nav bar, between back and •••.
|
||||||
|
private let BAR_PULL: CGFloat = 40
|
||||||
|
|
||||||
|
/// Hides the bar title in split view, and while [bare] (the header already shows it).
|
||||||
private struct SplitHidesTitle: ViewModifier {
|
private struct SplitHidesTitle: ViewModifier {
|
||||||
|
var bare = false
|
||||||
@Environment(Ui.self) private var ui
|
@Environment(Ui.self) private var ui
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
content.toolbar {
|
content.toolbar {
|
||||||
if ui.split { ToolbarItem(placement: .principal) { Color.clear.frame(width: 1, height: 1) } }
|
if ui.split || bare { ToolbarItem(placement: .principal) { Color.clear.frame(width: 1, height: 1) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ settings:
|
|||||||
# iOS needs a plain number for the bundle version; the label is what the app and releases show.
|
# iOS needs a plain number for the bundle version; the label is what the app and releases show.
|
||||||
MARKETING_VERSION: "0.10.1"
|
MARKETING_VERSION: "0.10.1"
|
||||||
VERSION_LABEL: "0.10.1"
|
VERSION_LABEL: "0.10.1"
|
||||||
CURRENT_PROJECT_VERSION: "58"
|
CURRENT_PROJECT_VERSION: "66"
|
||||||
# Dev builds override these (build-ipa.sh dev) so they install next to the release app.
|
# Dev builds override these (build-ipa.sh dev) so they install next to the release app.
|
||||||
APP_ID: org.cdnutter.stemify
|
APP_ID: org.cdnutter.stemify
|
||||||
APP_NAME: Stemify
|
APP_NAME: Stemify
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ def svg(mode="color", sash=False):
|
|||||||
'<stop offset="1" stop-color="#05040A"/></radialGradient>'
|
'<stop offset="1" stop-color="#05040A"/></radialGradient>'
|
||||||
'<rect width="1024" height="1024" fill="url(#bg)"/>')
|
'<rect width="1024" height="1024" fill="url(#bg)"/>')
|
||||||
# soft colored light pooling behind the bars
|
# soft colored light pooling behind the bars
|
||||||
aura = ('<g filter="url(#aura)" opacity="0.55">'
|
aura = ('<g filter="url(#aura)" opacity="0.35">'
|
||||||
f'<circle cx="330" cy="420" r="190" fill="{hx(STEMS[0])}"/>'
|
f'<circle cx="330" cy="420" r="190" fill="{hx(STEMS[0])}"/>'
|
||||||
f'<circle cx="690" cy="400" r="200" fill="{hx(STEMS[4])}"/>'
|
f'<circle cx="690" cy="400" r="200" fill="{hx(STEMS[4])}"/>'
|
||||||
f'<circle cx="520" cy="660" r="210" fill="{hx(STEMS[2])}"/>'
|
f'<circle cx="520" cy="660" r="210" fill="{hx(STEMS[2])}"/>'
|
||||||
@@ -76,11 +76,11 @@ def svg(mode="color", sash=False):
|
|||||||
return f'''<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
|
return f'''<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">
|
||||||
<defs>{"".join(defs)}
|
<defs>{"".join(defs)}
|
||||||
<filter id="aura" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="110"/></filter>
|
<filter id="aura" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="110"/></filter>
|
||||||
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="26"/></filter>
|
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="18"/></filter>
|
||||||
<filter id="drop" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="10"/></filter>
|
<filter id="drop" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="10"/></filter>
|
||||||
</defs>
|
</defs>
|
||||||
{bg}{aura}
|
{bg}{aura}
|
||||||
<g filter="url(#glow)" opacity="{0.25 if tint else 0.7}">{"".join(glow)}</g>
|
<g filter="url(#glow)" opacity="{0.15 if tint else 0.35}">{"".join(glow)}</g>
|
||||||
<g filter="url(#drop)" opacity="0.5" transform="translate(0,14)">{"".join(g.replace('fill="#', 'fill="#000" data-c="') for g in glow)}</g>
|
<g filter="url(#drop)" opacity="0.5" transform="translate(0,14)">{"".join(g.replace('fill="#', 'fill="#000" data-c="') for g in glow)}</g>
|
||||||
<g>{"".join(bars)}</g>
|
<g>{"".join(bars)}</g>
|
||||||
<g>{"".join(shine)}</g>
|
<g>{"".join(shine)}</g>
|
||||||
|
|||||||