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

Reply
 
Thread Tools Display Modes
Old 05-20-2017, 06:49 PM   #1
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default Action or API to focus MIDI editor

Reposting here from http://forum.cockos.com/showthread.php?t=176021

This is a simple request: provide an action and/or API function to focus the MIDI window.

API should receive a hwnd to focus, and the action can just focus the last focused MIDI editor.
tack is offline   Reply With Quote
Old 05-21-2017, 04:46 AM   #2
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

SWS/FNG: Focus Midi editor

snooks is offline   Reply With Quote
Old 05-21-2017, 07:58 AM   #3
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Quote:
Originally Posted by snooks View Post
SWS/FNG: Focus Midi editor
Oh, does this exist now? I don't see it in the latest release (2.8.8) and I don't see it in the release notes for the beta.
tack is offline   Reply With Quote
Old 05-21-2017, 03:16 PM   #4
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Aw crap, sorry - I must have added this to my local SWS ages ago under SWS/FNG for quickness. I'll make my own section and make a pull request in the next wee while, unless somebody else does it before then.
snooks is offline   Reply With Quote
Old 05-21-2017, 06:48 PM   #5
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Quote:
Originally Posted by snooks View Post
I'll make my own section and make a pull request in the next wee while, unless somebody else does it before then.
That would be awesome! I know many others would benefit from that.

Thanks snooks.
tack is offline   Reply With Quote
Old 05-22-2017, 11:45 AM   #6
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

No worries, what a boo boo! Anyway, that's it done. A pull request's been made but it might be a while before a release. Here's a link to a Win x64 version the stash in the meantime...

https://stash.reaper.fm/v/30780/sws_untested.rar

...or you can compile it from source right now via my fork of SWS here...

https://github.com/Lazzle/sws/tree/next

It's reaper.SN_FocusMIDIEditor() and a Focus MIDI Editor action too.

HTH!
snooks is offline   Reply With Quote
Old 05-22-2017, 12:07 PM   #7
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Quote:
Originally Posted by snooks View Post
Anyway, that's it done. A pull request's been made but it might be a while before a release. Here's a link to a Win x64 version the stash in the meantime...
The effort is very much appreciated, thanks snooks!

In the interest of completeness, it would be cool if SN_FocusMIDIEditor() could take a hwnd parameter, perhaps defaulting to the current active MIDI editor if hwnd is null (or even making it mandatory would be fine). But even as it is, it's immensely useful. I'll take your build out for a spin.

BTW, the comment for snooks.h indicates nofish.h. Guess we can see what you used as a template.
tack is offline   Reply With Quote
Old 05-22-2017, 12:14 PM   #8
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Yeah, I'll need to add that feature to remove that smoking gun!
snooks is offline   Reply With Quote
Old 05-22-2017, 12:18 PM   #9
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Just gave your build a try. Small bug (I hope): it works when the MIDI editor is undocked, but if it's docked, it actually moves focus from the MIDI editor to the arrange view.

Sorry it ended up not being completely trivial. No good deed goes unpunished, huh?
tack is offline   Reply With Quote
Old 05-22-2017, 03:43 PM   #10
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

I've updated the stash link and pull request so that it now focuses when the MIDI editor is in any docker, apart from a docker docked in the main window. Which is a small improvement, but it misses the main target. The links above point to the latest version.

I really can't see how to focus the MIDI editor when it's part of the main window in a docker. At least it's 2/3rds done now (or still 0% if you use an ME docked in the main window).

I also tried adding a generic FocusWindow that takes an HWND handle, but it smells as though one of the banks of steampunk-esque levers needs to be adjusted at Cockos's end for that. I could be completely wrong of course, but it wasn't working with a straight HWND, a pointer or a reference.
snooks is offline   Reply With Quote
Old 05-22-2017, 04:58 PM   #11
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Quote:
Originally Posted by snooks View Post
(or still 0% if you use an ME docked in the main window).
Which is me.

I'm deeply grateful for your attempt, snooks. Talk about going the extra mile.

I took a skim at your latest commit:

Code:
bool* is_floating = false;
int not_docked = -1; 
if (DockIsChildOfDock(win, is_floating) == not_docked)
I'd be surprised if the compiler doesn't throw a warning there given the dubious type conversion (assigning false to a pointer). This should be something like:

Code:
bool is_floating = false;
int not_docked = -1; 
if (DockIsChildOfDock(win, &is_floating) == not_docked)
Anyway I'm annoyed so much by this problem -- which infects Reaper at its deepest roots: Reaper is constantly insisting on moving the focus away from the MIDI editor and doesn't offer any way of letting the user unfuck its hopeless behaviour -- that I'm doing something I never expected I'd do: installing Microsoft dev tools.

Ultimately I can only just flounder around and hope to get lucky, not really knowing Reaper's internals. My great fear is that you're right and this will need to be resolved by Cockos.

