void TColorStyle::assignBlend(const TColorStyle &a, const TColorStyle &b, double t) { // Blend colors { int col, colCount = getColorParamCount(); assert(a.getColorParamCount() == colCount && b.getColorParamCount() == colCount); for (col = 0; col != colCount; ++col) setColorParamValue( col, blend(a.getColorParamValue(col), b.getColorParamValue(col), t)); } // Blend parameters { int par, parCount = getParamCount(); assert(a.getParamCount() == parCount && b.getParamCount() == parCount); for (par = 0; par != parCount; ++par) { switch (getParamType(par)) { case DOUBLE: setParamValue(par, (1 - t) * a.getParamValue(double_tag(), par) + t * b.getParamValue(double_tag(), par)); break; default: break; } } } invalidateIcon(); }
/** * Parses the command line, updating the flags or params according to its contents. * @param _argc The argument count of the command line. * @param _argv The arguments of the command line. * @exception UnknownArg if an argument doesn't exist * @exception MissingVal if a param hasn't got a value */ void Parser::parse (int _argc, char **_argv) { int i; for (i=1 ; i<_argc ; i++) { try { enableFlag(_argv[i]); } catch (UnknownArg& ) { //if it isn't a flag, perhaps is a param setParamValue(_argv[i], _argv[++i]); } } // after parsing the command line, check if all the required params have changed vector<Param>::iterator pos; for (pos=params.begin() ; pos!=params.end() ; pos++) if (pos->required() && !pos->changed()) break; // if there is an unchanged required param ... if (pos!=params.end()) { throw Parser::MissingReqParam(pos->shortName()); } };
// Swap params A/B. void synthv1widget::swapParams ( bool bOn ) { if (m_iUpdate > 0 || !bOn) return; #ifdef CONFIG_DEBUG qDebug("synthv1widget::swapParams(%d)", int(bOn)); #endif // resetParamKnobs(); for (uint32_t i = 0; i < synthv1::NUM_PARAMS; ++i) { const synthv1::ParamIndex index = synthv1::ParamIndex(i); synthv1widget_knob *pKnob = paramKnob(index); if (pKnob) { const float fOldValue = pKnob->value(); const float fNewValue = m_params_ab[index]; setParamValue(index, fNewValue); updateParam(index, fNewValue); m_params_ab[index] = fOldValue; } } const bool bSwapA = m_ui.SwapParamsAButton->isChecked(); m_ui.StatusBar->showMessage(tr("Swap %1").arg(bSwapA ? 'A' : 'B'), 5000); updateDirtyPreset(true); }
bool Parameters::loadParams(int argc, char ** argv) { // load params from commandline args //if( argc < 3 ) { // fprintf(stderr, "ERROR: No parameters. Use \"-config\" or \"-f\" to specify configuration file.\n"); // return false; //} bool load_from_file = false; std::set<std::string> setParams; int jumpBy = 0; for( int i = 1; i < argc; i += jumpBy ) { std::string param = argv[i]; if(param[0] != '-') { std::cerr << "Unknown parameter: " << param << std::endl; return false; } Utils::ltrim(param, "- "); // normalise parameter to long name param = normaliseParamName(param); // check if valid param name if(!isValidParamName(param)) { std::cerr << "Unknown param option \"" << param << "\"\n"; exit(EXIT_FAILURE); } setParams.insert(param); // needed to not overwrite param value if file is specified //if the parameter is of type booL no corresponding value if( getValueType(param) == kBoolValue ) { jumpBy = 1; assert(setParamValue(param, kTrueValue)); } else { //not of type bool so must have corresponding value assert(i+1 < argc); jumpBy = 2; std::string val = argv[i+1]; Utils::trim(val); if( param == "config" ) load_from_file = true; if(!setParamValue(param, val)) { std::cerr << "Invalid Param name->value " << param << "->" << val << std::endl; return false; } } } bool success = true; // load from file if specified if (load_from_file) success = loadParams(getParamValue("config"), setParams); return success; }
// LV2 port event dispatcher. void drumkv1widget_lv2::port_event ( uint32_t port_index, uint32_t buffer_size, uint32_t format, const void *buffer ) { if (format == 0 && buffer_size == sizeof(float)) { const drumkv1::ParamIndex index = drumkv1::ParamIndex(port_index - drumkv1_lv2::ParamBase); const float fValue = *(float *) buffer; setParamValue(index, fValue, m_params_def[index]); m_params_def[index] = false; } }
// Reset all param default values. void synthv1widget::resetParamValues (void) { resetSwapParams(); for (uint32_t i = 0; i < synthv1::NUM_PARAMS; ++i) { const synthv1::ParamIndex index = synthv1::ParamIndex(i); const float fValue = synthv1_param::paramDefaultValue(index); setParamValue(index, fValue, true); updateParam(index, fValue); m_params_ab[index] = fValue; } }
// LV2 port event dispatcher. void synthv1widget_lv2::port_event ( uint32_t port_index, uint32_t buffer_size, uint32_t format, const void *buffer ) { if (format == 0 && buffer_size == sizeof(float)) { const synthv1::ParamIndex index = synthv1::ParamIndex(port_index - synthv1_lv2::ParamBase); const float fValue = *(float *) buffer; #if 0//--legacy support < 0.3.0.4 -- begin if (index == synthv1::DEL1_BPM && fValue < 3.6f) fValue *= 100.0f; #endif setParamValue(index, fValue, m_params_def[index]); m_params_def[index] = false; } }
SWIGEXPORT void JNICALL Java_com_dsp_1faust_dsp_1faustJNI_setParamValue(JNIEnv *jenv, jclass jcls, jstring jarg1, jfloat jarg2) { char *arg1 = (char *) 0 ; float arg2 ; (void)jenv; (void)jcls; arg1 = 0; if (jarg1) { arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0); if (!arg1) return ; } arg2 = (float)jarg2; setParamValue((char const *)arg1,arg2); if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1); }
void OpenGLShaderPointLight::copyLight(PointLight &light) { setParamValue("position", light.getPosition()); setParamValue("ambient", light.getAmbient()); setParamValue("diffuse", light.getDiffuse()); setParamValue("specular", light.getSpecular()); setParamValue("attenuation", light.getAttenuation()); setParamValue("cutoff", light.getCutoff()); bind(); }
// Initialize param values. void synthv1widget::updateParamValues (void) { resetSwapParams(); synthv1_ui *pSynthUi = ui_instance(); for (uint32_t i = 0; i < synthv1::NUM_PARAMS; ++i) { const synthv1::ParamIndex index = synthv1::ParamIndex(i); const float fValue = (pSynthUi ? pSynthUi->paramValue(index) : synthv1_param::paramDefaultValue(index)); setParamValue(index, fValue, true); updateParam(index, fValue); // updateParamEx(index, fValue); m_params_ab[index] = fValue; } }
// Reset all param knobs to default values. void synthv1widget::resetParams (void) { synthv1_ui *pSynthUi = ui_instance(); if (pSynthUi == NULL) return; pSynthUi->reset(); resetSwapParams(); for (uint32_t i = 0; i < synthv1::NUM_PARAMS; ++i) { const synthv1::ParamIndex index = synthv1::ParamIndex(i); float fValue = synthv1_param::paramDefaultValue(index); synthv1widget_knob *pKnob = paramKnob(index); if (pKnob) fValue = pKnob->defaultValue(); setParamValue(index, fValue); updateParam(index, fValue); m_params_ab[index] = fValue; } m_ui.StatusBar->showMessage(tr("Reset preset"), 5000); updateDirtyPreset(false); }
// Return TRUE if character has to update visual params. BOOL LLPhysicsMotion::onUpdate(F32 time) { // static FILE *mFileWrite = fopen("c:\\temp\\avatar_data.txt","w"); if (!mParamDriver) return FALSE; if (!mLastTime) { mLastTime = time; return FALSE; } //////////////////////////////////////////////////////////////////////////////// // Get all parameters and settings // const F32 time_delta = time - mLastTime; // Don't update too frequently, to avoid precision errors from small time slices. if (time_delta <= .01) { return FALSE; } // If less than 1FPS, we don't want to be spending time updating physics at all. if (time_delta > 1.0) { mLastTime = time; return FALSE; } // Higher LOD is better. This controls the granularity // and frequency of updates for the motions. const F32 lod_factor = LLVOAvatar::sPhysicsLODFactor; if (lod_factor == 0) { return TRUE; } LLJoint *joint = mJointState->getJoint(); const F32 behavior_mass = getParamValue("Mass"); const F32 behavior_gravity = getParamValue("Gravity"); const F32 behavior_spring = getParamValue("Spring"); const F32 behavior_gain = getParamValue("Gain"); const F32 behavior_damping = getParamValue("Damping"); const F32 behavior_drag = getParamValue("Drag"); const BOOL physics_test = FALSE; // Enable this to simulate bouncing on all parts. F32 behavior_maxeffect = getParamValue("MaxEffect"); if (physics_test) behavior_maxeffect = 1.0f; // Normalize the param position to be from [0,1]. // We have to use normalized values because there may be more than one driven param, // and each of these driven params may have its own range. // This means we'll do all our calculations in normalized [0,1] local coordinates. const F32 position_user_local = (mParamDriver->getWeight() - mParamDriver->getMinWeight()) / (mParamDriver->getMaxWeight() - mParamDriver->getMinWeight()); // // End parameters and settings //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Calculate velocity and acceleration in parameter space. // //const F32 velocity_joint_local = calculateVelocity_local(time_iteration_step); const F32 velocity_joint_local = calculateVelocity_local(); const F32 acceleration_joint_local = calculateAcceleration_local(velocity_joint_local); // // End velocity and acceleration //////////////////////////////////////////////////////////////////////////////// BOOL update_visuals = FALSE; // Break up the physics into a bunch of iterations so that differing framerates will show // roughly the same behavior. for (F32 time_iteration = 0; time_iteration <= time_delta; time_iteration += TIME_ITERATION_STEP) { F32 time_iteration_step = TIME_ITERATION_STEP; if (time_iteration + TIME_ITERATION_STEP > time_delta) { time_iteration_step = time_delta-time_iteration; } // mPositon_local should be in normalized 0,1 range already. Just making sure... const F32 position_current_local = llclamp(mPosition_local, 0.0f, 1.0f); // If the effect is turned off then don't process unless we need one more update // to set the position to the default (i.e. user) position. if ((behavior_maxeffect == 0) && (position_current_local == position_user_local)) { return update_visuals; } //////////////////////////////////////////////////////////////////////////////// // Calculate the total force // // Spring force is a restoring force towards the original user-set breast position. // F = kx const F32 spring_length = position_current_local - position_user_local; const F32 force_spring = -spring_length * behavior_spring; // Acceleration is the force that comes from the change in velocity of the torso. // F = ma const F32 force_accel = behavior_gain * (acceleration_joint_local * behavior_mass); // Gravity always points downward in world space. // F = mg const LLVector3 gravity_world(0,0,1); const F32 force_gravity = (toLocal(gravity_world) * behavior_gravity * behavior_mass); // Damping is a restoring force that opposes the current velocity. // F = -kv const F32 force_damping = -behavior_damping * mVelocity_local; // Drag is a force imparted by velocity (intuitively it is similar to wind resistance) // F = .5kv^2 const F32 force_drag = .5*behavior_drag*velocity_joint_local*velocity_joint_local*llsgn(velocity_joint_local); const F32 force_net = (force_accel + force_gravity + force_spring + force_damping + force_drag); // // End total force //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Calculate new params // // Calculate the new acceleration based on the net force. // a = F/m const F32 acceleration_new_local = force_net / behavior_mass; static const F32 max_velocity = 100.0f; // magic number, used to be customizable. F32 velocity_new_local = mVelocity_local + acceleration_new_local*time_iteration_step; velocity_new_local = llclamp(velocity_new_local, -max_velocity, max_velocity); // Temporary debugging setting to cause all avatars to move, for profiling purposes. if (physics_test) { velocity_new_local = sin(time*4.0); } // Calculate the new parameters, or remain unchanged if max speed is 0. F32 position_new_local = position_current_local + velocity_new_local*time_iteration_step; if (behavior_maxeffect == 0) position_new_local = position_user_local; // Zero out the velocity if the param is being pushed beyond its limits. if ((position_new_local < 0 && velocity_new_local < 0) || (position_new_local > 1 && velocity_new_local > 0)) { velocity_new_local = 0; } // Check for NaN values. A NaN value is detected if the variables doesn't equal itself. // If NaN, then reset everything. if ((mPosition_local != mPosition_local) || (mVelocity_local != mVelocity_local) || (position_new_local != position_new_local)) { position_new_local = 0; mVelocity_local = 0; mVelocityJoint_local = 0; mAccelerationJoint_local = 0; mPosition_local = 0; mPosition_world = LLVector3(0,0,0); } const F32 position_new_local_clamped = llclamp(position_new_local, 0.0f, 1.0f); LLDriverParam *driver_param = dynamic_cast<LLDriverParam *>(mParamDriver); llassert_always(driver_param); if (driver_param) { // If this is one of our "hidden" driver params, then make sure it's // the default value. if ((driver_param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE) && (driver_param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT)) { mCharacter->setVisualParamWeight(driver_param, 0, FALSE); } for (LLDriverParam::entry_list_t::iterator iter = driver_param->mDriven.begin(); iter != driver_param->mDriven.end(); ++iter) { LLDrivenEntry &entry = (*iter); LLViewerVisualParam *driven_param = entry.mParam; setParamValue(driven_param,position_new_local_clamped, behavior_maxeffect); } } // // End calculate new params //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Conditionally update the visual params // // Updating the visual params (i.e. what the user sees) is fairly expensive. // So only update if the params have changed enough, and also take into account // the graphics LOD settings. // For non-self, if the avatar is small enough visually, then don't update. const F32 area_for_max_settings = 0.0; const F32 area_for_min_settings = 1400.0; const F32 area_for_this_setting = area_for_max_settings + (area_for_min_settings-area_for_max_settings)*(1.0-lod_factor); const F32 pixel_area = (F32)sqrt(mCharacter->getPixelArea()); const BOOL is_self = (dynamic_cast<LLVOAvatar *>(mCharacter) != NULL && ((LLVOAvatar*)mCharacter)->isSelf()); if ((pixel_area > area_for_this_setting) || is_self) { const F32 position_diff_local = llabs(mPositionLastUpdate_local-position_new_local_clamped); const F32 min_delta = (1.0001f-lod_factor)*0.4f; if (llabs(position_diff_local) > min_delta) { update_visuals = TRUE; mPositionLastUpdate_local = position_new_local; } } // // End update visual params //////////////////////////////////////////////////////////////////////////////// mVelocity_local = velocity_new_local; mAccelerationJoint_local = acceleration_joint_local; mPosition_local = position_new_local; } mLastTime = time; mPosition_world = joint->getWorldPosition(); mVelocityJoint_local = velocity_joint_local; /* // Write out debugging info into a spreadsheet. if (mFileWrite != NULL && is_self) { fprintf(mFileWrite,"%f\t%f\t%f \t\t%f \t\t%f\t%f\t%f\t \t\t%f\t%f\t%f\t%f\t%f \t\t%f\t%f\t%f\n", position_new_local, velocity_new_local, acceleration_new_local, time_delta, mPosition_world[0], mPosition_world[1], mPosition_world[2], force_net, force_spring, force_accel, force_damping, force_drag, spring_length, velocity_joint_local, acceleration_joint_local ); } */ return update_visuals; }
int synthv1_jack::process ( jack_nframes_t nframes ) { if (!m_activated) return 0; const uint16_t nchannels = synthv1::channels(); float *ins[nchannels], *outs[nchannels]; for (uint16_t k = 0; k < nchannels; ++k) { ins[k] = static_cast<float *> ( ::jack_port_get_buffer(m_audio_ins[k], nframes)); outs[k] = static_cast<float *> ( ::jack_port_get_buffer(m_audio_outs[k], nframes)); } const float bpm_sync = paramValue(synthv1::DEL1_BPMSYNC); if (bpm_sync > 0.0f) { const float bpm_host = paramValue(synthv1::DEL1_BPMHOST); if (bpm_host > 0.0f) { jack_position_t pos; jack_transport_query(m_client, &pos); if (pos.valid & JackPositionBBT) { const float bpm = float(pos.beats_per_minute); if (::fabs(bpm_host - bpm) > 0.01f) setParamValue(synthv1::DEL1_BPMHOST, bpm); } } } uint32_t ndelta = 0; #ifdef CONFIG_JACK_MIDI void *midi_in = ::jack_port_get_buffer(m_midi_in, nframes); if (midi_in) { const uint32_t nevents = ::jack_midi_get_event_count(midi_in); for (uint32_t n = 0; n < nevents; ++n) { jack_midi_event_t event; ::jack_midi_event_get(&event, midi_in, n); uint32_t nread = event.time - ndelta; if (nread > 0) { synthv1::process(ins, outs, nread); for (uint16_t k = 0; k < nchannels; ++k) { ins[k] += nread; outs[k] += nread; } } ndelta = event.time; synthv1::process_midi(event.buffer, event.size); } } #endif #ifdef CONFIG_ALSA_MIDI const jack_nframes_t buffer_size = ::jack_get_buffer_size(m_client); const jack_nframes_t frame_time = ::jack_last_frame_time(m_client); uint8_t event_buffer[1024]; jack_midi_event_t event; while (::jack_ringbuffer_peek(m_alsa_buffer, (char *) &event, sizeof(event)) == sizeof(event)) { if (event.time > frame_time) break; jack_nframes_t event_time = frame_time - event.time; if (event_time > buffer_size) event_time = 0; else event_time = buffer_size - event_time; if (event_time > ndelta) { const uint32_t nread = event_time - ndelta; if (nread > 0) { synthv1::process(ins, outs, nread); for (uint16_t k = 0; k < nchannels; ++k) { ins[k] += nread; outs[k] += nread; } } ndelta = event_time; } ::jack_ringbuffer_read_advance(m_alsa_buffer, sizeof(event)); ::jack_ringbuffer_read(m_alsa_buffer, (char *) event_buffer, event.size); synthv1::process_midi(event_buffer, event.size); } #endif // CONFIG_ALSA_MIDI synthv1::process(ins, outs, nframes - ndelta); return 0; }
void CHttpRequest::setParamValue(const char* key, const char* value) { setParamValue(string(key), string(value)); }