Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac363ea0f7 |
No files matched your search
@@ -581,14 +581,16 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
|
||||
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
||||
@@ -88,10 +88,11 @@ final class StemPlaylists {
|
||||
/// 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.
|
||||
@discardableResult
|
||||
/// A picked photo as a JPEG no bigger than 1200 px a side.
|
||||
/// A picked photo as a JPEG no bigger than 2000 px a side. The cropper's JPEGs pass through as they are.
|
||||
static func coverJpeg(_ data: Data) -> Data? {
|
||||
guard let img = UIImage(data: data) else { return nil }
|
||||
let side: CGFloat = 1200
|
||||
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 size = CGSize(width: (img.size.width * scale).rounded(), height: (img.size.height * scale).rounded())
|
||||
let fmt = UIGraphicsImageRendererFormat.default(); fmt.scale = 1
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,9 @@ final class Overlays {
|
||||
/// Set while the Photos picker is up; gets the picked image's data.
|
||||
var photoPick: ((Data) -> Void)?
|
||||
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.
|
||||
var level = 0
|
||||
|
||||
@@ -95,7 +98,7 @@ struct OverlayHost: ViewModifier {
|
||||
private var mine: Bool { overlays.level == level }
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
content.modifier(CropHost(overlays: overlays, mine: mine))
|
||||
.overlay {
|
||||
if mine, let h = overlays.hud {
|
||||
HudView(hud: h).transition(.opacity.combined(with: .scale(scale: 0.9))).allowsHitTesting(false)
|
||||
@@ -132,8 +135,9 @@ struct OverlayHost: ViewModifier {
|
||||
photo = nil
|
||||
overlays.photoPick = nil
|
||||
Task { @MainActor in
|
||||
if let data = try? await item.loadTransferable(type: Data.self) { run(data) }
|
||||
else { overlays.hud("Couldn't load that photo", "exclamationmark.triangle") }
|
||||
if let data = try? await item.loadTransferable(type: Data.self), let img = UIImage(data: data) {
|
||||
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
|
||||
@@ -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 {
|
||||
let hud: Overlays.Hud
|
||||
var body: some View {
|
||||
|
||||
@@ -1336,7 +1336,7 @@ private struct LyricsPanel: View {
|
||||
if g.playback.source == .Stems && g.playback.stemNames.contains("vocals") {
|
||||
HStack(spacing: 12) {
|
||||
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) }
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
@@ -1346,7 +1346,7 @@ private struct LyricsPanel: View {
|
||||
let db = g.settings.karaokeSoftDb
|
||||
HStack(spacing: 12) {
|
||||
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)
|
||||
}
|
||||
.padding(.horizontal, 28).padding(.top, 8)
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ settings:
|
||||
# iOS needs a plain number for the bundle version; the label is what the app and releases show.
|
||||
MARKETING_VERSION: "0.10.1"
|
||||
VERSION_LABEL: "0.10.1"
|
||||
CURRENT_PROJECT_VERSION: "64"
|
||||
CURRENT_PROJECT_VERSION: "65"
|
||||
# Dev builds override these (build-ipa.sh dev) so they install next to the release app.
|
||||
APP_ID: org.cdnutter.stemify
|
||||
APP_NAME: Stemify
|
||||
|
||||
Reference in new issue
Block a user