The frustrating part is that this little API is probably 10 minutes of work for Justin, and it's something for which I would gladly buy Reaper all over again just to have.
tack is offline   Reply With Quote
Old 05-22-2017, 06:22 PM   #12
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

And flounder I did. :/

The Reaper devs should do bounties. I mean I'd pay $50 just for this feature for all the frustration it causes me.
tack is offline   Reply With Quote
Old 05-22-2017, 11:20 PM   #13
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Good point with the pointer - I've changed that. Strangely there's zero warnings for the entire solution though, including that bit.

That's a pity you couldn't sniff something out, hopefully there could be something we've missed pointed out or an additional to the API before long.
snooks is offline   Reply With Quote
Old 05-23-2017, 08:41 PM   #14
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Well I actually made some progress. It's shameful, truly, but it kinda works well enough for me. The biggest problem is that the current note row changes, and this isn't easily fixed because while there is a MIDIEditor_GetSetting_int() to fetch the current note row, you'll be shocked -- shocked! -- to learn there is no equivalent MIDIEditor_SetSetting_int() with which to set it.

Too lazy for a diff.

[Deleted code which is all wrong. See next post.]

Last edited by tack; 05-23-2017 at 08:46 PM.
tack is offline   Reply With Quote
Old 05-23-2017, 08:48 PM   #15
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

While re-reading my post a new (simple) idea suddenly occurred to me, and I'll be damned if it didn't work.

This code now seems to work completely and elegantly. Huzzah!

Please feel free to merge this into your pull request, snooks

Code:
#include "Breeder/BR_Util.h"

// ...


void FocusMIDIEditor(COMMAND_T* ct)
{
    HWND editor = MIDIEditor_GetActive();
    if (editor != NULL)
    {
        // Check if editor is docked
        bool is_floating;
        if (DockIsChildOfDock(editor, &is_floating) == -1)
        {
            // MIDI editor isn't docked.
            FocusWindow(editor);
        } else {
            DockWindowActivate(editor);
            if (is_floating) {
                // MIDI editor is docked in another floating docker.
                FocusWindow(editor);
            } else {
                // MIDI editor is docked in the main window.
                HWND piano_view = GetPianoView(editor);
                FocusWindow(piano_view);
            }
        }
    }
}
tack is offline   Reply With Quote
Old 05-23-2017, 09:00 PM   #16
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

I've written a "focus follows mouse" script which sets focus to the arrange window, track list, or MIDI Editor and although there are a few kinks to work out, I can't even begin to describe how much better this makes Reaper to use.

And it also fixes some focus stealing bugs with the grid/notes option menus.

Awesome!
tack is offline   Reply With Quote
Old 05-24-2017, 02:41 AM   #17
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Cool, good detective work there - I've updated the code/pull request. Your script sounds interesting, I'll keep an eye out for it!
snooks is offline   Reply With Quote
Old 05-24-2017, 01:14 PM   #18
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

YES! Thank you! This is totally awesome and what I've desperately needed for the last week!!

Hopefully negates the need for any long winded workarounds...

Thank you again...

Look forward to the official SWS update release - but for now - this build is perfect!

L.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 05-24-2017, 01:17 PM   #19
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

snooks' build above doesn't have these latest changes, so I guess you don't have the MIDI editor docked in the main window? If not it did seem to work great.
tack is offline   Reply With Quote
Old 05-24-2017, 01:44 PM   #20
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by tack View Post
snooks' build above doesn't have these latest changes, so I guess you don't have the MIDI editor docked in the main window? If not it did seem to work great.
No - my MIDI window floats so shouldn't be a problem. Thanks. I'll assume Snooks will add that to the final release ??

Anyway - thank you for your work and testing on this - it will be invaluable hopefully. I couldn't work out why there were focus APIs for Arrange and some others - but not the MIDI Editor - when so many actions and scripts require the MIDI Editor to be focused.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 05-24-2017, 01:52 PM   #21
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

That's the version in the stash updated to the latest one with tack's final fix.
snooks is offline   Reply With Quote
Old 05-24-2017, 04:09 PM   #22
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by snooks View Post
That's the version in the stash updated to the latest one with tack's final fix.
Thanks so much Snooks - this has solved the major headache I was having!

Works perfectly.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 05-24-2017, 07:30 PM   #23
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,618
Default

Quote:
Originally Posted by snooks View Post
That's the version in the stash updated to the latest one with tack's final fix.
Actually this is my "final" fix.

It's really just a simplification of what I had before. It turns out that focusing the piano view works in the general docked case, whether docked in the main window or in a floating docker window.

This code looks nice and clean now, which is often a good sign that it's correct.

