Compare commits
2 Commits
c27c9988b7
...
024803f1d4
Author | SHA1 | Date |
---|---|---|
Christopher Arndt | 024803f1d4 | |
Christopher Arndt | cda8dc937f |
|
@ -1,5 +1,3 @@
|
||||||
## A simple amplifier LV2 plugin
|
|
||||||
|
|
||||||
import std/math
|
import std/math
|
||||||
import nymph
|
import nymph
|
||||||
|
|
||||||
|
@ -8,10 +6,12 @@ const PluginUri = "urn:nymph:examples:amp"
|
||||||
type
|
type
|
||||||
SampleBuffer = UncheckedArray[cfloat]
|
SampleBuffer = UncheckedArray[cfloat]
|
||||||
|
|
||||||
PluginPort {.pure.} = enum
|
PortIndex = enum
|
||||||
Input, Output, Gain
|
INPUT = 0,
|
||||||
|
OUTPUT = 1,
|
||||||
|
GAIN = 2
|
||||||
|
|
||||||
AmpPlugin = object
|
Amp = 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(AmpPlugin)
|
return createShared(Amp)
|
||||||
|
|
||||||
|
|
||||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||||
dataLocation: pointer) {.cdecl.} =
|
dataLocation: pointer) {.cdecl.} =
|
||||||
let amp = cast[ptr AmpPlugin](instance)
|
let amp = cast[ptr Amp](instance)
|
||||||
case cast[PluginPort](port)
|
case cast[PortIndex](port)
|
||||||
of PluginPort.Input:
|
of INPUT:
|
||||||
amp.input = cast[ptr SampleBuffer](dataLocation)
|
amp.input = cast[ptr SampleBuffer](dataLocation)
|
||||||
of PluginPort.Output:
|
of OUTPUT:
|
||||||
amp.output = cast[ptr SampleBuffer](dataLocation)
|
amp.output = cast[ptr SampleBuffer](dataLocation)
|
||||||
of PluginPort.Gain:
|
of 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 AmpPlugin](instance)
|
let amp = cast[ptr Amp](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 AmpPlugin](instance))
|
freeShared(cast[ptr Amp](instance))
|
||||||
|
|
||||||
|
|
||||||
proc extensionData(uri: cstring): pointer {.cdecl.} =
|
proc extensionData(uri: cstring): pointer {.cdecl.} =
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
|
# 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({
|
||||||
|
@ -19,8 +20,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)
|
||||||
|
@ -28,8 +29,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()
|
||||||
|
|
Loading…
Reference in New Issue