|
|
|
10-12-2020, 01:02 PM
|
#1
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
Need help with this script
Greetings awesome Reaper coders!
I'm using a script from me2beats. He hasn't logged in the forum since 2018, so maybe some one else can help. This script sets the MIDI velocity of the selected notes. It works great, except for one thing, after it completes, the focus changes from the MIDI editor window to the main window. I have to click the MIDI editor window to set the focus back...
I thought I could do a custom action that calls the script and then changes the focus back, but I can't access the function to set the focus to the MIDI editor when invoking custom actions from the MIDI editor.
I'm guessing it's a simple fix, but I have no clue what to do. Thanks in advance!
Here is the lua script: me2beats_Set velocity for selected notes.lua
Code:
-- @description Set velocity for selected notes
-- @version 1.0
-- @author me2beats
-- @changelog
-- + init
local r = reaper; local function nothing() end; local function bla() r.defer(nothing) end
take = r.MIDIEditor_GetTake(r.MIDIEditor_GetActive())
if not take then bla() return end
local _, notes = r.MIDI_CountEvts(take)
if notes == 0 then bla() return end
retval, vel = r.GetUserInputs('Velocity', 1, 'Velocity:','')
if retval == false then bla() return end
vel = tonumber(vel)
if not vel then bla() return end
if vel > 127 then vel = 127 elseif vel < 1 then vel = 1 end
vel = math.floor(vel+0.5)
r.Undo_BeginBlock() r.PreventUIRefresh(1)
for i = 0, notes - 1 do
local _, sel = r.MIDI_GetNote(take, i)
if sel then
r.MIDI_SetNote(take, i, nil, nil, nil, nil, nil, nil, vel, 0)
end
end
r.PreventUIRefresh(-1) r.Undo_EndBlock('Set velocity for sel notes', -1)
|
|
|
10-12-2020, 01:33 PM
|
#2
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
Its caused by the GetUserInputs function, when that dialog closes its setting focus on REAPER main window,
EDIT see post #4.
Last edited by Edgemeal; 10-12-2020 at 03:50 PM.
|
|
|
10-12-2020, 01:59 PM
|
#3
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
@ edgemeal;
I did the edit on the script, and no change. Do I have to save it as a different name, or somehow reload it into Reaper? I did close Reaper before I edited the script...
Edit:
I do have the SWS extensions.
But thanks a million already! I see that it does change the focus when the popup window opens.
|
|
|
10-12-2020, 03:42 PM
|
#4
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
No need to close/restart REAPER.
Just edit the script, change this part,
Code:
retval, vel = r.GetUserInputs('Velocity', 1, 'Velocity:','')
if retval == false then bla() return end
to this,
Code:
retval, vel = r.GetUserInputs('Velocity', 1, 'Velocity:','')
reaper.SN_FocusMIDIEditor()
if retval == false then bla() return end
Save it, and use.
Last edited by Edgemeal; 10-12-2020 at 03:51 PM.
|
|
|
10-15-2020, 12:11 PM
|
#5
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
Thanks again, edgemeal, but it's still not working...
I'm running the latest Reaper on Ubuntu linux. I don't think that matters though, I don't have problems with other scripts.
I'm curious, did you try this on your system? I see in your signature you're running Windows.
|
|
|
10-15-2020, 12:32 PM
|
#6
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
Must be a Linux thing, works as expected here on Win10.
|
|
|
10-15-2020, 01:48 PM
|
#7
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
@Pman
Can you post a LiceCap-gif that shows, how you try to use it?
Maybe this reveals some edgecases...
|
|
|
10-15-2020, 03:57 PM
|
#8
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
@Meo-Ada Mespotine,
Sadly, licecap does not run on Linux. But here is the use-case:
me2beats' wonderful script sets MIDI velocity so from the MIDI editor window I:
1) select a group of MIDI notes
2) click on the icon that is assigned to that script (when the popup window opens, the focus switches from the MIDI editor window to the popup window)
3) I enter a velocity value in the popup window and click "OK"
4) the popup window closes and the MIDI editor window does not have the focus. I have to click in the MIDI editor window to bring the focus back.
----
It doesn't crash or anything, but often what I do is unselect all selected notes (I have "u" assigned as the hotkey for that) after editing them. After 4 or 5 edits it gets annoying having to re-select the editor window every time...
I tried making a custom action that calls the script, then calls the SWS function 'MIDI editor focus', but I can't do that because 'MIDI editor focus' is not available in the MIDI editor section...
It's not the end of the world, but it sure would be nice if I could fix this.
Thanks!
|
|
|
10-16-2020, 06:40 AM
|
#9
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
You can make a script call a Main action from the MIDI editor, but the action 'MIDI editor focus' is probably calling the same SWS code that I posted so wouldn't matter, that SWS action probably needs an update to support Linux.
Another way is to save the handle of the active MIDI window before calling GetUserInputs, then set it as the foreground window afterwards, try editing the original code to look like this,..
Code:
local me_hwnd = reaper.MIDIEditor_GetActive()
retval, vel = r.GetUserInputs('Velocity', 1, 'Velocity:','')
reaper.BR_Win32_SetForegroundWindow(me_hwnd)
Hopefully Linux supports SetForegroundWindow!
|
|
|
10-17-2020, 10:46 AM
|
#10
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
Still not working...
I tried this: with the MIDI editor window open but not focused, I opened the action window and found the command "SWS/SN: Focus MIDI editor".
I ran that command from the action window and the MIDI editor window became active. I could do MIDI hotkey commands (no clicking in the editor window) and they work. So the SWS "Focus MIDI editor" command works in Linux.
How would I add this command to a custom command that originates from the MIDI editor section?
By the way, the action code for this command is: _SN_FOCUS_MIDI_EDITOR
Thanks again!
|
|
|
10-17-2020, 11:14 AM
|
#11
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
OK, then after the GetUserInputs line try this instead,..
Code:
retval, vel = r.GetUserInputs('Velocity', 1, 'Velocity:','')
reaper.Main_OnCommand(reaper.NamedCommandLookup('_SN_FOCUS_MIDI_EDITOR'), 0) -- SWS/SN: Focus MIDI editor
If that still doesn't work then I have no clue whats going on, all these solutions work in Win10.
|
|
|
10-19-2020, 08:32 AM
|
#12
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
It's still not working...
Thanks a million for your efforts, edgemeal!
I guess this is a Reaper Linux bug, I'll post it in the appropriate forum.
Thanks again!
|
|
|
10-22-2020, 03:55 PM
|
#13
|
Human being with feelings
Join Date: Aug 2019
Posts: 656
|
I never did get the set velocity script to set the focus back to the MIDI editor window, but I was able to create a custom action that runs the set velocity script, then the sws focus midi editor action.
Mission accomplished!
Thanks again for the feedback, edgemeal!
|
|
|
10-22-2020, 11:05 PM
|
#14
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
Quote:
Originally Posted by PMan
I never did get the set velocity script to set the focus back to the MIDI editor window, but I was able to create a custom action that runs the set velocity script, then the sws focus midi editor action.
Mission accomplished!
Thanks again for the feedback, edgemeal!
|
Weird, I guess its not all the same, or just bugs in Linux? Whatever works!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 07:51 PM.
|