Browse Source

Control knobs now work with LADSPA Integer and Logarithmic hints

master
waxfrenzy 22 years ago
parent
commit
74dec7d10c
4 changed files with 243 additions and 132 deletions
  1. +37
    -19
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.C
  2. +24
    -17
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.h
  3. +172
    -88
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.C
  4. +10
    -8
      SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.h

+ 37
- 19
SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.C View File

@@ -67,9 +67,10 @@ LADSPAPlugin::LADSPAPlugin()
{
#ifdef USE_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)
// We keep two things:
// 1. A reference counter, counting LADSPAPlugin instances
// 2. A pointer to the database. We can get away with just a pointer as
// all instances are in the same address space (SSM audio thread)

int shm_rc_fd;
int shm_db_fd;
@@ -157,17 +158,18 @@ LADSPAPlugin::LADSPAPlugin()
m_AudioCH->RegisterData("GetInputPortCount",ChannelHandler::OUTPUT,&(m_InputPortCount),sizeof(m_InputPortCount));

m_OutData.InputPortNames = (char *)malloc(256 * m_MaxInputPortCount);
m_OutData.InputPortSettings = (PortSettings *)malloc(sizeof(PortSettings) * m_MaxInputPortCount);
m_OutData.InputPortValues = (PortValues *)calloc(m_MaxInputPortCount, sizeof(PortValues));
m_OutData.InputPortSettings = (PortSetting *)malloc(sizeof(PortSetting) * m_MaxInputPortCount);
m_OutData.InputPortValues = (PortValue *)calloc(m_MaxInputPortCount, sizeof(PortValue));
m_OutData.InputPortDefaults = (float *)calloc(m_MaxInputPortCount, sizeof(float));

if (m_OutData.InputPortNames &&
m_OutData.InputPortDefaults &&
m_OutData.InputPortSettings &&
m_OutData.InputPortValues) {
m_OutData.InputPortValues &&
m_OutData.InputPortDefaults)
{
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("GetInputPortSettings", ChannelHandler::OUTPUT, m_OutData.InputPortSettings, sizeof(PortSetting) * m_MaxInputPortCount);
m_AudioCH->RegisterData("GetInputPortValues", ChannelHandler::OUTPUT, m_OutData.InputPortValues, sizeof(PortValue) * m_MaxInputPortCount);
m_AudioCH->RegisterData("GetInputPortDefaults", ChannelHandler::OUTPUT, m_OutData.InputPortDefaults, sizeof(float) * m_MaxInputPortCount);
} else {
cerr<<"LADSPA Plugin: Memory allocation error"<<endl;
@@ -1046,13 +1048,13 @@ void LADSPAPlugin::ResetPortSettings(void)
} else {
// These hints may be affected by SAMPLERATE, LOGARITHMIC and INTEGER
if (LADSPA_IS_HINT_DEFAULT_MINIMUM(HintDesc) &&
LADSPA_IS_HINT_BOUNDED_BELOW(HintDesc)) {
LADSPA_IS_HINT_BOUNDED_BELOW(HintDesc)) {
Default=m_PlugDesc->PortRangeHints[Port].LowerBound;
} else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(HintDesc) &&
LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc)) {
LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc)) {
Default=m_PlugDesc->PortRangeHints[Port].UpperBound;
} else if (LADSPA_IS_HINT_BOUNDED_BELOW(HintDesc) &&
LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc)) {
LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc)) {
// These hints require both upper and lower bounds
float lp = 0.0f, up = 0.0f;
float min = m_PlugDesc->PortRangeHints[Port].LowerBound;
@@ -1109,6 +1111,7 @@ void LADSPAPlugin::ResetPortSettings(void)
#warning www.ladspa.org
#warning Defaults will not be used.
#warning ************************************
Default = 0.0f;
#endif

m_InputPortMin.push_back(Min);
@@ -1124,16 +1127,31 @@ void LADSPAPlugin::SetGUIExports(void)
char *lbl_start;

lbl_start = m_OutData.InputPortNames;
for (unsigned long n = 0; n < m_InputPortCount; n++) {
lbl_length = m_PluginInfo.PortTips[n].size();
for (unsigned long p = 0; p < m_InputPortCount; p++) {
int Port = m_PortID[p];
LADSPA_PortRangeHintDescriptor HintDesc=m_PlugDesc->PortRangeHints[Port].HintDescriptor;

// Port Labels
lbl_length = m_PluginInfo.PortTips[p].size();
lbl_length = lbl_length > 255 ? 255 : lbl_length;
strncpy(lbl_start, m_PluginInfo.PortTips[n].c_str(), lbl_length);
strncpy(lbl_start, m_PluginInfo.PortTips[p].c_str(), lbl_length);
lbl_start[lbl_length] = '\0';
lbl_start += 256;

m_OutData.InputPortSettings[n].Min = m_InputPortMin[n];
m_OutData.InputPortSettings[n].Max = m_InputPortMax[n];
m_OutData.InputPortSettings[n].Clamp = m_InputPortClamp[n];
m_OutData.InputPortDefaults[n] = m_InputPortDefault[n];
m_OutData.InputPortSettings[p].Integer = LADSPA_IS_HINT_INTEGER(HintDesc);
if (LADSPA_IS_HINT_LOGARITHMIC(HintDesc)) {
if (LADSPA_IS_HINT_SAMPLE_RATE(HintDesc)) {
m_OutData.InputPortSettings[p].LogBase = 2.0f;
} else {
m_OutData.InputPortSettings[p].LogBase = 10.0f;
}
} else {
m_OutData.InputPortSettings[p].LogBase = 0.0f;
}

m_OutData.InputPortSettings[p].Min = m_InputPortMin[p];
m_OutData.InputPortSettings[p].Max = m_InputPortMax[p];
m_OutData.InputPortSettings[p].Clamp = m_InputPortClamp[p];
m_OutData.InputPortDefaults[p] = m_InputPortDefault[p];
}
}

+ 24
- 17
SpiralSound/Plugins/LADSPAPlugin/LADSPAPlugin.h View File

@@ -21,19 +21,28 @@
#ifndef __ladspa_plugin_h__
#define __ladspa_plugin_h__

#include <config.h>

#include <FL/Fl_Pixmap.H>
#include <ladspa.h>

#include "../SpiralPlugin.h"
#include "LADSPAInfo.h"

struct PortSettings
#ifdef USE_POSIX_SHM
#include <sys/types.h> // For pid_t data member
#include <unistd.h>
#endif

struct PortSetting
{
float Min;
float Max;
bool Clamp;
float Min;
float Max;
bool Clamp;
float LogBase; // >1.0 -> Logarithmic, otherwise linear
bool Integer;
};
struct PortValues
struct PortValue
{
float Value;
bool Connected;
@@ -62,17 +71,13 @@ public:
{
return (const char *)(m_OutData.InputPortNames + p * 256);
}
PortSettings GetInputPortSettings(unsigned long p)
PortSetting GetInputPortSetting(unsigned long p)
{
PortSettings settings;
settings.Min = m_InputPortMin[p];
settings.Max = m_InputPortMax[p];
settings.Clamp = m_InputPortClamp[p];
return settings;
return m_OutData.InputPortSettings[p];
}
float GetInputPortDefault(unsigned long p)
float GetInputPortDefault(unsigned long p)
{
return m_InputPortDefault[p];
return m_OutData.InputPortDefaults[p];
}

enum GUICommands
@@ -117,17 +122,17 @@ private:

unsigned long m_MaxInputPortCount;
unsigned long m_InputPortCount;
char m_Name[256];
char m_Name[256];
char m_Maker[256];

// Data sent to GUI
struct OutputChannelData
{
char *InputPortNames;
PortSettings *InputPortSettings;
PortValues *InputPortValues;
PortSetting *InputPortSettings;
PortValue *InputPortValues;
float *InputPortDefaults;
};
};

// Data received from GUI
struct InputChannelData
@@ -145,12 +150,14 @@ private:
OutputChannelData m_OutData;
InputChannelData m_InData;

#ifdef USE_POSIX_SHM
// 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
};

