PDA

View Full Version : Converting Python to EEL script requests


Argitoth
02-14-2014, 05:21 PM
here's the first request

Prepare track 1 for DDP export - set index and track markers_Input_2d.eel (http://www.elanhickler.com/_/Prepare track 1 for DDP export - set index and track markers_Input_2d.eel)

please test.

WyattRice
02-14-2014, 05:31 PM
here's the first request

Prepare track 1 for DDP export - set index and track markers_Input_2d.eel (http://www.elanhickler.com/_/Prepare track 1 for DDP export - set index and track markers_Input_2d.eel)

please test.
Wow! Many Thanks.

Will test and report back as soon as get a chance.
Edit: After a quick test it seems to be working great.
Will check more.
Thanks, Wyatt

WyattRice
02-14-2014, 08:01 PM
Here's another one I did awhile back that does reaper site search with google.

Is this one possible?

#Reaper Google Search.py
#Thanks gofer for the input box example.
import webbrowser
dialog_name = "Reaper Google Search"
howmanyfields = 1
field_names = "Search Reaper Forums"
default_values = ""
maxreturnlength = 100
User_Input = RPR_GetUserInputs(dialog_name,howmanyfields, field_names, default_values, maxreturnlength)

if User_Input[0] == 1:
UserValues = User_Input[4].split(',')
myinput = str(UserValues[0])
search = str('http://www.google.com/search?hl=en&biw=1280&bih=844&as_q=' + myinput +
'&as_epq=&as_oq=&as_eq=&tbs=&lr=&as_filetype=&ft=i&as_' +
'sitesearch=forum.cockos.com&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=images')
webbrowser.open(search)

Thanks, Wyatt

Argitoth
02-14-2014, 08:15 PM
oh no that's really too difficult... I just converted 200 lines of python code into eel, this new script you posted is FAR MORE DIFFICULT!

jk.

ill do it.

edit: which is what I would have said if the script didn't have "import webbrowser". I don't think it's possible to translate.
edit: I'll have to ask the gurus, maybe they know a solution.

spk77
02-16-2014, 09:36 AM
I converted this python script to EEL:

http://forum.cockos.com/showpost.php?p=1315299&postcount=458

http://stash.reaper.fm/19776/normalize%20to%20given%20range.gif

Normalize selected items to given range (fixed dB steps)

// Normalize selected items to given range
// ("take volumes" are adjusted)

function msg(m)
(
ShowConsoleMsg(m);
ShowConsoleMsg("\n");
);

function dialog()
(
#dialog_ret_vals = "-30.0,-6.0"; //default values
GetUserInputs("Normalize active takes to range", 2, "From (dB):,To (dB):", #dialog_ret_vals);
);

function normalize()
(
(sel_item_count = CountSelectedMediaItems(0)) >= 2 ? (
dialog() ? (
Undo_BeginBlock();
PreventUIRefresh(1);
Main_OnCommand(40108, 0); // normalize active takes to 0 dB (take volume)
match("%f,%f", #dialog_ret_vals, from_dB, to_dB);
i = 0;
loop(sel_item_count,
item = GetSelectedMediaItem(0, i);
take = GetActiveTake(item);
normalized_dB = 20 * log10(GetMediaItemTakeInfo_Value(take, "D_VOL")); // normalized_dB == take normalized to 0 dB
new_dB = normalized_dB + from_dB + (i * ((to_dB - from_dB) / (sel_item_count - 1)));
new_vol = pow(10, new_dB / 20);
SetMediaItemTakeInfo_Value(take, "D_VOL", new_vol);
i += 1;
);
PreventUIRefresh(-1);
Undo_EndBlock("Normalize to range", -1);
UpdateArrange();
)
) : ( // sel item count < 2 -> "quit" with error message
msg("Select at least two items");
);
);

normalize();

Argitoth
02-16-2014, 10:31 AM
spk77, I feel like that would be useful with a few additions. I think the goal here would be to take a handful of samples and even out their dynamics. For example:

"set peak value of items up to #dB closer to the average peak value of all selected items"

for example

db values: -10 -5 -4 -3 +1 +6
averaged/target db: -2.5
#db = 3dB

-10 becomes -7 (you may only change value up to 3db)
-5 becomes -2.5
-4 becomes -2.5
-3 becomes -2.5
-1 becomes -2
+6 becomes +3 (you may only change value up to 3db)

Argitoth
02-16-2014, 02:15 PM
http://www.elanhickler.com/_/select_items_same_color_eel.gif

Select items with color of selected items, way faster in EEL


// Select items with color of selected items

/* by Elan Hickler
www.Soundemote.com
www.elanhickler.com */

items = CountSelectedMediaItems(); // store number of items
items !=0 ? (
PreventUIRefresh(1);
Undo_BeginBlock2(0);

item = GetSelectedMediaItem(0, 0); // store first selected item
colorA = GetDisplayedMediaItemColor(item); // store color of first selected item
Main_OnCommand(40182,0); // *select all items
i=0;
loop(CountMediaItems(0), // *loop through every item and unselect if color does not match
item = GetMediaItem(0, i);
colorB = GetDisplayedMediaItemColor(item);
colorA != colorB ? (
SetMediaItemInfo_Value(item, "B_UISEL", 0); zz-=1;
);
i+=1;
);

Undo_EndBlock2(0, sprintf(#, "Select items with %{colorA}X color"), -1);
PreventUIRefresh(-1);
);

Argitoth
02-28-2014, 01:46 PM
It's crazy that REAPER doesn't have this as a default action.


// Set number of channels for selected tracks

// by Elan Hickler
// www.Soundemote.com
// www.elanhickler.com

tracks = CountSelectedTracks(0);
tracks > 0 ? (
#input = "2";
Query = GetUserInputs("Set track number of channel count", 1, "number of channels:", #input);
match("%{input}i",#input);
Query == 1 ? (
Undo_BeginBlock2(0);
i = 0;
loop(tracks,
track = GetSelectedTrack(0, i);
SetMediaTrackInfo_Value(track, "I_NCHAN", input);
i+=1;
);
Undo_EndBlock2(0, sprintf(#,"Set number of channels for %{tracks}i tracks"), -1);
);
);

gofer
03-01-2014, 03:43 PM
Shameless request for EELization of (some of) these :D:
http://forum.cockos.com/showthread.php?p=1322189

Snippets would already help a lot to get me started learning this fishy stuff.

Argitoth
03-06-2014, 09:09 AM
VERY USEFUL! Set item rate and decide whether you want to preserve length and or preserve pitch of item.

// Set item rate, 'preserve pitch', preserve length...

// by Elan Hickler
// www.Soundemote.com
// www.elanhickler.com

#userinputs = "0.5,0,0"; // defaults
query = GetUserInputs("Set item rate", 3, "rate,preserve pitch? (1=yes 0=no),preserve length? (1=yes 0=no)", #userinputs);
query == 1 ? (
Undo_BeginBlock();

match("%f,%i,%i",#userinputs,newRate,preservePitch,preserveLength) ;

items = CountSelectedMediaItems(0);
i=0;
loop(items,
item = GetSelectedMediaItem(0,i);
take = GetActiveTake(item);
length = GetMediaItemInfo_Value(item, "D_LENGTH");
rate = GetMediaItemTakeInfo_Value(take, "D_PLAYRATE");

// set rate
SetMediaItemTakeInfo_Value(take, "D_PLAYRATE", newRate);

// set preserve pitch
preservePitch != 0 ? #ppitch = ", clear 'preserve pitch'";
SetMediaItemTakeInfo_Value(take, "B_PPITCH", preservePitch);

// set preserve length
preserveLength != 0 ? #plength = " and preserve length";
preserveLength == 0 ? (
newLength = rate / newRate * length;
SetMediaItemLength(item, newLength, 0);
);
i+=1;
);

UpdateArrange();

sprintf(#undo,"Set item rate to %{newRate}g%{#plength}s%{#ppitch}s");
Undo_EndBlock(#undo, -1);
);

daxliniere
03-28-2014, 08:52 PM
Hey guys,
My cut tool (split items) was coded in Python and I'd love to see how much faster it would run in EEL. Unfortunately, I know nothing about coding, let alone converting from one language to another.
I would love it if someone could convert this to EEL, please. :)


from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
RPR_Undo_BeginBlock2(0)
try:
yield
finally:
RPR_Undo_EndBlock2(0,message,-1)


with undoable('Split item(s)'):
SelectItemUnderCursor = 40528
DeselectItems = 40289
MoveCursor = 40513
SplitItems = RPR_NamedCommandLookup('_SWS_AWSPLITXFADELEFT')
SelectPreviousItem = RPR_NamedCommandLookup('_SWS_SELPREVITEM2')
CrossfadeToTimeSel = 40916


selItems = RPR_CountSelectedMediaItems(0)
timeSel = RPR_GetSet_LoopTimeRange2(0, 0, 0, 0, 0, 0)[3] != RPR_GetSet_LoopTimeRange2(0, 0, 0, 0, 0, 0)[4]

RPR_Main_OnCommand(MoveCursor, 0)

if (selItems==0):
RPR_Main_OnCommand(SelectItemUnderCursor, 0)
RPR_Main_OnCommand(SplitItems, 0)
if (timeSel!=0):
RPR_Main_OnCommand(SelectPreviousItem, 0)
RPR_Main_OnCommand(CrossfadeToTimeSel, 0)
RPR_Main_OnCommand(DeselectItems, 0)

if (selItems!=0):
RPR_Main_OnCommand(SplitItems, 0)
if (timeSel!=0):
RPR_Main_OnCommand(SelectPreviousItem, 0)
RPR_Main_OnCommand(CrossfadeToTimeSel, 0)

timlloyd
03-29-2014, 04:23 AM
I would love it if someone could convert this to EEL, please. :)


function sel_prev_item_crossfade_to_time_sel()
(
Main_OnCommand(NamedCommandLookup("_SWS_SELPREVITEM2"), 0);
Main_OnCommand(40916, 0); // crossfade to time selection
);

function split_items()
(
Main_OnCommand(NamedCommandLookup("_SWS_AWSPLITXFADELEFT"), 0);
);

function dax_split()
(
PreventUIRefresh(1);
Undo_BeginBlock2(0);

GetSet_LoopTimeRange2(0, 0, 0, ts_start, ts_end, 0);
time_sel = ts_start !== ts_end;

Main_OnCommand(40513, 0); // move edit cursor to mouse cursor

CountSelectedMediaItems(0) === 0 ?
(
Main_OnCommand(40528, 0); // select item under cursor
split_items();

time_sel ?
sel_prev_item_crossfade_to_time_sel();

Main_OnCommand(40289, 0); // deselect items
) : // else
(
split_items();
time_sel ?
sel_prev_item_crossfade_to_time_sel();
);
PreventUIRefresh(-1);
Undo_EndBlock2(0, "Split item(s)", -1);
);

dax_split();



Here's a refactored Python version of your script also, for easier comparison:

from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
RPR_Undo_BeginBlock2(0)
try:
yield
finally:
RPR_Undo_EndBlock2(0, message, -1)


def split_items():
RPR_Main_OnCommand(RPR_NamedCommandLookup('_SWS_AW SPLITXFADELEFT'), 0)


def sel_prev_item_crossfade_to_time_sel():
RPR_Main_OnCommand(RPR_NamedCommandLookup("_SWS_SELPREVITEM2"), 0)
RPR_Main_OnCommand(40916, 0) # crossfade to time selection


with undoable('Split item(s)'):
time_sel = RPR_GetSet_LoopTimeRange2(0, 0, 0, 0, 0, 0)
time_sel = time_sel[3] != time_sel[4]

RPR_Main_OnCommand(40513, 0) # move edit cursor to mouse cursor

if RPR_CountSelectedMediaItems(0) == 0:
RPR_Main_OnCommand(40528, 0) # select item under cursor
split_items()

if time_sel:
sel_prev_item_crossfade_to_time_sel()

RPR_Main_OnCommand(40289, 0) # deselect items
else:
split_items()

if time_sel:
sel_prev_item_crossfade_to_time_sel()



They both prevent the UI from refreshing during the edit, which makes them feel quicker ...

daxliniere
03-29-2014, 07:13 AM
What a dude!! Thanks so much, Tim, I really appreciate it. :)

Viente
04-03-2014, 06:35 PM
Could somebody please convert this to EEL? (insert FX to a track)

Thanks in advance


RPR_Undo_BeginBlock()

FX = "H-Delay"
TrackIdx = 0
TrackCount = RPR_CountSelectedTracks(0)
while TrackIdx < TrackCount:
track = RPR_GetSelectedTrack(0, TrackIdx)
fxIdx = RPR_TrackFX_GetByName (track, FX, 1)
isOpen = RPR_TrackFX_GetOpen(track, fxIdx)
if isOpen ==0:
isOpen = 1
else:
isOpen = 0
RPR_TrackFX_SetOpen(track, fxIdx, isOpen)
TrackIdx +=1

RPR_Undo_EndBlock("Insert Waves H-Delay",0)

timlloyd
04-03-2014, 11:42 PM
function insert_fx()
(
fx = "H-Delay";
i = 0;
Undo_BeginBlock();
loop(CountSelectedTracks(0),
track = GetSelectedTrack(0, i);
fx_idx = TrackFX_GetByName(track, fx, 1);
is_open = !TrackFX_GetOpen(track, fx_idx);
TrackFX_SetOpen(track, fx_idx, is_open);
i += 1;
);
#undo_msg = "Insert ";
Undo_EndBlock(strcat(#undo_msg, fx), 0);
);

insert_fx();


You might want to think about changing the way undo is used (or named) in this script. At the moment, if fx has just been:
- added to the track, undo will remove it
- toggled closed on the track, undo will show the fx GUI
- reopened on the track, undo will do nothing

But I'll leave it up to you ;)

Viente
04-04-2014, 02:36 AM
Thanks! Do you know why undo message isnt working? It shows me "ReaScript : Run"

timlloyd
04-04-2014, 04:54 AM
Yeah, I've noticed that with EEL scripts as well, but I don't think it was occurring with that script when I checked it this morning ... don't remember :-/

IIRC you should actually be using a 2rd argument of -1 in Undo_EndBlock. -1 should be used if the state of the project is modified directly, rather than by calling 'native' reaper actions, in which case you can use 0.

See if it helps to remove the original call to Undo_EndBlock and just stick it at the end of the script ... not sure why that would make a difference.


function insert_fx()
(
fx = "ReaEQ";
i = 0;
Undo_BeginBlock();
loop(CountSelectedTracks(0),
track = GetSelectedTrack(0, i);
fx_idx = TrackFX_GetByName(track, fx, 1);
is_open = !TrackFX_GetOpen(track, fx_idx);
TrackFX_SetOpen(track, fx_idx, is_open);
i += 1;
);
#undo_msg = "Insert ";
strcat(#undo_msg, fx);
);

insert_fx();

Undo_EndBlock(#undo_msg, -1);

Viente
04-04-2014, 02:22 PM
Still the same. Should we make bug report?

timlloyd
04-04-2014, 05:37 PM
Yes, I think so.

heda
04-05-2014, 02:11 AM
I wonder if this can be converted to EEL easily
From the thread: Transposing items and regions scripts:
http://forum.cockos.com/showthread.php?t=137372

this one:
http://forum.cockos.com/showpost.php?p=1336964&postcount=32
and this one
http://forum.cockos.com/showpost.php?p=1337034&postcount=33

spk77
04-05-2014, 03:34 AM
I wonder if this can be converted to EEL easily
From the thread: Transposing items and regions scripts:
http://forum.cockos.com/showthread.php?t=137372

this one:
http://forum.cockos.com/showpost.php?p=1336964&postcount=32
and this one
http://forum.cockos.com/showpost.php?p=1337034&postcount=33

Add/Remove NO_TRP prefix (Creating an undo point doesn't work correctly - it adds an extra "ReaScript: run" -point. Tried also with "Undo_OnStateChange")

// Add/Remove NO_TRP prefix

function prepend_take_name() local (i)
(
i = 0;
#src_str = "(NO_TRP) ";
str_len = strlen(#src_str);
//Undo_BeginBlock();
loop(CountSelectedMediaItems(0),
(curr_item = GetSelectedMediaItem(0, i)) ? (
(take = GetActiveTake(curr_item)) ? (
GetTakeName(#take_name, take) ? (
match("(NO_TRP) *", #take_name) ? (
str_delsub(#take_name, 0, str_len); // deletes len chars at pos
) : (
str_insert(#take_name, "(NO_TRP) ", 0); //inserts srcstr at pos
);
GetSetMediaItemTakeInfo_String(take, "P_NAME", #take_name, 1);
);
);
);
i += 1;
);
//Undo_EndBlock("Add/Remove NO_TRP prefix", -1);
);
prepend_take_name();

heda
04-05-2014, 11:53 AM
thank you skp77. I am starting to learn Python and EEL. It helps. :)
EEL seems even more condensed language full of smilies :)

I forgot the "unselect items with NO_TRP in take name" script to be translated also:


###unselect items with NO_TRP in name 2###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
RPR_PreventUIRefresh(1)
try:
yield
finally:
RPR_PreventUIRefresh(-1)

def make_usmiL():
csmi = RPR_CountSelectedMediaItems(0)
for i in range(csmi):
CurrItem = RPR_GetSelectedMediaItem(0, i)
CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
GT = RPR_GetTake(CurrItem, int(CT))
if 'NO_TRP' in str(RPR_GetTakeName(GT)):
usmiL.append(CurrItem)

def unselect_from_usmiL():
while len(usmiL) >= 1:
unsel_item = usmiL.pop()
RPR_SetMediaItemSelected(unsel_item, 0)
RPR_UpdateItemInProject(unsel_item)

usmiL = []

with noUIRefresh():
make_usmiL()
unselect_from_usmiL()

spk77
04-05-2014, 01:06 PM
thank you skp77. I am starting to learn Python and EEL. It helps. :)
EEL seems even more condensed language full of smilies :)

I'm still learning too :) (manipulating strings is much easier in Python)

Unselect items with NO_TRP in name

// Unselect items with NO_TRP in name

function unselect() local (i)
(
i = 0;
//Undo_BeginBlock();
loop(CountSelectedMediaItems(0),
(curr_item = GetSelectedMediaItem(0, i)) ? (
(take = GetActiveTake(curr_item)) ? (
GetTakeName(#take_name, take) ? (
match("(NO_TRP) *", #take_name) == 0 ? (
// "(NO_TRP) " not found at the start of name -> unselect item
// -> subtract "1" from "i" to get the correct item at next iteration
SetMediaItemSelected(curr_item, 0);
i -= 1;
);
);
);
);
i += 1;
);
//Undo_EndBlock("Unselect items with NO_TRP in name", -1);
UpdateArrange();
);

unselect();

heda
04-05-2014, 01:48 PM
great :)
this selects only the items with NO_TRP in name
changing the 0 to 1 in the match line seems to do the unselect for those items :)
match("(NO_TRP) *", #take_name) == 1 ? (

daxliniere
04-09-2014, 11:11 PM
function insert_fx()
(
fx = "ReaEQ";
i = 0;
Undo_BeginBlock();
loop(CountSelectedTracks(0),
track = GetSelectedTrack(0, i);
fx_idx = TrackFX_GetByName(track, fx, 1);
is_open = !TrackFX_GetOpen(track, fx_idx);
TrackFX_SetOpen(track, fx_idx, is_open);
i += 1;
);
#undo_msg = "Insert ";
strcat(#undo_msg, fx);
);

insert_fx();

Undo_EndBlock(#undo_msg, -1);

Can I simply swap 'track' for 'item' to insert FX on an item?

Cheers!

timlloyd
04-10-2014, 02:53 PM
Can I simply swap 'track' for 'item' to insert FX on an item?

Cheers!

Nope, it's not that straight forward for item FX!

daxliniere
05-01-2014, 07:55 AM
Nope, it's not that straight forward for item FX!

Is it something you think you could do?

WyattRice
05-18-2014, 06:17 PM
Request needed. I have a track volume script that raises track volume in 1dB steps. How could I round the digits after the decimal point?
e.g If I have a track volume of +4.26 how could I round that to +4.30?
Thanks

Edit: Here's my script
TrackCount = CountSelectedTracks(0);
TrackIndex = 0;
Undo_BeginBlock();
while ( TrackIndex < TrackCount ) (
tr = GetSelectedTrack(0, TrackIndex);
GetTrackUIVolPan(tr, vol, pan);
//If vol is at -inf, set to -150dB
vol < 0.00000002818383 ? (
SetMediaTrackInfo_Value(tr, "D_VOL", 0.00000003162278);
):
SetMediaTrackInfo_Value(tr, "D_VOL", vol*1.1220184543019633);

TrackIndex +=1;
#undo_msg = "Adjust Track Volume";
);
Undo_EndBlock(#undo_msg, -1);

timlloyd
05-18-2014, 11:53 PM
How could I round the digits after the decimal point?
e.g If I have a track volume of +4.26 how could I round that to +4.30?

To round to 1 dp, add 0.05, then multiply by 10. Then floor() this value and multiply by 0.1 (divide by 10).


v = floor((v + 0.05) * 10) * 0.1;


I think you'll see this result as, for example, 4.299999 instead of 4.3 if you convert to string and print to the console.

To round to 2 dp, use 0.005, 100 and 0.01 instead, etc.

Could make a generic round(value, dp) function for you, but in a rush, sorry!

WyattRice
05-20-2014, 03:34 PM
To round to 1 dp, add 0.05, then multiply by 10. Then floor() this value and multiply by 0.1 (divide by 10).


v = floor((v + 0.05) * 10) * 0.1;


I think you'll see this result as, for example, 4.299999 instead of 4.3 if you convert to string and print to the console.

To round to 2 dp, use 0.005, 100 and 0.01 instead, etc.

Could make a generic round(value, dp) function for you, but in a rush, sorry!
Thanks Tim. I didn't do very well in math. Here's my latest try.
Could you check it for me? Thanks, Wyatt

//Round and adjust selected tracks volume in 1dB steps
//Can be used to adjust down also.
//On line starting with incr = +1 can be changed to -1 to decrease.
//Steps can changed to 0.5 etc.
TrackCount = CountSelectedTracks(0);
TrackIndex = 0;
Undo_BeginBlock();
while (TrackIndex < TrackCount) (
tr = GetSelectedTrack(0, TrackIndex);
GetTrackUIVolPan(tr, vol, pan);
// If vol is at -inf, set to -150dB
vol < 0.00000002818383 ? (
SetMediaTrackInfo_Value(tr, "D_VOL", 0.00000003162278);
):
incr = +1;
vol = GetMediaTrackInfo_Value(tr, "D_VOL");
v = (20.0 * log10(vol)) + incr;
v = floor((v + 0.05) * 10) * 0.1;
SetMediaTrackInfo_Value(tr, "D_VOL", 10.0 ^ (v / 20.0));
TrackIndex +=1;
#undo_msg = "Adjust Track Volume";
Undo_EndBlock(#undo_msg, -1);
);

FnA
01-22-2015, 06:29 AM
Seriously...

abc = "123"
x = int(abc)

then,

abc = "1,2,3"
x = int(abc)[2]

then,

abc = "1,2,3"
x = int(abc.split(",")[1])

edit- match, then?

_TIP_
04-29-2016, 02:11 PM
Hey guys, could someone please convert this Viente's python script to eel?

http://stash.reaper.fm/v/14367/Smart%20track%20rendering.py

jacques mk2
11-24-2016, 12:54 PM
It's crazy that REAPER doesn't have this as a default action.


// Set number of channels for selected tracks

// by Elan Hickler
// www.Soundemote.com
// www.elanhickler.com

tracks = CountSelectedTracks(0);
tracks > 0 ? (
#input = "2";
Query = GetUserInputs("Set track number of channel count", 1, "number of channels:", #input);
match("%{input}i",#input);
Query == 1 ? (
Undo_BeginBlock2(0);
i = 0;
loop(tracks,
track = GetSelectedTrack(0, i);
SetMediaTrackInfo_Value(track, "I_NCHAN", input);
i+=1;
);
Undo_EndBlock2(0, sprintf(#,"Set number of channels for %{tracks}i tracks"), -1);
);
);




any way to automaticly close the window ?