Old 04-17-2014, 05:52 AM   #1
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default switch from main actions to midi editor actions

Hi, is it possible in the same script to trigger actions for the main and for the midi editor?

An example:

- Open midi editor for selected item

- make some actions in the midi editor

possible?


thanks in advance!
spinlud is offline   Reply With Quote
Old 04-18-2014, 01:41 AM   #2
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Here's an EEL example (it opens the selected item in MIDI editor and selects all notes)

Code:
function do_actions_from_main_and_midi_sections()
(
	main_section_action = 40153; // 40153 == open selected item in MIDI editor
	midi_editor_section_action = 40003; // 40003 == select all notes
	
	Main_OnCommand(main_section_action, 0);
	MIDIEditor_OnCommand(MIDIEditor_GetActive(), midi_editor_section_action);
);

do_actions_from_main_and_midi_sections();
spk77 is offline   Reply With Quote
Old 04-18-2014, 04:17 AM   #3
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default

Quote:
Originally Posted by spk77 View Post
Here's an EEL example (it opens the selected item in MIDI editor and selects all notes)

Code:
function do_actions_from_main_and_midi_sections()
(
	main_section_action = 40153; // 40153 == open selected item in MIDI editor
	midi_editor_section_action = 40003; // 40003 == select all notes
	
	Main_OnCommand(main_section_action, 0);
	MIDIEditor_OnCommand(MIDIEditor_GetActive(), midi_editor_section_action);
);

do_actions_from_main_and_midi_sections();
Thank you man! It seems to me that ell script respond faster than python or is it a my impression?

I would like to learn one of these...which one would you suggest? Better learn python or ell?

thanks for your help!
spinlud is offline   Reply With Quote
Old 04-18-2014, 06:27 AM   #4
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by spinlud View Post
Thank you man! It seems to me that ell script respond faster than python or is it a my impression?

I would like to learn one of these...which one would you suggest? Better learn python or ell?

thanks for your help!
Yes, EEL scripts seem to respond faster (I don't know if there's a significant "speed difference" when f.ex. calling the API functions in a loop from a script). I'm still learning both languages, but I think Python might be easier (at least for a beginner).
spk77 is offline   Reply With Quote
Old 04-19-2014, 03:42 AM   #5
spinlud
Human being with feelings
 
Join Date: Jun 2012
Posts: 442
Default

Quote:
Originally Posted by spk77 View Post
Yes, EEL scripts seem to respond faster (I don't know if there's a significant "speed difference" when f.ex. calling the API functions in a loop from a script). I'm still learning both languages, but I think Python might be easier (at least for a beginner).
Thanks for the information. Both languages have the same possibilities inside Reaper or one is more versatile then the other?
spinlud is offline   Reply With Quote
Old 04-19-2014, 06:17 AM   #6
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by spinlud View Post
Thanks for the information. Both languages have the same possibilities inside Reaper or one is more versatile then the other?
There are almost the same API functions available for both languages (SWS ReaScript functions aren't supported in EEL currently), but f.ex. handling arrays (sorting etc.) and manipulating strings is easier in Python (I think ). Open the help menu in Reaper -> select ReaScript documentation - there you can see the current ReaScript API functions. I'm still using both languages for my scripts.
spk77 is offline   Reply With Quote
Old 04-26-2015, 02:36 PM   #7
djjedidiah
Human being with feelings
 
Join Date: Nov 2011
Location: Denver, CO, USA
Posts: 447
Default

Thank you so much spk77! I know nothing about scripting but I managed to modify that script to do something I always wanted to:

1) open midi editor
2) zoom to content
3) zoom to one loop iteration

All now bound to my 'E' key. Which also is bound to close my midi editor so it's like a toggle to open the midi editor just the way I like it!

I'm so happy right now.
djjedidiah is offline   Reply With Quote
Old 04-26-2015, 03:50 PM   #8
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by djjedidiah View Post
Thank you so much spk77! I know nothing about scripting but I managed to modify that script to do something I always wanted to:

1) open midi editor
2) zoom to content
3) zoom to one loop iteration

All now bound to my 'E' key. Which also is bound to close my midi editor so it's like a toggle to open the midi editor just the way I like it!

I'm so happy right now.
I'm glad it works for you
spk77 is offline   Reply With Quote
Old 04-26-2015, 04:09 PM   #9
Pasajeromoronmoreno
Human being with feelings
 