#endif // __ladspa_plugin_h__

+ 172
- 88
SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.C View File

@@ -25,8 +25,8 @@
#include <vector>
#include <algorithm>

#include <FL/fl_draw.h>
#include <FL/fl_draw.H>
#include <FL/Fl_Tooltip.H>

#include "LADSPAPluginGUI.h"
#include "LADSPAInfo.h"
@@ -41,16 +41,13 @@ SpiralPluginGUI(w,h,o,ch)
m_GUIColour = (Fl_Color)Info->GUI_COLOUR;
m_PluginList = PVec;

int Width=20;
int Height=100;

// Get maximum input port count
m_GUICH->GetData("GetMaxInputPortCount",&(m_MaxInputPortCount));

// Set up buffers for data transfer via ChannelHandler
m_InputPortNames = (char *)malloc(256 * m_MaxInputPortCount);
m_InputPortSettings = (PortSettings *)malloc(sizeof(PortSettings) * m_MaxInputPortCount);
m_InputPortValues = (PortValues *)calloc(m_MaxInputPortCount, sizeof(PortValues));
m_InputPortSettings = (PortSetting *)malloc(sizeof(PortSetting) * m_MaxInputPortCount);
m_InputPortValues = (PortValue *)calloc(m_MaxInputPortCount, sizeof(PortValue));
m_InputPortDefaults = (float *)calloc(m_MaxInputPortCount, sizeof(float));

