fix: more pointer type safety in example plugins
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
795a40258a
commit
a724f739ac
@ -33,7 +33,7 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
|
||||
if plug.map.isNil:
|
||||
freeShared(plug)
|
||||
return nil
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
let logPtr = cast[ptr Log](lv2FeaturesData(features, lv2LogLog))
|
||||
|
||||
@ -43,7 +43,7 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
plug.log.note("nymph amp LV2 plugin instance created.")
|
||||
return cast[Lv2Handle](plug)
|
||||
except OutOfMemDefect:
|
||||
return nil
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
|
||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||
|
||||
@ -21,12 +21,12 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]):
|
||||
Lv2Handle {.cdecl.} =
|
||||
try:
|
||||
let plug = cast[ptr FaustLPFPlugin](createShared(FaustLPFPlugin))
|
||||
let plug: ptr FaustLPFPlugin = createShared(FaustLPFPlugin)
|
||||
plug.flt = newfaustlpf()
|
||||
initfaustlpf(plug.flt, sampleRate.cint)
|
||||
return cast[Lv2Handle](plug)
|
||||
except OutOfMemDefect:
|
||||
return nil
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
|
||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||
@ -73,7 +73,7 @@ let descriptor = Lv2Descriptor(
|
||||
)
|
||||
|
||||
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
||||
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
||||
cdecl, dynlib, exportc: "lv2_descriptor".} =
|
||||
if index == 0:
|
||||
NimMain()
|
||||
return addr(descriptor)
|
||||
|
||||
@ -28,16 +28,19 @@ type
|
||||
proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]):
|
||||
Lv2Handle {.cdecl.} =
|
||||
let plug: ptr MidiTransposePlugin = createShared(MidiTransposePlugin)
|
||||
plug.map = cast[ptr UridMap](lv2FeaturesData(features, lv2UridMap))
|
||||
try:
|
||||
let plug: ptr MidiTransposePlugin = createShared(MidiTransposePlugin)
|
||||
plug.map = cast[ptr UridMap](lv2FeaturesData(features, lv2UridMap))
|
||||
|
||||
if plug.map.isNil:
|
||||
freeShared(plug)
|
||||
return nil
|
||||
if plug.map.isNil:
|
||||
freeShared(plug)
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
plug.midi_urid = plug.map.map(plug.map.handle, lv2MidiMidiEvent)
|
||||
plug.midi_urid = plug.map.map(plug.map.handle, lv2MidiMidiEvent)
|
||||
|
||||
return cast[Lv2Handle](plug)
|
||||
return cast[Lv2Handle](plug)
|
||||
except OutOfMemDefect:
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
|
||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||
@ -95,7 +98,7 @@ let descriptor = Lv2Descriptor(
|
||||
)
|
||||
|
||||
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
||||
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
||||
cdecl, dynlib, exportc: "lv2_descriptor".} =
|
||||
if index == 0:
|
||||
NimMain()
|
||||
return addr(descriptor)
|
||||
|
||||
@ -27,12 +27,12 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]):
|
||||
Lv2Handle {.cdecl.} =
|
||||
try:
|
||||
let plug = createShared(SVFPlugin)
|
||||
let plug: ptr SVFPlugin = createShared(SVFPlugin)
|
||||
plug.svf = initSVFilter(fmLowPass, sampleRate)
|
||||
plug.smoothCutoff = initParamSmooth(20.0, sampleRate)
|
||||
return cast[Lv2Handle](plug)
|
||||
except OutOfMemDefect:
|
||||
return nil
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
|
||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||
@ -91,7 +91,7 @@ let descriptor = Lv2Descriptor(
|
||||
)
|
||||
|
||||
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
||||
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
||||
cdecl, dynlib, exportc: "lv2_descriptor".} =
|
||||
if index == 0:
|
||||
NimMain()
|
||||
return addr(descriptor)
|
||||
|
||||
@ -30,12 +30,12 @@ proc instantiate(descriptor: ptr Lv2Descriptor; sampleRate: cdouble;
|
||||
bundlePath: cstring; features: ptr UncheckedArray[ptr Lv2Feature]):
|
||||
Lv2Handle {.cdecl.} =
|
||||
try:
|
||||
let plug = createShared(TiltFilterPlugin)
|
||||
let plug: ptr TiltFilterPlugin = createShared(TiltFilterPlugin)
|
||||
plug.flt = initTiltFilter(10_000.0, 1.0, fmLowPass, sampleRate)
|
||||
plug.smoothFreq = initParamSmooth(20.0, sampleRate)
|
||||
return cast[Lv2Handle](plug)
|
||||
except OutOfMemDefect:
|
||||
return nil
|
||||
return cast[Lv2Handle](nil)
|
||||
|
||||
|
||||
proc connectPort(instance: Lv2Handle; port: cuint;
|
||||
@ -91,7 +91,7 @@ let descriptor = Lv2Descriptor(
|
||||
)
|
||||
|
||||
proc lv2Descriptor(index: cuint): ptr Lv2Descriptor {.
|
||||
cdecl, exportc, dynlib, extern: "lv2_descriptor".} =
|
||||
cdecl, dynlib, exportc: "lv2_descriptor".} =
|
||||
if index == 0:
|
||||
NimMain()
|
||||
return addr(descriptor)
|
||||
|
||||
@ -92,7 +92,8 @@ const
|
||||
lv2CoreInstanceSampleRate* = lv2CorePrefix & "sampleRate"
|
||||
lv2CoreInstanceToggled* = lv2CorePrefix & "toggled"
|
||||
|
||||
type Lv2Handle* = pointer
|
||||
type
|
||||
Lv2Handle* = distinct pointer
|
||||
|
||||
type Lv2Feature* = object
|
||||
uri*: cstring
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user