Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 12-18-2016, 04:51 AM   #1
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,748
Default ReaScript: Undo_EndBlock with flags != -1 are not added to undo history

The undo text shows up in the menu bar of the main window, but it is not added to the list of undo points in the Undo History window.

EDIT: Could the meanings of the flags be added to the API documentation? The only place where this info is available on the internet, is in the thread Changing ReaScript Undo Name.

EDIT 2: If this behavior is intentional and not a bug, could the devs please confirm? In this case, these flags could be very useful for ending undo blocks without creating undo points. For example, if a scripts calls native Actions in a deferred loop using OnCommand, these flags can be used to bracket the Actions inside an undo block, thereby preventing the creation of undo points in each cycle.

EDIT 2017-06-04: I notice that some info regarding undo flags have been added to the ReaScript Introduction page:

-1: All undo info
0: ???? When only calling actions via OnCommand, since these create their own undo points
1: track configurations (track/master vol/pan/routing, ALL envelopes (master included))
2: track/master FX
4: track items
8: project states (loop selection, markers, regions)
16: freeze states

The page also states that:

"If you are simply calling other actions (via Main_OnCommand or similar functions), [the undo flags] should be 0. If you modify the state of the project directly, it's safest to set the bitmask to -1."

"A more specific combination of flags may be an optimization, depending on what your script is doing."

Last edited by juliansader; 06-04-2017 at 11:43 PM.
juliansader is online now   Reply With Quote
Old 12-18-2016, 12:29 PM   #2
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 10,964
Default

If you don't call with flags=-1, it will look at undo flags set by the actions you're using in the middle of the block. Depending on what you're doing, you might not be marking things dirty correctly (which means the things edited won't be checked for changes, which would cause an undo point not to be added as you describe) -- what's happening in the middle of that block?
Justin is online now   Reply With Quote
Old 12-18-2016, 02:48 PM   #3
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,748
Default

Quote:
Originally Posted by Justin View Post
what's happening in the middle of that block?
It seems that when I use *only* the new MIDI_SetAllEvts function to change an item's MIDI, and then use any flag other than -1 (in particular, I wanted to use flag=4 to limit the undo to items), I consistently get no undo point in the Undo History.

The other examples are inconsistent, so I have a feeling they might have been spillover effects from the SetAllEvts undo problem: For example, when I used flag=0, and the undo block consisted of only 1) an OnCommand of "Insert note at mouse cursor" and 2) a subsequent MIDI_GetNote, I sometimes - but not always - also got no undo history.
juliansader is online now   Reply With Quote
Old 12-24-2016, 01:35 AM   #4
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,748
Default

Am I doing something silly wrong when I try to use flag=4?

If I understand correctly, flag=4 will limit the information that is included in the undo point to changes that were made to *items*, so I assumed that it would cover
* ReaScript functions such as MIDI_SelectAll or MIDI_SetAllEvts, as well as
* Actions such as "Invert selection".

By excluding irrelevant stuff such as FX states, the creation of the undo point is much faster: <0.05 seconds versus >1 second.
juliansader is online now   Reply With Quote
Old 12-12-2017, 04:37 PM   #5
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 482
Default

I have the same problem. When using MIDI_GetNote this seems to mess with the Undo.

Here's my code: https://github.com/StephanRoemer/Rea...t%20cursor.lua


@Julian, did you ever find a solution to the issue?

Last edited by _Stevie_; 12-14-2017 at 05:33 AM.
_Stevie_ is offline   Reply With Quote
Old 12-14-2017, 04:29 AM   #6
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,748
Default

Unfortunately not.

It seems that some (or all?) of these MIDI functions do not play nice with Undo blocks. Even if you use flags = -1 in Undo_EndBlock (which should cover all types of changes), no undo point is created.

Justin mentioned above that the functions perhaps do not "mark things dirty correctly (which means the things edited won't be checked for changes, which would cause an undo point not to be added as you describe)".

However, strangely, other undo functions such as reaper.Undo_OnStateChange_Item and reaper.Undo_OnStateChange2 *do* work correctly with the MIDI functions, and do recognize that changes were made. (They are also much faster to execute.)

If you prefer to use Undo_Start/EndBlock, you can force REAPER to realize that changes were made by including any dummy change such as
Code:
reaper.SetMediaItemSelected(item, false)
reaper.SetMediaItemSelected(item, true)

(BTW, in your script, you use flag = 2, which refers to changes in track/master FX. If these Undo block bugs are eventually fixed, I expect that flag = 4: track items will be more appropriate.)

EDIT: reaper.MarkTrackItemsDirty can perhaps also be used to ensure that Undo gets activated.

Last edited by juliansader; 05-18-2018 at 04:17 AM.
juliansader is online now   Reply With Quote
Old 12-15-2017, 10:36 PM   #7
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 482
Default

Code:
reaper.SetMediaItemSelected(item, false)
reaper.SetMediaItemSelected(item, true)
Thanks, that worked perfectly!
I'm not familiar with reaper.Undo_OnStateChange_Item and reaper.Undo_OnStateChange2. Is it also possible to assign an "undo name"?

Quote:
Originally Posted by juliansader View Post
(BTW, in your script, you use flag = 2, which refers to changes in track/master FX. If these Undo block bugs are eventually fixed, I expect that flag = 4: track items will be more appropriate.)
Thanks, fixed!

Last edited by _Stevie_; 12-16-2017 at 05:59 AM.
_Stevie_ is offline   Reply With Quote
Old 12-16-2017, 02:54 AM   #8
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,748
Default

Quote:
Originally Posted by _Stevie_ View Post
I'm not familiar with reaper.Undo_OnStateChange_Item and reaper.Undo_OnStateChange2. Is it also possible to assign an "undo name"
Yep:
Code:
reaper.Undo_OnStateChange2(ReaProject proj, string descchange)

limited state change to items

Code:
reaper.Undo_OnStateChange_Item(ReaProject proj, string name, MediaItem item)

limited state change to one item
The "descchange" and "name" fields are the undo names.
juliansader is online now   Reply With Quote
Old 12-16-2017, 05:12 AM   #9
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 482
Default

Awesome, thanks Julian! Checking it out!

EDIT: this works great, thanks Julian!

Last edited by _Stevie_; 12-16-2017 at 05:58 AM.
_Stevie_ 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 08:43 AM.


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