Browse Source

Fixed on-load update of port display

master
waxfrenzy 22 years ago
parent
commit
ba657e97fc
4 changed files with 138 additions and 101 deletions
  1. +55
    -55
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.C
  2. +37
    -15
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.h
  3. +42
    -28
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.C
  4. +4
    -3
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.h

+ 55
- 55
SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.C View File

@@ -29,8 +29,10 @@
/* FIXME: No matter what, I can't let this as it!! */
static LADSPAPlugin * lg = NULL;

void describePluginLibrary(const char * pcFullFilename, void * pvPluginHandle,
LADSPA_Descriptor_Function pfDescriptorFunction) {
void describePluginLibrary(const char * pcFullFilename,
void * pvPluginHandle,
LADSPA_Descriptor_Function pfDescriptorFunction)
{
const LADSPA_Descriptor * psDescriptor;
long lIndex;
unsigned long lPluginIndex;
@@ -47,25 +49,25 @@ void describePluginLibrary(const char * pcFullFilename, void * pvPluginHandle,
}
for (lIndex = 0; (psDescriptor = pfDescriptorFunction(lIndex)) != NULL; lIndex++) {
int failure = 0;
testcond(!LADSPA_IS_REALTIME(psDescriptor->Properties), "ERROR: PLUGIN MUST RUN REAL TIME.\n");
testcond(psDescriptor->instantiate, "ERROR: PLUGIN HAS NO INSTANTIATE FUNCTION.\n");
testcond(psDescriptor->connect_port, "ERROR: PLUGIN HAS NO CONNECT_PORT FUNCTION.\n");
testcond(!LADSPA_IS_REALTIME(psDescriptor->Properties), "ERROR: PLUGIN MUST RUN REAL TIME.\n");
testcond(psDescriptor->instantiate, "ERROR: PLUGIN HAS NO INSTANTIATE FUNCTION.\n");
testcond(psDescriptor->connect_port, "ERROR: PLUGIN HAS NO CONNECT_PORT FUNCTION.\n");
testcond(psDescriptor->run, "ERROR: PLUGIN HAS NO RUN FUNCTION.\n");
testcond(!(psDescriptor->run_adding != 0 && psDescriptor->set_run_adding_gain == 0),
"ERROR: PLUGIN HAS RUN_ADDING FUNCTION BUT NOT SET_RUN_ADDING_GAIN.\n");
testcond(!(psDescriptor->run_adding == 0 && psDescriptor->set_run_adding_gain != 0),
"ERROR: PLUGIN HAS SET_RUN_ADDING_GAIN FUNCTION BUT NOT RUN_ADDING.\n");
testcond(psDescriptor->cleanup, "ERROR: PLUGIN HAS NO CLEANUP FUNCTION.\n");
testcond(!LADSPA_IS_INPLACE_BROKEN(psDescriptor->Properties),
"ERROR: PLUGIN HAS SET_RUN_ADDING_GAIN FUNCTION BUT NOT RUN_ADDING.\n");
testcond(psDescriptor->cleanup, "ERROR: PLUGIN HAS NO CLEANUP FUNCTION.\n");
testcond(!LADSPA_IS_INPLACE_BROKEN(psDescriptor->Properties),
"ERROR: THIS PLUGIN CANNOT USE IN-PLACE PROCESSING.\n");
testcond(psDescriptor->PortCount, "ERROR: PLUGIN HAS NO PORTS.\n");
testcond(psDescriptor->PortCount, "ERROR: PLUGIN HAS NO PORTS.\n");

if (!failure) {
LPluginInfo pi;
pi.Filename = pcFullFilename;
pi.Label = psDescriptor->Label;
pi.Name = psDescriptor->Name;
pi.InputPorts = getPortCountByType(psDescriptor, LADSPA_PORT_INPUT);
pi.InputPortCount = getPortCountByType(psDescriptor, LADSPA_PORT_INPUT);

// ARGH! I really can't stand this ugly hack
lg->m_LADSPAList.push_back(pi);
@@ -128,39 +130,39 @@ m_Amped(false)
m_PluginInfo.NumOutputs=1;
m_PluginInfo.PortTips.push_back("Nuffink yet");

m_ChannelData.MaxInputPorts = 0;
m_ChannelData.InputPorts = 0;
m_MaxInputPortCount = 0;
m_InputPortCount = 0;

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).InputPorts > m_ChannelData.MaxInputPorts)
m_ChannelData.MaxInputPorts = (*i).InputPorts;
if ((*i).InputPortCount > m_MaxInputPortCount)
m_MaxInputPortCount = (*i).InputPortCount;
}

// For receiving from GUI
m_AudioCH->Register("Gain",&(m_Gain));
m_AudioCH->Register("Amped",&(m_Amped));
m_AudioCH->RegisterData("PluginIndex", ChannelHandler::INPUT,&(m_ChannelData.PluginIndex),sizeof(m_ChannelData.PluginIndex));
m_AudioCH->Register("SetGain",&(m_InData.Gain));
m_AudioCH->Register("SetAmped",&(m_InData.Amped));
m_AudioCH->RegisterData("SetPluginIndex", ChannelHandler::INPUT,&(m_InData.PluginIndex),sizeof(m_InData.PluginIndex));

// For sending to GUI
m_AudioCH->RegisterData("Name",ChannelHandler::OUTPUT,m_ChannelData.Name,256);
m_AudioCH->RegisterData("Maker",ChannelHandler::OUTPUT,m_ChannelData.Maker,256);
m_AudioCH->RegisterData("MaxInputPorts",ChannelHandler::OUTPUT,&(m_ChannelData.MaxInputPorts),sizeof(m_ChannelData.MaxInputPorts));
m_AudioCH->RegisterData("InputPorts",ChannelHandler::OUTPUT,&(m_ChannelData.InputPorts),sizeof(m_ChannelData.InputPorts));
m_ChannelData.InputPortNames = (char *)malloc(256 * m_ChannelData.MaxInputPorts);
m_ChannelData.SetInputPortRanges = (PortRange *)malloc(sizeof(PortRange) * m_ChannelData.MaxInputPorts);
m_ChannelData.GetInputPortRanges = (PortRange *)malloc(sizeof(PortRange) * m_ChannelData.MaxInputPorts);
if (m_ChannelData.InputPortNames &&
m_ChannelData.SetInputPortRanges &&
m_ChannelData.GetInputPortRanges) {
m_AudioCH->RegisterData("InputPortNames", ChannelHandler::OUTPUT, m_ChannelData.InputPortNames, 256 * m_ChannelData.MaxInputPorts);
m_AudioCH->RegisterData("GetInputPortRanges", ChannelHandler::OUTPUT, m_ChannelData.GetInputPortRanges, sizeof(PortRange) * m_ChannelData.MaxInputPorts);
m_AudioCH->RegisterData("SetInputPortRanges", ChannelHandler::INPUT, m_ChannelData.SetInputPortRanges, sizeof(PortRange) * m_ChannelData.MaxInputPorts);
m_AudioCH->RegisterData("GetName",ChannelHandler::OUTPUT,m_Name,256);
m_AudioCH->RegisterData("GetMaker",ChannelHandler::OUTPUT,m_Maker,256);
m_AudioCH->RegisterData("GetMaxInputPortCount",ChannelHandler::OUTPUT,&(m_MaxInputPortCount),sizeof(m_MaxInputPortCount));
m_AudioCH->RegisterData("GetInputPortCount",ChannelHandler::OUTPUT,&(m_InputPortCount),sizeof(m_InputPortCount));
m_OutData.InputPortNames = (char *)malloc(256 * m_MaxInputPortCount);
m_OutData.InputPortRanges = (PortRange *)malloc(sizeof(PortRange) * m_MaxInputPortCount);
m_InData.InputPortRanges = (PortRange *)malloc(sizeof(PortRange) * m_MaxInputPortCount);
if (m_OutData.InputPortNames &&
m_OutData.InputPortRanges &&
m_InData.InputPortRanges) {
m_AudioCH->RegisterData("GetInputPortNames", ChannelHandler::OUTPUT, m_OutData.InputPortNames, 256 * m_MaxInputPortCount);
m_AudioCH->RegisterData("GetInputPortRanges", ChannelHandler::OUTPUT, m_OutData.InputPortRanges, sizeof(PortRange) * m_MaxInputPortCount);
m_AudioCH->RegisterData("SetInputPortRanges", ChannelHandler::INPUT, m_InData.InputPortRanges, sizeof(PortRange) * m_MaxInputPortCount);
} else {
cerr<<"Memory allocation error"<<endl;
}
@@ -169,9 +171,9 @@ m_Amped(false)
LADSPAPlugin::~LADSPAPlugin()
{
// Free allocated buffers
if (m_ChannelData.InputPortNames) free(m_ChannelData.InputPortNames);
if (m_ChannelData.SetInputPortRanges) free(m_ChannelData.SetInputPortRanges);
if (m_ChannelData.GetInputPortRanges) free(m_ChannelData.GetInputPortRanges);
if (m_OutData.InputPortNames) free(m_OutData.InputPortNames);
if (m_OutData.InputPortRanges) free(m_OutData.InputPortRanges);
if (m_InData.InputPortRanges) free(m_InData.InputPortRanges);
}

PluginInfo &LADSPAPlugin::Initialise(const HostInfo *Host)
@@ -255,8 +257,8 @@ void LADSPAPlugin::ExecuteCommands()
{
switch(m_AudioCH->GetCommand())
{
case (UPDATERANGES) : UpdatePortRanges(); break;
case (UPDATEPLUGIN) : UpdatePlugin(m_ChannelData.PluginIndex); break;
case (SETRANGES) : SetPortInfo(); break;
case (SELECTPLUGIN) : UpdatePlugin(m_InData.PluginIndex); break;
};
}
}
@@ -408,7 +410,7 @@ void LADSPAPlugin::StreamIn(istream &s)
}

