-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLadspaDescriptor.cs
More file actions
74 lines (70 loc) · 4.52 KB
/
LadspaDescriptor.cs
File metadata and controls
74 lines (70 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace LADSPA.NET
{
public class LadspaDescriptor
{
public readonly LadspaLibraryContext Library;
public readonly uint Index;
public readonly uint UniqueID;
public readonly LadspaPropertiesEnum Properties;
public readonly string Label;
public readonly string Name;
public readonly string Maker;
public readonly string Copyright;
public readonly LadspaPort[] Ports;
internal readonly IntPtr DataHandle;
internal readonly LadspaDescriptorInstantiateCallback Instantiate;
internal readonly LadspaDescriptorConnectPortCallback ConnectPort;
internal readonly LadspaDescriptorCallback Activate;
internal readonly LadspaDescriptorRunCallback Run;
internal readonly LadspaDescriptorRunCallback RunAdding;
internal readonly LadspaDescriptorSetRunGainCallback SetRunAddingGain;
internal readonly LadspaDescriptorCallback Deactivate;
internal readonly LadspaDescriptorCallback Cleanup;
internal LadspaDescriptor(LadspaLibraryContext library, uint index, IntPtr dataPtr)
{
LadspaDescriptorStruct data = (LadspaDescriptorStruct)Marshal.PtrToStructure(dataPtr, typeof(LadspaDescriptorStruct));
Library = library;
DataHandle = dataPtr;
Index = index;
UniqueID = data.UniqueID;
Properties = data.Properties;
Label = data.Label;
Name = data.Name;
Maker = data.Maker;
Copyright = data.Copyright;
Ports = new LadspaPort[data.PortCount];
int hintsSize = Marshal.SizeOf(typeof(LadspaPortRangeHintsStruct));
int[] types = new int[data.PortCount];
IntPtr[] names = new IntPtr[data.PortCount];
if (data.PortDescriptors != IntPtr.Zero) { Marshal.Copy(data.PortDescriptors, types, 0, types.Length); }
if (data.PortNames != IntPtr.Zero) { Marshal.Copy(data.PortNames, names, 0, names.Length); }
for (int i = 0; i < data.PortCount; i++)
{
string name = names[i] != IntPtr.Zero ? Marshal.PtrToStringAnsi(names[i]) : null;
LadspaPortRangeHintsStruct hints = data.PortRangeHints == IntPtr.Zero ? new LadspaPortRangeHintsStruct() :
(LadspaPortRangeHintsStruct)Marshal.PtrToStructure(IntPtr.Add(data.PortRangeHints, hintsSize * (int)i), typeof(LadspaPortRangeHintsStruct));
Ports[i] = new LadspaPort(this, i, (LadspaPortDescriptorEnum)types[i], hints.Hints, name, hints.LowerBound, hints.UpperBound);
}
if (data.Instantiate != IntPtr.Zero) { Instantiate = (LadspaDescriptorInstantiateCallback)Marshal.GetDelegateForFunctionPointer(data.Instantiate, typeof(LadspaDescriptorInstantiateCallback)); }
if (data.ConnectPort != IntPtr.Zero) { ConnectPort = (LadspaDescriptorConnectPortCallback)Marshal.GetDelegateForFunctionPointer(data.ConnectPort, typeof(LadspaDescriptorConnectPortCallback)); }
if (data.Activate != IntPtr.Zero) { Activate = (LadspaDescriptorCallback)Marshal.GetDelegateForFunctionPointer(data.Activate, typeof(LadspaDescriptorCallback)); }
if (data.Run != IntPtr.Zero) { Run = (LadspaDescriptorRunCallback)Marshal.GetDelegateForFunctionPointer(data.Run, typeof(LadspaDescriptorRunCallback)); }
if (data.RunAdding != IntPtr.Zero) { RunAdding = (LadspaDescriptorRunCallback)Marshal.GetDelegateForFunctionPointer(data.RunAdding, typeof(LadspaDescriptorRunCallback)); }
if (data.SetRunAddingGain != IntPtr.Zero) { SetRunAddingGain = (LadspaDescriptorSetRunGainCallback)Marshal.GetDelegateForFunctionPointer(data.SetRunAddingGain, typeof(LadspaDescriptorSetRunGainCallback)); }
if (data.Deactivate != IntPtr.Zero) { Deactivate = (LadspaDescriptorCallback)Marshal.GetDelegateForFunctionPointer(data.Deactivate, typeof(LadspaDescriptorCallback)); }
if (data.Cleanup != IntPtr.Zero) { Cleanup = (LadspaDescriptorCallback)Marshal.GetDelegateForFunctionPointer(data.Cleanup, typeof(LadspaDescriptorCallback)); }
}
public LadspaInstance CreateInstance(int sampleRate, int bufferSize = 1024)
{
IntPtr handle = Instantiate != null ? Instantiate(DataHandle, (uint)sampleRate) : IntPtr.Zero;
if (handle == IntPtr.Zero) { throw new Exception("Failed to create instance."); }
return (new LadspaInstance(this, handle, sampleRate, bufferSize));
}
}
}