if (!(m_InputPortNames && m_InputPortSettings &&
@@ -182,9 +179,9 @@ SpiralPluginGUI(w,h,o,ch)

LADSPAPluginGUI::~LADSPAPluginGUI(void)
{
if (m_InputPortNames) free(m_InputPortNames);
if (m_InputPortNames) free(m_InputPortNames);
if (m_InputPortSettings) free(m_InputPortSettings);
if (m_InputPortValues) free(m_InputPortValues);
if (m_InputPortValues) free(m_InputPortValues);
if (m_InputPortDefaults) free(m_InputPortDefaults);

m_PluginIDLookup.clear();
@@ -195,7 +192,7 @@ LADSPAPluginGUI::~LADSPAPluginGUI(void)
// Rearrange knobs depending on connections
// Knobs corresponding to connected ports are hidden,
// the rest are shown
void LADSPAPluginGUI::UpdateDefaultAdjustControls(void)
void LADSPAPluginGUI::UpdatePortControlKnobs(void)
{
int column = 0;

@@ -218,9 +215,9 @@ void LADSPAPluginGUI::UpdateDefaultAdjustControls(void)
for (unsigned long p = 0; p < m_InputPortCount; p++)
{
if (!m_InputPortValues[p].Connected) {
m_PortDefaultAdjust[p]->position(50 + column * 105, 0);
m_PortDefaultAdjust[p]->show();
NewGroup->add(m_PortDefaultAdjust[p]);
m_PortControlKnobs[p]->position(50 + column * 105, 0);
m_PortControlKnobs[p]->show();
NewGroup->add(m_PortControlKnobs[p]);

column++;
if ((column > 3) && (p < m_InputPortCount - 1)) {
@@ -231,7 +228,7 @@ void LADSPAPluginGUI::UpdateDefaultAdjustControls(void)
column = 0;
}
} else {
m_PortDefaultAdjust[p]->hide();
m_PortControlKnobs[p]->hide();
}
}

@@ -250,19 +247,20 @@ void LADSPAPluginGUI::UpdateValues(SpiralPlugin *o)

m_InputPortCount = Plugin->GetInputPortCount();
const char *name;
PortSettings settings;
float defolt;

for (unsigned long p = 0; p < m_InputPortCount; p++) {
name = Plugin->GetInputPortName(p);
settings = Plugin->GetInputPortSettings(p);
defolt = Plugin->GetInputPortDefault(p);
AddPortInfo(name);
SetPortSettings(p, settings.Min, settings.Max, settings.Clamp, defolt);
SetDefaultAdjust(p);
strncpy((char *)(m_InputPortNames + p * 256), name, 256);

m_InputPortSettings[p] = Plugin->GetInputPortSetting(p);
m_InputPortDefaults[p] = Plugin->GetInputPortDefault(p);

AddPortInfo(p);
SetPortSettings(p);
SetPortControlKnobValue(p);
}

UpdateDefaultAdjustControls();
UpdatePortControlKnobs();

m_PortIndex = m_InputPortCount;
}
@@ -370,34 +368,85 @@ void LADSPAPluginGUI::SetMaker(const char *s)
m_MakerLabel->label (m_Maker);
}

void LADSPAPluginGUI::SetPortSettings(unsigned long n, float min, float max, bool clamp, float defolt)
void LADSPAPluginGUI::SetPortSettings(unsigned long p)
{
char temp[256];
sprintf(temp,"%.4f",min);
m_PortMin[n]->value(temp);
sprintf(temp,"%.4f", m_InputPortSettings[p].Min);
m_PortMin[p]->value(temp);

sprintf(temp,"%.4f",max);
m_PortMax[n]->value(temp);
sprintf(temp,"%.4f", m_InputPortSettings[p].Max);
m_PortMax[p]->value(temp);

sprintf(temp, "%d",clamp);
m_PortClamp[n]->value(atoi(temp));
sprintf(temp, "%d", m_InputPortSettings[p].Clamp);
m_PortClamp[p]->value(atoi(temp));

sprintf(temp, "%.4f",defolt);
m_PortDefault[n]->value(temp);
sprintf(temp, "%.4f", m_InputPortDefaults[p]);
m_PortDefault[p]->value(temp);
}

void LADSPAPluginGUI::SetDefaultAdjust(unsigned long n)
void LADSPAPluginGUI::SetPortControlKnobValue(unsigned long p)
{
// Set default adjust knob
float min = atof(m_PortMin[n]->value());
float max = atof(m_PortMax[n]->value());
float def = atof(m_PortDefault[n]->value());
float value = ((max - min) > 0.0f) ? (def - min) / (max - min) : 0.5f;
float min = atof(m_PortMin[p]->value());
float max = atof(m_PortMax[p]->value());
float value = atof(m_PortDefault[p]->value());

if (m_InputPortSettings[p].LogBase > 1.0f) {
// Logarithmic control - requires conversion
if (min > 0.0f && max > 0.0f) {
// Straight log
value = logf(value) / logf(m_InputPortSettings[p].LogBase);
} else if (min < 0.0f && max < 0.0f) {
// Inverse, negated log
value = -logf(-value) / logf(m_InputPortSettings[p].LogBase);
} else {
// Linear if asymptote present
// Do nothing
}
}

m_PortControlKnobs[p]->value(value);
}

m_PortDefaultAdjust[n]->value(value);
void LADSPAPluginGUI::SetPortControlKnobRange(unsigned long p, float min, float max)
{
if (m_InputPortSettings[p].Integer) {
// Integer control - integer steps between minimum and maximum
min = floorf(min + 0.5f);
max = floorf(max + 0.5f);

m_PortControlKnobs[p]->minimum(min);
m_PortControlKnobs[p]->maximum(max);
m_PortControlKnobs[p]->step(1.0f);
m_PortControlKnobs[p]->scaleticks((int)(max - min));
} else {
if (m_InputPortSettings[p].LogBase > 1.0f) {
// Continuous logarithmic control
if (min > 0.0f && max > 0.0f) {
// Log of range
min = logf(min) / logf(m_InputPortSettings[p].LogBase);
max = logf(max) / logf(m_InputPortSettings[p].LogBase);
} else if (min < 0.0f && max < 0.0f) {
// Negative log of range
min = -logf(-min) / logf(m_InputPortSettings[p].LogBase);
max = -logf(-max) / logf(m_InputPortSettings[p].LogBase);
} else {
// Linear if asymptote present
// Do nothing
}
m_PortControlKnobs[p]->minimum(min);
m_PortControlKnobs[p]->maximum(max);
m_PortControlKnobs[p]->step((max - min) / 10000.0f);
} else {
// Continuous linear control - 10000 steps between min and max
m_PortControlKnobs[p]->minimum(min);
m_PortControlKnobs[p]->maximum(max);
m_PortControlKnobs[p]->step((max - min) / 10000.0f);
}
}
}

void LADSPAPluginGUI::AddPortInfo(const char *Info)
void LADSPAPluginGUI::AddPortInfo(unsigned long p)
{
Fl_Group* NewGroup = new Fl_Group(0,0,460,24,"");
NewGroup->box(FL_FLAT_BOX);
@@ -445,8 +494,9 @@ void LADSPAPluginGUI::AddPortInfo(const char *Info)

// Port Name
Fl_Box* NewText = new Fl_Box(320,0,10,18,"");
NewText->label(Info);
NewText->label((const char *)(m_InputPortNames + p * 256));
NewText->labelsize(10);
NewText->tooltip((const char *)(m_InputPortNames + p * 256));
NewText->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
NewGroup->add(NewText);

@@ -456,26 +506,27 @@ void LADSPAPluginGUI::AddPortInfo(const char *Info)

// Control knobs - these aren't displayed yet, as their display will depend
// on what is connected. All that is decided in UpdateControlKnobs()
int len = strlen(Info);
int len = strlen((const char *)(m_InputPortNames + p * 256));
len -= 5; // Get rid of (CV), (AU) bit
len = len > 20 ? 20 : len; // Truncate to fit
char *label = (char *)malloc(len + 1);
if (label)
{
strncpy(label, Info, len);
strncpy(label, (const char *)(m_InputPortNames + p * 256), len);
label[len] = '\0';
}
m_PortDefaultAdjustLabels.push_back(label);
m_PortControlLabels.push_back(label);

Fl_Knob* NewKnob = new Fl_Knob(0,0,40,40,"");
NewKnob->label(m_PortDefaultAdjustLabels[m_PortDefaultAdjustLabels.size() - 1]);
NewKnob->label(m_PortControlLabels[m_PortControlLabels.size() - 1]);
NewKnob->labelsize(10);
NewKnob->color(m_GUIColour);
NewKnob->maximum(1.0f);
NewKnob->step(0.001f);
NewKnob->callback((Fl_Callback *)cb_DefaultAdjust);
NewKnob->hide();
m_PortDefaultAdjust.push_back(NewKnob);
m_PortControlKnobs.push_back(NewKnob);

// Set up range for knob (integer, logarithmic etc)
SetPortControlKnobRange(p, m_InputPortSettings[p].Min, m_InputPortSettings[p].Max);
}

// This is done all the time
@@ -509,10 +560,10 @@ void LADSPAPluginGUI::Update(void)

sprintf(temp,"%.4f", m_InputPortDefaults[p]);
m_PortDefault[p]->value(temp);

SetDefaultAdjust(p);
m_PortDefault[p]->redraw();

SetPortControlKnobValue(p);

state_changed = true;
}

@@ -530,7 +581,7 @@ void LADSPAPluginGUI::Update(void)

// If a connection has been added/removed, we need to
// rearrange the knobs
if (state_changed) UpdateDefaultAdjustControls();
if (state_changed) UpdatePortControlKnobs();
}

