Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX DJ9// File : Packages/ORIXDJCore/Sources/orix-dj-bench/main.swift10// Description : Command-line companion: regenerates the schema-derived11// documentation, validates scripts, and runs the engine12// benchmarks (render cost, time stretching, analysis,13// automation timing). Prints measured values only.14// Module : orix-dj-bench15// Repository : https://git.spboucher.ai/orix-dj16// Created : 2026-11-2117// Last Modified : 2026-11-2118//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author : Simon-Pierre Boucher24// Position : Professor of Finance25// Institution : Université du Québec en Outaouais (UQO)26// Department : Département des sciences administratives27// Organization : SP Boucher28//29// Website : https://spboucher.ai30// Git : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General : info@spboucher.ai37// Professional : contact@spboucher.ai38// Direct : simon@spboucher.ai39// Research : research@spboucher.ai40// Development : dev@spboucher.ai41// Support : support@spboucher.ai42// Security/Admin : admin@spboucher.ai43// Notifications : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification : Public70// Distribution : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License : None specified (no license file in this repository)84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import Foundation92import ORIXAnalysis93import ORIXDSP94import ORIXDJEngine95import ORIXScript9697let arguments = Array(CommandLine.arguments.dropFirst())9899func usage() -> Never {100 print("""101 orix-dj-bench <command>102 docs <directory> write the generated ORIX Script reference chapters103 check <file.orixdj> compile and simulate a script, print diagnostics104 bench [seconds] measure render cost, time stretch quality, analysis speed and automation timing105 devices list audio output devices106 live [seconds] [buffer] open the default output device with the master muted and measure the real render thread107 analyze <folder> analyse every audio file of a folder (tempo, key, loudness) and print a table108 set <script.orixdj> <out.wav> <out.orixdjproject> <a> <b> <c> <d> render a four-deck scripted performance and save it as a project109 mix <a> <b> <out.wav> [preset] render a real automated transition between two files to a WAV file110 """)111 exit(2)112}113114guard let command = arguments.first else { usage() }115116switch command {117case "docs":118 guard arguments.count >= 2 else { usage() }119 let dir = URL(fileURLWithPath: arguments[1], isDirectory: true)120 for (file, content) in ReferenceGenerator.generatedChapters {121 try content.write(to: dir.appendingPathComponent(file), atomically: true, encoding: .utf8)122 print("wrote \(file) (\(content.count) characters)")123 }124case "check":125 guard arguments.count >= 2, let source = try? String(contentsOfFile: arguments[1], encoding: .utf8) else { usage() }126 let result = ScriptCompiler.compile(source)127 for d in result.diagnostics { print("\(arguments[1]):\(d)") }128 guard let program = result.program else { exit(1) }129 for automation in program.automations {130 let sim = Simulator.run(program, automation: automation.name)!131 let length = automation.requirements.lengthBeats.map { "\($0) beats" } ?? "open-ended"132 print("automation \"\(automation.name)\": decks \(automation.requirements.deckLetters), \(length), simulated \(sim.beats) beats, \(sim.actions.count) actions, state \(sim.state)")133 if let e = sim.error { print(" runtime error: \(e)"); exit(1) }134 }135case "devices":136 for d in AudioDevices.outputs() {137 print("\(d.isDefault ? "*" : " ") \(d.name) [\(d.transport)] \(d.outputChannels) ch, rates \(d.sampleRates.map { Int($0) }), now \(Int(d.currentSampleRate)) Hz, buffer \(d.bufferFrames) (\(d.bufferFrameRange.lowerBound)–\(d.bufferFrameRange.upperBound)), latency \(d.latencyFrames) frames")138 }139case "live":140 runLive(seconds: arguments.count >= 2 ? Double(arguments[1]) ?? 20 : 20, buffer: arguments.count >= 3 ? Int(arguments[2]) ?? 256 : 256)141case "analyze":142 guard arguments.count >= 2 else { usage() }143 analyzeFolder(arguments[1])144case "mix":145 guard arguments.count >= 4 else { usage() }146 renderMix(arguments[1], arguments[2], arguments[3], preset: arguments.count >= 5 ? arguments[4] : "Bass Swap")147case "set":148 guard arguments.count >= 8 else { usage() }149 renderSet(script: arguments[1], out: arguments[2], project: arguments[3], tracks: Array(arguments[4 ..< 8]))150case "bench":151 runBenchmarks(seconds: arguments.count >= 2 ? Double(arguments[1]) ?? 20 : 20)152default: usage()153}154