m_CurrentPlugin.Ports.reserve(PortCount);
for (int n=0; n<PortCount; n++)
{
m_CurrentPlugin.Ports[n].Min=m_PortMin[n];
@@ -601,33 +603,31 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool
}
}

// Finally, we need to supply the GUI with information via
// ChannelHandler.
m_ChannelData.InputPorts = m_PluginInfo.NumInputs;
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_ChannelData.Name, m_CurrentPlugin.Name.substr(0, lbl_length).c_str(), lbl_length);
m_ChannelData.Name[lbl_length] = '\0';
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_ChannelData.Maker, m_CurrentPlugin.Maker.substr(0, lbl_length).c_str(), lbl_length);
m_ChannelData.Maker[lbl_length] = '\0';
strncpy(m_Maker, m_CurrentPlugin.Maker.substr(0, lbl_length).c_str(), lbl_length);
m_Maker[lbl_length] = '\0';

lbl_start = m_ChannelData.InputPortNames;
for (unsigned long n = 0; n < m_ChannelData.InputPorts; n++) {
lbl_start = m_OutData.InputPortNames;
for (unsigned long n = 0; n < m_InputPortCount; n++) {
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;

m_ChannelData.GetInputPortRanges[n].Min = m_CurrentPlugin.Ports[n].Min;
m_ChannelData.GetInputPortRanges[n].Max = m_CurrentPlugin.Ports[n].Max;
m_ChannelData.GetInputPortRanges[n].Clamp = m_CurrentPlugin.Ports[n].Clamped;
m_OutData.InputPortRanges[n].Min = m_CurrentPlugin.Ports[n].Min;
m_OutData.InputPortRanges[n].Max = m_CurrentPlugin.Ports[n].Max;
m_OutData.InputPortRanges[n].Clamp = m_CurrentPlugin.Ports[n].Clamped;
}

return true;
@@ -639,11 +639,11 @@ bool LADSPAPlugin::UpdatePlugin(const char * filename, const char * label, bool
return false;
}

void LADSPAPlugin::UpdatePortRanges(void)
void LADSPAPlugin::SetPortInfo(void)
{
for (unsigned long n = 0; n < m_ChannelData.InputPorts; n++) {
m_PortMin[n] = m_ChannelData.SetInputPortRanges[n].Min;
m_PortMax[n] = m_ChannelData.SetInputPortRanges[n].Max;
m_PortClamp[n] = m_ChannelData.SetInputPortRanges[n].Clamp;
for (unsigned long n = 0; n < m_InputPortCount; n++) {
m_PortMin[n] = m_InData.InputPortRanges[n].Min;
m_PortMax[n] = m_InData.InputPortRanges[n].Max;
m_PortClamp[n] = m_InData.InputPortRanges[n].Clamp;
}
}

+ 37
- 15
SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.h View File

@@ -32,12 +32,12 @@ public:
string Label;
string Name;
string Maker;
unsigned long InputPorts;
unsigned long InputPortCount;

struct LPortDetails
{
string Name;
float Min,Max;
float Min, Max;
bool Clamped;
};

@@ -76,17 +76,29 @@ public:
virtual void StreamOut(ostream &s);
virtual void StreamIn(istream &s);

float GetGain() { return m_Gain; }
bool GetAmped() { return m_Amped; }
float GetGain() { return m_Gain; }
bool GetAmped() { return m_Amped; }
const char *GetName() { return (const char *)m_Name; }
const char *GetMaker() { return (const char *)m_Maker; }
unsigned long GetInputPortCount() { return m_InputPortCount; }
const char *GetPortName(unsigned long p) { return (const char *)(m_OutData.InputPortNames + p * 256); }
PortRange GetPortRange(unsigned long p)
{
PortRange range;
range.Min = m_PortMin[p];
range.Max = m_PortMax[p];
range.Clamp = m_PortClamp[p];
return range;
}

enum GUICommands{NONE,UPDATERANGES,UPDATEPLUGIN};
enum GUICommands{NONE,SETRANGES,SELECTPLUGIN};

private:

void UpdatePortRange(void);
bool UpdatePlugin(int n);
bool UpdatePlugin(const char * filename, const char * label, bool PortClampReset=true);
void UpdatePortRanges(void);
void SetPortInfo(void);

friend void describePluginLibrary(const char * pcFullFilename, void * pvPluginHandle, LADSPA_Descriptor_Function pfDescriptorFunction);
void LoadPluginList(void);
@@ -108,20 +120,30 @@ private:

float m_Gain;
bool m_Amped;
unsigned long m_MaxInputPortCount;
unsigned long m_InputPortCount;
char m_Name[256];
char m_Maker[256];

struct ChannelData

// Data sent to GUI
struct OutputChannelData
{
unsigned long PluginIndex;
char Name[256];
char Maker[256];
unsigned long MaxInputPorts;
unsigned long InputPorts;
char *InputPortNames;
PortRange *SetInputPortRanges;
PortRange *GetInputPortRanges;
PortRange *InputPortRanges;
};

// Data received from GUI
struct InputChannelData
{
unsigned long PluginIndex;
float Gain;
bool Amped;
PortRange *InputPortRanges;
};

ChannelData m_ChannelData;
OutputChannelData m_OutData;
InputChannelData m_InData;
};

#endif

+ 42
- 28
SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.C View File

@@ -51,13 +51,13 @@ SpiralPluginGUI(w,h,o,ch)
}