void LADSPAPluginGUI::ClearPlugin(void)
@@ -558,14 +609,16 @@ void LADSPAPluginGUI::ClearPlugin(void)
m_PortMax.clear();
m_PortClamp.clear();
m_PortDefault.clear();
m_PortDefaultAdjust.clear();
m_PortControlKnobs.clear();

for (vector<char *>::iterator i = m_PortDefaultAdjustLabels.begin();
i != m_PortDefaultAdjustLabels.end(); i++)
for (vector<char *>::iterator i = m_PortControlLabels.begin();
i != m_PortControlLabels.end(); i++)
{
if (*i) free (*i);
}
m_PortDefaultAdjustLabels.clear();
m_PortControlLabels.clear();

redraw();
}

void LADSPAPluginGUI::SelectPlugin(void)
@@ -582,16 +635,12 @@ void LADSPAPluginGUI::SelectPlugin(void)
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]);

SetDefaultAdjust(p);
AddPortInfo(p);
SetPortSettings(p);
SetPortControlKnobValue(p);
}

UpdateDefaultAdjustControls();
UpdatePortControlKnobs();
m_PortIndex = m_InputPortCount;

redraw();
@@ -621,16 +670,16 @@ inline void LADSPAPluginGUI::cb_Select_i(Fl_Choice* o)