Join Date: Nov 2013
Location: Argentina
Posts: 326
Default

Please djjedidiah ! Share that script! I heard and lived so Many times that , about the midi editor opening with the most desconcerting zoom settings... I, and many others for sure, gonna be very gratefull...

edit: reading the script example of spk77, it's so simple to understand, i think I'm gonna try to modify it myself, seems easy enough for a first step in scripting. Anyways, still think it's a good idea the upload of your script to the stash
__________________
Living la vida loca

Last edited by Pasajeromoronmoreno; 04-26-2015 at 04:35 PM.
Pasajeromoronmoreno is offline   Reply With Quote
Old 04-27-2015, 07:28 AM   #10
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Pasajeromoronmoreno View Post
Please djjedidiah ! Share that script! I heard and lived so Many times that , about the midi editor opening with the most desconcerting zoom settings... I, and many others for sure, gonna be very gratefull...

edit: reading the script example of spk77, it's so simple to understand, i think I'm gonna try to modify it myself, seems easy enough for a first step in scripting. Anyways, still think it's a good idea the upload of your script to the stash
Try this:

(Add this to the MAIN section of the action list)
Code:
function do_actions_from_main_and_midi_sections()
(
   Main_OnCommand(40153, 0); // MAIN section action 40153: "open selected item in MIDI editor"
   active_MIDI_editor = MIDIEditor_GetActive(); // Now the MIDI editor is opened -> get MIDI editor ID
   MIDIEditor_OnCommand(active_MIDI_editor, 40466); // ME action: "zoom to content"
   MIDIEditor_OnCommand(active_MIDI_editor, 40468); // ME action: "zoom to one loop iteration"
);

do_actions_from_main_and_midi_sections();
spk77 is offline   Reply With Quote
Old 04-28-2015, 12:37 AM   #11
drew
Mobile
 
drew's Avatar
 
Join Date: Jan 2006
Location: London & São Paulo. Hardcore commercial REAPERite
Posts: 1,669
Default

Out of interest, why is Python slower than EEL in REAPER? I've been trying to find ways to speed up the initial latency when calling a script.

Kind of wish they could be preloaded as C++ plugins are so:
1) They're ready to go immediately
2) Could have multiple functions in a .py (instead of 16 files where you need actions for channels 1-16 etc)
__________________
Proudly using REAPER exclusively for...
* Media and event music composition & production, sound design + auto-processing at Qsonics.com
* Broadcast branding, promos, education & training and narration voice-overs at DrewWhite.com
drew is offline   Reply With Quote
Old 04-30-2015, 05:52 AM   #12
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Spk77,

This works like a charm for me, great script, thanks !!
I have it binded to a key shortcut.

Is it somehow possible to alter the script, so that that same key shortcut also CLOSES the midi editor ?? So that it is a toggle ?



Quote:
Originally Posted by spk77 View Post
Try this:

(Add this to the MAIN section of the action list)
Code:
function do_actions_from_main_and_midi_sections()
(
   Main_OnCommand(40153, 0); // MAIN section action 40153: "open selected item in MIDI editor"
   active_MIDI_editor = MIDIEditor_GetActive(); // Now the MIDI editor is opened -> get MIDI editor ID
   MIDIEditor_OnCommand(active_MIDI_editor, 40466); // ME action: "zoom to content"
   MIDIEditor_OnCommand(active_MIDI_editor, 40468); // ME action: "zoom to one loop iteration"
);

do_actions_from_main_and_midi_sections();
vanhaze is offline   Reply With Quote
Old 04-30-2015, 06:55 AM   #13
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Maybe add this after the MIDI Editor actions:
Code:
MIDIEditor_OnCommand(active_MIDI_editor, 40477); // ME action: "Close window if not docked"
X-Raym is offline   Reply With Quote
Old 04-30-2015, 09:21 AM   #14
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by drew View Post
Out of interest, why is Python slower than EEL in REAPER? I've been trying to find ways to speed up the initial latency when calling a script.

I've been wondering this too. I noticed that when calling ReaScript functions f.ex. from a tkinter GUI, there is no noticeable latency.
spk77 is offline   Reply With Quote
Old 04-30-2015, 11:14 AM   #15
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

