Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Feature Requests

Reply
 
Thread Tools Display Modes
Old 07-20-2021, 06:29 AM   #1
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default Changing note length via script in MIDI editor doesn't update fast enough

When using a script to shorten the MIDI note length (via GetSetAllEvts) and literally holding the action, the MIDI editor is not updating fast enough to reflect the changes. Only when I release the action, I see the current state of the note length.

Feature request: could have have the MIDI editor updating for scripts the same way as in the arrange?


1. My script action, notice the first resizing is visible for a split second, and then visual feedback ceases UNTIL, I release my shortcut key







2. The native REAPER action: updates perfectly, while holding the key:







3. My same script from 1., but now used in the arrange window: updates perfectly!

__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 07-20-2021, 07:45 AM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,378
Default

My Interactive Toolbar uses also GetSetAllEvt API. Works as fast as arrange. Seems there is a problem somewhere in your code.
__________________
SoundCloud | MPL Scripts discussion | ReaPack
mpl is offline   Reply With Quote
Old 07-20-2021, 08:15 AM   #3
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Hey mpl, thanks will investigate!

EDIT: had a look, I was wrong, I'm using the MIDISetNote method for this one, that's why.

EDIT2_: I tried with my nudge notes script (that one definitely is based on SetAllEvts, with a similar outcome. First SetAllEvts and then "move notes one pixel". For the record, there are a LOT of notes in that project:



The less notes in the project, the faster the update of the notes via SetAllEvts. The native "move notes" action doesn't seem to care for how many notes there are in a project. It's always smooth.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom

Last edited by _Stevie_; 07-20-2021 at 05:10 PM.
_Stevie_ is offline   Reply With Quote
Old 07-20-2021, 06:40 PM   #4
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Found the culprit: I have set the key repeat rate to maximum. Apparently, Reaper doesn't really like that and scripts get executed too frequently, when pressing and holding a key.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 07-21-2021, 12:09 PM   #5
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Investigating further. because with the current project I'm working on, I still have issues, even though I have reduced the key repeat rate.

Definitely not a big project:


Here's what it looks like when changing note lengths via my script:



Here's the code I'm using:

Code:
local function ChangeNoteLengthMIDIEditor(take)

    local got_all_ok, midi_string = reaper.MIDI_GetAllEvts(take, "") -- write MIDI events to midi_string, get all events okay
    if not got_all_ok then reaper.ShowMessageBox("Error while loading MIDI", "Error", 0) return(false) end -- if getting the MIDI data failed
    
    local table_events = {} -- initialize table, MIDI events will temporarily be stored in this table until they are concatenated into a string again
    local midi_len = #midi_string -- get string length
    local string_pos = 1 -- position in midi_string while parsing through events 
    local offset, flags, msg
    

        while string_pos < midi_len-12 do -- parse through all events in the MIDI string, one-by-one, excluding the final 12 bytes, which provides REAPER's All-notes-off end-of-take message
        offset, flags, msg, string_pos = string.unpack("i4Bs4", midi_string, string_pos) -- unpack MIDI-string on string_pos
        local status_byte = msg:byte(1)>>4 -- writing to a variable speeds up the comparison in the next if statement

        if #msg == 3
        and status_byte == 8 -- note-off
        and flags&1 == 1 -- only selected notes
        then
            table.insert(table_events, string.pack("i4Bs4", offset+new_length, flags, msg)) -- move the note on event by new_position
            table.insert(table_events, string.pack("i4Bs4", -new_length, 0, "")) -- put an empty event after the note on event, to maintain the distance
        else
            table.insert(table_events, string.pack("i4Bs4", offset, flags, msg)) -- re-pack MIDI string and write unchanged events
        end
    end
    reaper.MIDI_SetAllEvts(take, table.concat(table_events) .. midi_string:sub(-12))
    reaper.MIDI_Sort(take)
end
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 09-22-2022, 07:47 AM   #6
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Summing this up, since today I found the culprit. It turns out that the issue is, that the MIDI Editor isn't refreshed fast / often enough. Spamming a key literally freezes the ME update, until you lift the key. I tested this on macOS and Windows, and apparently, only Windows is affected.

The only solution to solve this is to use a function from the JS API:
Code:
reaper.JS_Window_Update( windowHWND )
But to be honest, this is ridiculous. I have to use a 3rd party library in order to make MIDI scripts update fast enough, really?

I'm truly annoyed by the fact that I wasted so much time on something (coding, finding workarounds, finding the issue...), that should work out of the box!
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 09-22-2022, 08:15 AM   #7
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 9,230
Default

Quote:
Originally Posted by _Stevie_ View Post
Summing this up, since today I found the culprit. It turns out that the issue is, that the MIDI Editor isn't refreshed fast / often enough. Spamming a key literally freezes the ME update, until you lift the key. I tested this on macOS and Windows, and apparently, only Windows is affected.

The only solution to solve this is to use a function from the JS API:
Code:
reaper.JS_Window_Update( windowHWND )
But to be honest, this is ridiculous. I have to use a 3rd party library in order to make MIDI scripts update fast enough, really?

I'm truly annoyed by the fact that I wasted so much time on something (coding, finding workarounds, finding the issue...), that should work out of the box!
Maybe it's a bug and the devs aren't aware of it?
vitalker is online now   Reply With Quote
Old 09-22-2022, 08:25 AM   #8
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Hopefully, they will read this and tell us.

I have quite a bunch of posts about this issue and never got feedback / confirmation about it.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 09-22-2022, 08:41 AM   #9
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 9,230
Default

Quote:
Originally Posted by _Stevie_ View Post
Hopefully, they will read this and tell us.

I have quite a bunch of posts about this issue and never got feedback / confirmation about it.
Did you post it to bug reports forum?
vitalker is online now   Reply With Quote
Old 09-22-2022, 08:45 AM   #10
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Yes:
https://forums.cockos.com/showthread.php?t=269072
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 09-22-2022, 08:51 AM   #11
vitalker
Human being with feelings
 
vitalker's Avatar
 
Join Date: Dec 2012
Posts: 9,230
Default

Quote:
Originally Posted by _Stevie_ View Post
Okay, bumped.
vitalker is online now   Reply With Quote
Old 09-22-2022, 02:30 PM   #12
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 4,585
Default

Thanks!
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_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 02:51 AM.


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