Esempio n. 1
0
static bool EnvelopeToString(CStringA &s, const InstrumentEnvelope &env)
//----------------------------------------------------------------------
{
	// We don't want to copy empty envelopes
	if(env.empty())
	{
		return false;
	}

	s.Preallocate(2048);
	s = pszEnvHdr;
	s.AppendFormat(pszEnvFmt, env.size(), env.nSustainStart, env.nSustainEnd, env.nLoopStart, env.nLoopEnd,
		env.dwFlags[ENV_SUSTAIN] ? 1 : 0, env.dwFlags[ENV_LOOP] ? 1 : 0, env.dwFlags[ENV_CARRY] ? 1 : 0);
	for(auto &p : env)
	{
		s.AppendFormat("%d,%d\r\n", p.tick, p.value);
	}

	// Writing release node
	s.AppendFormat("%u\r\n", env.nReleaseNode);
	return true;
}
Esempio n. 2
0
CString stripRTF(const CStringA& rtf, unsigned codepage)
{
	CStringA out;
	out.Preallocate(rtf.GetLength());

	int state = 0;
	const char *p = (const char *)rtf;
	while (*p)
	{
		char ch = *p;

		if (state == 0)
		{
			if (ch == '\\')
				state = 1;
			else if (ch == '\r')
				/*ignore*/;
			else
//				out += wchar_t(ch);
				out += ch;
		}
		else if (state == 1)
		{
			if (ch == '\\' || ch == '{')
			{
				out += ch; // escaped characters
				state = 0;
			}
			else if (ch == '\'')
			{
				out += unhex(p[1], p[2]);
				p += 2;
				state = 0;
			}
			else if (ch == 'u')
			{
				// unicode character
//				out += wchar_t((unsigned)atoi(p+1));
//				p += strspn(p, "0123456789");
//				state = 0;
				ASSERT(FALSE);
			}
			else
			{
				state = 2;
			}
		}
		else if (state == 2)
		{
			if (ch == ' ' || ch == '\n' || ch == '}' || ch == '{')
				state = 0;
			else if (ch == '\\')
				state = 1;
		}

		++p;
	}

	CString out2;
	LPTSTR buf = out2.GetBuffer(out.GetLength() + 10);
	MultiByteToWideChar(codepage, 0, out, -1, buf, out.GetLength() + 10);
	out2.ReleaseBuffer();

	return out2;
}