if (m_UniqueID != 0) {
// Plugin selected
m_GUICH->SetData("SetUniqueID",&m_UniqueID);
m_GUICH->SetCommand(LADSPAPlugin::SELECTPLUGIN);
m_GUICH->Wait();
m_GUICH->SetData("SetUniqueID",&m_UniqueID);
m_GUICH->SetCommand(LADSPAPlugin::SELECTPLUGIN);
m_GUICH->Wait();
}
SelectPlugin();

// redraw();
}
void LADSPAPluginGUI::cb_Select(Fl_Choice* o)
{ // Group Tab GUI
{ // Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()))->cb_Select_i(o);
}

@@ -642,7 +691,7 @@ inline void LADSPAPluginGUI::cb_UpdateInputs_i(Fl_LED_Button* o)
m_GUICH->SetCommand(LADSPAPlugin::SETUPDATEINPUTS);
}
void LADSPAPluginGUI::cb_UpdateInputs(Fl_LED_Button* o)
{ // Group Tab GUI
{ // Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()))->cb_UpdateInputs_i(o);
}

@@ -665,25 +714,45 @@ inline void LADSPAPluginGUI::cb_Default_i(Fl_Input* o)
m_Min = atof(m_PortMin[m_PortIndex]->value());
m_Max = atof(m_PortMax[m_PortIndex]->value());

// Pass current port index
m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);