Quote:
Originally Posted by spk77 View Post
I've been wondering this too. I noticed that when calling ReaScript functions f.ex. from a tkinter GUI, there is no noticeable latency.
I think that's because every time REAPER calls .py script, it has to get compiled into byte code and then interpreted by virtual machine (or something like that, I'm not really familiar with details of Python implementation)

I always wondered if REAPER could maybe cache .pyc files and call those instead if original .py is unchanged (and upon exiting REAPER, delete those cached .pyc files). Maybe that could speed things up a bit?
Then again...what if some other file (which is not a REAPER script) included in the script changes? :/

Last edited by Breeder; 04-30-2015 at 11:24 AM.
Breeder is offline   Reply With Quote
Old 05-04-2015, 07:36 AM   #16
plamuk
Human being with feelings
 
Join Date: Feb 2007
Posts: 3,221
Default

fellas! i've been trying to make this work with single midi notes for a LONG time (midi note triggers action from main and also from midi editor -- specifically "fold" to hide unused/unnamed note rows) and it wasn't working...this solves my problem!! if the OP was any more specific, it'd have been my doppelganger

thank you so much, and thank you for finally giving me the impetus to start working with reascripts!

breeder, you keep popping up everywhere i look, i'm not stalking you i promise
plamuk is offline   Reply With Quote
Old 09-23-2015, 12:11 PM   #17
Big Bob
Human being with feelings
 
Big Bob's Avatar
 
Join Date: Feb 2013
Location: Apple Valley, California
Posts: 84
Default

If I modify the code in post #2, changing the ME action 40003 with 40151 'Go to edit cursor'. It doesn't seem to work because I still have to execute 40151 after the MIDI editor opens.

Yet, it does seem to work fine with 'Select all notes'

Can anyone shed any light on this?

Code:
function do_actions_from_main_and_midi_sections()
(
	main_section_action = 40153; // 40153 == open selected item in MIDI editor
	midi_editor_section_action = 40151; // 40151 == go to edit cursor
	
	Main_OnCommand(main_section_action, 0);
	MIDIEditor_OnCommand(MIDIEditor_GetActive(), midi_editor_section_action);
);

do_actions_from_main_and_midi_sections();
Reajoice,

Bob
__________________
The Heavens Declare the Glory of God
Big Bob is offline   Reply With Quote
Old 09-24-2015, 01:51 PM   #18
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default

Bump.... I'm interested in an answer to Bob's question too. Anybody know?

Quote:
Originally Posted by Big Bob View Post
If I modify the code in post #2, changing the ME action 40003 with 40151 'Go to edit cursor'. It doesn't seem to work because I still have to execute 40151 after the MIDI editor opens.

Yet, it does seem to work fine with 'Select all notes'

Can anyone shed any light on this?

Code:
function do_actions_from_main_and_midi_sections()
(
	main_section_action = 40153; // 40153 == open selected item in MIDI editor
	midi_editor_section_action = 40151; // 40151 == go to edit cursor
	
	Main_OnCommand(main_section_action, 0);
	MIDIEditor_OnCommand(MIDIEditor_GetActive(), midi_editor_section_action);
);

do_actions_from_main_and_midi_sections();
Reajoice,

Bob
Tod is offline   Reply With Quote
Old 09-25-2015, 09:41 AM   #19
Big Bob
Human being with feelings
 
Big Bob's Avatar
 
Join Date: Feb 2013
Location: Apple Valley, California
Posts: 84
Default

Thank you for your response Veto,

Quote:
Originally Posted by Veto View Post
Don't have Reaper installed atm, but did you try to place a ME action called "...pause 0.1s..." or so between those two actions? From time to time it helps..
I'm not aware of any ME action to introduce any wait time (there are some in the Main actions). However, I did try many equivalents such as inserting several other ME actions prior to 40151. I also tried using several 40151's in sequence, etc.

No matter which of these things I did, once the ME is open, hitting the hot key for 40151 would move the view to where I had hoped the macro would have already positioned it. Therefore, I conclude that the action 40151 in the macro is not taking effect.

Quote:
I tried it, the "Go to edit cursor" action only works if the "start position" of the edit cursor is within the bounds of the opened item.
Well if the view already includes the cursor, one doesn't need the 'go to cursor' action because it's already accomplished. The whole idea of this macro was to put the cursor in view after opening the ME for those situations where the cursor is outside the last ME viewing area.

Reajoice,

Bob
__________________
The Heavens Declare the Glory of God
Big Bob 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 08:37 AM.


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