Old 11-02-2017, 12:50 PM   #1
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default Issue with script, executed too fast?

I'm executing some commands within a LUA script:

Quote:
reaper.Undo_BeginBlock() -- to create a consolidated undo point in the Undo History

-- run Main window actions:
reaper.Main_OnCommand(reaper.NamedCommandLookup("_ BR_SAVE_CURSOR_POS_SLOT_1"),0) -- SWS/BR: Save edit cursor position, slot 01
reaper.Main_OnCommand(41174, 0) -- Item navigation: Move cursor to end of items
reaper.Main_OnCommand(reaper.NamedCommandLookup("_ BR_SAVE_CURSOR_POS_SLOT_2"),0) -- SWS/BR: Save edit cursor position, slot 02
reaper.Main_OnCommand(reaper.NamedCommandLookup("_ BR_RESTORE_CURSOR_POS_SLOT_1"),0) -- SWS/BR: Save edit cursor position, slot 01
reaper.Main_OnCommand(41311, 0) -- Item edit: Trim right edge of item to edit cursor
reaper.Main_OnCommand(reaper.NamedCommandLookup("_ BR_RESTORE_CURSOR_POS_SLOT_2"),0) -- SWS/BR: Save edit cursor position, slot 02
reaper.Main_OnCommand(reaper.NamedCommandLookup("_ XENAKIOS_MOVECUR10PIX_LEFTCTS"),0) -- Xenakios/SWS: Move cursor left 10 pixels, creating time selection
reaper.Main_OnCommand(reaper.NamedCommandLookup("_ BR_RESTORE_CURSOR_POS_SLOT_1"),0) -- SWS/BR: Save edit cursor position, slot 01
reaper.Main_OnCommand(40153, 0) -- Item: Open in built-in MIDI editor (set default behavior in preferences)

hwnd = reaper.MIDIEditor_GetActive() -- get active MIDI editor
-- run MIDI editor actions:

reaper.MIDIEditor_OnCommand(hwnd, 40746) -- Edit: Select all notes in time selection
reaper.MIDIEditor_OnCommand(hwnd, 40791) -- Edit: Trim right edge of note to edit cursor
reaper.MIDIEditor_OnCommand(hwnd, 2) -- File: Close window
reaper.Main_OnCommand(40635, 0) -- Time selection: Remove time selection


reaper.Undo_EndBlock("Script: Expand Item and Notes to Cursor", -1 )
It worked at first, as shown here:


But now, sometimes I have some irregular bugs, like the notes are not extended to the end of the item. Could it be, that the script is executed too fast?
Afterall, the editor is opened and closed very fast.
_Stevie_ is offline   Reply With Quote
Old 11-02-2017, 04:59 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

You would get better results by using the scripting API rather than running GUI actions one after the other. It would run faster too without GUI flickering.

Try "Set item end to cursor and resize trailing MIDI notes" which I just added in ReaPack/ReaTeam Scripts.

Last edited by cfillion; 11-02-2017 at 05:06 PM.
cfillion is offline   Reply With Quote
Old 11-02-2017, 05:31 PM   #3
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Merci cfillion, you rock!I will check it in a few!
I started using Reaper some days ago. I've used Cubase before and did a lot of additional scripting
in AutoHotkey. There seems to be no need anymore :-)
But that also means I have to dive into LUA, since I never coded in that language.

EDIT: tried it, OMG, this is so amazing, thank you so much!

Last edited by _Stevie_; 11-02-2017 at 07:08 PM.
_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 11:05 AM.


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