@@ -1,28 +1,31 @@ | |||
/* | |||
LADSPAInfo.h - Header file for LADSPA Plugin info class | |||
Copyright (C) 2002 Mike Rawes | |||
This program is free software; you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation; either version 2 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | |||
along with this program; if not, write to the Free Software | |||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
*/ | |||
// | |||
// LADSPAInfo.h - Header file for LADSPA Plugin info class | |||
// | |||
// Copyleft (C) 2002 Mike Rawes <myk@waxfrenzy.org> | |||
// | |||
// This program is free software; you can redistribute it and/or modify | |||
// it under the terms of the GNU General Public License as published by | |||
// the Free Software Foundation; either version 2 of the License, or | |||
// (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
// | |||
#ifndef __ladspa_info_h__ | |||
#define __ladspa_info_h__ | |||
#include <config.h> | |||
#include <string> | |||
#include <vector> | |||
#include <list> | |||
#include <map> | |||
#include <ladspa.h> | |||
@@ -33,124 +36,164 @@ public: | |||
// Also examine supplied path list | |||
// For all paths, add basic plugin information for later lookup, | |||
// instantiation and so on. | |||
LADSPAInfo(bool override, const char *path_list); | |||
LADSPAInfo(bool override = false, const char *path_list = ""); | |||
// Unload all loaded plugins and clean up | |||
~LADSPAInfo(); | |||
~LADSPAInfo(); | |||
// ************************************************************************ | |||
// Loading/Unloading plugin libraries | |||
// | |||
// At first, no library dlls are loaded. | |||
// | |||
// Each library has an associated reference count, which is initially 0. | |||
// As descriptors are requested, using GetDescriptorByID, this count | |||
// is incremented. The library dll is loaded on the first request. | |||
// At descriptors are discarded, the count is decremented, and when this | |||
// reaches 0, the library is unloaded. | |||
// A plugin library may have more than one plugin descriptor. The | |||
// descriptor is used to instantiate, activate, execute plugin instances. | |||
// Administration of plugin instances are outwith the scope of this class, | |||
// instead, descriptors are requested using GetDecriptorByID, and disposed | |||
// of using DiscardDescriptorByID. | |||
// | |||
// Each library keeps a reference count of descriptors requested. A library | |||
// is loaded when a descriptor is requested for the first time, and remains | |||
// loaded until the number of discards matches the number of requests. | |||
// Rescan all paths in $LADSPA_PATH, as per constructor. | |||
// This will also unload all libraries, and make any descriptors that | |||
// have not been discarded with DiscardDescriptorByID invalid. | |||
void RescanPlugins(void); | |||
void RescanPlugins(void); | |||
// Unload all dlopened libraries. This will make any descriptors that | |||
// have not been discarded with DiscardDescriptorByID invalid. | |||
void UnloadAllLibraries(void); | |||
void UnloadAllLibraries(void); | |||
// Get descriptor of plugin with given ID. This increments the descriptor | |||
// count for the corresponding library. | |||
const LADSPA_Descriptor *GetDescriptorByID(unsigned long unique_id); | |||
const LADSPA_Descriptor *GetDescriptorByID(unsigned long unique_id); | |||
// Notify that a descriptor corresponding to the given ID has been | |||
// discarded. This decrements the descriptor count for the corresponding | |||
// library. | |||
void DiscardDescriptorByID(unsigned long unique_id); | |||
// Get unique ID of plugin identified by given library filename and label. | |||
unsigned long GetIDFromFilenameAndLabel(std::string filename, | |||
std::string label); | |||
void DiscardDescriptorByID(unsigned long unique_id); | |||
struct PluginEntry | |||
{ | |||
unsigned long UniqueID; | |||
std::string Name; | |||
}; | |||
// ************************************************************************ | |||
// SSM Specific options | |||
// Get a list of plugins ordered by name (duplicate names are | |||
// appended with a (number) | |||
const std::vector<PluginEntry> GetPluginList(void); | |||
// Get unique ID of plugin identified by given library filename and label. | |||
// This is for backwards compatibility with older versions of SSM where the | |||
// path and label of the plugin was stored in the configuration - current | |||
// versions store the Unique ID | |||
unsigned long GetIDFromFilenameAndLabel(std::string filename, | |||
std::string label); | |||
// Struct for plugin information returned by queries | |||
struct PluginEntry | |||
{ | |||
unsigned int Depth; | |||
unsigned long UniqueID; | |||
std::string Name; | |||
bool operator<(const PluginEntry& pe) | |||
{ | |||
return (Name<pe.Name); | |||
} | |||
}; | |||
// Get ordered list of plugin names and IDs for plugin menu | |||
const std::vector<PluginEntry> GetMenuList(void); | |||
// Get the index in the above list for given Unique ID | |||
// If not found, this returns the size of the above list | |||
unsigned long GetPluginListEntryByID(unsigned long unique_id); | |||
unsigned long GetPluginListEntryByID(unsigned long unique_id); | |||
// Get the number of input ports for the plugin with the most | |||
// input ports | |||
unsigned long GetMaxInputPortCount(void) { return m_MaxInputPortCount; } | |||
void PrintInfo(void); | |||
unsigned long GetMaxInputPortCount(void) { return m_MaxInputPortCount; } | |||
private: | |||
void CleanUp(void); | |||
void ScanPathList(const char *path_list, | |||
void (LADSPAInfo::*ExamineFunc)(const std::string, | |||
const std::string)); | |||
void ExaminePluginLibrary(const std::string path, | |||
const std::string basename); | |||
// See LADSPAInfo.C for comments on these functions | |||
void DescendGroup(std::string prefix, | |||
const std::string group, | |||
unsigned int depth); | |||
std::list<std::string> GetSubGroups(const std::string group); | |||
void CleanUp(void); | |||
void ScanPathList(const char *path_list, | |||
void (LADSPAInfo::*ExamineFunc)(const std::string, | |||
const std::string)); | |||
void ExaminePluginLibrary(const std::string path, | |||
const std::string basename); | |||
bool CheckPlugin(const LADSPA_Descriptor *desc); | |||
LADSPA_Descriptor_Function GetDescriptorFunctionForLibrary(unsigned long library_index); | |||
#ifdef HAVE_LIBLRDF | |||
void ExamineRDFFile(const std::string path, | |||
const std::string basename); | |||
void ExamineRDFFile(const std::string path, | |||
const std::string basename); | |||
void MetadataRDFDescend(const char *uri, | |||
unsigned long parent); | |||
#endif | |||
bool CheckPlugin(const LADSPA_Descriptor *desc); | |||
LADSPA_Descriptor_Function GetDescriptorFunctionForLibrary(unsigned long library_index); | |||
struct LibraryInfo | |||
{ | |||
unsigned long PathIndex; // Index of path in m_Paths | |||
std::string Basename; // Filename | |||
unsigned long RefCount; // Count of descriptors requested from library | |||
void *Handle; // DLL Handle, NULL | |||
}; | |||
struct PluginInfo | |||
{ | |||
unsigned long LibraryIndex; // Index of library in m_Libraries | |||
unsigned long Index; // Plugin index in library | |||
const LADSPA_Descriptor *Descriptor; // Descriptor, NULL | |||
}; | |||
typedef std::map<unsigned long, | |||
unsigned long, | |||
std::less<unsigned long> > IDMap; | |||
typedef std::map<std::string, | |||
unsigned long, | |||
std::less<std::string> > StringMap; | |||
// For sorting vectors of PluginEntries | |||
struct PluginEntrySortAsc | |||
{ | |||
bool operator()(const PluginEntry &begin, const PluginEntry &end) | |||
{ | |||
return begin.Name < end.Name; | |||
} | |||
}; | |||
bool m_LADSPAPathOverride; | |||
char *m_ExtraPaths; | |||
std::vector<std::string> m_Paths; | |||
std::vector<LibraryInfo> m_Libraries; | |||
std::vector<PluginInfo> m_Plugins; | |||
IDMap m_IDLookup; | |||
StringMap m_FilenameLookup; | |||
std::vector<PluginEntry> m_OrderedPluginList; | |||
unsigned long m_MaxInputPortCount; | |||
// For cached library information | |||
struct LibraryInfo | |||
{ | |||
unsigned long PathIndex; // Index of path in m_Paths | |||
std::string Basename; // Filename | |||
unsigned long RefCount; // Count of descriptors requested | |||
void *Handle; // DLL Handle, NULL | |||
}; | |||
// For cached plugin information | |||
struct PluginInfo | |||
{ | |||
unsigned long LibraryIndex; // Index of library in m_Libraries | |||
unsigned long Index; // Plugin index in library | |||
unsigned long UniqueID; // Unique ID | |||
std::string Label; // Plugin label | |||
std::string Name; // Plugin Name | |||
const LADSPA_Descriptor *Descriptor; // Descriptor, NULL | |||
}; | |||
// For cached RDF uri information | |||
struct RDFURIInfo | |||
{ | |||
std::string URI; // Full URI for use with lrdf | |||
std::string Label; // Label | |||
std::vector<unsigned long> Parents; // Index of parents in m_RDFURIs | |||
std::vector<unsigned long> Children; // Indices of children in m_RDFURIs | |||
std::vector<unsigned long> Plugins; // Indices of plugins in m_Plugins | |||
}; | |||
// Lookup maps | |||
typedef std::map<unsigned long, | |||
unsigned long, | |||
std::less<unsigned long> > IDMap; | |||
typedef std::map<std::string, | |||
unsigned long, | |||
std::less<std::string> > StringMap; | |||
bool m_LADSPAPathOverride; | |||
char *m_ExtraPaths; | |||
// LADSPA Plugin information database | |||
std::vector<std::string> m_Paths; | |||
std::vector<LibraryInfo> m_Libraries; | |||
std::vector<PluginInfo> m_Plugins; | |||
// Plugin lookup maps | |||
IDMap m_IDLookup; | |||
// RDF URI database | |||
std::vector<RDFURIInfo> m_RDFURIs; | |||
// RDF URI lookup map | |||
StringMap m_RDFURILookup; | |||
// RDF Label lookup map | |||
StringMap m_RDFLabelLookup; | |||
// SSM specific data | |||
std::vector<PluginEntry> m_SSMMenuList; | |||
StringMap m_FilenameLookup; | |||
unsigned long m_MaxInputPortCount; | |||
}; | |||
#endif // __ladspa_info_h__ |
@@ -1,5 +1,7 @@ | |||
/* SpiralSound | |||
/* LADSPAPlugin.C | |||
* Copyleft (C) 2001 David Griffiths <dave@pawfal.org> | |||
* LADSPA Plugin by Nicolas Noble <nicolas@nobis-crew.org> | |||
* Modified by Mike Rawes <myk@waxfrenzy.org> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -20,6 +22,14 @@ | |||
#include <cstring> | |||
#include <cmath> | |||
#ifdef HAVE_POSIX_SHM | |||
// All this, just for SHM | |||
#include <unistd.h> // For ftruncate | |||
#include <fcntl.h> // For O_CREAT, O_RDONLY etc | |||
#include <sys/types.h> // shm_* | |||
#include <sys/mman.h> // shm_* | |||
#endif | |||
#include "SpiralIcon.xpm" | |||
#include "LADSPAPlugin.h" | |||
#include "LADSPAPluginGUI.h" | |||
@@ -53,7 +63,65 @@ string SpiralPlugin_GetGroupName() | |||
LADSPAPlugin::LADSPAPlugin() | |||
{ | |||
#ifdef HAVE_POSIX_SHM | |||
// Share the LADSPA Database via SHM | |||
// We keep two things: A reference counter, and a pointer to the | |||
// database. We can get away with just a pointer as all instances | |||
// are in the same address space (process + thread) | |||
int shm_rc_fd; | |||
int shm_db_fd; | |||
shm_rc_fd = shm_open(m_SHMRefCountPath, O_RDWR, 0644); | |||
if (shm_rc_fd > 0) { | |||
// Got an existing refcount | |||
m_SHMRefCount = (unsigned long *)mmap(0, sizeof(unsigned long), PROT_READ | PROT_WRITE, MAP_SHARED, | |||
shm_rc_fd, 0); | |||
(*m_SHMRefCount)++; | |||
shm_db_fd = shm_open(m_SHMLDBPath, O_RDONLY, 0644); | |||
if (shm_db_fd > 0) { | |||
// Got LADSPA Database | |||
m_SHMLDB = (LADSPAInfo **)mmap(0, sizeof(LADSPAInfo *), PROT_READ, MAP_SHARED, | |||
shm_db_fd, 0); | |||
m_LADSPAInfo = *m_SHMLDB; | |||
} else { | |||
std::cerr << "LADSPAPlugin: ERROR: Could not open SHM file '" << m_SHMLDBPath << std::cerr; | |||
} | |||
} else { | |||
// Need to create a new SHM file for ref counter | |||
shm_rc_fd = shm_open(m_SHMRefCountPath, O_CREAT | O_RDWR, 0644); | |||
if (shm_rc_fd > 0) { | |||
ftruncate(shm_rc_fd, sizeof(unsigned long)); | |||
m_SHMRefCount = (unsigned long *)mmap(0, sizeof(unsigned long), PROT_READ | PROT_WRITE, MAP_SHARED, | |||
shm_rc_fd, 0); | |||
// Initilise to 1 (this instance) | |||
*m_SHMRefCount = 1; | |||
shm_db_fd = shm_open(m_SHMLDBPath, O_CREAT | O_RDWR, 0644); | |||
if (shm_db_fd > 0) { | |||
// Create LADSPA Plugin Database | |||
m_LADSPAInfo = new LADSPAInfo(false, ""); | |||
ftruncate(shm_db_fd, sizeof(LADSPAInfo *)); | |||
m_SHMLDB = (LADSPAInfo **)mmap(0, sizeof(LADSPAInfo *), PROT_READ | PROT_WRITE, MAP_SHARED, | |||
shm_db_fd, 0); | |||
*m_SHMLDB = m_LADSPAInfo; | |||
} else { | |||
std::cerr << "LADSPAPlugin: ERROR: Could not create SHM file '" << m_SHMLDBPath << "'" << std::endl; | |||
} | |||
} else { | |||
std::cerr << "LADSPAPlugin: ERROR: Could not create SHM file '" << m_SHMRefCountPath << "'" << std::endl; | |||
} | |||
} | |||
#else | |||
// No POSIX SHM, just create a new database | |||
m_LADSPAInfo = new LADSPAInfo(false, ""); | |||
#endif | |||
m_PlugDesc = NULL; | |||
@@ -71,7 +139,7 @@ LADSPAPlugin::LADSPAPlugin() | |||
m_MaxInputPortCount = m_LADSPAInfo->GetMaxInputPortCount(); | |||
// For receiving from GUI | |||
m_AudioCH->RegisterData("SetPluginIndex", ChannelHandler::INPUT,&(m_InData.PluginIndex), sizeof(m_InData.PluginIndex)); | |||
m_AudioCH->RegisterData("SetUniqueID", ChannelHandler::INPUT,&(m_InData.UniqueID), sizeof(m_InData.UniqueID)); | |||
m_AudioCH->RegisterData("SetTabIndex", ChannelHandler::INPUT,&(m_InData.TabIndex), sizeof(m_InData.TabIndex)); | |||
m_AudioCH->RegisterData("SetUpdateInputs", ChannelHandler::INPUT,&(m_InData.UpdateInputs),sizeof(m_InData.UpdateInputs)); | |||
m_AudioCH->RegisterData("SetInputPortIndex", ChannelHandler::INPUT, &(m_InData.InputPortIndex), sizeof(m_InData.InputPortIndex)); | |||
@@ -93,13 +161,14 @@ LADSPAPlugin::LADSPAPlugin() | |||
if (m_OutData.InputPortNames && | |||
m_OutData.InputPortDefaults && | |||
m_OutData.InputPortSettings) { | |||
m_OutData.InputPortSettings && | |||
m_OutData.InputPortValues) { | |||
m_AudioCH->RegisterData("GetInputPortNames", ChannelHandler::OUTPUT, m_OutData.InputPortNames, 256 * m_MaxInputPortCount); | |||
m_AudioCH->RegisterData("GetInputPortSettings", ChannelHandler::OUTPUT, m_OutData.InputPortSettings, sizeof(PortSettings) * m_MaxInputPortCount); | |||
m_AudioCH->RegisterData("GetInputPortValues", ChannelHandler::OUTPUT, m_OutData.InputPortValues, sizeof(PortValues) * m_MaxInputPortCount); | |||
m_AudioCH->RegisterData("GetInputPortDefaults", ChannelHandler::OUTPUT, m_OutData.InputPortDefaults, sizeof(float) * m_MaxInputPortCount); | |||
} else { | |||
cerr<<"Memory allocation error"<<endl; | |||
cerr<<"LADSPA Plugin: Memory allocation error"<<endl; | |||
} | |||
} | |||
@@ -114,7 +183,25 @@ LADSPAPlugin::~LADSPAPlugin() | |||
if (m_OutData.InputPortValues) free(m_OutData.InputPortValues); | |||
if (m_OutData.InputPortDefaults) free(m_OutData.InputPortDefaults); | |||
#ifdef HAVE_POSIX_SHM | |||
// Clean up SHM things | |||
(*m_SHMRefCount)--; | |||
if ((*m_SHMRefCount) == 0) { | |||
// Last instance, so unmap and unlink | |||
munmap(m_SHMRefCount, sizeof(unsigned long)); | |||
shm_unlink(m_SHMRefCountPath); | |||
munmap(m_SHMLDB, sizeof(LADSPAInfo *)); | |||
shm_unlink(m_SHMLDBPath); | |||
// Delete the database itself | |||
delete m_LADSPAInfo; | |||
} else { | |||
// Other instances still out there, so just unmap | |||
munmap(m_SHMRefCount, sizeof(unsigned long)); | |||
munmap(m_SHMLDB, sizeof(LADSPAInfo *)); | |||
} | |||
#else | |||
delete m_LADSPAInfo; | |||
#endif | |||
} | |||
PluginInfo &LADSPAPlugin::Initialise(const HostInfo *Host) | |||
@@ -128,7 +215,7 @@ PluginInfo &LADSPAPlugin::Initialise(const HostInfo *Host) | |||
SpiralGUIType *LADSPAPlugin::CreateGUI() | |||
{ | |||
return new LADSPAPluginGUI(m_PluginInfo.Width, m_PluginInfo.Height, | |||
this, m_AudioCH, m_HostInfo, m_LADSPAInfo->GetPluginList()); | |||
this, m_AudioCH, m_HostInfo, m_LADSPAInfo->GetMenuList()); | |||
} | |||
void LADSPAPlugin::Execute() | |||
@@ -205,8 +292,7 @@ void LADSPAPlugin::ExecuteCommands() | |||
break; | |||
case (SELECTPLUGIN): | |||
{ | |||
vector<LADSPAInfo::PluginEntry> pe = m_LADSPAInfo->GetPluginList(); | |||
UpdatePlugin(pe[m_InData.PluginIndex - 1].UniqueID); | |||
UpdatePlugin(m_InData.UniqueID); | |||
} | |||
break; | |||
case (CLEARPLUGIN): | |||
@@ -857,7 +943,6 @@ bool LADSPAPlugin::SelectPlugin(unsigned long UniqueID) | |||
UpdatePluginInfoWithHost(); | |||
m_UniqueID = m_PlugDesc->UniqueID; | |||
m_PluginIndex = m_LADSPAInfo->GetPluginListEntryByID(m_UniqueID) + 1; | |||
m_InputPortCount = m_PluginInfo.NumInputs; | |||
int lbl_length; | |||
@@ -891,7 +976,6 @@ void LADSPAPlugin::ClearPlugin(void) | |||
m_TabIndex = 1; | |||
m_UpdateInputs = true; | |||
m_UniqueID = 0; | |||
m_PluginIndex = 0; | |||
m_InputPortCount = 0; | |||
strncpy(m_Name, "None\0", 5); | |||
strncpy(m_Maker, "None\0", 5); | |||
@@ -1,5 +1,7 @@ | |||
/* SpiralSound | |||
/* LADSPAPlugin.h | |||
* Copyleft (C) 2001 David Griffiths <dave@pawfal.org> | |||
* LADSPA Plugin by Nicolas Noble <nicolas@nobis-crew.org> | |||
* Modified by Mike Rawes <myk@waxfrenzy.org> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -40,7 +42,7 @@ struct PortValues | |||
class LADSPAPlugin : public SpiralPlugin | |||
{ | |||
public: | |||
LADSPAPlugin(); | |||
LADSPAPlugin(); | |||
virtual ~LADSPAPlugin(); | |||
virtual PluginInfo &Initialise(const HostInfo *Host); | |||
@@ -50,7 +52,7 @@ public: | |||
virtual void StreamOut(ostream &s); | |||
virtual void StreamIn(istream &s); | |||
unsigned long GetPluginIndex() { return m_PluginIndex; } | |||
unsigned long GetUniqueID() { return m_UniqueID; } | |||
const char *GetName() { return (const char *)m_Name; } | |||
const char *GetMaker() { return (const char *)m_Maker; } | |||
int GetTabIndex() { return m_TabIndex; } | |||
@@ -130,7 +132,7 @@ private: | |||
// Data received from GUI | |||
struct InputChannelData | |||
{ | |||
unsigned long PluginIndex; | |||
unsigned long UniqueID; | |||
int TabIndex; | |||
bool UpdateInputs; | |||
unsigned long InputPortIndex; | |||
@@ -142,6 +144,13 @@ private: | |||
OutputChannelData m_OutData; | |||
InputChannelData m_InData; | |||
// SHM stuff - for sharing the LADSPA Plugin database | |||
static const char * const m_SHMRefCountPath = "/SpiralSynthModular-LADSPAPlugin-RefCount"; | |||
static const char * const m_SHMLDBPath = "/SpiralSynthModular-LADSPAPlugin-Database"; | |||
unsigned long *m_SHMRefCount; | |||
LADSPAInfo **m_SHMLDB; | |||
}; | |||
#endif // __ladspa_plugin_h__ |
@@ -1,6 +1,7 @@ | |||
/* SpiralPlugin | |||
/* LADSPAPluginGUI.C | |||
* Copyleft (C) 2000 David Griffiths <dave@pawfal.org> | |||
* LADSPA Plugin by Nicolas Noble <nicolas@nobis-crew.org> | |||
* Modified by Mike Rawes <myk@waxfrenzy.org> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -37,8 +38,8 @@ LADSPAPluginGUI::LADSPAPluginGUI(int w, int h, | |||
const vector<LADSPAInfo::PluginEntry> &PVec) : | |||
SpiralPluginGUI(w,h,o,ch) | |||
{ | |||
m_GUIColour = (Fl_Color)Info->GUI_COLOUR; | |||
m_PluginList = PVec; | |||
m_GUIColour = (Fl_Color)Info->GUI_COLOUR; | |||
m_PluginList = PVec; | |||
int Width=20; | |||
int Height=100; | |||
@@ -54,7 +55,7 @@ SpiralPluginGUI(w,h,o,ch) | |||
if (!(m_InputPortNames && m_InputPortSettings && | |||
m_InputPortValues && m_InputPortDefaults)) { | |||
cerr<<"Memory allocation error\n"<<endl; | |||
cerr<<"LADSPA Plugin (GUI): Memory allocation error\n"<<endl; | |||
} | |||
// Set up widgets | |||
@@ -76,7 +77,7 @@ SpiralPluginGUI(w,h,o,ch) | |||
add(m_Tab); | |||
m_ControlGroup = new Fl_Group (5, 80, 490, 230, "Control"); | |||
m_ControlGroup->box (FL_PLASTIC_UP_BOX); | |||
m_ControlGroup->box (FL_PLASTIC_UP_BOX); | |||
m_ControlGroup->labelsize(12); | |||
m_ControlScroll = new Fl_Scroll (10, 85, 480, 220, ""); | |||
@@ -88,7 +89,7 @@ SpiralPluginGUI(w,h,o,ch) | |||
m_ControlScroll->add(m_ControlPack); | |||
m_SetupGroup = new Fl_Group (5, 80, 490, 230, "Setup"); | |||
m_SetupGroup->box (FL_PLASTIC_UP_BOX); | |||
m_SetupGroup->box (FL_PLASTIC_UP_BOX); | |||
m_SetupGroup->labelsize(12); | |||
m_Browser = new Fl_Choice(50,85,440,22,"Plugin:"); | |||
@@ -97,37 +98,32 @@ SpiralPluginGUI(w,h,o,ch) | |||
m_Browser->callback((Fl_Callback *)cb_Select); | |||
m_Browser->add("(None)"); | |||
m_PluginIDLookup.push_back(0); | |||
for (vector<LADSPAInfo::PluginEntry>::iterator i=m_PluginList.begin(); | |||
// The plugin list is already formatted for addition to our drop-down, | |||
// so just add all items as they are | |||
unsigned long size = m_Browser->size(); | |||
int depth = 1; | |||
for (vector<LADSPAInfo::PluginEntry>::iterator i=m_PluginList.begin(); | |||
i!=m_PluginList.end(); i++) | |||
{ | |||
unsigned long len = i->Name.length(); | |||
unsigned long esc_count = 0; | |||
const char *tmp = i->Name.c_str(); | |||
char *dest; | |||
m_Browser->add(i->Name.c_str()); | |||
for (unsigned long c = 0; c < len; c++) { | |||
if (tmp[c] == '/') esc_count++; | |||
} | |||
unsigned int dsize = m_Browser->size() - size; | |||
int ddepth = i->Depth - depth; | |||
dest = (char *)malloc(len + 1 + esc_count); | |||
if (dest) { | |||
unsigned long d = 0; | |||
for (unsigned long c = 0; c < len; c++, d++) { | |||
if (tmp[c] == '/' || tmp[c] == '|') { | |||
dest[d] = '\\'; | |||
d++; | |||
dest[d] = tmp[c]; | |||
} else { | |||
dest[d] = tmp[c]; | |||
} | |||
} | |||
dest[len + esc_count] = '\0'; | |||
m_Browser->add(dest); | |||
free(dest); | |||
size = m_Browser->size(); | |||
depth = i->Depth; | |||
// Add blanks to ID Lookup vector to account for sub-menus | |||
for (unsigned long j = 1; j < (dsize - ddepth); j++) { | |||
m_PluginIDLookup.push_back(0); | |||
} | |||
} | |||
// Add to ID Lookup vector (this maps Menu Items to Unique IDs) | |||
m_PluginIDLookup.push_back(i->UniqueID); | |||
} | |||
m_Browser->value(0); | |||
m_SetupGroup->add(m_Browser); | |||
@@ -143,29 +139,29 @@ SpiralPluginGUI(w,h,o,ch) | |||
m_SetupGroup->add(m_InputScroll); | |||
m_ValueLabel = new Fl_Box(15,115,60,15,"Value"); | |||
m_ValueLabel = new Fl_Box(15,115,60,15,"Value"); | |||
m_ValueLabel->labelsize(12); | |||
m_SetupGroup->add(m_ValueLabel); | |||
m_SetupGroup->add(m_ValueLabel); | |||
m_DefaultLabel = new Fl_Box(77,115,60,15,"Default"); | |||
m_DefaultLabel = new Fl_Box(77,115,60,15,"Default"); | |||
m_DefaultLabel->labelsize(12); | |||
m_SetupGroup->add(m_DefaultLabel); | |||
m_SetupGroup->add(m_DefaultLabel); | |||
m_MinLabel = new Fl_Box(139,115,60,15,"Min"); | |||
m_MinLabel = new Fl_Box(139,115,60,15,"Min"); | |||
m_MinLabel->labelsize(12); | |||
m_SetupGroup->add(m_MinLabel); | |||
m_SetupGroup->add(m_MinLabel); | |||
m_MaxLabel = new Fl_Box(201,115,60,15,"Max"); | |||
m_MaxLabel = new Fl_Box(201,115,60,15,"Max"); | |||
m_MaxLabel->labelsize(12); | |||
m_SetupGroup->add(m_MaxLabel); | |||
m_SetupGroup->add(m_MaxLabel); | |||
m_ClampLabel = new Fl_Box(280,115,10,15,"Clamp?"); | |||
m_ClampLabel = new Fl_Box(280,115,10,15,"Clamp?"); | |||
m_ClampLabel->labelsize(12); | |||
m_SetupGroup->add(m_ClampLabel); | |||
m_SetupGroup->add(m_ClampLabel); | |||
m_PortLabel = new Fl_Box(325,115,60,15,"Port Name"); | |||
m_PortLabel = new Fl_Box(325,115,60,15,"Port Name"); | |||
m_PortLabel->labelsize(12); | |||
m_SetupGroup->add(m_PortLabel); | |||
m_SetupGroup->add(m_PortLabel); | |||
m_UpdateInputs = new Fl_LED_Button (10, 282, 25, 25, "Update input values?"); | |||
m_UpdateInputs->labelsize(12); | |||
@@ -190,6 +186,9 @@ LADSPAPluginGUI::~LADSPAPluginGUI(void) | |||
if (m_InputPortSettings) free(m_InputPortSettings); | |||
if (m_InputPortValues) free(m_InputPortValues); | |||
if (m_InputPortDefaults) free(m_InputPortDefaults); | |||
m_PluginIDLookup.clear(); | |||
Fl::check(); | |||
} | |||
@@ -243,7 +242,7 @@ void LADSPAPluginGUI::UpdateDefaultAdjustControls(void) | |||
void LADSPAPluginGUI::UpdateValues(SpiralPlugin *o) | |||
{ | |||
LADSPAPlugin* Plugin = (LADSPAPlugin*)o; | |||
SetPluginIndex(Plugin->GetPluginIndex()); | |||
SetUniqueID(Plugin->GetUniqueID()); | |||
SetName(Plugin->GetName()); | |||
SetMaker(Plugin->GetMaker()); | |||
SetTabIndex(Plugin->GetTabIndex()); | |||
@@ -336,10 +335,17 @@ void LADSPAPluginGUI::SetUpdateInputs(bool state) | |||
m_UpdateInputs->value(m_UpdateInputState); | |||
} | |||
void LADSPAPluginGUI::SetPluginIndex(unsigned long n) | |||
void LADSPAPluginGUI::SetUniqueID(unsigned long n) | |||
{ | |||
m_PluginIndex = n; | |||
m_Browser->value(m_PluginIndex); | |||
m_UniqueID = n; | |||
vector<unsigned long>::iterator i = std::find(m_PluginIDLookup.begin(), m_PluginIDLookup.end(), m_UniqueID); | |||
if (i != m_PluginIDLookup.end()) { | |||
m_Browser->value(i - m_PluginIDLookup.begin()); | |||
} else { | |||
m_Browser->value(0); | |||
} | |||
} | |||
void LADSPAPluginGUI::SetName(const char *s) | |||
@@ -529,7 +535,6 @@ void LADSPAPluginGUI::Update(void) | |||
void LADSPAPluginGUI::ClearPlugin(void) | |||
{ | |||
m_PluginIndex = 0; | |||
m_InputPortCount = 0; | |||
m_PortIndex = 0; | |||
@@ -573,22 +578,22 @@ void LADSPAPluginGUI::SelectPlugin(void) | |||
m_GUICH->GetData("GetInputPortSettings", m_InputPortSettings); | |||
m_GUICH->GetData("GetInputPortDefaults", m_InputPortDefaults); | |||
SetName((const char *)m_Name); | |||
SetName((const char *)m_Name); | |||
SetMaker((const char *)m_Maker); | |||
for (unsigned long p = 0; p < m_InputPortCount; p++) { | |||
AddPortInfo((const char *)(m_InputPortNames + p * 256)); | |||
SetPortSettings(p, m_InputPortSettings[p].Min, | |||
m_InputPortSettings[p].Max, | |||
m_InputPortSettings[p].Clamp, | |||
m_InputPortDefaults[p]); | |||
m_InputPortSettings[p].Max, | |||
m_InputPortSettings[p].Clamp, | |||
m_InputPortDefaults[p]); | |||
SetDefaultAdjust(p); | |||
} | |||
UpdateDefaultAdjustControls(); | |||
m_PortIndex = m_InputPortCount; | |||
redraw(); | |||
} | |||
@@ -612,15 +617,15 @@ inline void LADSPAPluginGUI::cb_Select_i(Fl_Choice* o) | |||
{ | |||
ClearPlugin(); | |||
m_PluginIndex = o->value(); | |||
unsigned long m_UniqueID = m_PluginIDLookup[o->value()]; | |||
if (m_PluginIndex != 0) { | |||
// Plugin selected | |||
m_GUICH->SetData("SetPluginIndex",&m_PluginIndex); | |||
if (m_UniqueID != 0) { | |||
// Plugin selected | |||
m_GUICH->SetData("SetUniqueID",&m_UniqueID); | |||
m_GUICH->SetCommand(LADSPAPlugin::SELECTPLUGIN); | |||
m_GUICH->Wait(); | |||
m_GUICH->Wait(); | |||
} | |||
SelectPlugin(); | |||
SelectPlugin(); | |||
// redraw(); | |||
} | |||
@@ -1,5 +1,7 @@ | |||
/* SpiralPlugin | |||
/* LADSPAPluginGUI.h | |||
* Copyleft (C) 2000 David Griffiths <dave@pawfal.org> | |||
* LADSPA Plugin by Nicolas Noble <nicolas@nobis-crew.org> | |||
* Modified by Mike Rawes <myk@waxfrenzy.org> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
@@ -63,7 +65,7 @@ private: | |||
void AddPortInfo(const char *Info); | |||
void SetTabIndex(int index); | |||
void SetUpdateInputs(bool state); | |||
void SetPluginIndex(unsigned long n); | |||
void SetUniqueID(unsigned long n); | |||
void SetName(const char *s); | |||
void SetMaker(const char *s); | |||
void SetPortSettings(unsigned long n, float min, float max, bool clamp, float defolt); | |||
@@ -72,8 +74,8 @@ private: | |||
void ClearPlugin(void); | |||
void SelectPlugin(void); | |||
Fl_Color m_GUIColour; | |||
Fl_Box *m_NameLabel; | |||
Fl_Color m_GUIColour; | |||
Fl_Box *m_NameLabel; | |||
Fl_Box *m_MakerLabel; | |||
Fl_Tabs *m_Tab; | |||
Fl_Group *m_ControlGroup; | |||
@@ -82,12 +84,12 @@ private: | |||
Fl_Group *m_SetupGroup; | |||
Fl_Choice *m_Browser; | |||
Fl_Box *m_ValueLabel; | |||
Fl_Box *m_DefaultLabel; | |||
Fl_Box *m_MinLabel; | |||
Fl_Box *m_MaxLabel; | |||
Fl_Box *m_ClampLabel; | |||
Fl_Box *m_PortLabel; | |||
Fl_Box *m_ValueLabel; | |||
Fl_Box *m_DefaultLabel; | |||
Fl_Box *m_MinLabel; | |||
Fl_Box *m_MaxLabel; | |||
Fl_Box *m_ClampLabel; | |||
Fl_Box *m_PortLabel; | |||
Fl_Scroll *m_InputScroll; | |||
Fl_Pack *m_InputPack; | |||
@@ -101,6 +103,7 @@ private: | |||
std::vector<char *> m_PortDefaultAdjustLabels; | |||
std::vector<LADSPAInfo::PluginEntry> m_PluginList; | |||
std::vector<unsigned long> m_PluginIDLookup; | |||
unsigned long m_PortIndex; | |||
float m_Default; | |||
@@ -108,7 +111,7 @@ private: | |||
float m_Max; | |||
bool m_Clamp; | |||
unsigned long m_PluginIndex; | |||
unsigned long m_UniqueID; | |||
int m_TabIndex; | |||
bool m_UpdateInputState; | |||
char m_Name[256]; | |||
@@ -120,7 +123,7 @@ private: | |||
PortValues *m_InputPortValues; | |||
float *m_InputPortDefaults; | |||
inline void cb_TabChange_i(Fl_Tabs *o); | |||
inline void cb_TabChange_i(Fl_Tabs *o); | |||
static void cb_TabChange(Fl_Tabs *o); | |||
inline void cb_Select_i(Fl_Choice* o); | |||
static void cb_Select(Fl_Choice* o); | |||
@@ -138,6 +141,4 @@ private: | |||
static void cb_DefaultAdjust(Fl_Knob *o); | |||
}; | |||
#endif // __ladspa_plugin_gui_h__ |