Build on Linux: compile locally, link/sign on the iPhone; FFmpeg audio decoders; SDK stub patching

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-10-27 20:22:19 -05:00
commit 66f4e7e3ea
2 changed files with 700 additions and 48 deletions

View file

@ -1,17 +1,36 @@
import AVFoundation
/// Decoder for formats Apple doesn't handle (Ogg Vorbis/Opus, WMA, APE, WavPack, Musepack, DSD, trackers…).
/// Backed by FFmpeg when the build links it (MULBERRY_FFMPEG); otherwise nothing opens.
/// Backed by FFmpeg (Native/ffdecode.c) when the build links it (MULBERRY_FFMPEG); otherwise nothing opens.
final class FFSource: AudioSource {
static func open(_ url: URL) -> FFSource? {
#if MULBERRY_FFMPEG
return FFSource(url: url)
#else
return nil
#endif
#if MULBERRY_FFMPEG
private let d: OpaquePointer
let frames: AVAudioFramePosition
private init(_ d: OpaquePointer) {
self.d = d
frames = AVAudioFramePosition(ff_frames(d))
}
deinit { ff_close(d) }
static func open(_ url: URL) -> FFSource? {
guard let d = ff_open(url.path) else { return nil }
return FFSource(d)
}
func read(into buffer: AVAudioPCMBuffer) -> Bool {
guard let ch = buffer.floatChannelData else { return false }
let n = ff_read(d, ch[0], ch[1], Int32(buffer.frameCapacity))
buffer.frameLength = AVAudioFrameCount(max(0, n))
return n > 0
}
func seek(to frame: AVAudioFramePosition) { ff_seek(d, Int64(frame)) }
#else
static func open(_ url: URL) -> FFSource? { nil }
var frames: AVAudioFramePosition { 0 }
func read(into buffer: AVAudioPCMBuffer) -> Bool { false }
func seek(to frame: AVAudioFramePosition) {}
#endif
}

View file

@ -1,5 +1,6 @@
import SwiftUI
import PhotosUI
import _PhotosUI_SwiftUI
/// Tag editor for one or many songs (Android TagEditorActivity). Fields that differ across a selection
/// show "Keep" and are left alone unless edited.
@ -30,39 +31,9 @@ struct TagEditorView: View {
let p = theme.palette
NavigationStack {
Form {
Section {
HStack(spacing: 16) {
Group {
if let coverPreview { Image(uiImage: coverPreview).resizable().scaledToFill() }
else if cover == .some(nil) { p.cSurfaceHighest.overlay(Image(systemName: "photo.badge.minus")) }
else { CoverThumb(song: songs.first, size: 96, radius: 16) }
}
.frame(width: 96, height: 96)
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
VStack(alignment: .leading, spacing: 10) {
PhotosPicker(selection: $photo, matching: .images) { Label("Choose image", systemImage: "photo") }
Button { lookup = true } label: { Label("Search online", systemImage: "magnifyingglass") }
Button(role: .destructive) { cover = .some(nil); coverPreview = nil } label: { Label("Remove cover", systemImage: "trash") }
}
.font(.system(size: 15))
}
.listRowBackground(p.cSurfaceC)
}
coverSection
Section(songs.count == 1 ? songs[0].fileName : "\(songs.count) songs") {
ForEach($fields) { $f in
VStack(alignment: .leading, spacing: 4) {
Text(f.label).font(.system(size: 12, weight: .medium)).foregroundColor(p.cPrimary)
if f.multiline {
TextEditor(text: Binding(get: { f.value }, set: { f.value = $0; f.touched = true }))
.frame(minHeight: 120)
.scrollContentBackground(.hidden)
} else {
TextField(f.mixed && !f.touched ? "Keep (different values)" : "", text: Binding(get: { f.value }, set: { f.value = $0; f.touched = true }))
.keyboardType(["year", "track", "disc"].contains(f.id) ? .numbersAndPunctuation : .default)
}
}
.listRowBackground(p.cSurfaceC)
}
ForEach($fields) { $f in fieldRow($f) }
}
if let error {
Section { Text(error).foregroundColor(Color(rgb: p.error)) }.listRowBackground(p.cSurfaceC)
@ -101,6 +72,51 @@ struct TagEditorView: View {
}
}
private var coverSection: some View {
let p = theme.palette
return Section {
HStack(spacing: 16) {
coverImage
.frame(width: 96, height: 96)
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
VStack(alignment: .leading, spacing: 10) {
PhotosPicker(selection: $photo, matching: .images) { Label("Choose image", systemImage: "photo") }
Button { lookup = true } label: { Label("Search online", systemImage: "magnifyingglass") }
Button(role: .destructive) { cover = .some(nil); coverPreview = nil } label: { Label("Remove cover", systemImage: "trash") }
}
.font(.system(size: 15))
}
.listRowBackground(p.cSurfaceC)
}
}
@ViewBuilder private var coverImage: some View {
if let coverPreview {
Image(uiImage: coverPreview).resizable().scaledToFill()
} else if case .some(.none) = cover {
theme.palette.cSurfaceHighest.overlay(Image(systemName: "photo.badge.minus"))
} else {
CoverThumb(song: songs.first, size: 96, radius: 16)
}
}
private func fieldRow(_ f: Binding<Field>) -> some View {
let p = theme.palette
let field = f.wrappedValue
let text = Binding<String>(get: { f.wrappedValue.value }, set: { f.wrappedValue.value = $0; f.wrappedValue.touched = true })
let numeric = ["year", "track", "disc"].contains(field.id)
let hint = field.mixed && !field.touched ? "Keep (different values)" : ""
return VStack(alignment: .leading, spacing: 4) {
Text(field.label).font(.system(size: 12, weight: .medium)).foregroundColor(p.cPrimary)
if field.multiline {
TextEditor(text: text).frame(minHeight: 120).scrollContentBackground(.hidden)
} else {
TextField(hint, text: text).keyboardType(numeric ? .numbersAndPunctuation : .default)
}
}
.listRowBackground(p.cSurfaceC)
}
private func load() {
func common(_ f: (Song) -> String) -> (String, Bool) {
let vals = Set(songs.map(f))