Code:
void FocusMIDIEditor(COMMAND_T* ct)
{
    HWND editor = MIDIEditor_GetActive();
    if (editor != NULL)
    {
        // Check if editor is docked
        bool is_floating;
        if (DockIsChildOfDock(editor, &is_floating) == -1)
        {
            // MIDI editor isn't docked.
            FocusWindow(editor);
        } else {
            // MIDI editor is docked.  Activate it and focus the piano view.
            DockWindowActivate(editor);
            FocusWindow(GetPianoView(editor));
        }
    }
}
tack is offline   Reply With Quote
Old 05-25-2017, 12:52 PM   #24
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Yes, that's better. I've whittled it down to this...

Code:
void Snooks::FocusMIDIEditor(COMMAND_T* ct)
{
    HWND editor = MIDIEditor_GetActive();
    if (editor != NULL) {   
	DockWindowActivate(editor); // in case it's docked and not visible
	FocusWindow(GetPianoView(editor));
    }
}
... which you could eat your dinner off, if I do say so myself.
snooks is offline   Reply With Quote
Old 06-02-2017, 02:23 AM   #25
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

I think I've had a few issues with other API's in your SWS build.

A script of mine uses BR_EnvAlloc, BR_EnvGetProperties, BR_EnvSetProperties and BR_EnvFree.

I haven't exhaustively tested to work out exactly where the crash is - but when I call my functions which contain these calls - Reaper bombs out and you get the dreaded 'Reaper has stopped working' windows message.


I knew this code worked a few weeks back - so swapped back the old SWS files (without your awesome MIDI Editor focus action) - and the code started working again.

I guess I need to test some more to try and pinpoint exactly what call is causing the issue - but thought I'd let you know.

Cheers,
L.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 06-02-2017, 03:01 AM   #26
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Ok - I've managed to solve it by calling BR_EnvFree with false for the commit parameter.

This still seems to set the properties as I want which is very strange.

But if ever I call it with true for commit - it bombs out - but only with the untested SWS. The SWS downloaded from the SWS website works fine with commit = true or commit = false.

Anyway - I'll keep checking that my code works ok with commit = false - and if so - keep this setting. No idea why the properties still appear to be set when I set commit to false, nor why it crashes when commit = true.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 06-03-2017, 02:05 PM   #27
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

This FR would indeed be useful, as it would allow script GUIs to return focus to the MIDI editor after closing.

As I wrote once in the How-to subforum, Keep MIDI editor focused after opening and closing popup windows:
Quote:
Originally Posted by juliansader View Post
When I open one of REAPER's built-in popup windows / dialog boxes from the MIDI editor, such as Filter or Humanize, the focus returns to the MIDI editor after closing the popup.

However, if I open a script GUI or an SWS contextual toolbar from the MIDI editor, the focus goes to the main arrange window after closing the GUI or toolbar. (If I forget to re-focus the MIDI editor and carelessly press a shortcut key, the command goes to the main window and then I have to undo the mess.)

I am therefore wondering if there is any setting or function that would allow the MIDI editor to keep the focus after opening and closing windows?
juliansader is offline   Reply With Quote
Old 06-07-2017, 03:12 PM   #28
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

Quote:
Originally Posted by lb0 View Post
Ok - I've managed to solve it by calling BR_EnvFree with false for the commit parameter.

This still seems to set the properties as I want which is very strange.

But if ever I call it with true for commit - it bombs out - but only with the untested SWS. The SWS downloaded from the SWS website works fine with commit = true or commit = false.

Anyway - I'll keep checking that my code works ok with commit = false - and if so - keep this setting. No idea why the properties still appear to be set when I set commit to false, nor why it crashes when commit = true.
I don't know, it doesn't do it here but there have been changes done to support a feature in the pre-releases (which I am running a version of) so maybe that would be it. You could try a pre-release to see if that solves it.
snooks is offline   Reply With Quote
Old 06-15-2017, 04:49 AM   #29
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by snooks View Post
I don't know, it doesn't do it here but there have been changes done to support a feature in the pre-releases (which I am running a version of) so maybe that would be it. You could try a pre-release to see if that solves it.
Thanks - I'll try that out. Does the pre-release include this action?
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 06-15-2017, 08:40 AM   #30
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

I mean a Reaper pre-release, which has a feature that Breeder functions in the development branch of SWS have been altered to work with. So maybe there's an incompatibility with previous Reaper versions. Which is fine because SWS releases always have a note saying which minimum Reaper version they require.
snooks is offline   Reply With Quote
Old 06-16-2017, 03:40 AM   #31
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by snooks View Post
I mean a Reaper pre-release, which has a feature that Breeder functions in the development branch of SWS have been altered to work with. So maybe there's an incompatibility with previous Reaper versions. Which is fine because SWS releases always have a note saying which minimum Reaper version they require.
ah ok - thanks - can get confusing Will try out some Reaper pre-releases.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 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:43 PM.


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