Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 03-19-2014, 10:16 AM   #1
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default Load different toolbar under mouse cursor depending on context

EDIT:
The functionality is now implemented directly in SWS. For more details go here

I will leave the details of the previous post bellow in case anyone is interested on implementing this from ReaScript (while SWS Contextual toolbars are trying to work out as much stuff as possible, there's always a possiblity you need something else which can get implemented using ReaScript)

ORIGINAL POST:
Last SWS pre (2.4.0.4) includes new ReaScript API to inspect where mouse cursor is so here's one useful script using that functionality.



It's meant to be generic so you can easily fit it to your needs:
Code:
from sws_python import *

###########################################
# Generic actions for all toolbars        #
###########################################

toolbarActions = {
	1: [41679, 41111], # Toolbar number: [Open/close, Open at mouse cursor]
	2: [41680, 41112], 
	3: [41681, 41113], 
	4: [41682, 41114], 
	5: [41683, 41655], 
	6: [41684, 41656], 
	7: [41685, 41657], 
	8: [41686, 41658]
}

def IsToolbarOpen (num):
	num = toolbarActions.get(num)
	if num and RPR_GetToggleCommandState(num[0]):
		return True
	return False

def CloseToolbar (num):
	num = toolbarActions.get(num)	
	if num and RPR_GetToggleCommandState(num[0]):
			RPR_Main_OnCommand(num[0], 0)

def OpenToolbarMouse (num):
	num = toolbarActions.get(num)
	if num:
		RPR_Main_OnCommand(num[1], 0)

###########################################
# Individual  actions for user toolbars   #
###########################################

# Set toolbar id's here
color    = 1
envelope = 5
item     = 6

# Set your toolbars here
def CloseAllToolbars ():
	CloseToolbar(color)
	CloseToolbar(envelope)
	CloseToolbar(item)

# Set your toolbars here
def AreToolbarsOpen ():
	if IsToolbarOpen(color):
		return True
	if IsToolbarOpen(envelope):
		return True
	if IsToolbarOpen(item):
		return True
	return False

# Set conditions for toggling toolbars here
def OpenContextToolbarUnderMouse ():

	window, context, details, empty = BR_GetMouseCursorContext(0, 0, 0, 128)

	if window in ("tcp", "mcp") and context in ("track", "empty"):
		OpenToolbarMouse(color)		
	elif window == "arrange" and details == "item":
		OpenToolbarMouse(item)
	elif context == "envelope" or details in ("env_point", "env_segment"):
		OpenToolbarMouse(envelope)
	
if AreToolbarsOpen():
	CloseAllToolbars()
else:
	OpenContextToolbarUnderMouse()

Last edited by Breeder; 11-24-2014 at 08:09 AM.
Breeder is offline   Reply With Quote
Old 03-19-2014, 01:29 PM   #2
jackacid
Human being with feelings
 
jackacid's Avatar
 
Join Date: Jun 2012
Location: Southern Appalachia
Posts: 149
Default

Wonderful! Thank you. Now I really need more toolbars.
jackacid is offline   Reply With Quote
Old 03-19-2014, 01:34 PM   #3
Viente
Human being with feelings
 
Viente's Avatar
 
Join Date: Feb 2012
Posts: 1,972
Default

Thanks! You've made my day!
Viente is offline   Reply With Quote
Old 03-19-2014, 01:42 PM   #4
Viente
Human being with feelings
 
Viente's Avatar
 
Join Date: Feb 2012
Posts: 1,972
Default

I didn't inspect the code so much, but is it detect UI elements or listen only for x,y coordinates?
Viente is offline   Reply With Quote
Old 03-19-2014, 01:54 PM   #5
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by Viente View Post
I didn't inspect the code so much, but is it detect UI elements or listen only for x,y coordinates?
SWS does the hard part. The script only asks SWS to do it

BR_GetMouseCursorContext() tells you over which element the mouse cursor is at the time the function is called. You can see more in ReaScript documentation.

edit: if you mean how it works in SWS. First of all, it's messy as hell (but tested so much I really hope there are no bugs). In short, it asks the OS for mouse cursor position, then checks for window under it. Then it uses all sorts of Reaper and OS API to calculate which element is where.

Last edited by Breeder; 03-19-2014 at 02:20 PM.
Breeder is offline   Reply With Quote
Old 03-19-2014, 02:10 PM   #6
Halma
Human being with feelings
 
Halma's Avatar
 
Join Date: Jun 2013
Posts: 288
Default

Dangit, you made my day. I was thinking about something like this lately and how cool that would be.

Many thanks.

Regards
Sebastian
__________________
Underground Music Production: Sound Design, Machine Funk, High Tech Soul
Halma is offline   Reply With Quote
Old 03-19-2014, 02:53 PM   #7
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
Default

Quote:
Originally Posted by Breeder View Post
SWS does the hard part. The script only asks SWS to do it

BR_GetMouseCursorContext() tells you over which element the mouse cursor is at the time the function is called. You can see more in ReaScript documentation.

edit: if you mean how it works in SWS. First of all, it's messy as hell (but tested so much I really hope there are no bugs). In short, it asks the OS for mouse cursor position, then checks for window under it. Then it uses all sorts of Reaper and OS API to calculate which element is where.
beyond elements, how is this working in specifically the arrange?

I see this as potentially a way to do drag actions. I can basically do whatever I want combining python and autohotkey (organizing it all is such a pain however) but it's awkward at best because you can only really drag in one direction if the macro involves splitting and selecting the item under the mouse cursor... (and a lot of useful things do)


take swiping... an eraser tool...

so, as a start I'd want to be able to tell if the mouse was dragged left or right, and select the item right of the mouse cursor if dragged left, and vice versa.

I know EEL can track mouse button and modifiers (i suppose Python as well), and so I think AutoHotKey can be completely bypassed here, simply triggering macros depending on mouse movements.

any further info would be most welcome?
James HE is offline   Reply With Quote
Old 03-19-2014, 03:33 PM   #8
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

That's pretty cool!

And there's other gems in the new SWS beta. The dummy and exclusive toggles look extremely usefull. I did some stuff like that with ExtState and a lot of scripting, now it's almost a breathe.

Thanks for the heads up, all the work and this cool script, it will get lots of use and cuddling (tweaking)


Unavoidable question, someone will have to ask sooner or later: Would you also be able to get reasonable contexts in an open MIDI editor? Like Note area, Note, CC(or other) lane, CC event, Piano key and whatnot?
gofer is offline   Reply With Quote
Old 03-19-2014, 04:28 PM   #9
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by James HE View Post
so, as a start I'd want to be able to tell if the mouse was dragged left or right, and select the item right of the mouse cursor if dragged left, and vice versa.
Uh, that wouldn't be so easy.
As far as I known, EEL can tell you mouse state only for it's window. Python can't do these things natively, but you could use pywin32 to call win32 API, but that makes your script windows only.

But if we ignore all the those troubles with mouse/keyboard input you could track changes of time position and track under mouse (saving and recalling them with SetExtState API) and then using RPR_defer() to delete whatever is in between.

Quote:
Originally Posted by gofer View Post
Unavoidable question, someone will have to ask sooner or later: Would you also be able to get reasonable contexts in an open MIDI editor? Like Note area, Note, CC(or other) lane, CC event, Piano key and whatnot?
Already planned for when I find the time.

It should be able to tell you CC lane and value in CC lane/note row or piano key/time position so you could find all the events that reside there. Maybe it could also tell you MIDI events...we'll see when the time comes.
Breeder is offline   Reply With Quote
Old 03-19-2014, 05:24 PM   #10
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Quote:
Originally Posted by Breeder View Post

Already planned for when I find the time.
Sir, you just made my day!
gofer is offline   Reply With Quote
Old 03-20-2014, 02:27 AM   #11
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,891
Default

Ouch!
IXix is online now   Reply With Quote
Old 03-20-2014, 04:22 AM   #12
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,268
Default

This is great!
but I have all my toolbars full :/

How can we have more toolbars? please?
heda is offline   Reply With Quote
Old 04-04-2014, 10:14 AM   #13
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,268
Default

Inspired by this thread, I want to consolidate/reorganize my 8 toolbars until the devs gives us 64 toolbars.
Is there a way to move buttons from one toolbar to another?
heda is offline   Reply With Quote
Old 04-29-2014, 09:16 AM   #14
Seventh
Human being with feelings
 
Seventh's Avatar
 
Join Date: Sep 2010
Location: Finland
Posts: 776
Default

You can copy&paste the buttons/actions in the Customize toolbar menu. Oh and this is a really nice addition to the API. I'm gonna try and learn some EEL, and create an action which groups either items or tracks depending on focus.
Seventh is offline   Reply With Quote
Old 04-29-2014, 10:05 AM   #15
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by gofer View Post
Unavoidable question, someone will have to ask sooner or later: Would you also be able to get reasonable contexts in an open MIDI editor? Like Note area, Note, CC(or other) lane, CC event, Piano key and whatnot?
Done for the next beta build!
Unfortunately, since we can't know all visible/editable takes in MIDI editor (only active), I refrained from giving out event under mouse cursor information for now.

If you really need note event under mouse cursor you can do (binary) search with mouse cursor position.

Quote:
Originally Posted by Seventh View Post
I'm gonna try and learn some EEL, and create an action which groups either items or tracks depending on focus.
Unfortunately, exported API can't be used in EEL for now So it's Python only atm
Breeder is offline   Reply With Quote
Old 04-29-2014, 10:54 AM   #16
Seventh
Human being with feelings
 
Seventh's Avatar
 
Join Date: Sep 2010
Location: Finland
Posts: 776
Default

EDIT: Creating a new thread for this script so I won't hijack this one. =)

Last edited by Seventh; 04-29-2014 at 11:28 AM.
Seventh is offline   Reply With Quote
Old 05-30-2014, 08:25 AM   #17
pakkuncung
Human being with feelings
 
pakkuncung's Avatar
 
Join Date: Sep 2012
Location: Indonesia
Posts: 91
Default

please pardon my newbieness to this extraordinary wonderful script.

could anybody explain how to install/load/edit/implement this script?

i have used reascript (with python 2.7 installed) and latest SWS extensions with no problems.

but i can't figure out how to use this script.

thank you very much
__________________
JRENG!
EHX
pakkuncung is offline   Reply With Quote
Old 06-10-2014, 08:41 AM   #18
wol
Human being with feelings
 
Join Date: Oct 2013
Posts: 93
Default

Copy the code in a text file and put it in Reaper resource path/Script folder, then in the action window load it and assign a shortcut.
wol is offline   Reply With Quote
Old 06-10-2014, 11:47 PM   #19
pakkuncung
Human being with feelings
 
pakkuncung's Avatar
 
Join Date: Sep 2012
Location: Indonesia
Posts: 91
Default

Quote:
Originally Posted by wol View Post
Copy the code in a text file and put it in Reaper resource path/Script folder, then in the action window load it and assign a shortcut.
thanks for the response wol.

i've done that before asking (my previous post). but i always get an error (python 2.7).

anyway i managed to load toolbar under cursor with sws extension/mouse modifier instead.
__________________
JRENG!
EHX
pakkuncung is offline   Reply With Quote
Old 06-11-2014, 02:27 AM   #20
sinkmusic
Human being with feelings
 
sinkmusic's Avatar
 
Join Date: Feb 2006
Location: decepticon mothership in a hidden place inside a mountain
Posts: 3,754
Default

Wow, i never had noticed this : it seems excellent !
Thank you very much for your creation.
sinkmusic is offline   Reply With Quote
Old 06-11-2014, 06:22 AM   #21
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by pakkuncung View Post
thanks for the response wol.

i've done that before asking (my previous post). but i always get an error (python 2.7).
What kind of error? Did you try updating python? I'm using 3.4.1 without any problems.

Btw, this will probably get recreated directly in SWS when I catch some time so you won't have to deal with code anymore.
Breeder is offline   Reply With Quote
Old 06-11-2014, 07:12 AM   #22
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default

Quote:
Originally Posted by Breeder View Post
What kind of error? Did you try updating python? I'm using 3.4.1 without any problems.

Btw, this will probably get recreated directly in SWS when I catch some time so you won't have to deal with code anymore.
Hi Breeder, thank you very much for this script is fantastic! Do you think is possibile to code it in eel instead of python to make opening/closing toolbar faster?
spinlud is offline   Reply With Quote
Old 06-11-2014, 07:17 AM   #23
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by spinlud View Post
Do you think is possibile to code it in eel instead of python to make opening/closing toolbar faster?
Not at the moment (EEL doesn't support exported functions from extensions) but when I recreate it for SWS it should be much faster - have patience, I will be quite busy for the next few weeks but after that it should happen in no time
Breeder is offline   Reply With Quote
Old 06-11-2014, 07:31 AM   #24
pakkuncung
Human being with feelings
 
pakkuncung's Avatar
 
Join Date: Sep 2012
Location: Indonesia
Posts: 91
Default

Quote:
Originally Posted by Breeder View Post
What kind of error? Did you try updating python? I'm using 3.4.1 without any problems.

Btw, this will probably get recreated directly in SWS when I catch some time so you won't have to deal with code anymore.


i've already tried with python 3.4 (both 32-bit/64-bit) with no luck.

I don't understand how to edit the python script

Can't wait for the SWS version.

Thank you Breeder.
Attached Images
File Type: jpg Untitled-1.jpg (28.8 KB, 1055 views)
__________________
JRENG!
EHX
pakkuncung is offline   Reply With Quote
Old 06-11-2014, 07:33 AM   #25
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

For starters, try downloading pre-release version from here (scroll down a bit)
Breeder is offline   Reply With Quote
Old 06-11-2014, 07:54 AM   #26
pakkuncung
Human being with feelings
 
pakkuncung's Avatar
 
Join Date: Sep 2012
Location: Indonesia
Posts: 91
Default

Quote:
Originally Posted by Breeder View Post
For starters, try downloading pre-release version from here (scroll down a bit)
wow great! thanks!
__________________
JRENG!
EHX
pakkuncung is offline   Reply With Quote
Old 06-11-2014, 02:33 PM   #27
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default

Quote:
Originally Posted by Breeder View Post
Not at the moment (EEL doesn't support exported functions from extensions) but when I recreate it for SWS it should be much faster - have patience, I will be quite busy for the next few weeks but after that it should happen in no time
Yeah, very good news!


Quote:
For starters, try downloading pre-release version from here (scroll down a bit)
I see only v2.4.0 #9 in the prerelease section, missing something?
spinlud is offline   Reply With Quote
Old 06-12-2014, 09:14 AM   #28
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by spinlud View Post
I see only v2.4.0 #9 in the prerelease section, missing something?
I was answering to Pakkuncung, he's error was related to not having installed the latest SWS pre-release.
Breeder is offline   Reply With Quote
Old 07-02-2014, 06:26 AM   #29
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default

Quote:
Originally Posted by Breeder View Post
Not at the moment (EEL doesn't support exported functions from extensions) but when I recreate it for SWS it should be much faster - have patience, I will be quite busy for the next few weeks but after that it should happen in no time
Any news for sws integration?

cheers!
spinlud is offline   Reply With Quote
Old 07-02-2014, 07:06 AM   #30
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by spinlud View Post
Any news for sws integration?

cheers!
Patience is a virtue! When it happens, it happens...and it will happen
Breeder is offline   Reply With Quote
Old 07-02-2014, 08:45 AM   #31
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default

Quote:
Originally Posted by Breeder View Post
Patience is a virtue! When it happens, it happens...and it will happen
I WANT IT ALL!...AND I WANT IT NOW!! (thanks Queen)

joking, take your time.

cheers!
spinlud is offline   Reply With Quote
Old 10-10-2014, 10:42 AM   #32
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 735
Default

Quote:
Originally Posted by Breeder View Post


I see that the Track Icon is indented - how do you do that?
Stroudy is offline   Reply With Quote
Old 11-24-2014, 08:10 AM   #33
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Contextual toolbars have been implemented directly in SWS. For more details go here.
Breeder is offline   Reply With Quote
Old 11-25-2014, 03:28 PM   #34
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 735
Default

Outstanding work. Love the contextual toolbars interface.

Seriously though - your indented icon... how?
Stroudy is offline   Reply With Quote
Old 11-25-2014, 03:32 PM   #35
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by Stroudy View Post
Seriously though - your indented icon... how?
Sorry for not answering sooner, I thought you found it already
Just go to Preferences->Appearance->Track Control Panels and then uncheck Align TCP controls when track icons are used
Breeder is offline   Reply With Quote
Old 11-26-2014, 05:10 AM   #36
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 735
Default

That's what I thought, but it doesn't work for me. See the screen shot.

I'll probably get on with more pressing issues, but it I do find those kind of things annoying.

Thanks Breeder. And thanks again for the tremendous work on the contextual toolbars.
Attached Images
File Type: png Screen Shot 2014-11-26 at 11.53.16.403.png (56.7 KB, 307 views)
Stroudy 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 12:29 PM.


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