From 75f3ce03b3345c4c0afd3a348c60f41c8ad7c660 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Fri, 27 Sep 2024 19:24:06 +0200 Subject: [PATCH] refactor: some file and object renaming Signed-off-by: Christopher Arndt --- .gitignore | 1 + examples/amp.lv2/amp.ttl | 2 +- examples/{amp.nim => amp_plugin.nim} | 0 examples/miditranspose.lv2/miditranspose.ttl | 2 +- ...transpose.nim => miditranspose_plugin.nim} | 5 +++ .../manifest.ttl | 4 +-- .../multimodefilter.ttl} | 4 +-- ..._filter.nim => multimodefilter_plugin.nim} | 6 ++-- examples/svf.nim | 32 +++++++++---------- nymph.nimble | 4 +-- 10 files changed, 33 insertions(+), 27 deletions(-) rename examples/{amp.nim => amp_plugin.nim} (100%) rename examples/{miditranspose.nim => miditranspose_plugin.nim} (96%) rename examples/{multimode_filter.lv2 => multimodefilter.lv2}/manifest.ttl (65%) rename examples/{multimode_filter.lv2/multimode_filter.ttl => multimodefilter.lv2/multimodefilter.ttl} (96%) rename examples/{multimode_filter.nim => multimodefilter_plugin.nim} (95%) diff --git a/.gitignore b/.gitignore index fb778fb..f740294 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ nimble.paths *.so *.dll /.lv2/ +*.code-workspace diff --git a/examples/amp.lv2/amp.ttl b/examples/amp.lv2/amp.ttl index 80c984f..5399a0b 100644 --- a/examples/amp.lv2/amp.ttl +++ b/examples/amp.lv2/amp.ttl @@ -8,7 +8,7 @@ @prefix units: . - a lv2:Plugin, lv2:AmplifierPlugin , doap:Project ; + a lv2:Plugin , lv2:AmplifierPlugin , doap:Project ; lv2:optionalFeature lv2:hardRTCapable , bufs:boundedBlockLength , opts:options ; diff --git a/examples/amp.nim b/examples/amp_plugin.nim similarity index 100% rename from examples/amp.nim rename to examples/amp_plugin.nim diff --git a/examples/miditranspose.lv2/miditranspose.ttl b/examples/miditranspose.lv2/miditranspose.ttl index 24017ab..e4c01c5 100644 --- a/examples/miditranspose.lv2/miditranspose.ttl +++ b/examples/miditranspose.lv2/miditranspose.ttl @@ -12,7 +12,7 @@ @prefix urid: . - a lv2:Plugin, lv2:MIDIPlugin , doap:Project ; + a lv2:Plugin , lv2:MIDIPlugin , doap:Project ; lv2:optionalFeature lv2:hardRTCapable , bufs:boundedBlockLength , opts:options ; diff --git a/examples/miditranspose.nim b/examples/miditranspose_plugin.nim similarity index 96% rename from examples/miditranspose.nim rename to examples/miditranspose_plugin.nim index 866621c..a8c8c4a 100644 --- a/examples/miditranspose.nim +++ b/examples/miditranspose_plugin.nim @@ -19,6 +19,11 @@ type map: ptr UridMap midi_urid: Urid + MidiEvent = object + size: uint32 + frames: int64 + data: ptr UncheckedArray[byte] + proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble; bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]): diff --git a/examples/multimode_filter.lv2/manifest.ttl b/examples/multimodefilter.lv2/manifest.ttl similarity index 65% rename from examples/multimode_filter.lv2/manifest.ttl rename to examples/multimodefilter.lv2/manifest.ttl index 9e2afd9..939e9ec 100644 --- a/examples/multimode_filter.lv2/manifest.ttl +++ b/examples/multimodefilter.lv2/manifest.ttl @@ -3,6 +3,6 @@ a lv2:Plugin ; - lv2:binary ; - rdfs:seeAlso . + lv2:binary ; + rdfs:seeAlso . diff --git a/examples/multimode_filter.lv2/multimode_filter.ttl b/examples/multimodefilter.lv2/multimodefilter.ttl similarity index 96% rename from examples/multimode_filter.lv2/multimode_filter.ttl rename to examples/multimodefilter.lv2/multimodefilter.ttl index 45ad768..01bc3e1 100644 --- a/examples/multimode_filter.lv2/multimode_filter.ttl +++ b/examples/multimodefilter.lv2/multimodefilter.ttl @@ -9,8 +9,8 @@ @prefix rdfs: . @prefix units: . - - a lv2:Plugin, lv2:AmplifierPlugin , doap:Project ; + + a lv2:Plugin , lv2:FilterPlugin , doap:Project ; lv2:optionalFeature lv2:hardRTCapable , bufs:boundedBlockLength , opts:options ; diff --git a/examples/multimode_filter.nim b/examples/multimodefilter_plugin.nim similarity index 95% rename from examples/multimode_filter.nim rename to examples/multimodefilter_plugin.nim index 4ee698d..53f6ce9 100644 --- a/examples/multimode_filter.nim +++ b/examples/multimodefilter_plugin.nim @@ -5,7 +5,7 @@ import nymph import paramsmooth import svf -const PluginUri = "urn:nymph:examples:multimode-filter" +const PluginUri = "urn:nymph:examples:multimodefilter" type SampleBuffer = UncheckedArray[cfloat] @@ -19,7 +19,7 @@ type cutoff: ptr cfloat q: ptr cfloat mode: ptr cfloat - svf: FilterSV + svf: SVFilter smoothCutoff: ParamSmooth @@ -28,7 +28,7 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble; Lv2Handle {.cdecl.} = try: let plug = createShared(SVFPlugin) - plug.svf = initFilterSV(fmLowPass, sampleRate) + plug.svf = initSVFilter(fmLowPass, sampleRate) plug.smoothCutoff = initParamSmooth(20.0, sampleRate) return cast[Lv2Handle](plug) except OutOfMemDefect: diff --git a/examples/svf.nim b/examples/svf.nim index 095c7bf..47a0ad5 100644 --- a/examples/svf.nim +++ b/examples/svf.nim @@ -9,32 +9,32 @@ type FilterMode* = enum fmLowPass, fmHighPass, fmBandPass, fmBandReject - FilterSV* = object + SVFilter* = object mode: FilterMode cutoff, q, lowPass, hiPass, bandPass, bandReject, a, b, maxCutoff: float sampleRate: float64 - needs_update: bool + needsUpdate: bool -proc reset*(self: var FilterSV) = +proc reset*(self: var SVFilter) = self.lowPass = 0.0 self.hiPass = 0.0 self.bandPass = 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.sampleRate = sampleRate result.reset() result.a = 0.0 result.b = 0.0 result.maxCutoff = sampleRate / 6.0 - result.needs_update = true + result.needsUpdate = true -proc calcCoef*(self: var FilterSV) = - if self.needs_update: +proc calcCoef*(self: var SVFilter) = + if self.needsUpdate: self.a = 2.0 * sin(PI * self.cutoff / self.sampleRate) if self.q > 0.0: @@ -42,36 +42,36 @@ proc calcCoef*(self: var FilterSV) = else: 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) if fc != self.cutoff: 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: 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 -proc setSampleRate*(self: var FilterSV, sampleRate: float) = +proc setSampleRate*(self: var SVFilter, sampleRate: float) = if sampleRate != self.sampleRate: self.sampleRate = sampleRate - self.needs_update = true + self.needsUpdate = true self.reset() 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.hiPass = sample - (self.lowPass + (self.b * self.bandPass)) self.bandPass += self.a * self.hiPass diff --git a/nymph.nimble b/nymph.nimble index df46a29..5e0a27c 100644 --- a/nymph.nimble +++ b/nymph.nimble @@ -25,8 +25,8 @@ type Example = tuple const examples = to_table({ "amp": "urn:nymph:examples:amp", - "multimode_filter": "urn:nymph:examples:multimode-filter", "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], "") let examplesDir = thisDir() / "examples" - result.source = examplesDir / changeFileExt(result.name, "nim") + result.source = examplesDir / result.name & "_plugin.nim" if not fileExists(result.source): quit(&"Example '{result.name}' not found.")