PulseCanvas / app · pulsecanvas.ai / scripts / OpenGLReviewRender.swift
| 1 | import AppKit |
| 2 | @preconcurrency import AVFoundation |
| 3 | import Foundation |
| 4 | |
| 5 | /// One preset per process isolates shader/translator failures during review. |
| 6 | @main struct OpenGLReviewRender { |
| 7 | @MainActor static func main() async { |
| 8 | NSApplication.shared.setActivationPolicy(.accessory) |
| 9 | do { |
| 10 | let args = CommandLine.arguments |
| 11 | guard args.count == 4, let index = Int(args[1]) else { throw ExportError("Usage: OpenGLReviewRender CATALOG_INDEX AUDIO OUTPUT") } |
| 12 | let catalogURL = URL(fileURLWithPath: "Sources/PulseCanvas/Resources/ProjectM/catalog.json") |
| 13 | let catalog = try JSONDecoder().decode([ProjectMPreset].self, from: Data(contentsOf: catalogURL)) |
| 14 | guard catalog.indices.contains(index), let scene = ProjectMPresets.shared.scene(for: catalog[index].id) else { throw ExportError("Preset is not in the bundled library") } |
| 15 | let state = RenderState() |
| 16 | state.scene = scene |
| 17 | state.chaos = 1 |
| 18 | state.speed = 1 |
| 19 | state.brightness = 1 |
| 20 | state.zoom = 1 |
| 21 | state.rotation = 0 |
| 22 | state.motionBlur = 0 |
| 23 | state.strobeEnabled = false |
| 24 | state.projectMFramesPerSecond = 30 |
| 25 | let key = "PulseCanvas.videoFormat.v1" |
| 26 | let saved = UserDefaults.standard.data(forKey: key) |
| 27 | defer { |
| 28 | if let saved { UserDefaults.standard.set(saved, forKey: key) } |
| 29 | else { UserDefaults.standard.removeObject(forKey: key) } |
| 30 | } |
| 31 | let exporter = SocialExportController() |
| 32 | exporter.aspect = .wide; exporter.resolution = 720; exporter.fps = 30 |
| 33 | let destination = URL(fileURLWithPath: args[3]) |
| 34 | await exporter.export(audioURL: URL(fileURLWithPath: args[2]), render: state, to: destination) |
| 35 | guard exporter.exportedURL == destination else { throw ExportError(exporter.status) } |
| 36 | print("Rendered \(catalog[index].title) — \(catalog[index].id)") |
| 37 | } catch { |
| 38 | fputs("REVIEW ERROR: \(error.localizedDescription)\n", stderr) |
| 39 | exit(1) |
| 40 | } |
| 41 | } |
| 42 | } |