Old 05-26-2020, 05:56 AM   #1
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default C++ SetEnvelopeStateChunk

Greetings all,

I'm trying to successfully write to the EnvelopeStateChunk... but not succeeding.
So far I have,

char chunk[20000]; // silly large amount. Have tried smaller ie 2000 just in case the problem is here
int help = 20000;
GetEnvelopeStateChunk(GetTrackEnvelopeByChunkName( x->TrkVec[0].MTrk, "<VOLENV2"), chunk, help, true); //TrackEnvelope is valid. have checked by reading returned chunk.
std::string msg1(chunk);
std::cout << "pre edit - " << msg1 << std::endl;
size_t f = msg1.find("ARM");
msg1.replace(f, 5, "ARM 1");
std::cout << "post edit - " << msg1 << std::endl;
// The above appears to correctly change the text in msg1

bool test = SetEnvelopeStateChunk(tootle, msg1.c_str(), true);
// returns false and chunk is not updated. I have also tried 'false' for bool isundoOptional

Am I missing a simple step here?
Any help graciously and thankfully received.
Kind regards,
Leigh Hunt
leighhunt is offline   Reply With Quote
Old 05-26-2020, 07:50 AM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,109
Default

Hi,

hm..your code (with slight modifications to make it executeable) seems to work here on a quick test. I can use it to set volume env. not armed > armed (which I guess is the goal of this code?)

The code I used:
Code:
char chunk[20000]; // silly large amount. Have tried smaller ie 2000 just in case the problem is here
int help = 20000;
MediaTrack* tr1 = CSurf_TrackFromID(1, false);
TrackEnvelope* volEnv = GetTrackEnvelopeByChunkName(tr1, "<VOLENV2");
GetEnvelopeStateChunk(volEnv, chunk, help, true); //TrackEnvelope is valid. have checked by reading returned chunk.
std::string msg1(chunk);
std::cout << "pre edit - " << msg1 << std::endl;
size_t f = msg1.find("ARM");
msg1.replace(f, 5, "ARM 1");
std::cout << "post edit - " << msg1 << std::endl;
// The above appears to correctly change the text in msg1

bool test = SetEnvelopeStateChunk(volEnv, msg1.c_str(), true);
// returns false and chunk is not updated. I have also tried 'false' for bool isundoOptional
(sidenote: you may consider putting your posted code between code tags for a bit easier reading (and keeping formatting intact.)

Debugging screenshot (note the test == true at the bottom)



Does this help in any way?
Btw. I wonder what is 'tootle' in your last line?

edit:
sidenote2:
You can also do
Code:
GetEnvelopeStateChunk(volEnv, chunk, sizeof(chunk), true);
and skip the help variable for a slight code improvement.

Last edited by nofish; 05-26-2020 at 08:05 AM.
nofish is offline   Reply With Quote
Old 05-26-2020, 08:42 AM   #3
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default

Thanks for the reply.
I'm wondering whether the positioning of this code could be the issue here, as it stubbornly refuses to set the chunk.
fyi - I'm using this code in a vst2 plugin, in an OSC receive thread. I do a lot of other api stuff in there too which runs absolutely fine.
Thanks for the size of(chunk) heads up.. I know this, and completely forgot!
leighhunt is offline   Reply With Quote
Old 05-26-2020, 08:56 AM   #4
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default

oh, and 'tootle' was a residual temporary name I used, randomly typed !
leighhunt is offline   Reply With Quote
Old 05-26-2020, 09:05 AM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,109
Default

Quote:
Originally Posted by leighhunt View Post
Thanks for the reply.
I'm wondering whether the positioning of this code could be the issue here, as it stubbornly refuses to set the chunk.
fyi - I'm using this code in a vst2 plugin, in an OSC receive thread. I do a lot of other api stuff in there too which runs absolutely fine.
Thanks for the size of(chunk) heads up.. I know this, and completely forgot!
That's not my field of experience, sorry, but I remember this statement from Justin saying
Quote:
most REAPER APIs are designed only to be used from the main (GUI) thread, not from audio threads or from plug-in-created threads.
https://www.askjf.com/index.php?q=3889
nofish is offline   Reply With Quote
Old 05-26-2020, 11:31 AM   #6
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default

Quote:
Originally Posted by nofish View Post
That's not my field of experience, sorry, but I remember this statement from Justin saying


https://www.askjf.com/index.php?q=3889
Yes, I am aware of the potential for the code messing up big time as a result of not keeping to using the api where it is advised to be used.
I have done a lot of testing and it's a personal project.
I did find that triggering any actions using ON_COMMAND in my code caused problems (so I pipe OSC through to actions in Reaper).
This indeed might be a second anomaly that could prove to be something of a hurdle.
I'm reluctant to move this project over to a Reascript and/or control surface project as my knowledge in that area is pretty basic.
I've currently implemented quite a lot of the project;
OSC streams to and from 5 sources including 2 touchscreens (using good old Maxmsp to build the GUI) .
Midi to and from 5 devices.
A complete data structure for quite a lot of data.
JSON for easily readable data storage.

I have no idea what is possible in Reascript regarding the above (and possibly quite some more bits and bobs I've implemented), so I will soldier on for now and see if I can find a solution for this.

Thanks muchly for your help and suggestions.
Kind regards,
Leigh
leighhunt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.