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 nymph
|
||||
|
||||
|
@ -8,10 +6,12 @@ const PluginUri = "urn:nymph:examples:amp"
|
|||
type
|
||||
SampleBuffer = UncheckedArray[cfloat]
|
||||
|
||||
PluginPort {.pure.} = enum
|
||||
Input, Output, Gain
|
||||
PortIndex = enum
|
||||
INPUT = 0,
|
||||
OUTPUT = 1,
|
||||
GAIN = 2
|
||||
|
||||
AmpPlugin = object
|
||||
Amp = object
|
||||
input: ptr SampleBuffer
|
||||
output: ptr SampleBuffer
|
||||
gain: ptr cfloat
|
||||
|
@ -24,18 +24,18 @@ template db2coeff(db: cfloat): cfloat =
|
|||
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
bundlePath: cstring; features: ptr ptr Lv2Feature):
|
||||
Lv2Handle {.cdecl.} =
|
||||
return createShared(AmpPlugin)
|
||||
return createShared(Amp)
|
||||
|
||||
|
||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||
dataLocation: pointer) {.cdecl.} =
|
||||
let amp = cast[ptr AmpPlugin](instance)
|
||||
case cast[PluginPort](port)
|
||||
of PluginPort.Input:
|
||||
let amp = cast[ptr Amp](instance)
|
||||
case cast[PortIndex](port)
|
||||
of INPUT:
|
||||
amp.input = cast[ptr SampleBuffer](dataLocation)
|
||||
of PluginPort.Output:
|
||||
of OUTPUT:
|
||||
amp.output = cast[ptr SampleBuffer](dataLocation)
|
||||
of PluginPort.Gain:
|
||||
of GAIN:
|
||||
amp.gain = cast[ptr cfloat](dataLocation)
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ proc activate(instance: Lv2Handle) {.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:
|
||||
amp.output[pos] = amp.input[pos] * db2coeff(amp.gain[])
|
||||
|
||||
|
@ -54,7 +54,7 @@ proc deactivate(instance: Lv2Handle) {.cdecl.} =
|
|||
|
||||
|
||||
proc cleanup(instance: Lv2Handle) {.cdecl.} =
|
||||
freeShared(cast[ptr AmpPlugin](instance))
|
||||
freeShared(cast[ptr Amp](instance))
|
||||
|
||||
|
||||
proc extensionData(uri: cstring): pointer {.cdecl.} =
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
# Package
|
||||
import std/strformat
|
||||
|
||||
# Package definition
|
||||
|
||||
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"
|
||||
|
||||
|
||||
# Custom tasks
|
||||
|
||||
const examples = to_table({
|
||||
|
@ -19,8 +20,8 @@ const examples = to_table({
|
|||
})
|
||||
|
||||
|
||||
proc parseArgs(): tuple[options: seq[string], args: seq[string]] =
|
||||
## Parse task specific command line arguments into option switches and positional arguments
|
||||
proc parseArgs(): tuple[options: seq[string], args: seq[string]] =
|
||||
for arg in commandLineParams:
|
||||
if arg[0] == '-': # -d:foo or --define:foo
|
||||
result.options.add(arg)
|
||||
|
@ -28,8 +29,8 @@ proc parseArgs(): tuple[options: seq[string], args: seq[string]] =
|
|||
result.args.add(arg)
|
||||
|
||||
|
||||
proc showArgs() =
|
||||
## Show task environment (for debugging when writing nimble tasks)
|
||||
proc showArgs() =
|
||||
echo "Command: ", getCommand()
|
||||
echo "ProjectName: ", projectName()
|
||||
echo "ProjectDir: ", projectDir()
|
||||
|
|
Loading…
Reference in New Issue