示例#1
0
EnvelopeProcessor::ErrorCode EnvelopeProcessor::processSelectedTrackEnv()
{
	TrackEnvelope* envelope = GetSelectedTrackEnvelope(0);
	if(!envelope)
		return eERRORCODE_NOENVELOPE;

	Undo_BeginBlock2(0);

	double dStartPos, dEndPos;
	GetTimeSegmentPositions(_envModParams.timeSegment, dStartPos, dEndPos);

	if(dStartPos==dEndPos)
		return eERRORCODE_NULLTIMESELECTION;

	double dValMin, dValMax;
	ErrorCode res = getTrackEnvelopeMinMax(envelope, dValMin, dValMax);
	if(res != eERRORCODE_OK)
		return res;

	char* envState = GetSetObjectState(envelope, "");
	string newState;
	res = processPoints(envState, newState, dStartPos, dEndPos, dValMin, dValMax, _envModParams.type, _envModParams.strength, _envModParams.offset);
	if(GetSetObjectState(envelope, newState.c_str()))
		res = eERRORCODE_UNKNOWN;
	else
		FreeHeapPtr(envState);

//UpdateTimeline();
/* JFB "recursive" undo point, enabled at top level
	Undo_OnStateChangeEx("Envelope Processor", UNDO_STATE_ALL, -1);
*/
	Undo_EndBlock2(NULL, __LOCALIZE("Track envelope processor","sws_undo"), UNDO_STATE_TRACKCFG);
	return res;
}
示例#2
0
EnvelopeProcessor::ErrorCode EnvelopeProcessor::getTrackEnvelopeMinMax(TrackEnvelope* envelope, double &dEnvMinVal, double &dEnvMaxVal)
{
	if(!envelope)
		return eERRORCODE_NOENVELOPE;

	char* envState = GetSetObjectState(envelope, "");
	if(!envState)
		return eERRORCODE_NOOBJSTATE;

	dEnvMinVal = 0.0;
	dEnvMaxVal = 1.0;
	double dTmp[2];
	int iTmp;

	stringstream envStateStream;
	envStateStream << envState;
	std::vector<string> tokens;
	while(!envStateStream.eof())
	{
		string str;
		getline(envStateStream, str, '\n');
		tokens.push_back(str);
	}

	for(vector<string>::const_iterator it = tokens.begin(); it !=tokens.end(); ++it)
	{
		// Track envelope: Volume
		if(!strcmp(it->c_str(), "<VOLENV") || !strcmp(it->c_str(), "<VOLENV2"))
		{
			dEnvMaxVal = 2.0;
			break;
		}

		// Track envelope: Pan
		if(!strcmp(it->c_str(), "<PANENV") || !strcmp(it->c_str(), "<PANENV2"))
		{
			dEnvMinVal = -1.0;
			break;
		}

		// Track envelope: Param (VST index, min value, max value)
		if(sscanf(it->c_str(), "<PARMENV %d %lf %lf", &iTmp, &dTmp[0], &dTmp[1]) == 3)
		{
			dEnvMinVal = dTmp[0];
			dEnvMaxVal = dTmp[1];
			break;
		}

		if(!strcmp(it->c_str(), ">"))
			break;
	}

	FreeHeapPtr(envState);
	return eERRORCODE_OK;
}
示例#3
0
bool SNM_GetSetObjectState(void* _obj, WDL_FastString* _state, bool _setnewvalue, bool _minstate)
{
    bool ok = false;
    if (_state && g_script_strs.Find(_state)>=0 && (ValidatePtr(_obj, "MediaTrack*") || ValidatePtr(_obj, "MediaItem*") || ValidatePtr(_obj, "TrackEnvelope*")))
    {
        int fxstate = SNM_PreObjectState(_setnewvalue ? _state : NULL, _minstate);
        char* p = GetSetObjectState(_obj, _setnewvalue ? _state->Get() : NULL);
        if (_setnewvalue)
        {
            ok = (p==NULL);
        }
        else if (p)
        {
            _state->Set(p);
            FreeHeapPtr((void*)p);
            ok = true;
        }
        SNM_PostObjectState(fxstate);
    }
    return ok;
}
示例#4
0
文件: SnM_Misc.cpp 项目: tweed/sws
bool SNM_GetSetObjectState(void* _obj, WDL_FastString* _state, bool _setnewvalue, bool _minstate)
{
	bool ok = false;
	if (_obj && _state)
	{
		int fxstate = SNM_PreObjectState(_setnewvalue ? _state : NULL, _minstate);
		char* p = GetSetObjectState(_obj, _setnewvalue ? _state->Get() : NULL);
		if (_setnewvalue)
		{
			ok = (p==NULL);
		}
		else if (p)
		{
			_state->Set(p);
			FreeHeapPtr((void*)p);
			ok = true;
		}
		SNM_PostObjectState(fxstate);
	}
	return ok;
}
示例#5
0
EnvelopeProcessor::ErrorCode EnvelopeProcessor::generateTrackLfo(TrackEnvelope* envelope, double dStartPos, double dEndPos, LfoWaveParams &waveParams, double dPrecision)
{
	if(!envelope)
		return eERRORCODE_NOENVELOPE;

	if(dStartPos==dEndPos)
		return eERRORCODE_NULLTIMESELECTION;

	char* envState = GetSetObjectState(envelope, "");
	if(!envState)
		return eERRORCODE_NOOBJSTATE;

	string newState;
	double dValMin = 0.0;
	double dValMax = 1.0;
	double dTmp[2];
	int iTmp;

	//! \todo Use with GetMinMax()
	char* token = strtok(envState, "\n");
	while(token != NULL)
	{
		if(!strcmp(token, "<VOLENV") || !strcmp(token, "<VOLENV2"))
			dValMax = 2.0;

		if(!strcmp(token, "<PANENV") || !strcmp(token, "<PANENV2"))
			dValMin = -1.0;

		// VST index, min value, max value
		if(sscanf(token, "<PARMENV %d %lf %lf", &iTmp, &dTmp[0], &dTmp[1]) == 3)
		{
			dValMin = dTmp[0];
			dValMax = dTmp[1];
		}

		// Position, value, shape
		if(sscanf(token, "PT %lf %lf %d\n", &dTmp[0], &dTmp[1], &iTmp) == 3)
		{
			if(dTmp[0]>=dEndPos)
				break;
			if(dTmp[0]>dStartPos)
			{
				token = strtok(NULL, "\n");
				continue;
			}
		}

		if(!strcmp(token, ">"))
			break;

		newState.append(token);
		newState.append("\n");
		token = strtok(NULL, "\n");
	}

	writeLfoPoints(newState, dStartPos, dEndPos, dValMin, dValMax, waveParams, dPrecision);

	newState.append(token);
	newState.append("\n");
	token = strtok(NULL, "\n");
	while(token != NULL)
	{
		newState.append(token);
		newState.append("\n");
		token = strtok(NULL, "\n");
	}

	FreeHeapPtr(envState);

	if(GetSetObjectState(envelope, newState.c_str()))
		return eERRORCODE_UNKNOWN;

/* JFB commented: leads to "recursive" undo point, enabled at top level
	Undo_OnStateChangeEx("Track Envelope LFO", UNDO_STATE_ALL, -1);
*/
	return eERRORCODE_OK;
}