// Get maximum input port count
m_GUICH->GetData("MaxInputPorts",&(m_ChannelData.MaxInputPorts));
m_GUICH->GetData("GetMaxInputPortCount",&(m_InData.MaxInputPorts));

// Set up buffers for data transfer via ChannelHandler
m_ChannelData.InputPortNames = (char *)malloc(256 * m_ChannelData.MaxInputPorts);
m_ChannelData.InputPortRanges = (PortRange *)malloc(sizeof(PortRange) * m_ChannelData.MaxInputPorts);
m_InData.InputPortNames = (char *)malloc(256 * m_InData.MaxInputPorts);
m_InData.InputPortRanges = (PortRange *)malloc(sizeof(PortRange) * m_InData.MaxInputPorts);

if (!(m_ChannelData.InputPortNames && m_ChannelData.InputPortRanges)) {
if (!(m_InData.InputPortNames && m_InData.InputPortRanges)) {
cerr<<"Memory allocation error\n"<<endl;
}

@@ -114,8 +114,8 @@ SpiralPluginGUI(w,h,o,ch)

LADSPAPluginGUI::~LADSPAPluginGUI(void)
{
if (m_ChannelData.InputPortNames) free(m_ChannelData.InputPortNames);
if (m_ChannelData.InputPortRanges) free(m_ChannelData.InputPortRanges);
if (m_InData.InputPortNames) free(m_InData.InputPortNames);
if (m_InData.InputPortRanges) free(m_InData.InputPortRanges);
Fl::check();
}

@@ -225,11 +225,25 @@ void LADSPAPluginGUI::UpdateValues(SpiralPlugin *o)
{
LADSPAPlugin* Plugin = (LADSPAPlugin*)o;
m_OutputGain->value(Plugin->GetGain());
m_PowerAmp->value(Plugin->GetAmped());
SetName(Plugin->GetName());
SetMaker(Plugin->GetMaker());

unsigned long n = Plugin->GetInputPortCount();
const char *name;
PortRange range;

for (unsigned long p = 0; p < n; p++) {
name = Plugin->GetPortName(p);
range = Plugin->GetPortRange(p);
AddPortInfo(name);
SetMinMax(p, range.Min, range.Max, range.Clamp);
}
}

inline void LADSPAPluginGUI::cb_Gain_i(Fl_Knob* o, void* v)
{
m_GUICH->Set("Gain",(float)(o->value()));
m_GUICH->Set("SetGain",(float)(o->value()));
}
void LADSPAPluginGUI::cb_Gain(Fl_Knob* o, void* v)
{
@@ -241,30 +255,30 @@ 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("PluginIndex",o->value()-1);
m_GUICH->SetCommand(LADSPAPlugin::UPDATEPLUGIN);
m_GUICH->Set("SetPluginIndex",o->value()-1);
m_GUICH->SetCommand(LADSPAPlugin::SELECTPLUGIN);

// Wait until next update for data to be set up for new plugin
// Wait until next update for plugin to be loaded etc.
m_GUICH->Wait();

// Now get the new values to populate GUI controls
m_GUICH->GetData("Name", m_ChannelData.Name);
m_GUICH->GetData("Maker", m_ChannelData.Maker);
m_GUICH->GetData("InputPorts", &(m_ChannelData.InputPorts));
m_GUICH->GetData("InputPortNames", m_ChannelData.InputPortNames);
m_GUICH->GetData("GetInputPortRanges", m_ChannelData.InputPortRanges);
m_GUICH->GetData("GetName", m_InData.Name);
m_GUICH->GetData("GetMaker", m_InData.Maker);
m_GUICH->GetData("GetInputPortCount", &(m_InData.InputPorts));
m_GUICH->GetData("GetInputPortNames", m_InData.InputPortNames);
m_GUICH->GetData("GetInputPortRanges", m_InData.InputPortRanges);

SetName((const char *)m_ChannelData.Name);
SetMaker((const char *)m_ChannelData.Maker);
SetName((const char *)m_InData.Name);
SetMaker((const char *)m_InData.Maker);

// Clear out port info, and refresh
ClearPortInfo();

for (unsigned long n = 0; n < m_ChannelData.InputPorts; n++) {
AddPortInfo((const char *)(m_ChannelData.InputPortNames + n * 256));
SetMinMax(n, m_ChannelData.InputPortRanges[n].Min,
m_ChannelData.InputPortRanges[n].Max,
m_ChannelData.InputPortRanges[n].Clamp);
for (unsigned long n = 0; n < m_InData.InputPorts; n++) {
AddPortInfo((const char *)(m_InData.InputPortNames + n * 256));
SetMinMax(n, m_InData.InputPortRanges[n].Min,
m_InData.InputPortRanges[n].Max,
m_InData.InputPortRanges[n].Clamp);
}
}
void LADSPAPluginGUI::cb_Select(Fl_Hold_Browser* o)
@@ -278,26 +292,26 @@ inline void LADSPAPluginGUI::cb_MinMax_i(Fl_Button* o, void* v)
for (vector<Fl_Input*>::iterator i=m_PortMin.begin();
i!=m_PortMin.end(); i++)
{
m_ChannelData.InputPortRanges[n].Min = atof((*i)->value());
m_InData.InputPortRanges[n].Min = atof((*i)->value());
n++;
}
n=0;
for (vector<Fl_Input*>::iterator i=m_PortMax.begin();
i!=m_PortMax.end(); i++)
{
m_ChannelData.InputPortRanges[n].Max = atof((*i)->value());
m_InData.InputPortRanges[n].Max = atof((*i)->value());
n++;
}
n=0;
for (vector<Fl_Check_Button*>::iterator i=m_PortClamp.begin();
i!=m_PortClamp.end(); i++)
{
m_ChannelData.InputPortRanges[n].Clamp = (bool)((*i)->value());
m_InData.InputPortRanges[n].Clamp = (bool)((*i)->value());
n++;
}

m_GUICH->SetData("SetInputPortRanges", m_ChannelData.InputPortRanges);
m_GUICH->SetCommand(LADSPAPlugin::UPDATERANGES);
m_GUICH->SetData("SetInputPortRanges", m_InData.InputPortRanges);
m_GUICH->SetCommand(LADSPAPlugin::SETRANGES);
}
void LADSPAPluginGUI::cb_MinMax(Fl_Button* o, void* v)
{
@@ -306,7 +320,7 @@ void LADSPAPluginGUI::cb_MinMax(Fl_Button* o, void* v)

inline void LADSPAPluginGUI::cb_PowerAmp_i(Fl_Button* o, void* v)
{
m_GUICH->Set("Amped",(bool)(o->value()));
m_GUICH->Set("SetAmped",(bool)(o->value()));
}
void LADSPAPluginGUI::cb_PowerAmp(Fl_Button* o, void* v)
{


+ 4
- 3
SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.h View File

@@ -103,8 +103,9 @@ private:
inline void cb_PowerAmp_i(Fl_Button* o, void* v);
static void cb_PowerAmp(Fl_Button* o, void* v);

struct ChannelData
struct InChannelData
{
float Gain;
char Name[256];
char Maker[256];
unsigned long MaxInputPorts;
@@ -112,8 +113,8 @@ private:
char *InputPortNames;
PortRange *InputPortRanges;
};
ChannelData m_ChannelData;
InChannelData m_InData;
};




Loading…
Cancel
Save