public LadspaLibraryContext(string fileName)
 {
     library = LoadLibrary(fileName);
     if (library == IntPtr.Zero)
     {
         throw new Exception("Failed to load library - file not found or not a valid library.");
     }
     try
     {
         IntPtr func     = GetProcAddress(library, "ladspa_descriptor");
         IntPtr dssiFunc = GetProcAddress(library, "dssi_descriptor");
         if (func == IntPtr.Zero && dssiFunc == IntPtr.Zero)
         {
             throw new Exception("Not a LADSPA plugin: ladspa_descriptor not found.");
         }
         List <LadspaDescriptor> descriptors     = new List <LadspaDescriptor>();
         List <DssiDescriptor>   dssiDescriptors = new List <DssiDescriptor>();
         if (func != IntPtr.Zero)
         {
             LadspaDescriptorCallback callback = (LadspaDescriptorCallback)Marshal.GetDelegateForFunctionPointer(func, typeof(LadspaDescriptorCallback));
             for (uint index = 0; true; index++)
             {
                 IntPtr data = callback(index);
                 if (data == IntPtr.Zero)
                 {
                     break;
                 }
                 descriptors.Add(new LadspaDescriptor(this, index, data));
             }
         }
         if (dssiFunc != IntPtr.Zero)
         {
             LadspaDescriptorCallback callback = (LadspaDescriptorCallback)Marshal.GetDelegateForFunctionPointer(dssiFunc, typeof(LadspaDescriptorCallback));
             for (uint index = 0; true; index++)
             {
                 IntPtr data = callback(index);
                 if (data == IntPtr.Zero)
                 {
                     break;
                 }
                 dssiDescriptors.Add(new DssiDescriptor(this, index, data));
             }
         }
         LadspaDescriptors = descriptors.ToArray();
         DssiDescriptors   = dssiDescriptors.ToArray();
     }
     catch
     {
         FreeLibrary(library);
         throw;
     }
 }
示例#2
0
        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));
            }
        }