// If default is out of [Min, Max] range, stretch range
if (m_Default < m_Min) {
m_PortMin[m_PortIndex]->value(m_PortDefault[m_PortIndex]->value());
m_PortMin[m_PortIndex]->redraw();
m_Min = m_Default;

// Pass new Minimum to plugin
m_GUICH->SetData("SetInputPortMin", &m_Min);
m_GUICH->SetCommand(LADSPAPlugin::SETMAX);
m_GUICH->Wait();

// Reconfigure knob range
SetPortControlKnobRange(m_PortIndex, m_Min, m_Max);
} else if (m_Default > m_Max) {
m_PortMax[m_PortIndex]->value(m_PortDefault[m_PortIndex]->value());
m_PortMax[m_PortIndex]->redraw();
m_Max = m_Default;

// Pass new Maximum to plugin
m_GUICH->SetData("SetInputPortMax", &m_Max);
m_GUICH->SetCommand(LADSPAPlugin::SETMAX);
m_GUICH->Wait();

// Reconfigure knob range
SetPortControlKnobRange(m_PortIndex, m_Min, m_Max);
}

// Pass value to plugin
m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
// Pass new default to plugin
m_GUICH->SetData("SetInputPortDefault", &m_Default);
m_GUICH->SetCommand(LADSPAPlugin::SETDEFAULT);

// Set Default Adjust knob to corresponding position
SetDefaultAdjust(m_PortIndex);
// Set knob to corresponding position
SetPortControlKnobValue(m_PortIndex);
}
void LADSPAPluginGUI::cb_Default(Fl_Input* o)
{ // Group Pack Scroll Group Tab GUI
{ // Group Pack Scroll Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Default_i(o);
}

@@ -702,7 +771,7 @@ inline void LADSPAPluginGUI::cb_Min_i(Fl_Input* o)
m_PortIndex = distance(m_PortMin.begin(), i);
}

// Pass value to plugin
// Pass current port index
m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);

// Check that min is really min and max is really max
@@ -746,11 +815,12 @@ inline void LADSPAPluginGUI::cb_Min_i(Fl_Input* o)
m_PortDefault[m_PortIndex]->redraw();
}

// Reposition Default Adjust knob to reflect new range
SetDefaultAdjust(m_PortIndex);
// Reposition and reconfigure knob to reflect new range
SetPortControlKnobValue(m_PortIndex);
SetPortControlKnobRange(m_PortIndex, m_Min, m_Max);
}
void LADSPAPluginGUI::cb_Min(Fl_Input* o)
{ // Group Pack Scroll Group Tab GUI
{ // Group Pack Scroll Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Min_i(o);
}

@@ -814,11 +884,12 @@ inline void LADSPAPluginGUI::cb_Max_i(Fl_Input* o)
m_PortDefault[m_PortIndex]->redraw();
}

