Old 07-28-2014, 02:40 PM   #1
Tritone
Human being with feelings
 
Tritone's Avatar
 
Join Date: Jun 2014
Posts: 38
Default Reascript: Run script on item selection (spk77?)

I can't figure out how i can trigger a function whenever an item becomes selected.

I referenced spk because his item inspector seems to accmish this, yet, I can't figure out what native he's using to catch the item selection.
Any tips? Thank you

Last edited by Tritone; 07-28-2014 at 06:44 PM.
Tritone is offline   Reply With Quote
Old 07-28-2014, 08:34 PM   #2
Tritone
Human being with feelings
 
Tritone's Avatar
 
Join Date: Jun 2014
Posts: 38
Default

I'm a bit late to the JS boat, so I had to do some basic research on this. I found that:

Quote:
The @gfx section gets executed around 30 times a second when the plug-ins GUI is open. You can do whatever processing you like in this (Typically using gfx_*()). Note that this code runs in a separate thread from the audio processing, so you may have both running simultaneously which could leave certain variables/RAM in an unpredictable state.
I need to now translate this polling script that uses beyond reaper in to EEL (It failed miserably to achieve the goal, mostly because it was spamming my undo history with 'reascript' events.):

Code:
import beyond.Reaper
import beyond.Screen
import beyond.Reaper.Track
import beyond.Reaper.Item
from time import sleep

@ProgramStart
class Main(Parallel):
	def Start()
		
		with Reaper as r:
			Project=r.ProjectSelected
			# Project.UndoEvent("KB_Raise_VEP")
			while True:
			
				while r.CountSelectedMediaItems(Project.Address) > 0:
				
					for Item in Project.ItemsSelected:
						Item.Receive()				
						if Item.Address not in stored:
							stored.append(Item)
							T = r.Track(r.GetMediaItem_Track(Item.Address))											
							if not T.Selected:T.Selected = True
								
					d=[stored.remove(I) for I in stored if I not in Project.ItemsSelected] # Just to be pythonic
						
						
					sleep(.05)


1. How do you append things to the end of an array in eel?
2. How do you delete a specific value from an array?
3. Is there comprehensive documentation besides http://reaper.fm/sdk/js/js.php where I can see some examples of these more basic scripting questions?

Thanks for any help!

Last edited by Tritone; 07-29-2014 at 05:11 AM.
Tritone is offline   Reply With Quote
Old 07-29-2014, 07:58 AM   #3
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Maybe you could use the defer function.

Code:
Python: RPR_defer(String code)

Adds code to be executed at some point after the current script execution finishes.

This EEL script just shows a message when item selection changes:

Code:
function msg_s(m)
(
  ShowConsoleMsg(m);
);

function main()
(
  current_sel_item = GetSelectedMediaItem(0, 0); // get first selected item
  current_sel_item != last_sel_item ? (
    msg_s("Item selection changed\n");
    last_sel_item = current_sel_item;
  );
  defer("main();");
);

main();


(Go to Menu -> Actions to terminate the script)
spk77 is offline   Reply With Quote
Old 07-30-2014, 07:40 AM   #4
Tritone
Human being with feelings
 
Tritone's Avatar
 
Join Date: Jun 2014
Posts: 38
Default

Made a new thread http://forum.cockos.com/showthread.php?t=143470

Last edited by Tritone; 07-31-2014 at 09:00 AM.
Tritone is offline   Reply With Quote
Old 12-13-2017, 12:53 PM   #5
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,032
Default

But 30 times per second is a quite high number. Is this really necessary? What about 2 times per second, possible?
TonE 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:27 AM.


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