static ControlData * parse_control (const LADSPA_Descriptor * desc, int port) { g_return_val_if_fail (desc->PortNames[port], NULL); const LADSPA_PortRangeHint * hint = & desc->PortRangeHints[port]; ControlData * control = g_slice_new (ControlData); control->port = port; control->name = g_strdup (desc->PortNames[port]); control->is_toggle = LADSPA_IS_HINT_TOGGLED (hint->HintDescriptor) ? 1 : 0; control->min = LADSPA_IS_HINT_BOUNDED_BELOW (hint->HintDescriptor) ? hint->LowerBound : LADSPA_IS_HINT_BOUNDED_ABOVE (hint->HintDescriptor) ? hint->UpperBound - 100 : -100; control->max = LADSPA_IS_HINT_BOUNDED_ABOVE (hint->HintDescriptor) ? hint->UpperBound : LADSPA_IS_HINT_BOUNDED_BELOW (hint->HintDescriptor) ? hint->LowerBound + 100 : 100; if (LADSPA_IS_HINT_SAMPLE_RATE (hint->HintDescriptor)) { control->min *= 96000; control->max *= 96000; } if (LADSPA_IS_HINT_DEFAULT_0 (hint->HintDescriptor)) control->def = 0; else if (LADSPA_IS_HINT_DEFAULT_1 (hint->HintDescriptor)) control->def = 1; else if (LADSPA_IS_HINT_DEFAULT_100 (hint->HintDescriptor)) control->def = 100; else if (LADSPA_IS_HINT_DEFAULT_440 (hint->HintDescriptor)) control->def = 440; else if (LADSPA_IS_HINT_DEFAULT_MINIMUM (hint->HintDescriptor)) control->def = control->min; else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM (hint->HintDescriptor)) control->def = control->max; else if (LADSPA_IS_HINT_DEFAULT_LOW (hint->HintDescriptor)) { if (LADSPA_IS_HINT_LOGARITHMIC (hint->HintDescriptor)) control->def = expf (0.75 * logf (control->min) + 0.25 * logf (control->max)); else control->def = 0.75 * control->min + 0.25 * control->max; } else if (LADSPA_IS_HINT_DEFAULT_HIGH (hint->HintDescriptor)) { if (LADSPA_IS_HINT_LOGARITHMIC (hint->HintDescriptor)) control->def = expf (0.25 * logf (control->min) + 0.75 * logf (control->max)); else control->def = 0.25 * control->min + 0.75 * control->max; } else { if (LADSPA_IS_HINT_LOGARITHMIC (hint->HintDescriptor)) control->def = expf (0.5 * logf (control->min) + 0.5 * logf (control->max)); else control->def = 0.5 * control->min + 0.5 * control->max; } return control; }
void DemoJuceFilter::setParameter (int index, float value) { // if (index == 0) // { // if (gain != value) // { // gain = value; // // // if this is changing the gain, broadcast a change message which // // our editor will pick up. // sendChangeMessage (this); // } // } jassert (index >= 0 && index < pars.size ()); const LADSPA_PortRangeHint* hint = & ladspa->PortRangeHints [pars [index]]; float lower = hint->LowerBound * (LADSPA_IS_HINT_SAMPLE_RATE (hint->HintDescriptor) ? samplingRate : 1.0f); float upper = hint->UpperBound * (LADSPA_IS_HINT_SAMPLE_RATE (hint->HintDescriptor) ? samplingRate : 1.0f); // @TODO - Handle better lower/upper bound. this is ok for most cases // but in some others it don't if (LADSPA_IS_HINT_TOGGLED (hint->HintDescriptor)) { if (value < 0.5f) normalized [index] = 0.0f; else normalized [index] = 1.0f; } else if (LADSPA_IS_HINT_BOUNDED_BELOW (hint->HintDescriptor) && LADSPA_IS_HINT_BOUNDED_ABOVE (hint->HintDescriptor)) { if (LADSPA_IS_HINT_LOGARITHMIC(hint->HintDescriptor) && (lower >= 1.0f && upper >= 1.0f)) normalized [index] = expf(logf(lower) * value + logf(upper) * (1.0f - value)); else normalized [index] = lower + (upper - lower) * value; } else if (LADSPA_IS_HINT_BOUNDED_BELOW (hint->HintDescriptor)) { normalized [index] = value; } else if (LADSPA_IS_HINT_BOUNDED_ABOVE (hint->HintDescriptor)) { normalized [index] = value * upper; } if (LADSPA_IS_HINT_INTEGER (hint->HintDescriptor)) normalized [index] = (float) ((int) normalized [index]); params [index] = value; }
static void print_ctl_info(AVFilterContext *ctx, int level, LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values, int print) { const LADSPA_PortRangeHint *h = s->desc->PortRangeHints + map[ctl]; av_log(ctx, level, "c%i: %s [", ctl, s->desc->PortNames[map[ctl]]); if (LADSPA_IS_HINT_TOGGLED(h->HintDescriptor)) { av_log(ctx, level, "toggled (1 or 0)"); if (LADSPA_IS_HINT_HAS_DEFAULT(h->HintDescriptor)) av_log(ctx, level, " (default %i)", (int)values[ctl]); } else { if (LADSPA_IS_HINT_INTEGER(h->HintDescriptor)) { av_log(ctx, level, "<int>"); if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor)) av_log(ctx, level, ", min: %i", (int)h->LowerBound); if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor)) av_log(ctx, level, ", max: %i", (int)h->UpperBound); if (print) av_log(ctx, level, " (value %d)", (int)values[ctl]); else if (LADSPA_IS_HINT_HAS_DEFAULT(h->HintDescriptor)) av_log(ctx, level, " (default %d)", (int)values[ctl]); } else { av_log(ctx, level, "<float>"); if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor)) av_log(ctx, level, ", min: %f", h->LowerBound); if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor)) av_log(ctx, level, ", max: %f", h->UpperBound); if (print) av_log(ctx, level, " (value %f)", values[ctl]); else if (LADSPA_IS_HINT_HAS_DEFAULT(h->HintDescriptor)) av_log(ctx, level, " (default %f)", values[ctl]); } if (LADSPA_IS_HINT_SAMPLE_RATE(h->HintDescriptor)) av_log(ctx, level, ", multiple of sample rate"); if (LADSPA_IS_HINT_LOGARITHMIC(h->HintDescriptor)) av_log(ctx, level, ", logarithmic scale"); } av_log(ctx, level, "]\n"); }
port_controls_t * port_controls_new (plugin_slot_t * plugin_slot) { plugin_desc_t *desc; unsigned long i; port_controls_t *port_controls_array; port_controls_t *port_controls; desc = plugin_slot->plugin->desc; /* make the controls array */ port_controls_array = g_malloc (sizeof (port_controls_t) * desc->control_port_count); /* contruct the control rows */ for (i = 0; i < desc->control_port_count; i++) { port_controls = port_controls_array + i; port_controls->lock = NULL; port_controls->locked = TRUE; port_controls->lock_copy = 0; port_controls->plugin_slot = plugin_slot; port_controls->control_index = i; port_controls->port_index = desc->control_port_indicies[i]; /* get the port control type from the hints */ #ifdef HAVE_LRDF if (lrdf_get_scale_values(desc->id, port_controls->port_index) != NULL) port_controls->type = JR_CTRL_POINTS; else #endif if (LADSPA_IS_HINT_TOGGLED (desc->port_range_hints[port_controls->port_index].HintDescriptor)) port_controls->type = JR_CTRL_BOOL; else if (LADSPA_IS_HINT_INTEGER (desc->port_range_hints[port_controls->port_index].HintDescriptor)) port_controls->type = JR_CTRL_INT; else port_controls->type = JR_CTRL_FLOAT; if (LADSPA_IS_HINT_LOGARITHMIC (desc->port_range_hints[port_controls->port_index].HintDescriptor)) port_controls->logarithmic = TRUE; else port_controls->logarithmic = FALSE; port_controls->controls = g_malloc (sizeof (controls_t) * plugin_slot->plugin->copies); plugin_slot_create_control_table_row (plugin_slot, port_controls); } return port_controls_array; }
void LadspaEffectDialog::HandleText() { // if we don't add the following three lines, changing // the value of the slider will change the text, which // will change the slider, and so on. This gets rid of // the implicit loop. if (inSlider) return; inText = true; for (unsigned long p = 0; p < numParams; p++) { double dval; float val; float lower = float(0.0); float upper = float(10.0); float range; LADSPA_PortRangeHint hint = mData->PortRangeHints[ports[p]]; if (LADSPA_IS_HINT_TOGGLED(hint.HintDescriptor)) { continue; } dval = Internat::CompatibleToDouble(fields[p]->GetValue()); val = dval; if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) lower = hint.LowerBound; if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) upper = hint.UpperBound; if (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor)) { lower *= sampleRate; upper *= sampleRate; } range = upper - lower; if (val < lower) val = lower; if (val > upper) val = upper; inputControls[ports[p]] = val; sliders[p]->SetValue((int)(((val-lower)/range) * 1000.0 + 0.5)); } inText = false; }
static void add_port_to_metadata( mlt_properties p, plugin_desc_t* desc, int j ) { LADSPA_Data sample_rate = 48000; LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor; mlt_properties_set( p, "title", desc->port_names[ j ] ); if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) ) { mlt_properties_set( p, "type", "integer" ); mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) ); } else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) ) { mlt_properties_set( p, "type", "boolean" ); mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) ); } else { mlt_properties_set( p, "type", "float" ); mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) ); } /* set upper and lower, possibly adjusted to the sample rate */ if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) ) { LADSPA_Data lower = desc->port_range_hints[j].LowerBound; if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) ) lower *= sample_rate; if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) ) { if (lower < FLT_EPSILON) lower = FLT_EPSILON; } mlt_properties_set_double( p, "minimum", lower ); } if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) ) { LADSPA_Data upper = desc->port_range_hints[j].UpperBound; if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) ) upper *= sample_rate; mlt_properties_set_double( p, "maximum", upper ); } if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) ) mlt_properties_set( p, "scale", "log" ); }
//============================================================================== void LadspaPlugin::setParameterReal (int index, float value) { jassert (index >= 0 && index < pars.size ()); const LADSPA_PortRangeHint* hint = & ptrPlug->PortRangeHints [pars [index]]; float lower = hint->LowerBound * (LADSPA_IS_HINT_SAMPLE_RATE (hint->HintDescriptor) ? samplingRate : 1.0f); float upper = hint->UpperBound * (LADSPA_IS_HINT_SAMPLE_RATE (hint->HintDescriptor) ? samplingRate : 1.0f); // @TODO - Handle better lower/upper bound. this is ok for most cases // but in some others it don't if (LADSPA_IS_HINT_TOGGLED (hint->HintDescriptor)) { if (value < 0.5f) normalized [index] = 0.0f; else normalized [index] = 1.0f; } else if (LADSPA_IS_HINT_BOUNDED_BELOW (hint->HintDescriptor) && LADSPA_IS_HINT_BOUNDED_ABOVE (hint->HintDescriptor)) { if (LADSPA_IS_HINT_LOGARITHMIC(hint->HintDescriptor) && lower > 0.0f && upper > 0.0f) normalized [index] = expf(logf(lower) * value + logf(upper) * (1.0f - value)); else normalized [index] = lower + (upper - lower) * value; } else if (LADSPA_IS_HINT_BOUNDED_BELOW (hint->HintDescriptor)) { normalized [index] = value; } else if (LADSPA_IS_HINT_BOUNDED_ABOVE (hint->HintDescriptor)) { normalized [index] = value * upper; } if (LADSPA_IS_HINT_INTEGER (hint->HintDescriptor)) normalized [index] = (float) ((int) normalized [index]); params [index] = value; }
bool LadspaManager::isPortToggled( const ladspa_key_t & _plugin, uint32_t _port ) { if( m_ladspaManagerMap.contains( _plugin ) && _port < getPortCount( _plugin ) ) { LADSPA_Descriptor_Function descriptorFunction = m_ladspaManagerMap[_plugin]->descriptorFunction; const LADSPA_Descriptor * descriptor = descriptorFunction( m_ladspaManagerMap[_plugin]->index ); LADSPA_PortRangeHintDescriptor hintDescriptor = descriptor->PortRangeHints[_port].HintDescriptor; return( LADSPA_IS_HINT_TOGGLED( hintDescriptor ) ); } else { return( false ); } }
static mlt_properties metadata( mlt_service_type type, const char *id, char *data ) { char file[ PATH_MAX ]; if( type == filter_type ) { snprintf( file, PATH_MAX, "%s/jackrack/%s", mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "filter_ladspa.yml" ); } else { snprintf( file, PATH_MAX, "%s/jackrack/%s", mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "producer_ladspa.yml" ); } mlt_properties result = mlt_properties_parse_yaml( file ); #ifdef GPL if ( !strncmp( id, "ladspa.", 7 ) ) { // Annotate the yaml properties with ladspa control port info. plugin_desc_t *desc = plugin_mgr_get_any_desc( g_jackrack_plugin_mgr, strtol( id + 7, NULL, 10 ) ); if ( desc ) { mlt_properties params = mlt_properties_new(); mlt_properties p; char key[20]; int i; mlt_properties_set( result, "identifier", id ); mlt_properties_set( result, "title", desc->name ); mlt_properties_set( result, "creator", desc->maker ? desc->maker : "unknown" ); mlt_properties_set( result, "description", "LADSPA plugin" ); mlt_properties_set_data( result, "parameters", params, 0, (mlt_destructor) mlt_properties_close, NULL ); for ( i = 0; i < desc->control_port_count; i++ ) { int j = desc->control_port_indicies[i]; LADSPA_Data sample_rate = 48000; LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor; p = mlt_properties_new(); snprintf( key, sizeof(key), "%d", i ); mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL ); snprintf( key, sizeof(key), "%d", j ); mlt_properties_set( p, "identifier", key ); mlt_properties_set( p, "title", desc->port_names[ j ] ); if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) ) { mlt_properties_set( p, "type", "integer" ); mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) ); } else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) ) { mlt_properties_set( p, "type", "boolean" ); mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) ); } else { mlt_properties_set( p, "type", "float" ); mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) ); } /* set upper and lower, possibly adjusted to the sample rate */ if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) ) { LADSPA_Data lower = desc->port_range_hints[j].LowerBound; if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) ) lower *= sample_rate; if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) ) { if (lower < FLT_EPSILON) lower = FLT_EPSILON; } mlt_properties_set_double( p, "minimum", lower ); } if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) ) { LADSPA_Data upper = desc->port_range_hints[j].UpperBound; if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) ) upper *= sample_rate; mlt_properties_set_double( p, "maximum", upper ); } if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) ) mlt_properties_set( p, "scale", "log" ); mlt_properties_set( p, "mutable", "yes" ); } if( type == filter_type ) { p = mlt_properties_new(); snprintf( key, sizeof(key), "%d", i ); mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL ); mlt_properties_set( p, "identifier", "wetness" ); mlt_properties_set( p, "title", "Wet/Dry" ); mlt_properties_set( p, "type", "float" ); mlt_properties_set_double( p, "default", 1 ); mlt_properties_set_double( p, "minimum", 0 ); mlt_properties_set_double( p, "maximum", 1 ); mlt_properties_set( p, "mutable", "yes" ); } } } #endif return result; }
CAMLprim value ocaml_ladspa_port_is_boolean(value d, value n) { return Val_bool(LADSPA_IS_HINT_TOGGLED(LADSPA_descr_val(d)->PortRangeHints[Int_val(n)].HintDescriptor)); }
LadspaEffectDialog::LadspaEffectDialog(LadspaEffect *eff, wxWindow * parent, const LADSPA_Descriptor *data, float *inputControls, int sampleRate, double length) :wxDialog(parent, -1, LAT1CTOWX(data->Name), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), effect(eff) { mLength = length; numParams = 0; this->mData = data; this->inputControls = inputControls; this->sampleRate = sampleRate; #ifdef __WXMSW__ // On Windows, for some reason, wxWindows calls OnTextCtrl during creation // of the text control, and LadspaEffectDialog::OnTextCtrl calls HandleText, // which assumes all the fields have been initialized. // This can give us a bad pointer crash, so manipulate inSlider to // no-op HandleText during creation. inSlider = true; #else inSlider = false; #endif inText = false; toggles = new wxCheckBox*[mData->PortCount]; sliders = new wxSlider*[mData->PortCount]; fields = new wxTextCtrl*[mData->PortCount]; labels = new wxStaticText*[mData->PortCount]; ports = new unsigned long [mData->PortCount]; unsigned long p; for(p=0; p<mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (LADSPA_IS_PORT_CONTROL(d) && LADSPA_IS_PORT_INPUT(d)) { ports[numParams] = p; numParams++; } } wxControl *item; wxBoxSizer *vSizer = new wxBoxSizer(wxVERTICAL); if (mData->Maker && mData->Maker[0] && LAT1CTOWX(mData->Maker) != wxString(_("None"))) { item = new wxStaticText(this, 0, wxString(_("Author: "))+LAT1CTOWX(mData->Maker)); vSizer->Add(item, 0, wxALL, 5); } if (mData->Copyright && mData->Copyright[0] && LAT1CTOWX(mData->Copyright) != wxString(_("None"))) { item = new wxStaticText(this, 0, LAT1CTOWX(mData->Copyright)); vSizer->Add(item, 0, wxALL, 5); } wxScrolledWindow *w = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxTAB_TRAVERSAL); // Try to give the window a sensible default/minimum size w->SetMinSize(wxSize( wxMax(600, parent->GetSize().GetWidth() * 2/3), parent->GetSize().GetHeight() / 2)); w->SetScrollRate(0, 20); vSizer->Add(w, 1, wxEXPAND|wxALL, 5); // Preview, OK, & Cancel buttons vSizer->Add(CreateStdButtonSizer(this, ePreviewButton|eCancelButton|eOkButton), 0, wxEXPAND); SetSizer(vSizer); wxSizer *paramSizer = new wxStaticBoxSizer(wxVERTICAL, w, _("Effect Settings")); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(5, 0, 0); gridSizer->AddGrowableCol(3); for (p = 0; p < numParams; p++) { wxString labelText = LAT1CTOWX(mData->PortNames[ports[p]]); item = new wxStaticText(w, 0, labelText + wxT(":")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); wxString fieldText; LADSPA_PortRangeHint hint = mData->PortRangeHints[ports[p]]; if (LADSPA_IS_HINT_TOGGLED(hint.HintDescriptor)) { toggles[p] = new wxCheckBox(w, p, wxT("")); toggles[p]->SetName(labelText); toggles[p]->SetValue(inputControls[ports[p]] > 0); gridSizer->Add(toggles[p], 0, wxALL, 5); ConnectFocus(toggles[p]); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); } else { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor)) fieldText.Printf(wxT("%d"), (int)(inputControls[ports[p]] + 0.5)); else fieldText = Internat::ToDisplayString(inputControls[ports[p]]); fields[p] = new wxTextCtrl(w, p, fieldText); fields[p]->SetName(labelText); gridSizer->Add(fields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); ConnectFocus(fields[p]); wxString bound; double lower = 0.0; double upper = 0.0; bool haslo = false; bool hashi = false; bool forceint = false; if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { lower = hint.LowerBound; haslo = true; } if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { upper = hint.UpperBound; hashi = true; } if (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor)) { lower *= sampleRate * 1000; upper *= sampleRate; forceint = true; } wxString str; if (haslo) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) str.Printf(wxT("%d"), (int)(lower + 0.5)); else str = Internat::ToDisplayString(lower); item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } sliders[p] = new wxSlider(w, p, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); sliders[p]->SetName(labelText); gridSizer->Add(sliders[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); ConnectFocus(sliders[p]); if (hashi) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) str.Printf(wxT("%d"), (int)(upper + 0.5)); else str = Internat::ToDisplayString(upper); item = new wxStaticText(w, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } } } // Now add the length control if (effect->GetEffectFlags() & INSERT_EFFECT) { item = new wxStaticText(w, 0, _("Length (seconds)")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); mSeconds = new wxTextCtrl(w, LADSPA_SECONDS_ID, Internat::ToDisplayString(length)); mSeconds->SetName(_("Length (seconds)")); gridSizer->Add(mSeconds, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); ConnectFocus(mSeconds); } // Set all of the sliders based on the value in the // text fields inSlider = false; // Now we're ready for HandleText to actually do something. HandleText(); paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); w->SetSizer(paramSizer); Layout(); Fit(); SetSizeHints(GetSize()); }
static GParamSpec * gst_ladspa_class_get_param_spec (GstLADSPAClass * klass, gint portnum) { LADSPA_Descriptor *desc; GParamSpec *ret; gchar *name; gint hintdesc, perms; gfloat lower, upper, def; desc = klass->descriptor; name = gst_ladspa_class_get_param_name (klass, portnum); perms = G_PARAM_READABLE; if (LADSPA_IS_PORT_INPUT (desc->PortDescriptors[portnum])) perms |= G_PARAM_WRITABLE | G_PARAM_CONSTRUCT; if (LADSPA_IS_PORT_CONTROL (desc->PortDescriptors[portnum])) perms |= GST_PARAM_CONTROLLABLE; /* short name for hint descriptor */ hintdesc = desc->PortRangeHints[portnum].HintDescriptor; if (LADSPA_IS_HINT_TOGGLED (hintdesc)) { ret = g_param_spec_boolean (name, name, name, FALSE, perms); g_free (name); return ret; } if (LADSPA_IS_HINT_BOUNDED_BELOW (hintdesc)) lower = desc->PortRangeHints[portnum].LowerBound; else lower = -G_MAXFLOAT; if (LADSPA_IS_HINT_BOUNDED_ABOVE (hintdesc)) upper = desc->PortRangeHints[portnum].UpperBound; else upper = G_MAXFLOAT; if (LADSPA_IS_HINT_SAMPLE_RATE (hintdesc)) { /* FIXME! */ lower *= 44100; upper *= 44100; } if (LADSPA_IS_HINT_INTEGER (hintdesc)) { lower = CLAMP (lower, G_MININT, G_MAXINT); upper = CLAMP (upper, G_MININT, G_MAXINT); } /* default to lower bound */ def = lower; #ifdef LADSPA_IS_HINT_HAS_DEFAULT if (LADSPA_IS_HINT_HAS_DEFAULT (hintdesc)) { if (LADSPA_IS_HINT_DEFAULT_0 (hintdesc)) def = 0.0; else if (LADSPA_IS_HINT_DEFAULT_1 (hintdesc)) def = 1.0; else if (LADSPA_IS_HINT_DEFAULT_100 (hintdesc)) def = 100.0; else if (LADSPA_IS_HINT_DEFAULT_440 (hintdesc)) def = 440.0; if (LADSPA_IS_HINT_DEFAULT_MINIMUM (hintdesc)) def = lower; else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM (hintdesc)) def = upper; else if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) { if (LADSPA_IS_HINT_DEFAULT_LOW (hintdesc)) def = exp (0.75 * log (lower) + 0.25 * log (upper)); else if (LADSPA_IS_HINT_DEFAULT_MIDDLE (hintdesc)) def = exp (0.5 * log (lower) + 0.5 * log (upper)); else if (LADSPA_IS_HINT_DEFAULT_HIGH (hintdesc)) def = exp (0.25 * log (lower) + 0.75 * log (upper)); } else { if (LADSPA_IS_HINT_DEFAULT_LOW (hintdesc)) def = 0.75 * lower + 0.25 * upper; else if (LADSPA_IS_HINT_DEFAULT_MIDDLE (hintdesc)) def = 0.5 * lower + 0.5 * upper; else if (LADSPA_IS_HINT_DEFAULT_HIGH (hintdesc)) def = 0.25 * lower + 0.75 * upper; } } #endif /* LADSPA_IS_HINT_HAS_DEFAULT */ if (lower > upper) { gfloat tmp; /* silently swap */ tmp = lower; lower = upper; upper = tmp; } def = CLAMP (def, lower, upper); if (LADSPA_IS_HINT_INTEGER (hintdesc)) { ret = g_param_spec_int (name, name, name, lower, upper, def, perms); } else { ret = g_param_spec_float (name, name, name, lower, upper, def, perms); } g_free (name); return ret; }
void LadspaEffect::RefreshControls(bool outputOnly) { if (!mParent) { return; } for (unsigned long p = 0; p < mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (!(LADSPA_IS_PORT_CONTROL(d))) { continue; } wxString fieldText; LADSPA_PortRangeHint hint = mData->PortRangeHints[p]; bool forceint = false; if (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor)) { forceint = true; } if (LADSPA_IS_PORT_OUTPUT(d)) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) { fieldText.Printf(wxT("%d"), (int)(mOutputControls[p] + 0.5)); } else { fieldText = Internat::ToDisplayString(mOutputControls[p]); } mFields[p]->SetValue(fieldText); continue; } if (outputOnly) { continue; } if (LADSPA_IS_HINT_TOGGLED(hint.HintDescriptor)) { mToggles[p]->SetValue(mInputControls[p] > 0); continue; } if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) { fieldText.Printf(wxT("%d"), (int)(mInputControls[p] + 0.5)); } else { fieldText = Internat::ToDisplayString(mInputControls[p]); } // Set the textctrl value. This will trigger an event so OnTextCtrl() // can update the slider. mFields[p]->SetValue(fieldText); } }
bool LadspaEffect::PopulateUI(wxWindow *parent) { mParent = parent; mEventHelper = new LadspaEffectEventHelper(this); mParent->PushEventHandler(mEventHelper); mToggles = new wxCheckBox*[mData->PortCount]; mSliders = new wxSlider*[mData->PortCount]; mFields = new wxTextCtrl*[mData->PortCount]; mLabels = new wxStaticText*[mData->PortCount]; memset(mFields, 0, mData->PortCount * sizeof(wxTextCtrl *)); wxSizer *marginSizer = new wxBoxSizer(wxVERTICAL); if (mNumInputControls) { wxSizer *paramSizer = new wxStaticBoxSizer(wxVERTICAL, mParent, _("Effect Settings")); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(5, 0, 0); gridSizer->AddGrowableCol(3); wxControl *item; // Add the duration control for generators if (GetType() == EffectTypeGenerate) { item = new wxStaticText(mParent, 0, _("Duration:")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); mDuration = new NumericTextCtrl(NumericConverter::TIME, mParent, ID_DURATION, _("hh:mm:ss + milliseconds"), mHost->GetDuration(), mSampleRate, wxDefaultPosition, wxDefaultSize, true); mDuration->SetName(_("Duration")); mDuration->EnableMenu(); gridSizer->Add(mDuration, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); } for (unsigned long p = 0; p < mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (LADSPA_IS_PORT_AUDIO(d) || LADSPA_IS_PORT_OUTPUT(d)) { continue; } wxString labelText = LAT1CTOWX(mData->PortNames[p]); item = new wxStaticText(mParent, 0, labelText + wxT(":")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); wxString fieldText; LADSPA_PortRangeHint hint = mData->PortRangeHints[p]; if (LADSPA_IS_HINT_TOGGLED(hint.HintDescriptor)) { mToggles[p] = new wxCheckBox(mParent, ID_TOGGLES + p, wxT("")); mToggles[p]->SetName(labelText); mToggles[p]->SetValue(mInputControls[p] > 0); gridSizer->Add(mToggles[p], 0, wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); continue; } wxString bound; double lower = -FLT_MAX; double upper = FLT_MAX; bool haslo = false; bool hashi = false; bool forceint = false; if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { lower = hint.LowerBound; haslo = true; } if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { upper = hint.UpperBound; hashi = true; } if (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor)) { lower *= mSampleRate; upper *= mSampleRate; forceint = true; } // Don't specify a value at creation time. This prevents unwanted events // being sent to the OnTextCtrl() handler before the associated slider // has been created. mFields[p] = new wxTextCtrl(mParent, ID_TEXTS + p); mFields[p]->SetName(labelText); gridSizer->Add(mFields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); wxString str; if (haslo) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) { str.Printf(wxT("%d"), (int)(lower + 0.5)); } else { str = Internat::ToDisplayString(lower); } item = new wxStaticText(mParent, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } mSliders[p] = new wxSlider(mParent, ID_SLIDERS + p, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); mSliders[p]->SetName(labelText); gridSizer->Add(mSliders[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); if (hashi) { if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) { str.Printf(wxT("%d"), (int)(upper + 0.5)); } else { str = Internat::ToDisplayString(upper); } item = new wxStaticText(mParent, 0, str); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 5); } else { gridSizer->Add(1, 1, 0); } if (LADSPA_IS_HINT_INTEGER(hint.HintDescriptor) || forceint) { fieldText.Printf(wxT("%d"), (int)(mInputControls[p] + 0.5)); wxIntegerValidator<float> vld(&mInputControls[p]); vld.SetRange(haslo ? lower : INT_MIN, hashi ? upper : INT_MAX); mFields[p]->SetValidator(vld); } else { fieldText = Internat::ToDisplayString(mInputControls[p]); // > 12 decimal places can cause rounding errors in display. wxFloatingPointValidator<float> vld(12, &mInputControls[p]); vld.SetRange(haslo ? lower : -FLT_MAX, hashi ? upper : FLT_MAX); // Set number of decimal places if (upper - lower < 10.0) { vld.SetStyle(wxNUM_VAL_THREE_TRAILING_ZEROES); } else if (upper - lower < 100.0) { vld.SetStyle(wxNUM_VAL_TWO_TRAILING_ZEROES); } else { vld.SetStyle(wxNUM_VAL_ONE_TRAILING_ZERO); } mFields[p]->SetValidator(vld); } // Set the textctrl value. This will trigger an event so OnTextCtrl() // can update the slider. mFields[p]->SetValue(fieldText); } paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); marginSizer->Add(paramSizer, 1, wxEXPAND | wxALL, 5); } if (mNumOutputControls > 0 ) { wxSizer *paramSizer = new wxStaticBoxSizer(wxVERTICAL, mParent, _("Effect Output")); wxFlexGridSizer *gridSizer = new wxFlexGridSizer(2, 0, 0); gridSizer->AddGrowableCol(3); wxControl *item; for (unsigned long p = 0; p < mData->PortCount; p++) { LADSPA_PortDescriptor d = mData->PortDescriptors[p]; if (LADSPA_IS_PORT_AUDIO(d) || LADSPA_IS_PORT_INPUT(d)) { continue; } wxString labelText = LAT1CTOWX(mData->PortNames[p]); item = new wxStaticText(mParent, 0, labelText + wxT(":")); gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); wxString fieldText; mFields[p] = new wxTextCtrl(mParent, wxID_ANY, fieldText, wxDefaultPosition, wxDefaultSize, wxTE_READONLY); mFields[p]->SetName(labelText); gridSizer->Add(mFields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); } paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); marginSizer->Add(paramSizer, 1, wxEXPAND | wxALL, 5); RefreshControls(true); } mParent->SetSizer(marginSizer); return true; }
bool qtractorLadspaPluginParam::isToggled (void) const { return LADSPA_IS_HINT_TOGGLED(m_portHints); }
void PluginAClientConfig::initialize(PluginServer *server) { delete_objects(); const LADSPA_Descriptor *lad_desc = server->lad_descriptor; const LADSPA_PortDescriptor *port_desc = lad_desc->PortDescriptors; const LADSPA_PortRangeHint *lad_hint = lad_desc->PortRangeHints; int port_count = lad_desc->PortCount; for(int i = 0; i < port_count; i++) { if( !LADSPA_IS_PORT_INPUT(port_desc[i]) ) continue; if( !LADSPA_IS_PORT_CONTROL(port_desc[i]) ) continue; ++total_ports; } port_data = new LADSPA_Data[total_ports]; port_type = new int[total_ports]; for(int port = 0, i = 0; i < port_count; i++) { if( !LADSPA_IS_PORT_INPUT(port_desc[i]) ) continue; if( !LADSPA_IS_PORT_CONTROL(port_desc[i]) ) continue; // Convert LAD default to default value float value = 0.0; LADSPA_PortRangeHintDescriptor hint_desc = lad_hint->HintDescriptor; // Store type of port for GUI use port_type[port] = PORT_NORMAL; if( LADSPA_IS_HINT_SAMPLE_RATE(hint_desc) /* && LADSPA_IS_HINT_BOUNDED_ABOVE(hint_desc) && LADSPA_IS_HINT_BOUNDED_BELOW(hint_desc) */ ) // LAD frequency table port_type[port] = PORT_FREQ_INDEX; else if(LADSPA_IS_HINT_TOGGLED(hint_desc)) port_type[port] = PORT_TOGGLE; else if(LADSPA_IS_HINT_INTEGER(hint_desc)) port_type[port] = PORT_INTEGER; // Get default of port using crazy hinting system if( LADSPA_IS_HINT_DEFAULT_0(hint_desc) ) value = 0.0; else if( LADSPA_IS_HINT_DEFAULT_1(hint_desc) ) value = 1.0; else if( LADSPA_IS_HINT_DEFAULT_100(hint_desc) ) value = 100.0; else if( LADSPA_IS_HINT_DEFAULT_440(hint_desc) ) value = port_type[port] == PORT_FREQ_INDEX ? 440.0 / 44100 : 440.0; else if( LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_desc) ) value = lad_hint->UpperBound; else if( LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_desc) ) value = lad_hint->LowerBound; else if( LADSPA_IS_HINT_DEFAULT_LOW(hint_desc) ) value = LADSPA_IS_HINT_LOGARITHMIC(hint_desc) ? exp(log(lad_hint->LowerBound) * 0.25 + log(lad_hint->UpperBound) * 0.75) : lad_hint->LowerBound * 0.25 + lad_hint->UpperBound * 0.75; else if( LADSPA_IS_HINT_DEFAULT_MIDDLE(hint_desc) ) value = LADSPA_IS_HINT_LOGARITHMIC(hint_desc) ? exp(log(lad_hint->LowerBound) * 0.5 + log(lad_hint->UpperBound) * 0.5) : lad_hint->LowerBound * 0.5 + lad_hint->UpperBound * 0.5; else if( LADSPA_IS_HINT_DEFAULT_HIGH(hint_desc) ) value = LADSPA_IS_HINT_LOGARITHMIC(hint_desc) ? exp(log(lad_hint->LowerBound) * 0.75 + log(lad_hint->UpperBound) * 0.25) : lad_hint->LowerBound * 0.75 + lad_hint->UpperBound * 0.25; port_data[port] = value; ++port; } }