2024-04-22 18:35:35 +02:00
|
|
|
import std/os except commandLineParams
|
2024-04-20 02:50:10 +02:00
|
|
|
import std/strformat
|
|
|
|
|
|
|
|
# Package definition
|
2024-04-19 12:07:48 +02:00
|
|
|
|
|
|
|
version = "0.1.0"
|
|
|
|
author = "Christopher Arndt"
|
|
|
|
description = "A Nim library for writing audio and MIDI plugins conforming to the LV2 standard"
|
|
|
|
license = "MIT"
|
|
|
|
srcDir = "src"
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
|
|
|
|
requires "nim >= 2.0"
|
2024-04-20 02:50:10 +02:00
|
|
|
|
|
|
|
# Custom tasks
|
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
type Example = tuple
|
|
|
|
name: string
|
|
|
|
uri: string
|
|
|
|
source: string
|
|
|
|
bundle: string
|
|
|
|
dll: string
|
|
|
|
|
|
|
|
|
2024-04-20 02:50:10 +02:00
|
|
|
const examples = to_table({
|
|
|
|
"amp": "urn:nymph:examples:amp"
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
proc parseArgs(): tuple[options: seq[string], args: seq[string]] =
|
|
|
|
## Parse task specific command line arguments into option switches and positional arguments
|
|
|
|
for arg in commandLineParams:
|
|
|
|
if arg[0] == '-': # -d:foo or --define:foo
|
|
|
|
result.options.add(arg)
|
|
|
|
else:
|
|
|
|
result.args.add(arg)
|
|
|
|
|
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
proc getExample(task_name: string): Example =
|
|
|
|
let (_, args) = parseArgs()
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
if args.len == 0:
|
|
|
|
quit(&"Usage: nimble {task_name} <example name>")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
result.name = changeFileExt(args[^1], "")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
let examplesDir = thisDir() / "examples"
|
|
|
|
result.source = examplesDir / changeFileExt(result.name, "nim")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
if not fileExists(result.source):
|
|
|
|
quit(&"Example '{result.name}' not found.")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
result.uri = examples.getOrDefault(result.name)
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
if result.uri == "":
|
|
|
|
quit(&"Plugin URI for example '{result.name}' not set.")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
result.bundle = examplesDir / changeFileExt(result.name, "lv2")
|
|
|
|
result.dll = result.bundle / toDll(result.name)
|
2024-04-20 02:50:10 +02:00
|
|
|
|
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
task build_ex, "Build given example plugin":
|
|
|
|
let ex = getExample("build_ex")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
switch("app", "lib")
|
|
|
|
switch("noMain", "on")
|
|
|
|
switch("mm", "arc")
|
|
|
|
switch("out", ex.dll)
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
when not defined(release) and not defined(debug):
|
|
|
|
echo &"Compiling plugin {ex.name} in release mode."
|
|
|
|
switch("define", "release")
|
|
|
|
switch("opt", "speed")
|
|
|
|
switch("define", "lto")
|
|
|
|
switch("define", "strip")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
setCommand("compile", ex.source)
|
2024-04-20 02:50:10 +02:00
|
|
|
|
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
task lv2lint, "Run lv2lint check on given example plugin":
|
|
|
|
let ex = getExample("lv2lint")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
if fileExists(ex.dll):
|
|
|
|
exec(&"lv2lint -s NimMain -I \"{ex.bundle}\" \"{ex.uri}\"")
|
|
|
|
else:
|
|
|
|
echo &"Example '{ex.name}' shared library not found. Use task 'build_ex' to build it."
|
2024-04-20 02:50:10 +02:00
|
|
|
|
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
task lv2bm, "Run lv2bm benchmark on given example plugin":
|
|
|
|
let ex = getExample("lv2bm")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
if ex.uri == "":
|
|
|
|
echo &"Plugin URI for example '{ex.name}' not set."
|
|
|
|
return
|
2024-04-20 02:50:10 +02:00
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
if fileExists(ex.dll):
|
2024-04-20 02:50:10 +02:00
|
|
|
let lv2_path = getEnv("LV2_PATH")
|
2024-04-22 18:35:35 +02:00
|
|
|
let tempLv2Dir = thisDir() / ".lv2"
|
2024-04-23 05:01:52 +02:00
|
|
|
let bundleLink = tempLv2Dir / changeFileExt(ex.name, "lv2")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
|
|
|
mkDir(tempLv2Dir)
|
|
|
|
rmFile(bundleLink)
|
2024-04-23 05:01:52 +02:00
|
|
|
exec(&"ln -s \"{ex.bundle}\" \"{bundleLink}\"")
|
2024-04-20 02:50:10 +02:00
|
|
|
|
|
|
|
if lv2_path == "":
|
|
|
|
putEnv("LV2_PATH", tempLv2Dir)
|
|
|
|
else:
|
|
|
|
putEnv("LV2_PATH", tempLv2Dir & ":" & lv2_path)
|
|
|
|
|
2024-04-23 05:01:52 +02:00
|
|
|
exec(&"lv2bm --full-test -i white \"{ex.uri}\"")
|
2024-04-20 02:50:10 +02:00
|
|
|
else:
|
2024-04-23 05:01:52 +02:00
|
|
|
echo &"Example '{ex.name}' shared library not found. Use task 'build_ex' to build it."
|
2024-04-20 02:50:10 +02:00
|
|
|
|