feat: wrap LV2_Lib_Descriptor
Use lv2_lib_descriptor in amp example plugin to improve lib memory handling Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
a724f739ac
commit
3714d38241
@ -60,7 +60,7 @@ proc connectPort(instance: Lv2Handle; port: cuint;
|
|||||||
|
|
||||||
proc activate(instance: Lv2Handle) {.cdecl.} =
|
proc activate(instance: Lv2Handle) {.cdecl.} =
|
||||||
let plug = cast[ptr AmpPlugin](instance)
|
let plug = cast[ptr AmpPlugin](instance)
|
||||||
plug.log.note("nymph amp plugin activated.")
|
plug.log.note("nymph amp LV2 plugin activated.")
|
||||||
|
|
||||||
|
|
||||||
proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} =
|
proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} =
|
||||||
@ -71,12 +71,12 @@ proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} =
|
|||||||
|
|
||||||
proc deactivate(instance: Lv2Handle) {.cdecl.} =
|
proc deactivate(instance: Lv2Handle) {.cdecl.} =
|
||||||
let plug = cast[ptr AmpPlugin](instance)
|
let plug = cast[ptr AmpPlugin](instance)
|
||||||
plug.log.note("nymph amp plugin deactivated.")
|
plug.log.note("nymph amp LV2 plugin deactivated.")
|
||||||
|
|
||||||
|
|
||||||
proc cleanup(instance: Lv2Handle) {.cdecl.} =
|
proc cleanupInstance(instance: Lv2Handle) {.cdecl.} =
|
||||||
let plug = cast[ptr AmpPlugin](instance)
|
let plug = cast[ptr AmpPlugin](instance)
|
||||||
plug.log.note("De-allocating nymph amp plugin instance.")
|
plug.log.note("nymph amp LV2 plugin instance will be de-allocated.")
|
||||||
freeShared(cast[ptr AmpPlugin](instance))
|
freeShared(cast[ptr AmpPlugin](instance))
|
||||||
|
|
||||||
|
|
||||||
@ -85,26 +85,44 @@ proc extensionData(uri: cstring): pointer {.cdecl.} =
|
|||||||
|
|
||||||
|
|
||||||
proc NimMain() {.cdecl, importc.}
|
proc NimMain() {.cdecl, importc.}
|
||||||
|
proc NimDestroyGlobals() {.cdecl, importc.}
|
||||||
|
|
||||||
|
|
||||||
let descriptor = Lv2Descriptor(
|
let pluginDescriptor = Lv2Descriptor(
|
||||||
uri: cstring(PluginUri),
|
uri: cstring(PluginUri),
|
||||||
instantiate: instantiate,
|
instantiate: instantiate,
|
||||||
connectPort: connectPort,
|
connectPort: connectPort,
|
||||||
activate: activate,
|
activate: activate,
|
||||||
run: run,
|
run: run,
|
||||||
deactivate: deactivate,
|
deactivate: deactivate,
|
||||||
cleanup: cleanup,
|
cleanup: cleanupInstance,
|
||||||
extensionData: extensionData,
|
extensionData: extensionData,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
|
||||||
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
|
||||||
|
|
||||||
echo fmt"nymph am plugin descriptor #{index} requested"
|
proc cleanupLib(handle: Lv2LibHandle) {.cdecl.} =
|
||||||
|
echo "Cleaning up nymph amp library globals."
|
||||||
|
NimDestroyGlobals()
|
||||||
|
|
||||||
|
|
||||||
|
proc getPlugin(handle: Lv2Libhandle, index: cuint): ptr Lv2Descriptor {.cdecl.} =
|
||||||
if index == 0:
|
if index == 0:
|
||||||
NimMain()
|
echo &"Providing nymph amp LV2 plugin descriptor #{index} to host."
|
||||||
return addr(descriptor)
|
return addr(pluginDescriptor)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
|
||||||
|
let libDescriptor = Lv2LibDescriptor(
|
||||||
|
handle: cast[Lv2LibHandle](nil),
|
||||||
|
size: sizeof(Lv2LibDescriptor).cuint,
|
||||||
|
cleanup: cleanupLib,
|
||||||
|
getPlugin: getPlugin,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
proc lv2LibDescriptor(bundlePath: cstring, features: ptr UncheckedArray[ptr Lv2Feature]): ptr Lv2LibDescriptor {.
|
||||||
|
cdecl, dynlib, exportc: "lv2_lib_descriptor".} =
|
||||||
|
NimMain()
|
||||||
|
echo "Providing nymph amp LV2 library descriptor to host."
|
||||||
|
return addr(libDescriptor)
|
||||||
|
|||||||
@ -11,7 +11,7 @@ srcDir = "src"
|
|||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "nim >= 2.0"
|
requires "nim >= 2.2.2"
|
||||||
|
|
||||||
# Custom tasks
|
# Custom tasks
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ task lv2lint, "Run lv2lint check on given example plugin":
|
|||||||
let ex = getExample("lv2lint")
|
let ex = getExample("lv2lint")
|
||||||
|
|
||||||
if fileExists(ex.dll):
|
if fileExists(ex.dll):
|
||||||
exec(&"lv2lint -s NimMain -s NimDestroyGlobals -I \"{ex.bundle}\" \"{ex.uri}\"")
|
exec(&"lv2lint -s NimMain -s NimDestroyGlobals -s lv2_lib_descriptor -I \"{ex.bundle}\" \"{ex.uri}\"")
|
||||||
else:
|
else:
|
||||||
echo &"Example '{ex.name}' shared library not found. Use task 'build_ex' to build it."
|
echo &"Example '{ex.name}' shared library not found. Use task 'build_ex' to build it."
|
||||||
|
|
||||||
|
|||||||
@ -95,27 +95,29 @@ const
|
|||||||
type
|
type
|
||||||
Lv2Handle* = distinct pointer
|
Lv2Handle* = distinct pointer
|
||||||
|
|
||||||
type Lv2Feature* = object
|
Lv2LibHandle* = distinct pointer
|
||||||
uri*: cstring
|
|
||||||
data*: pointer
|
|
||||||
|
|
||||||
type Lv2Descriptor* = object
|
Lv2Feature* = object
|
||||||
uri*: cstring
|
uri*: cstring
|
||||||
|
data*: pointer
|
||||||
|
|
||||||
instantiate*: proc(descriptor: ptr Lv2Descriptor, sampleRate: cdouble, bundlePath: cstring,
|
Lv2Descriptor* = object
|
||||||
features: ptr UncheckedArray[ptr Lv2Feature]): Lv2Handle {.cdecl.}
|
uri*: cstring
|
||||||
|
instantiate*: proc(descriptor: ptr Lv2Descriptor, sampleRate: cdouble, bundlePath: cstring,
|
||||||
|
features: ptr UncheckedArray[ptr Lv2Feature]): Lv2Handle {.cdecl.}
|
||||||
|
connectPort*: proc(instance: Lv2Handle, port: cuint, dataLocation: pointer) {.cdecl.}
|
||||||
|
activate*: proc(instance: Lv2Handle) {.cdecl.}
|
||||||
|
run*: proc(instance: Lv2Handle, sampleCount: cuint) {.cdecl.}
|
||||||
|
deactivate*: proc(instance: Lv2Handle) {.cdecl.}
|
||||||
|
cleanup*: proc(instance: Lv2Handle) {.cdecl.}
|
||||||
|
extensionData*: proc(uri: cstring): pointer {.cdecl.}
|
||||||
|
|
||||||
connectPort*: proc(instance: Lv2Handle, port: cuint, dataLocation: pointer) {.cdecl.}
|
Lv2LibDescriptor* = object
|
||||||
|
handle*: Lv2LibHandle
|
||||||
|
size*: cuint
|
||||||
|
cleanup*: proc(handle: Lv2LibHandle) {.cdecl.}
|
||||||
|
getPlugin*: proc(handle: Lv2LibHandle, index: cuint): ptr Lv2Descriptor {.cdecl.}
|
||||||
|
|
||||||
activate*: proc(instance: Lv2Handle) {.cdecl.}
|
lv2Descriptor* = proc(index: cuint): ptr Lv2Descriptor {.cdecl.}
|
||||||
|
|
||||||
run*: proc(instance: Lv2Handle, sampleCount: cuint) {.cdecl.}
|
|
||||||
|
|
||||||
deactivate*: proc(instance: Lv2Handle) {.cdecl.}
|
|
||||||
|
|
||||||
cleanup*: proc(instance: Lv2Handle) {.cdecl.}
|
|
||||||
|
|
||||||
extensionData*: proc(uri: cstring): pointer {.cdecl.}
|
|
||||||
|
|
||||||
type lv2Descriptor* = proc(index: cuint): ptr Lv2Descriptor {.cdecl.}
|
|
||||||
|
|
||||||
|
lv2LibDescriptor* = proc(bundle_path: cstring, features: ptr UncheckedArray[ptr Lv2Feature]): LV2_Lib_Descriptor {.cdecl.}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user