// Reposition Default Adjust knob to reflect new range
SetDefaultAdjust(m_PortIndex);
// Reposition and reconfigure knob to reflect new range
SetPortControlKnobValue(m_PortIndex);
SetPortControlKnobRange(m_PortIndex, m_Min, m_Max);
}
void LADSPAPluginGUI::cb_Max(Fl_Input* o)
{ // Group Pack Scroll Group Tab GUI
{ // Group Pack Scroll Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Max_i(o);
}

@@ -845,7 +916,7 @@ inline void LADSPAPluginGUI::cb_Clamp_i(Fl_Check_Button* o)
m_GUICH->SetCommand(LADSPAPlugin::SETCLAMP);
}
void LADSPAPluginGUI::cb_Clamp(Fl_Check_Button* o)
{ // Group Pack Scroll Group Tab GUI
{ // Group Pack Scroll Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_Clamp_i(o);
}

@@ -853,23 +924,36 @@ inline void LADSPAPluginGUI::cb_DefaultAdjust_i(Fl_Knob *o)
{
// First, find which knob is being adjusted
bool do_search = false;
if (m_PortIndex == m_PortDefaultAdjust.size()) { do_search = true; }
if (!do_search) { do_search = (o != (m_PortDefaultAdjust[m_PortIndex])) ? true : false; }
if (m_PortIndex == m_PortControlKnobs.size()) { do_search = true; }
if (!do_search) { do_search = (o != (m_PortControlKnobs[m_PortIndex])) ? true : false; }

if (do_search) {
// Only bother to re-query knob if it is different from last one adjusted
vector<Fl_Knob *>::iterator i = std::find(m_PortDefaultAdjust.begin(),
m_PortDefaultAdjust.end(),
vector<Fl_Knob *>::iterator i = std::find(m_PortControlKnobs.begin(),
m_PortControlKnobs.end(),
o);
m_PortIndex = distance(m_PortDefaultAdjust.begin(), i);
m_PortIndex = distance(m_PortControlKnobs.begin(), i);
}

// Get value
m_Default = o->value();

// Convert knob value [0.0, 1.0] to value in Min, Max range
float min = atof(m_PortMin[m_PortIndex]->value());
float max = atof(m_PortMax[m_PortIndex]->value());
m_Default = ((max - min) > 0.0f) ? min + (max - min) * m_Default : min;
if (m_InputPortSettings[m_PortIndex].LogBase > 1.0f) {
// Logarithmic control - convert back to actual value
float min = o->minimum();
float max = o->maximum();

if (min > 0.0f && max > 0.0f) {
// Straight exp
m_Default = powf(m_InputPortSettings[m_PortIndex].LogBase, m_Default);
} else if (min < 0.0f && max < 0.0f) {
// Inverse, negated exp
m_Default = -powf(m_InputPortSettings[m_PortIndex].LogBase, -m_Default);
} else {
// Linear if asymptote present
// Do nothing
}
}

// Pass value to plugin
m_GUICH->SetData("SetInputPortIndex", &m_PortIndex);
@@ -883,6 +967,6 @@ inline void LADSPAPluginGUI::cb_DefaultAdjust_i(Fl_Knob *o)
}

void LADSPAPluginGUI::cb_DefaultAdjust(Fl_Knob *o)
{ // Group Pack Scroll Group Tab GUI
{ // Group Pack Scroll Group Tab GUI
((LADSPAPluginGUI*)(o->parent()->parent()->parent()->parent()->parent()->parent()))->cb_DefaultAdjust_i(o);
}

+ 10
- 8
SpiralSound/Plugins/LADSPAPlugin/LADSPAPluginGUI.h View File

@@ -62,15 +62,16 @@ public:
protected:
const string GetHelpText(const string &loc);
private:
void AddPortInfo(const char *Info);
void AddPortInfo(unsigned long p);
void SetTabIndex(int index);
void SetUpdateInputs(bool state);
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);
void SetDefaultAdjust(unsigned long n);
void UpdateDefaultAdjustControls(void);
void SetPortSettings(unsigned long p);
void SetPortControlKnobValue(unsigned long p);
void SetPortControlKnobRange(unsigned long p, float min, float max);
void UpdatePortControlKnobs(void);
void ClearPlugin(void);
void SelectPlugin(void);

@@ -99,8 +100,9 @@ private:
std::vector<Fl_Input*> m_PortMax;
std::vector<Fl_Check_Button*> m_PortClamp;
std::vector<Fl_Input*> m_PortDefault;
std::vector<Fl_Knob*> m_PortDefaultAdjust;
std::vector<char *> m_PortDefaultAdjustLabels;
std::vector<Fl_Knob*> m_PortControlKnobs;
std::vector<Fl_Slider*> m_PortControlSliders;
std::vector<char *> m_PortControlLabels;

std::vector<LADSPAInfo::PluginEntry> m_PluginList;
std::vector<unsigned long> m_PluginIDLookup;
@@ -119,8 +121,8 @@ private:
unsigned long m_MaxInputPortCount;
unsigned long m_InputPortCount;
char *m_InputPortNames;
PortSettings *m_InputPortSettings;
PortValues *m_InputPortValues;
PortSetting *m_InputPortSettings;
PortValue *m_InputPortValues;
float *m_InputPortDefaults;

inline void cb_TabChange_i(Fl_Tabs *o);


Loading…
Cancel
Save