| @@ -17,7 +17,9 @@ | |||
| */ | |||
| #include "LADSPAPlugin.h" | |||
| #include "LADSPAPluginGUI.h" | |||
| #include <stdio.h> | |||
| #include <cstdio> | |||
| #include <cstdlib> | |||
| #include <cstring> | |||
| #include "SpiralIcon.xpm" | |||
| #include "utils.h" | |||
| #include <algorithm> | |||
| @@ -63,7 +65,9 @@ void describePluginLibrary(const char * pcFullFilename, void * pvPluginHandle, | |||
| pi.Filename = pcFullFilename; | |||
| pi.Label = psDescriptor->Label; | |||
| pi.Name = psDescriptor->Name; | |||
| /* ARGH! I really can't stand this ugly hack */ | |||
| pi.InputPortCount = getPortCountByType(psDescriptor, LADSPA_PORT_INPUT); | |||
| // ARGH! I really can't stand this ugly hack | |||
| lg->m_LADSPAList.push_back(pi); | |||
| } else { | |||
| cerr << "Plugin ignored...\n\n"; | |||
| @@ -76,6 +80,7 @@ void describePluginLibrary(const char * pcFullFilename, void * pvPluginHandle, | |||
| void LADSPAPlugin::LoadPluginList(void) | |||
| { | |||
| m_LADSPAList.clear(); | |||
| m_CurrentPlugin.Name = ""; | |||
| m_CurrentPlugin.Filename = ""; | |||
| m_CurrentPlugin.Label = ""; | |||
| @@ -85,7 +90,7 @@ void LADSPAPlugin::LoadPluginList(void) | |||
| lg = NULL; | |||
| sort(m_LADSPAList.begin(), m_LADSPAList.end(), LPluginInfoSortAsc()); | |||
| } | |||
| } | |||
| //////////////////////////////////////////////////// | |||
| @@ -108,35 +113,74 @@ int GetID() | |||
| /////////////////////////////////////////////////////// | |||
| LADSPAPlugin::LADSPAPlugin() : | |||
| PlugHandle(0), | |||
| LADSPAPlugin::LADSPAPlugin() : | |||
| PlugHandle(0), | |||
| PlugDesc(NULL), | |||
| m_Gain(1.0f), | |||
| m_Amped(false) | |||
| { | |||
| m_Version=3; | |||
| m_PluginInfo.Name="LADSPA"; | |||
| m_PluginInfo.Width=600; | |||
| m_PluginInfo.Height=300; | |||
| m_PluginInfo.NumInputs=0; | |||
| m_PluginInfo.NumOutputs=1; | |||
| m_PluginInfo.PortTips.push_back("Nuffink yet"); | |||
| m_PluginInfo.PortTips.push_back("Nuffink yet"); | |||
| m_InputPortCountMax = 0; | |||
| m_InputPortCount = 0; | |||
| // For receiving from GUI | |||
| m_AudioCH->Register("Gain",&m_Gain); | |||
| m_AudioCH->Register("Amped",&m_Amped); | |||
| m_AudioCH->RegisterData("Desc",ChannelHandler::OUTPUT,&PlugDesc,sizeof(PlugDesc)); | |||
| m_AudioCH->Register("Num",&m_GUIArgs.Num); | |||
| m_AudioCH->Register("Value",&m_GUIArgs.Value); | |||
| m_AudioCH->Register("Clamp",&m_GUIArgs.Clamp); | |||
| m_AudioCH->RegisterData("Filename",ChannelHandler::INPUT,&m_GUIArgs.Filename,sizeof(m_GUIArgs.Filename)); | |||
| m_AudioCH->RegisterData("Label",ChannelHandler::INPUT,&m_GUIArgs.Label,sizeof(m_GUIArgs.Label)); | |||
| m_AudioCH->RegisterData("PluginIndex", ChannelHandler::INPUT,&m_PluginIndex,sizeof(m_PluginIndex)); | |||
| LoadPluginList(); | |||
| // Examine plugin list and find highest input port count | |||
| for (vector<LPluginInfo>::iterator i = m_LADSPAList.begin(); | |||
| i != m_LADSPAList.end(); i++) { | |||
| if ((*i).InputPortCount > m_InputPortCountMax) | |||
| m_InputPortCountMax = (*i).InputPortCount; | |||
| } | |||
| // Now we have a maximum input port count, so we can allocate and register our | |||
| // port info arrays | |||
| m_AudioCH->RegisterData("InputPortCountMax",ChannelHandler::OUTPUT,&m_InputPortCountMax,sizeof(m_InputPortCountMax)); | |||
| m_AudioCH->RegisterData("InputPortCount",ChannelHandler::OUTPUT,&m_InputPortCount,sizeof(m_InputPortCount)); | |||
| m_InputPortMin = (float *)malloc(sizeof(float) * m_InputPortCountMax); | |||
| m_InputPortMax = (float *)malloc(sizeof(float) * m_InputPortCountMax); | |||
| m_InputPortClamp = (bool *)malloc(sizeof(bool) * m_InputPortCountMax); | |||
| m_InputPortNames = (char *)malloc(256 * m_InputPortCountMax); | |||
| m_Name = (char *)malloc(256); | |||
| m_Maker = (char *)malloc(256); | |||
| if (m_InputPortMin && m_InputPortMax && m_InputPortClamp && m_InputPortNames && | |||
| m_Name && m_Maker) { | |||
| m_AudioCH->RegisterData("InputPortMin", ChannelHandler::OUTPUT, m_InputPortMin, sizeof(float) * m_InputPortCountMax); | |||
| m_AudioCH->RegisterData("InputPortMax", ChannelHandler::OUTPUT, m_InputPortMax, sizeof(float) * m_InputPortCountMax); | |||
| m_AudioCH->RegisterData("InputPortClamp", ChannelHandler::OUTPUT, m_InputPortClamp, sizeof(bool) * m_InputPortCountMax); | |||
| m_AudioCH->RegisterData("InputPortNames", ChannelHandler::OUTPUT, m_InputPortNames, 256 * m_InputPortCountMax); | |||
| m_AudioCH->RegisterData("Name",ChannelHandler::OUTPUT,m_Name,256); | |||
| m_AudioCH->RegisterData("Maker",ChannelHandler::OUTPUT,m_Maker,256); | |||
| } else { | |||
| cerr<<"Memory allocation error\n"<<endl; | |||
| } | |||
| } | |||
| LADSPAPlugin::~LADSPAPlugin() | |||
| { | |||
| // Free allocated buffers | |||
| if (m_InputPortMin) free(m_InputPortMin); | |||
| if (m_InputPortMax) free(m_InputPortMax); | |||
| if (m_InputPortClamp) free(m_InputPortClamp); | |||
| if (m_InputPortNames) free(m_InputPortNames); | |||
| if (m_Name) free(m_Name); | |||
| if (m_Maker) free(m_Maker); | |||
| } | |||
| PluginInfo &LADSPAPlugin::Initialise(const HostInfo *Host) | |||
| @@ -144,12 +188,13 @@ PluginInfo &LADSPAPlugin::Initialise(const HostInfo *Host) | |||
| PluginInfo& Info = SpiralPlugin::Initialise(Host); | |||
| LADSPA_Data *NewPort = new LADSPA_Data[m_HostInfo->BUFSIZE]; | |||
| m_LADSPABufVec.push_back(NewPort); | |||
| return Info; | |||
| return Info; | |||
| } | |||
| SpiralGUIType *LADSPAPlugin::CreateGUI() | |||
| { | |||
| return new LADSPAPluginGUI(m_PluginInfo.Width,m_PluginInfo.Height,this,m_AudioCH,m_HostInfo,m_LADSPAList); | |||
| return new LADSPAPluginGUI(m_PluginInfo.Width, m_PluginInfo.Height, | |||
| this, m_AudioCH, m_HostInfo, m_LADSPAList); | |||
| } | |||
| void LADSPAPlugin::Execute() | |||
| @@ -188,10 +233,10 @@ void LADSPAPlugin::Execute() | |||
| for (int i=0; i<m_HostInfo->BUFSIZE; i++) m_LADSPABufVec[n][i]=0; | |||
| } | |||
| } | |||
| // run plugin | |||
| PlugDesc->run(PlugInstHandle,m_HostInfo->BUFSIZE); | |||
| PlugDesc->run(PlugInstHandle,m_HostInfo->BUFSIZE); | |||
| // convert outputs | |||
| for (int n=0; n<m_PluginInfo.NumOutputs; n++) | |||
| { | |||
| @@ -219,10 +264,8 @@ void LADSPAPlugin::ExecuteCommands() | |||
| { | |||
| switch(m_AudioCH->GetCommand()) | |||
| { | |||
| case (SETMIN) : SetMin(m_GUIArgs.Num,m_GUIArgs.Value); break; | |||
| case (SETMAX) : SetMax(m_GUIArgs.Num,m_GUIArgs.Value); break; | |||
| case (SETCLAMP) : SetPortClamp(m_GUIArgs.Num,m_GUIArgs.Clamp); break; | |||
| case (UPDATEPLUGIN) : UpdatePlugin(m_GUIArgs.Num); break; | |||
| case (UPDATERANGES) : break; | |||
| case (UPDATEPLUGIN) : UpdatePlugin(m_PluginIndex); break; | |||
| }; | |||
| } | |||
| } | |||
| @@ -230,7 +273,7 @@ void LADSPAPlugin::ExecuteCommands() | |||
| void LADSPAPlugin::StreamOut(ostream &s) | |||
| { | |||
| s<<m_Version<<" "; | |||
| switch (m_Version) | |||
| { | |||
| case 3: | |||
| @@ -329,7 +372,7 @@ void LADSPAPlugin::StreamIn(istream &s) | |||
| { | |||
| UpdatePlugin(Filename.c_str(), Label.c_str(), false); | |||
| } | |||
| m_CurrentPlugin.Ports.reserve(PortCount); | |||
| for (int n=0; n<PortCount; n++) | |||
| @@ -390,7 +433,7 @@ void LADSPAPlugin::StreamIn(istream &s) | |||
| string Filename,Label; | |||
| s>>Filename>>Label; | |||
| if (Filename!="None") | |||
| { | |||
| UpdatePlugin(Filename.c_str(), Label.c_str()); | |||
| @@ -430,10 +473,10 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| PlugHandle = 0; | |||
| return 0; | |||
| } | |||
| m_PluginInfo.NumInputs=getPortCountByType(PlugDesc, LADSPA_PORT_INPUT); | |||
| m_PluginInfo.NumOutputs=getPortCountByType(PlugDesc, LADSPA_PORT_OUTPUT); | |||
| ///////////////////////////////// | |||
| // LADSPA Buffers | |||
| @@ -442,9 +485,9 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| { | |||
| if (*i) delete[] (*i); | |||
| } | |||
| m_LADSPABufVec.clear(); | |||
| unsigned long c=0; | |||
| m_LADSPABufVec.clear(); | |||
| unsigned long c=0; | |||
| for (unsigned int n=0; n<PlugDesc->PortCount; n++) | |||
| { | |||
| if (LADSPA_IS_PORT_INPUT(PlugDesc->PortDescriptors[n])) | |||
| @@ -452,11 +495,11 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| LADSPA_Data *NewPort = new LADSPA_Data[m_HostInfo->BUFSIZE]; | |||
| m_LADSPABufVec.push_back(NewPort); | |||
| PlugDesc->connect_port(PlugInstHandle, n, m_LADSPABufVec[c]); | |||
| m_PortID.push_back(n); | |||
| m_PortID.push_back(n); | |||
| c++; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| for (unsigned int n=0; n<PlugDesc->PortCount; n++) | |||
| { | |||
| if (LADSPA_IS_PORT_OUTPUT(PlugDesc->PortDescriptors[n])) | |||
| @@ -466,9 +509,9 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| PlugDesc->connect_port(PlugInstHandle, n, m_LADSPABufVec[c]); | |||
| m_PortID.push_back(n); | |||
| c++; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| // activate the plugin now | |||
| if (PlugDesc->activate) | |||
| PlugDesc->activate(PlugInstHandle); | |||
| @@ -481,9 +524,9 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| RemoveAllOutputs(); | |||
| // Reallocate the i/o buffers required | |||
| for (int n=0; n<m_PluginInfo.NumInputs; n++) AddInput(); | |||
| for (int n=0; n<m_PluginInfo.NumInputs; n++) AddInput(); | |||
| for (int n=0; n<m_PluginInfo.NumOutputs; n++) AddOutput(); | |||
| ////////////////////////////// | |||
| // Update the GUI stuff | |||
| @@ -491,55 +534,55 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| m_CurrentPlugin.Maker=PlugDesc->Maker; | |||
| m_CurrentPlugin.Filename=filename; | |||
| m_CurrentPlugin.Label=label; | |||
| m_CurrentPlugin.Ports.clear(); | |||
| m_PluginInfo.PortTips.clear(); | |||
| string desc; | |||
| c=0; | |||
| for (unsigned int i = 0; i < PlugDesc->PortCount; i++) | |||
| for (unsigned int i = 0; i < PlugDesc->PortCount; i++) | |||
| { | |||
| if (LADSPA_IS_PORT_INPUT(PlugDesc->PortDescriptors[i])) | |||
| if (LADSPA_IS_PORT_INPUT(PlugDesc->PortDescriptors[i])) | |||
| { | |||
| desc = string(PlugDesc->PortNames[i]) + | |||
| (LADSPA_IS_PORT_CONTROL(PlugDesc->PortDescriptors[i]) ? " (CV)" : " (AU)"); | |||
| m_PluginInfo.PortTips.push_back(desc.c_str()); | |||
| LPluginInfo::LPortDetails PortDetails; | |||
| PortDetails.Name=m_PluginInfo.PortTips[c].c_str(); | |||
| m_CurrentPlugin.Ports.push_back(PortDetails); | |||
| c++; | |||
| } | |||
| } | |||
| for (unsigned int i = 0; i < PlugDesc->PortCount; i++) | |||
| { | |||
| for (unsigned int i = 0; i < PlugDesc->PortCount; i++) | |||
| { | |||
| if (LADSPA_IS_PORT_OUTPUT(PlugDesc->PortDescriptors[i])) { | |||
| desc = string(PlugDesc->PortNames[i]) + | |||
| (LADSPA_IS_PORT_CONTROL(PlugDesc->PortDescriptors[i]) ? " (CV)" : " (AU)"); | |||
| m_PluginInfo.PortTips.push_back(desc.c_str()); | |||
| } | |||
| } | |||
| UpdatePluginInfoWithHost(); | |||
| if (PortClampReset) | |||
| { | |||
| m_PortMin.clear(); | |||
| m_PortMax.clear(); | |||
| m_PortMax.clear(); | |||
| m_PortClamp.clear(); | |||
| for (int n=0; n<m_PluginInfo.NumInputs; n++) | |||
| { | |||
| float Max=1.0f, Min=-1.0f; | |||
| int Port=m_PortID[n]; | |||
| // Get the bounding hints for the port | |||
| LADSPA_PortRangeHintDescriptor HintDesc=PlugDesc->PortRangeHints[Port].HintDescriptor; | |||
| if (LADSPA_IS_HINT_BOUNDED_BELOW(HintDesc)) | |||
| if (LADSPA_IS_HINT_BOUNDED_BELOW(HintDesc)) | |||
| { | |||
| Min=PlugDesc->PortRangeHints[Port].LowerBound; | |||
| if (LADSPA_IS_HINT_SAMPLE_RATE(HintDesc)) | |||
| @@ -547,7 +590,7 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| Min*=m_HostInfo->SAMPLERATE; | |||
| } | |||
| } | |||
| if (LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc)) | |||
| if (LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc)) | |||
| { | |||
| Max=PlugDesc->PortRangeHints[Port].UpperBound; | |||
| if (LADSPA_IS_HINT_SAMPLE_RATE(HintDesc)) | |||
| @@ -555,23 +598,53 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool | |||
| Max*=m_HostInfo->SAMPLERATE; | |||
| } | |||
| } | |||
| m_PortMin.push_back(Min); | |||
| m_PortMax.push_back(Max); | |||
| // PortClamp defaults to true | |||
| m_PortClamp.push_back(true); | |||
| m_CurrentPlugin.Ports[n].Min=Min; | |||
| m_CurrentPlugin.Ports[n].Max=Max; | |||
| m_CurrentPlugin.Ports[n].Clamped=true; | |||
| } | |||
| } | |||
| } | |||
| // Finally, we need to supply the GUI with information via | |||
| // ChannelHandler. | |||
| m_InputPortCount = m_PluginInfo.NumInputs; | |||
| int lbl_length; | |||
| char *lbl_start; | |||
| lbl_length = m_CurrentPlugin.Name.size(); | |||
| lbl_length = lbl_length > 255 ? 255 : lbl_length; | |||
| strncpy(m_Name, m_CurrentPlugin.Name.substr(0, lbl_length).c_str(), lbl_length); | |||
| m_Name[lbl_length] = '\0'; | |||
| lbl_length = m_CurrentPlugin.Maker.size(); | |||
| lbl_length = lbl_length > 255 ? 255 : lbl_length; | |||
| strncpy(m_Maker, m_CurrentPlugin.Maker.substr(0, lbl_length).c_str(), lbl_length); | |||
| m_Maker[lbl_length] = '\0'; | |||
| lbl_start = m_InputPortNames; | |||
| for (unsigned long n = 0; n < m_InputPortCount; n++) { | |||
| m_InputPortMin[n] = m_CurrentPlugin.Ports[n].Min; | |||
| m_InputPortMax[n] = m_CurrentPlugin.Ports[n].Max; | |||
| m_InputPortClamp[n] = m_CurrentPlugin.Ports[n].Clamped; | |||
| lbl_length = m_CurrentPlugin.Ports[n].Name.size(); | |||
| lbl_length = lbl_length > 255 ? 255 : lbl_length; | |||
| strncpy(lbl_start, m_CurrentPlugin.Ports[n].Name.substr(0, lbl_length).c_str(), lbl_length); | |||
| lbl_start[lbl_length] = '\0'; | |||
| lbl_start += 256; | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| cerr << "Error loading LADSPA Plugin.\n"; | |||
| return false; | |||
| } | |||
| @@ -14,7 +14,7 @@ | |||
| * 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. | |||
| */ | |||
| */ | |||
| #include "../SpiralPlugin.h" | |||
| #include <FL/Fl_Pixmap.H> | |||
| @@ -32,16 +32,17 @@ public: | |||
| string Label; | |||
| string Name; | |||
| string Maker; | |||
| unsigned long InputPortCount; | |||
| struct LPortDetails | |||
| { | |||
| string Name; | |||
| float Min,Max; | |||
| bool Clamped; | |||
| }; | |||
| vector<LPortDetails> Ports; | |||
| bool operator<(const LPluginInfo & li) { return (Name < li.Name); } | |||
| bool operator==(const LPluginInfo& li) { return (Name == li.Name); } | |||
| }; | |||
| @@ -60,34 +61,22 @@ class LADSPAPlugin : public SpiralPlugin | |||
| public: | |||
| LADSPAPlugin(); | |||
| virtual ~LADSPAPlugin(); | |||
| virtual PluginInfo &Initialise(const HostInfo *Host); | |||
| virtual SpiralGUIType *CreateGUI(); | |||
| virtual void Execute(); | |||
| virtual void ExecuteCommands(); | |||
| virtual void ExecuteCommands(); | |||
| virtual void StreamOut(ostream &s); | |||
| virtual void StreamIn(istream &s); | |||
| float GetGain() { return m_Gain; } | |||
| bool GetAmped() { return m_Amped; } | |||
| enum GUICommands{NONE,SETMIN,SETMAX,SETCLAMP,UPDATEPLUGIN}; | |||
| struct GUIArgs | |||
| { | |||
| int Num; | |||
| float Value; | |||
| bool Clamp; | |||
| char Filename[256]; | |||
| char Label[256]; | |||
| }; | |||
| private: | |||
| GUIArgs m_GUIArgs; | |||
| enum GUICommands{NONE,UPDATERANGES,UPDATEPLUGIN}; | |||
| private: | |||
| void SetMin(int n,float min) { m_PortMin[n]=min; } | |||
| void SetMax(int n,float max) { m_PortMax[n]=max; } | |||
| void SetPortClamp(int n,bool i) { m_PortClamp[n]=i; } | |||
| void UpdatePortRange(void); | |||
| bool UpdatePlugin(int n); | |||
| bool UpdatePlugin(const char * filename, const char * label, bool PortClampReset=true); | |||
| @@ -96,20 +85,33 @@ private: | |||
| void * PlugHandle; | |||
| const LADSPA_Descriptor * PlugDesc; | |||
| vector<LADSPA_Data*> m_LADSPABufVec; | |||
| LADSPA_Handle PlugInstHandle; | |||
| vector<int> m_PortID; | |||
| vector<int> m_PortID; | |||
| vector<float> m_PortMin; | |||
| vector<float> m_PortMax; | |||
| vector<bool> m_PortClamp; | |||
| vector<float> m_PortMax; | |||
| vector<bool> m_PortClamp; | |||
| // our database of ladspa plugins | |||
| vector<LPluginInfo> m_LADSPAList; | |||
| LPluginInfo m_CurrentPlugin; | |||
| float m_Gain; | |||
| bool m_Amped; | |||
| float m_Gain; | |||
| bool m_Amped; | |||
| unsigned long m_PluginIndex; | |||
| char *m_Name; | |||
| char *m_Maker; | |||
| unsigned long m_InputPortCountMax; // Maximum number of input ports | |||
| // Corresponds to input port count of one | |||
| // (or more) plugins found | |||
| unsigned long m_InputPortCount; // Number of input ports in current plugin | |||
| float *m_InputPortMin; // Input port range minima | |||
| float *m_InputPortMax; // Input port range maxima | |||
| bool *m_InputPortClamp; // Input port clamp state | |||
| char *m_InputPortNames; // Input port names | |||
| }; | |||
| #endif | |||
| @@ -21,8 +21,8 @@ | |||
| #include <FL/fl_draw.h> | |||
| #include <FL/fl_draw.H> | |||
| #include "ladspa.h" | |||
| #include <stdio.h> | |||
| #include <math.h> | |||
| #include <cstdio> | |||
| #include <cmath> | |||
| #include <dlfcn.h> | |||
| #include <vector> | |||
| #include "utils.h" | |||
| @@ -35,7 +35,7 @@ LADSPAPluginGUI::LADSPAPluginGUI(int w, int h,LADSPAPlugin *o, ChannelHandler *c | |||
| SpiralPluginGUI(w,h,o,ch) | |||
| { | |||
| PluginList=PVec; | |||
| m_Filename="None"; | |||
| int Width=20; | |||
| @@ -43,13 +43,30 @@ SpiralPluginGUI(w,h,o,ch) | |||
| m_Browser= new Fl_Hold_Browser(5,20,290,260,"LADSPA Plugins"); | |||
| m_Browser->callback((Fl_Callback*)cb_Select); | |||
| for (vector<LPluginInfo>::iterator i=PluginList.begin(); | |||
| i!=PluginList.end(); i++) | |||
| { | |||
| m_Browser->add((*i).Name.c_str()); | |||
| } | |||
| // Get maximum input port count | |||
| m_GUICH->GetData("InputPortCountMax",&m_InputPortCountMax); | |||
| // Set up buffers for data transfer via ChannelHandler | |||
| m_InputPortMin = (float *)malloc(sizeof(float) * m_InputPortCountMax); | |||
| m_InputPortMax = (float *)malloc(sizeof(float) * m_InputPortCountMax); | |||
| m_InputPortClamp = (bool *)malloc(sizeof(bool) * m_InputPortCountMax); | |||
| m_InputPortNames = (char *)malloc(256 * m_InputPortCountMax); | |||
| m_NameString = (char *)malloc(256); | |||
| m_MakerString = (char *)malloc(256); | |||
| if (!(m_InputPortMin && m_InputPortMax && m_InputPortClamp && m_InputPortNames && | |||
| m_NameString && m_MakerString)) { | |||
| cerr<<"Memory allocation error\n"<<endl; | |||
| } | |||
| m_InputScroll = new Fl_Scroll(300,80,290,150," Value Min Max Clamp?"); | |||
| m_InputScroll->align(FL_ALIGN_TOP_LEFT); | |||
| m_InputScroll->type(Fl_Scroll::VERTICAL); | |||
| @@ -57,71 +74,77 @@ SpiralPluginGUI(w,h,o,ch) | |||
| add(m_InputScroll); | |||
| m_InputPack = new Fl_Pack(300,85,300,100,""); | |||
| m_InputScroll->add(m_InputPack); | |||
| m_Name = new Fl_Box(290,20,10,20,"None"); | |||
| m_Name->align(FL_ALIGN_RIGHT); | |||
| m_Name->labelcolor(GUI_COLOUR); | |||
| m_Name->labelsize(10); | |||
| add(m_Name); | |||
| m_Maker = new Fl_Box(290,40,10,20,"None"); | |||
| m_Maker->align(FL_ALIGN_RIGHT); | |||
| m_Maker->labelcolor(GUI_COLOUR); | |||
| m_Maker->labelsize(10); | |||
| add(m_Maker); | |||
| m_OutputGain = new Fl_Knob(545,240,40,40,"Output Gain"); | |||
| m_OutputGain->color(GUI_COLOUR); | |||
| m_OutputGain->type(Fl_Knob::DOTLIN); | |||
| m_OutputGain->maximum(2); | |||
| m_OutputGain->step(0.001); | |||
| m_OutputGain->value(1.0); | |||
| m_OutputGain->step(0.001); | |||
| m_OutputGain->value(1.0); | |||
| m_OutputGain->labelsize(10); | |||
| m_OutputGain->callback((Fl_Callback*)cb_Gain); | |||
| add(m_OutputGain); | |||
| m_UpdateInputs = new Fl_Button(480,252,50,25,"Refresh"); | |||
| m_UpdateInputs->labelsize(10); | |||
| m_UpdateInputs->value(1); | |||
| m_UpdateInputs->type(1); | |||
| add(m_UpdateInputs); | |||
| m_UpdateMinMax = new Fl_Button(400,252,85,25,"Update Min/Max"); | |||
| m_UpdateMinMax->labelsize(10); | |||
| m_UpdateMinMax->callback((Fl_Callback*)cb_MinMax); | |||
| add(m_UpdateMinMax); | |||
| m_PowerAmp = new Fl_Button(320,252,80,25,"PowerAmp"); | |||
| m_PowerAmp->labelsize(10); | |||
| m_PowerAmp->value(0); | |||
| m_PowerAmp->type(1); | |||
| m_PowerAmp->callback((Fl_Callback*)cb_PowerAmp); | |||
| add(m_PowerAmp); | |||
| end(); | |||
| } | |||
| LADSPAPluginGUI::~LADSPAPluginGUI(void) | |||
| LADSPAPluginGUI::~LADSPAPluginGUI(void) | |||
| { | |||
| if (m_InputPortMin) free(m_InputPortMin); | |||
| if (m_InputPortMax) free(m_InputPortMax); | |||
| if (m_InputPortClamp) free(m_InputPortClamp); | |||
| if (m_InputPortNames) free(m_InputPortNames); | |||
| if (m_NameString) free(m_NameString); | |||
| if (m_MakerString) free(m_MakerString); | |||
| Fl::check(); | |||
| } | |||
| void LADSPAPluginGUI::UpdatePortDisplay(int n, float v) | |||
| { | |||
| if (!m_UpdateInputs->value()) return; | |||
| char temp[256]; | |||
| sprintf(temp,"%f",v); | |||
| sprintf(temp,"%f",v); | |||
| m_PortOutput[n]->value(temp); | |||
| } | |||
| void LADSPAPluginGUI::SetMinMax(int n, float min, float max, bool clamp) | |||
| { | |||
| char temp[256]; | |||
| sprintf(temp,"%f",min); | |||
| sprintf(temp,"%f",min); | |||
| m_PortMin[n]->value(temp); | |||
| sprintf(temp,"%f",max); | |||
| sprintf(temp,"%f",max); | |||
| m_PortMax[n]->value(temp); | |||
| sprintf(temp, "%d",clamp); | |||
| @@ -144,7 +167,7 @@ void LADSPAPluginGUI::SetMaker(const char *s) | |||
| { | |||
| m_Maker->label(s); | |||
| } | |||
| void LADSPAPluginGUI::ClearPortInfo() | |||
| { | |||
| for (vector<Fl_Group*>::iterator i=m_PackVec.begin(); | |||
| @@ -152,12 +175,12 @@ void LADSPAPluginGUI::ClearPortInfo() | |||
| { | |||
| m_InputPack->remove((*i)); | |||
| } | |||
| m_InputScroll->remove(m_InputPack); | |||
| m_InputScroll->remove(m_InputPack); | |||
| delete m_InputPack; | |||
| m_InputPack = new Fl_Pack(x()+300,y()+85,300,100,""); | |||
| m_InputScroll->add(m_InputPack); | |||
| m_InputScroll->add(m_InputPack); | |||
| m_PortOutput.clear(); | |||
| m_PackVec.clear(); | |||
| m_PortMin.clear(); | |||
| @@ -166,24 +189,24 @@ void LADSPAPluginGUI::ClearPortInfo() | |||
| } | |||
| void LADSPAPluginGUI::AddPortInfo(const char *Info) | |||
| { | |||
| { | |||
| Fl_Group* NewGroup = new Fl_Group(0,85,150,15,""); | |||
| NewGroup->box(FL_FLAT_BOX); | |||
| m_InputPack->add(NewGroup); | |||
| m_PackVec.push_back(NewGroup); | |||
| Fl_Box* NewText = new Fl_Box(100,85,80,15,""); | |||
| NewText->label(Info); | |||
| NewText->labelsize(8); | |||
| NewText->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); | |||
| NewGroup->add(NewText); | |||
| Fl_Output* NewOutput = new Fl_Output(5,85,20,15,""); | |||
| NewOutput->value(0); | |||
| NewOutput->textsize(10); | |||
| NewGroup->add(NewOutput); | |||
| m_PortOutput.push_back(NewOutput); | |||
| Fl_Input* NewInput = new Fl_Input(26,85,20,15,""); | |||
| NewInput->value(0); | |||
| NewInput->textsize(10); | |||
| @@ -195,7 +218,7 @@ void LADSPAPluginGUI::AddPortInfo(const char *Info) | |||
| NewInput->textsize(10); | |||
| NewGroup->add(NewInput); | |||
| m_PortMax.push_back(NewInput); | |||
| Fl_Check_Button* NewCheckButton = new Fl_Check_Button(80,85,15,15,""); | |||
| NewCheckButton->value(0); | |||
| NewGroup->add(NewCheckButton); | |||
| @@ -204,63 +227,92 @@ void LADSPAPluginGUI::AddPortInfo(const char *Info) | |||
| NewGroup->redraw(); | |||
| m_InputPack->redraw(); | |||
| m_InputScroll->redraw(); | |||
| redraw(); | |||
| } | |||
| void LADSPAPluginGUI::UpdateValues(SpiralPlugin *o) | |||
| { | |||
| LADSPAPlugin* Plugin = (LADSPAPlugin*)o; | |||
| m_OutputGain->value(Plugin->GetGain()); | |||
| } | |||
| inline void LADSPAPluginGUI::cb_Gain_i(Fl_Knob* o, void* v) | |||
| { m_GUICH->Set("Gain",(float)(o->value())); } | |||
| void LADSPAPluginGUI::cb_Gain(Fl_Knob* o, void* v) | |||
| { ((LADSPAPluginGUI*)(o->parent()))->cb_Gain_i(o,v); } | |||
| inline void LADSPAPluginGUI::cb_Gain_i(Fl_Knob* o, void* v) | |||
| { | |||
| m_GUICH->Set("Gain",(float)(o->value())); | |||
| } | |||
| void LADSPAPluginGUI::cb_Gain(Fl_Knob* o, void* v) | |||
| { | |||
| ((LADSPAPluginGUI*)(o->parent()))->cb_Gain_i(o,v); | |||
| } | |||
| inline void LADSPAPluginGUI::cb_Select_i(Fl_Hold_Browser* o) | |||
| { | |||
| inline void LADSPAPluginGUI::cb_Select_i(Fl_Hold_Browser* o) | |||
| { | |||
| m_Filename=PluginList[o->value()-1].Filename; | |||
| m_Label=PluginList[o->value()-1].Label; | |||
| m_GUICH->Set("Num",o->value()-1); | |||
| m_GUICH->Set("PluginIndex",o->value()-1); | |||
| m_GUICH->SetCommand(LADSPAPlugin::UPDATEPLUGIN); | |||
| // Wait until next update for data to be set up for new plugin | |||
| m_GUICH->Wait(); | |||
| // Now get the new values to populate GUI controls | |||
| m_GUICH->GetData("Name", m_NameString); | |||
| m_GUICH->GetData("Maker", m_MakerString); | |||
| m_GUICH->GetData("InputPortCount", &m_InputPortCount); | |||
| m_GUICH->GetData("InputPortMin", m_InputPortMin); | |||
| m_GUICH->GetData("InputPortMax", m_InputPortMax); | |||
| m_GUICH->GetData("InputPortClamp", m_InputPortClamp); | |||
| m_GUICH->GetData("InputPortNames", m_InputPortNames); | |||
| SetName((const char *)m_NameString); | |||
| SetMaker((const char *)m_MakerString); | |||
| // Clear out port info, and refresh | |||
| ClearPortInfo(); | |||
| for (unsigned long n = 0; n < m_InputPortCount; n++) { | |||
| AddPortInfo((const char *)(m_InputPortNames + n * 256)); | |||
| SetMinMax(n, m_InputPortMin[n], m_InputPortMax[n], m_InputPortClamp[n]); | |||
| } | |||
| } | |||
| void LADSPAPluginGUI::cb_Select(Fl_Hold_Browser* o) | |||
| { | |||
| ((LADSPAPluginGUI*)(o->parent()))->cb_Select_i(o); | |||
| } | |||
| void LADSPAPluginGUI::cb_Select(Fl_Hold_Browser* o) | |||
| { ((LADSPAPluginGUI*)(o->parent()))->cb_Select_i(o);} | |||
| inline void LADSPAPluginGUI::cb_MinMax_i(Fl_Button* o, void* v) | |||
| { | |||
| inline void LADSPAPluginGUI::cb_MinMax_i(Fl_Button* o, void* v) | |||
| { | |||
| int n=0; | |||
| for (vector<Fl_Input*>::iterator i=m_PortMin.begin(); | |||
| i!=m_PortMin.end(); i++) | |||
| i!=m_PortMin.end(); i++) | |||
| { | |||
| m_GUICH->Set("Min",(float)(n,atof((*i)->value()))); | |||
| n++; | |||
| } | |||
| n=0; | |||
| for (vector<Fl_Input*>::iterator i=m_PortMax.begin(); | |||
| i!=m_PortMax.end(); i++) | |||
| i!=m_PortMax.end(); i++) | |||
| { | |||
| m_GUICH->Set("Max",(n,atof((*i)->value()))); | |||
| n++; | |||
| } | |||
| n=0; | |||
| for (vector<Fl_Check_Button*>::iterator i=m_PortClamp.begin(); | |||
| i!=m_PortClamp.end(); i++) | |||
| { | |||
| m_GUICH->Set("Clamp",(bool)(n,(*i)->value())); | |||
| n++; | |||
| } | |||
| } | |||
| void LADSPAPluginGUI::cb_MinMax(Fl_Button* o, void* v) | |||
| { ((LADSPAPluginGUI*)(o->parent()))->cb_MinMax_i(o,v);} | |||
| void LADSPAPluginGUI::cb_MinMax(Fl_Button* o, void* v) | |||
| { | |||
| ((LADSPAPluginGUI*)(o->parent()))->cb_MinMax_i(o,v); | |||
| } | |||
| inline void LADSPAPluginGUI::cb_PowerAmp_i(Fl_Button* o, void* v) | |||
| { | |||
| inline void LADSPAPluginGUI::cb_PowerAmp_i(Fl_Button* o, void* v) | |||
| { | |||
| m_GUICH->Set("Amped",(bool)(o->value())); | |||
| } | |||
| void LADSPAPluginGUI::cb_PowerAmp(Fl_Button* o, void* v) | |||
| { ((LADSPAPluginGUI*)(o->parent()))->cb_PowerAmp_i(o,v);} | |||
| void LADSPAPluginGUI::cb_PowerAmp(Fl_Button* o, void* v) | |||
| { | |||
| ((LADSPAPluginGUI*)(o->parent()))->cb_PowerAmp_i(o,v); | |||
| } | |||
| @@ -39,8 +39,8 @@ | |||
| #ifndef LADSPAGUI | |||
| #define LADSPAGUI | |||
| #include <stdio.h> | |||
| #include <math.h> | |||
| #include <cstdio> | |||
| #include <cmath> | |||
| #include <dlfcn.h> | |||
| #include <vector> | |||
| @@ -65,35 +65,35 @@ public: | |||
| string GetLabel() { return m_Label; } | |||
| void SetFilename(string s) { m_Filename=s; } | |||
| void SetLabel(string s) { m_Label=s; } | |||
| private: | |||
| LPluginInfo m_CurrentPlugin; | |||
| Fl_Scroll *m_InputScroll; | |||
| Fl_Pack *m_InputPack; | |||
| Fl_Hold_Browser *m_Browser; | |||
| Fl_Knob *m_OutputGain; | |||
| Fl_Box *m_Name; | |||
| Fl_Box *m_Maker; | |||
| Fl_Button *m_UpdateInputs; | |||
| Fl_Button *m_UpdateMinMax; | |||
| Fl_Button *m_PowerAmp; | |||
| vector<Fl_Output*> m_PortOutput; | |||
| vector<Fl_Input*> m_PortMin; | |||
| vector<Fl_Input*> m_PortMax; | |||
| Fl_Scroll *m_InputScroll; | |||
| Fl_Pack *m_InputPack; | |||
| Fl_Hold_Browser *m_Browser; | |||
| Fl_Knob *m_OutputGain; | |||
| Fl_Box *m_Name; | |||
| Fl_Box *m_Maker; | |||
| Fl_Button *m_UpdateInputs; | |||
| Fl_Button *m_UpdateMinMax; | |||
| Fl_Button *m_PowerAmp; | |||
| vector<Fl_Output*> m_PortOutput; | |||
| vector<Fl_Input*> m_PortMin; | |||
| vector<Fl_Input*> m_PortMax; | |||
| vector<Fl_Check_Button*> m_PortClamp; | |||
| vector<LPluginInfo> PluginList; | |||
| // this is needed as fltk seems to crash if you delete | |||
| // the pack, is won't delete the children properly??? | |||
| vector<Fl_Group*> m_PackVec; | |||
| int inited; | |||
| string m_Filename; | |||
| string m_Label; | |||
| inline void cb_Select_i(Fl_Hold_Browser* o); | |||
| static void cb_Select(Fl_Hold_Browser* o); | |||
| inline void cb_Gain_i(Fl_Knob* o, void* v); | |||
| @@ -103,6 +103,19 @@ private: | |||
| inline void cb_PowerAmp_i(Fl_Button* o, void* v); | |||
| static void cb_PowerAmp(Fl_Button* o, void* v); | |||
| // This lot is for copying plugin info from the audio thread | |||
| // to the GUI thread, via ChannelHandler | |||
| char *m_NameString; // Plugin Name | |||
| char *m_MakerString; // Plugin Maker; | |||
| unsigned long m_InputPortCountMax; // Maximum number of input ports | |||
| // Corresponds to input port count of one | |||
| // (or more) plugins found | |||
| unsigned long m_InputPortCount; // Number of input ports in current plugin | |||
| float *m_InputPortMin; // Input port range minima | |||
| float *m_InputPortMax; // Input port range maxima | |||
| bool *m_InputPortClamp; // Input port clamp state | |||
| char *m_InputPortNames; // Input port names | |||
| }; | |||