refactor: some file and object renaming

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
Christopher Arndt 2024-09-27 19:24:06 +02:00
parent 4d60684b07
commit 75f3ce03b3
10 changed files with 33 additions and 27 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ nimble.paths
*.so *.so
*.dll *.dll
/.lv2/ /.lv2/
*.code-workspace

View File

@ -19,6 +19,11 @@ type
map: ptr UridMap map: ptr UridMap
midi_urid: Urid midi_urid: Urid
MidiEvent = object
size: uint32
frames: int64
data: ptr UncheckedArray[byte]
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble; proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]): bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]):

View File

@ -3,6 +3,6 @@
<urn:nymph:examples:multimode-filter> <urn:nymph:examples:multimode-filter>
a lv2:Plugin ; a lv2:Plugin ;
lv2:binary <libmultimode_filter.so> ; lv2:binary <libmultimodefilter.so> ;
rdfs:seeAlso <multimode_filter.ttl> . rdfs:seeAlso <multimodefilter.ttl> .

View File

@ -9,8 +9,8 @@
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix units: <http://lv2plug.in/ns/extensions/units#> . @prefix units: <http://lv2plug.in/ns/extensions/units#> .
<urn:nymph:examples:multimode-filter> <urn:nymph:examples:multimodefilter>
a lv2:Plugin, lv2:AmplifierPlugin , doap:Project ; a lv2:Plugin , lv2:FilterPlugin , doap:Project ;
lv2:optionalFeature lv2:hardRTCapable , bufs:boundedBlockLength , opts:options ; lv2:optionalFeature lv2:hardRTCapable , bufs:boundedBlockLength , opts:options ;

View File

@ -5,7 +5,7 @@ import nymph
import paramsmooth import paramsmooth
import svf import svf
const PluginUri = "urn:nymph:examples:multimode-filter" const PluginUri = "urn:nymph:examples:multimodefilter"
type type
SampleBuffer = UncheckedArray[cfloat] SampleBuffer = UncheckedArray[cfloat]
@ -19,7 +19,7 @@ type
cutoff: ptr cfloat cutoff: ptr cfloat
q: ptr cfloat q: ptr cfloat
mode: ptr cfloat mode: ptr cfloat
svf: FilterSV svf: SVFilter
smoothCutoff: ParamSmooth smoothCutoff: ParamSmooth
@ -28,7 +28,7 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
Lv2Handle {.cdecl.} = Lv2Handle {.cdecl.} =
try: try:
let plug = createShared(SVFPlugin) let plug = createShared(SVFPlugin)
plug.svf = initFilterSV(fmLowPass, sampleRate) plug.svf = initSVFilter(fmLowPass, sampleRate)
plug.smoothCutoff = initParamSmooth(20.0, sampleRate) plug.smoothCutoff = initParamSmooth(20.0, sampleRate)
return cast[Lv2Handle](plug) return cast[Lv2Handle](plug)
except OutOfMemDefect: except OutOfMemDefect:

View File

@ -9,32 +9,32 @@ type
FilterMode* = enum FilterMode* = enum
fmLowPass, fmHighPass, fmBandPass, fmBandReject fmLowPass, fmHighPass, fmBandPass, fmBandReject
FilterSV* = object SVFilter* = object
mode: FilterMode mode: FilterMode
cutoff, q, lowPass, hiPass, bandPass, bandReject, a, b, maxCutoff: float cutoff, q, lowPass, hiPass, bandPass, bandReject, a, b, maxCutoff: float
sampleRate: float64 sampleRate: float64
needs_update: bool needsUpdate: bool
proc reset*(self: var FilterSV) = proc reset*(self: var SVFilter) =
self.lowPass = 0.0 self.lowPass = 0.0
self.hiPass = 0.0 self.hiPass = 0.0
self.bandPass = 0.0 self.bandPass = 0.0
self.bandReject = 0.0 self.bandReject = 0.0
proc initFilterSV*(mode: FilterMode = fmLowPass, sampleRate: float64 = 48_000.0): FilterSV = proc initSVFilter*(mode: FilterMode = fmLowPass, sampleRate: float64 = 48_000.0): SVFilter =
result.mode = mode result.mode = mode
result.sampleRate = sampleRate result.sampleRate = sampleRate
result.reset() result.reset()
result.a = 0.0 result.a = 0.0
result.b = 0.0 result.b = 0.0
result.maxCutoff = sampleRate / 6.0 result.maxCutoff = sampleRate / 6.0
result.needs_update = true result.needsUpdate = true
proc calcCoef*(self: var FilterSV) = proc calcCoef*(self: var SVFilter) =
if self.needs_update: if self.needsUpdate:
self.a = 2.0 * sin(PI * self.cutoff / self.sampleRate) self.a = 2.0 * sin(PI * self.cutoff / self.sampleRate)
if self.q > 0.0: if self.q > 0.0:
@ -42,36 +42,36 @@ proc calcCoef*(self: var FilterSV) =
else: else:
self.b = 0.0 self.b = 0.0
self.needs_update = false self.needsUpdate = false
proc setCutoff*(self: var FilterSV, cutoff: float) = proc setCutoff*(self: var SVFilter, cutoff: float) =
let fc = min(self.maxCutoff, cutoff) let fc = min(self.maxCutoff, cutoff)
if fc != self.cutoff: if fc != self.cutoff:
self.cutoff = fc self.cutoff = fc
self.needs_update = true self.needsUpdate = true
proc setQ*(self: var FilterSV, q: float) = proc setQ*(self: var SVFilter, q: float) =
if q != self.q: if q != self.q:
self.q = q self.q = q
self.needs_update = true self.needsUpdate = true
proc setMode*(self: var FilterSV, mode: FilterMode) = proc setMode*(self: var SVFilter, mode: FilterMode) =
self.mode = mode self.mode = mode
proc setSampleRate*(self: var FilterSV, sampleRate: float) = proc setSampleRate*(self: var SVFilter, sampleRate: float) =
if sampleRate != self.sampleRate: if sampleRate != self.sampleRate:
self.sampleRate = sampleRate self.sampleRate = sampleRate
self.needs_update = true self.needsUpdate = true
self.reset() self.reset()
self.calcCoef() self.calcCoef()
proc process*(self: var FilterSV, sample: float): float = proc process*(self: var SVFilter, sample: float): float =
self.lowPass += self.a * self.bandPass self.lowPass += self.a * self.bandPass
self.hiPass = sample - (self.lowPass + (self.b * self.bandPass)) self.hiPass = sample - (self.lowPass + (self.b * self.bandPass))
self.bandPass += self.a * self.hiPass self.bandPass += self.a * self.hiPass

View File

@ -25,8 +25,8 @@ type Example = tuple
const examples = to_table({ const examples = to_table({
"amp": "urn:nymph:examples:amp", "amp": "urn:nymph:examples:amp",
"multimode_filter": "urn:nymph:examples:multimode-filter",
"miditranspose": "urn:nymph:examples:miditranspose", "miditranspose": "urn:nymph:examples:miditranspose",
"multimodefilter": "urn:nymph:examples:multimode-filter",
}) })
@ -48,7 +48,7 @@ proc getExample(task_name: string): Example =
result.name = changeFileExt(args[^1], "") result.name = changeFileExt(args[^1], "")
let examplesDir = thisDir() / "examples" let examplesDir = thisDir() / "examples"
result.source = examplesDir / changeFileExt(result.name, "nim") result.source = examplesDir / result.name & "_plugin.nim"
if not fileExists(result.source): if not fileExists(result.source):
quit(&"Example '{result.name}' not found.") quit(&"Example '{result.name}' not found.")