C++ SetEnvelopeStateChunk making Reaper crash.
I have been tying to implement Volume and MUTE envelope automation ARM and UNARM functions using "GetEnvelopeStateChunk"/"SetEnvelopeStateChunk" API calls, but Reaper keeps 'unexpectedly quiting" as soon as the "SetEnvelopeStateChunk" function is executed.
This is part of the code that I use
#include <string>
#include <string.h>
/************************************************** **********************************/
// void ArmVolEnv(int trackid)
/************************************************** ***********************************/
void ArmVolEnv(int trackid)
{
std::string msgtofind("ARM");
std::string rplmsg("ARM 1");
TrackEnvelope* trackEnvelope = GetTrackEnvelopeByChunkName(GetTrack(nil,trackid), "<VOLENV2"); //Get Volume envelope from trackid
char chunk[2000];
chunk[0] = 0;
if(GetEnvelopeStateChunk(trackEnvelope, chunk, 1999, true))
{
std::string msg1(chunk);
std::size_t found = msg1.find(msgtofind);
msg1.replace(found, 5, rplmsg);
std::string msg1(chunk);
std::size_t found = msg1.find(msgtofind);
msg1.replace(found, 5, rplmsg);
char * modchunk = new char[msg1.length()+1];
std::strcpy (modchunk, msg1.c_str());
SetEnvelopeStateChunk(trackEnvelope,modchunk , 0);
//Test that chunk is correctly extracted:
char msgbuf1[32];
ShowConsoleMsg("Original msg: \n");
ShowConsoleMsg(chunk);
ShowConsoleMsg(" \n");
sprintf(msgbuf1,"%lu",strlen(chunk));
ShowConsoleMsg("caracter count in chunk:");
ShowConsoleMsg(msgbuf1);
ShowConsoleMsg(" \n");
//test that "modchunk" is modified:
sprintf(msgbuf1,"%lu",strlen(modchunk));
ShowConsoleMsg("caracter count in modchunk:");
ShowConsoleMsg(msgbuf1);
ShowConsoleMsg(" \n");
ShowConsoleMsg("Replaced by :\n");
sprintf(msgbuf1,"%s",msg1.c_str());
ShowConsoleMsg(msgbuf1);
// SetEnvelopeStateChunk(trackEnvelope, modchunk, 1);
}
}
if I comment out "SetEnvelopeStateChunk", it makes Reaper systematically crash.
I have attached the OSX crash report
Any help on that issue would be appreciated
dbmdbu
Last edited by dbmdbu; 07-30-2017 at 07:26 AM.
|