Compare commits

..

2 Commits

Author SHA1 Message Date
Christopher Arndt c27c9988b7 Add stub readme and license file
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
2024-04-20 04:16:16 +02:00
Christopher Arndt a151e96233 Add nimble tasks and example 'amp' plugin
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
2024-04-20 04:16:16 +02:00
2 changed files with 17 additions and 18 deletions

View File

@ -1,3 +1,5 @@
## A simple amplifier LV2 plugin
import std/math import std/math
import nymph import nymph
@ -6,12 +8,10 @@ const PluginUri = "urn:nymph:examples:amp"
type type
SampleBuffer = UncheckedArray[cfloat] SampleBuffer = UncheckedArray[cfloat]
PortIndex = enum PluginPort {.pure.} = enum
INPUT = 0, Input, Output, Gain
OUTPUT = 1,
GAIN = 2
Amp = object AmpPlugin = object
input: ptr SampleBuffer input: ptr SampleBuffer
output: ptr SampleBuffer output: ptr SampleBuffer
gain: ptr cfloat gain: ptr cfloat
@ -24,18 +24,18 @@ template db2coeff(db: cfloat): cfloat =
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble; proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
bundlePath: cstring; features: ptr ptr Lv2Feature): bundlePath: cstring; features: ptr ptr Lv2Feature):
Lv2Handle {.cdecl.} = Lv2Handle {.cdecl.} =
return createShared(Amp) return createShared(AmpPlugin)
proc connectPort(instance: Lv2Handle; port: cuint; proc connectPort(instance: Lv2Handle; port: cuint;
dataLocation: pointer) {.cdecl.} = dataLocation: pointer) {.cdecl.} =
let amp = cast[ptr Amp](instance) let amp = cast[ptr AmpPlugin](instance)
case cast[PortIndex](port) case cast[PluginPort](port)
of INPUT: of PluginPort.Input:
amp.input = cast[ptr SampleBuffer](dataLocation) amp.input = cast[ptr SampleBuffer](dataLocation)
of OUTPUT: of PluginPort.Output:
amp.output = cast[ptr SampleBuffer](dataLocation) amp.output = cast[ptr SampleBuffer](dataLocation)
of GAIN: of PluginPort.Gain:
amp.gain = cast[ptr cfloat](dataLocation) amp.gain = cast[ptr cfloat](dataLocation)
@ -44,7 +44,7 @@ proc activate(instance: Lv2Handle) {.cdecl.} =
proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} = proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} =
let amp = cast[ptr Amp](instance) let amp = cast[ptr AmpPlugin](instance)
for pos in 0 ..< nSamples: for pos in 0 ..< nSamples:
amp.output[pos] = amp.input[pos] * db2coeff(amp.gain[]) amp.output[pos] = amp.input[pos] * db2coeff(amp.gain[])
@ -54,7 +54,7 @@ proc deactivate(instance: Lv2Handle) {.cdecl.} =
proc cleanup(instance: Lv2Handle) {.cdecl.} = proc cleanup(instance: Lv2Handle) {.cdecl.} =
freeShared(cast[ptr Amp](instance)) freeShared(cast[ptr AmpPlugin](instance))
proc extensionData(uri: cstring): pointer {.cdecl.} = proc extensionData(uri: cstring): pointer {.cdecl.} =

View File

@ -1,18 +1,17 @@
# Package
import std/strformat import std/strformat
# Package definition
version = "0.1.0" version = "0.1.0"
author = "Christopher Arndt" author = "Christopher Arndt"
description = "A Nim library for writing audio and MIDI plugins conforming to the LV2 standard" description = "A Nim library for writing audio and MIDI plugins conforming to the LV2 standard"
license = "MIT" license = "MIT"
srcDir = "src" srcDir = "src"
# Dependencies # Dependencies
requires "nim >= 2.0" requires "nim >= 2.0"
# Custom tasks # Custom tasks
const examples = to_table({ const examples = to_table({
@ -20,8 +19,8 @@ const examples = to_table({
}) })
## Parse task specific command line arguments into option switches and positional arguments
proc parseArgs(): tuple[options: seq[string], args: seq[string]] = 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: for arg in commandLineParams:
if arg[0] == '-': # -d:foo or --define:foo if arg[0] == '-': # -d:foo or --define:foo
result.options.add(arg) result.options.add(arg)
@ -29,8 +28,8 @@ proc parseArgs(): tuple[options: seq[string], args: seq[string]] =
result.args.add(arg) result.args.add(arg)
## Show task environment (for debugging when writing nimble tasks)
proc showArgs() = proc showArgs() =
## Show task environment (for debugging when writing nimble tasks)
echo "Command: ", getCommand() echo "Command: ", getCommand()
echo "ProjectName: ", projectName() echo "ProjectName: ", projectName()
echo "ProjectDir: ", projectDir() echo "ProjectDir: ", projectDir()