|
|
|
04-17-2014, 07:11 PM
|
#1
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
EEL for dummies..
So i've decided to slowly move to EEL because i like the idea of portability and GUI creation.
Now as i have some experience in Python i must admit i don't know nothing about EEL really...I only heard its syntax is similar to JS. So i've decided to start with something really simple and already stuck.
I want to create a simple script as exercise : Count selected tracks and do simple if/else function with it. So i've googled how to do it in JS and found this:
Code:
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
okay..
so in ELL it should look like this then
Code:
a = CountSelectedTracks(0);
if (a < 1)
}
ShowMessageBox("No Tracks Selected.", "Error", 0)
{
And i've got error.
Whats wrong?
P.S. I want to make this topic like FAQ about EEL.
Of course i want to try everything by myself first. So if there anything like syntax guide to EEL somewhere i would really like to check it out too!
|
|
|
04-17-2014, 07:20 PM
|
#2
|
Human being with feelings
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
|
For one, the } and { look the wrong way around...
Try this (not tested...):
Code:
a = CountSelectedTracks(0);
a < 1 ?
(
ShowMessageBox("No Tracks Selected.", "Error", 0);
);
See reference here, re: "conditional branching":
Code:
Conditional branching is done using the ? or ? : operator, rather than if()/else.
a < 5 ? b = 6; // if a is less than 5, set b to 6
a < 5 ? b = 6 : c = 7; // if a is less than 5, set b to 6, otherwise set c to 7
a < 5 ? ( // if a is less than 5, set b to 6 and c to 7
b = 6;
c = 7;
);
The ? and ?: operators can also be used as the lvalue of expressions:
(a < 5 ? b : c) = 8; // if a is less than 5, set b to 8, otherwise set c to 8
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Last edited by Banned; 04-17-2014 at 07:27 PM.
|
|
|
04-17-2014, 07:24 PM
|
#3
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Thanks for reply
it was typo...even with correct {} it still shows error.
I will try your solution
|
|
|
04-17-2014, 07:25 PM
|
#4
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Yes it works...so my question now is...Where to learn it if its not really like JS syntax?
EDIT : Oh..looks like a lot of stuff could be found here (I look in ReaScript section before and didn't find anything about EEL)
http://www.reaper.fm/sdk/js/basiccode.php#js_basic
Last edited by Viente; 04-17-2014 at 07:31 PM.
|
|
|
04-17-2014, 07:38 PM
|
#5
|
Human being with feelings
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
|
Good.
Something else which may be confusing (to noobs like me, anyway): things seem to be slightly different in OSCII-bot (which also uses EEL2 as a scripting language) as they are in JS or ReaScript...
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
|
|
|
04-17-2014, 07:41 PM
|
#6
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Thanks Banned!
So its not worth to search for JS examples on Google then?
|
|
|
04-17-2014, 08:03 PM
|
#7
|
Human being with feelings
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
|
Quote:
Originally Posted by Viente
So its not worth to search for JS examples on Google then?
|
Well, to some extent. I think that you should never simply expect code to be interchangeable between environments like JS, ReaScript or OSCII-bot, simply because they all (can) use EEL.
The biggest difference to keep in mind is that typical code examples affect quite different domains. I'd guess that for ReaScript, knowing how to use REAPER's API (and/or how .RPP files are structured) is most important, and JS doesn't do any of that. Conversely, for JS you typically need to know more about DSP and/or MIDI to do useful things, while ReaScript typically doesn't get into the DSP domain (afaik).
But for some basic stuff, like learning the proper syntax, you may definitely still be able to find many useful bits of code.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
|
|
|
04-18-2014, 06:39 AM
|
#8
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Im trying to make a script which check the start and end coordinates of item
But for some reason ShowConsoleCommand don't work because im doing something wrong and i can't debug my script because of this. What im doing wrong?
Code:
function GetSelectedItem()
(
selItem = GetSelectedMediaItem(0,0);
);
function CheckItemStart()
(
getPos = GetMediaItemInfo_Value(selItem, "D_POSITION");
modeOverride = 2; // 2=beats
#itemStart = "";
format_timestr_pos(getPos, #itemStart, modeOverride);
);
function CheckItemEnd()
(
getLength = GetMediaItemInfo_Value(selItem, "D_LENGTH");
modeOverride = 2; // 2=beats
#itemLength = "";
format_timestr_pos(getLength, #itemLength, modeOverride);
itemEnd = itemStart + itemLength;
);
CheckItemStart();
CheckItemEnd();
ShowConsoleMsg(itemEnd);
|
|
|
04-20-2014, 03:18 AM
|
#9
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Don't you have to call GetSelectedItem at least once first ?
|
|
|
04-20-2014, 04:09 AM
|
#10
|
Human being with feelings
Join Date: Mar 2010
Posts: 4,713
|
Quote:
Originally Posted by Viente
Im trying to make a script which check the start and end coordinates of item
But for some reason ShowConsoleCommand don't work because im doing something wrong and i can't debug my script because of this. What im doing wrong?
|
A few things have gone a bit wrong there
In EEL you can only print strings to the console. All other types have to be converted to string first, using sprintf.
Also, check your usage of itemStart vs #itemStart etc. They are not the same variable.
Code:
function demo()
(
test = "hello";
// this will work:
ShowConsoleMsg(test);
// this will not ...
// ShowConsoleMsg(#test);
);
demo();
Here's a demo of how to do what you want:
Code:
function check_item_start_end()
(
sel_item = GetSelectedMediaItem(0, 0);
start = GetMediaItemInfo_Value(sel_item, "D_POSITION");
end = start + GetMediaItemInfo_Value(sel_item, "D_LENGTH");
ShowConsoleMsg("Item start and end in 'time'\n");
// change float to string before printing
ShowConsoleMsg(sprintf(#, "%f", start));
ShowConsoleMsg("\n");
ShowConsoleMsg(sprintf(#, "%f", end));
ShowConsoleMsg("\n\n");
ShowConsoleMsg("Item start and end in 'measures.beats'\n");
// change format to measures.beats
// this is a string (e.g. 17.4.15), so no need for sprintf
format_timestr_pos(start, #start_beats, 2);
format_timestr_pos(end, #end_beats, 2);
ShowConsoleMsg(#start_beats);
ShowConsoleMsg("\n");
ShowConsoleMsg(#end_beats);
);
check_item_start_end();
|
|
|
04-20-2014, 04:31 AM
|
#11
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Quote:
Originally Posted by airon
Don't you have to call GetSelectedItem at least once first ?
|
Its still the same.
Quote:
Originally Posted by timlloyd
A few things have gone a bit wrong there
In EEL you can only print strings to the console. All other types have to be converted to string first, using sprintf.
Also, check your usage of itemStart vs #itemStart etc. They are not the same variable.
|
Thanks Tim for great explanation! What is # means then? a string variable?
|
|
|
04-20-2014, 04:36 AM
|
#12
|
Human being with feelings
Join Date: May 2012
Posts: 1,216
|
Thank you guys for all the nice eel scripts. Good starting points to get into this stuff and some scripts are already filling a couple of editing holes.
I have a question. How would you change track names with eel ?
For some macros i want to add a slash (/) as a suffix to track names,
so when rendering reaper creates a subfolder for the rendered items.
After rendering i want to remove the slash again.
(Edit: Oops. Wrong thread ? Sorry !)
|
|
|
04-20-2014, 04:40 AM
|
#13
|
Human being with feelings
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
|
Quote:
Originally Posted by Viente
Its still the same.
Thanks Tim for great explanation! What is # means then? a string variable?
|
I think that's for a mutable string.
(I also think they do NOT exist in OSCII-bot's flavor of EEL...)
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
|
|
|
04-20-2014, 04:48 AM
|
#14
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Three (ShowConsoleMsg) functions for debugging (converts float/int to string):
Code:
// m = string
function msg_s(m)
(
ShowConsoleMsg(m);
ShowConsoleMsg("\n");
);
// m = int (convert int to string and show "m")
function msg_d(m)
(
ShowConsoleMsg(sprintf(#, "%d", m));
ShowConsoleMsg("\n");
);
// m = float (convert float to string and show "m")
function msg_f(m)
(
ShowConsoleMsg(sprintf(#, "%f", m));
ShowConsoleMsg("\n");
);
// example:
a = "Some string"; // a = string
b = 4; // b = int
c = 5.343243; // c = float
msg_s(a);
msg_d(b);
msg_f(c);
|
|
|
04-20-2014, 05:10 AM
|
#15
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by witti
Thank you guys for all the nice eel scripts. Good starting points to get into this stuff and some scripts are already filling a couple of editing holes.
I have a question. How would you change track names with eel ?
For some macros i want to add a slash (/) as a suffix to track names,
so when rendering reaper creates a subfolder for the rendered items.
After rendering i want to remove the slash again.
(Edit: Oops. Wrong thread ? Sorry !)
|
This is the "add suffix" part:
Code:
i = 0;
loop(CountSelectedTracks(0),
(track = GetSelectedTrack(0, i)) ? ( // if track pointer != 0 -> do the code inside brackets
GetSetMediaTrackInfo_String(track, "P_NAME", #track_name, 0); // get track name
#track_name += "/"; // add "/" suffix
GetSetMediaTrackInfo_String(track, "P_NAME", #track_name, 1); // set track name
);
i += 1;
);
|
|
|
04-20-2014, 05:14 AM
|
#16
|
Human being with feelings
Join Date: May 2012
Posts: 1,216
|
Cool. Thanks !
|
|
|
04-20-2014, 12:52 PM
|
#17
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Thanks spk77!
This is exactly what i need
|
|
|
04-22-2014, 01:18 PM
|
#18
|
Human being with feelings
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
|
Quote:
Originally Posted by Banned
Quote:
Originally Posted by Viente
[...] What is # means then? a string variable?
|
I think that's for a mutable string.
(I also think they do NOT exist in OSCII-bot's flavor of EEL...)
|
LOL, two days later, with OSCII-bot v0.3, this statement no longer seems to be true. That's how fast Cockos moves.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
|
|
|
03-20-2015, 11:07 AM
|
#19
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
What is #retvals_csv means here?
Code:
bool GetUserInputs("title", int num_inputs, "captions_csv", #retvals_csv)
|
|
|
03-20-2015, 11:33 AM
|
#20
|
Human being with feelings
Join Date: Jun 2012
Location: Spain
Posts: 7,268
|
Quote:
Originally Posted by Viente
What is #retvals_csv means here?
Code:
bool GetUserInputs("title", int num_inputs, "captions_csv", #retvals_csv)
|
the variable where the user inputs will be stored. it's a comma separated string.
|
|
|
03-20-2015, 11:38 AM
|
#21
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Quote:
Originally Posted by heda
the variable where the user inputs will be stored. it's a comma separated string.
|
Thank you.
|
|
|
03-20-2015, 11:45 AM
|
#22
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
|
|
|
03-20-2015, 01:05 PM
|
#23
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Quote:
Originally Posted by X-Raym
|
Thank you! Very nice example here.
|
|
|
03-20-2015, 05:16 PM
|
#24
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Is anybody have a snippet of code to check if time selection is set?
I'll appreciate if somebody could share
|
|
|
03-20-2015, 06:01 PM
|
#25
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@Viente
You can start with the doc:
Code:
GetSet_LoopTimeRange2(ReaProject proj, bool isSet, bool isLoop, &startOut, &endOut, bool allowautoseek)
We can say that if startOut and endOut is equal (or equal to 0 in EEL or nil in Lua - I dont verify it but I guess it is that-, then there is no time selection.
On what are you working?
|
|
|
03-20-2015, 06:05 PM
|
#26
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Thats my problem (shame)....
In Python i know how to parse thru values in the list like
Code:
def checkTimeSelection(): return RPR_GetSet_LoopTimeRange(0,0,0,0,0)[2]
if checkTimeSelection() != 0: # Check if there is time selection set
etc..
But in EEL i have no idea
I'm converting a lot of my old Python scripts to EEL
|
|
|
03-20-2015, 06:43 PM
|
#27
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@Viente
There is nothing to parse here
try this.
Code:
GetSet_LoopTimeRange2(0, 0, 1, startOut, endOut, 0);
startOut == endout ? (
// ACTIONS
);
Some EEL functions can return variable named in parameters. They have the & symbol on the doc.
These are not parameters that will influence the action, but variable name that will stock the returning values of the functions.
|
|
|
03-20-2015, 07:27 PM
|
#28
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Quote:
Originally Posted by X-Raym
@Viente
There is nothing to parse here
try this.
Code:
GetSet_LoopTimeRange2(0, 0, 1, startOut, endOut, 0);
startOut == endout ? (
// ACTIONS
);
Some EEL functions can return variable named in parameters. They have the & symbol on the doc.
These are not parameters that will influence the action, but variable name that will stock the returning values of the functions.
|
I'm starting to understand how things works in EEL Thank you!
|
|
|
05-29-2022, 04:22 AM
|
#29
|
Human being with feelings
Join Date: May 2009
Posts: 31
|
Please, help me. I need example eel no GUI no dialogs, simply minimalist. One Click.
How to select midi notes all/odd/even etc?
How to move, rundomize midi notes?
Where is examples to start language?
|
|
|
05-29-2022, 04:25 AM
|
#30
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
@semiono
For what you want to do, use lua. it will be simpler and you will have access to way more resource. And existing MIDI scripts shared for free via reapack you can mod.
|
|
|
05-30-2022, 04:38 PM
|
#31
|
Human being with feelings
Join Date: May 2009
Posts: 31
|
Howto insert something before code that get "SELECT ALL" to midi notes?
LUA/EEL
Code:
--- SELECT ALL MIDI NOTES AND RUN CODE?
-- @description Select only odd notes
-- @version 1.0
-- @author me2beats
-- @changelog
-- + init
local r = reaper; local function nothing() end; local function bla() r.defer(nothing) end
function bool_to_num(bool)
if bool == true then return 1 elseif bool == false then return 0 end
end
take = r.MIDIEditor_GetTake(r.MIDIEditor_GetActive())
if take then
_, notes = r.MIDI_CountEvts(take)
if notes > 1 then
t = {}
t_pos = {}
for k = 0, notes-1 do
_, sel, _, start_ppq = r.MIDI_GetNote(take, k)
if sel == true then t_pos[#t_pos+1] = start_ppq end
end
table.sort(t_pos)
tabu = {}
for k = 0, notes-1 do
_, sel, muted, start_ppq, end_ppq, chan, pitch, vel = r.MIDI_GetNote(take, k)
if sel == true then
for j = 1, #t_pos do
if t_pos[j] == start_ppq then
for i = 1, #tabu do
if j == tabu[i] then
found = 1
break
end
end
if not found then
t[j] = {bool_to_num(muted), start_ppq, end_ppq, chan, pitch, vel, k}
tabu[#tabu+1] = j
break
else found = nil end
end
end
end
end
last = -1
r.Undo_BeginBlock()
r.MIDIEditor_LastFocused_OnCommand(40214, 0) -- unselect all notes
for i = 1, #t do
muted, start_ppq, end_ppq, chan, pitch, vel, k = table.unpack(t[i])
if start_ppq > last then
if not pass then
pass = 1
r.MIDI_SetNote(take, k, 1, muted, start_ppq, end_ppq, chan, pitch, vel)
else pass = nil end
last = start_ppq
elseif start_ppq == last then
if pass then
r.MIDI_SetNote(take, k, 1, muted, start_ppq, end_ppq, chan, pitch, vel)
end
end
end
r.Undo_EndBlock('Select only odd notes', -1)
else bla() end
else bla() end
How it look a func or procedure for keep all notes?
Code:
// DO CTRL+A :)
take = MIDIEditor_GetTake(MIDIEditor_GetActive()); // GET TAKE IN MIDI EDITOR
MIDI_CountEvts(take, notes, ccs, sysex); // COUNT MIDI NOTES
j = 0; // INIT
loop(notes, // EXECUTE THE ACTION BASED ON NUMBER OF NOTES
MIDI_GetNote(take, j, sel, muted, start, end, chan, pitch, vel); // GET NOTE J
sel == 1 ? ( // IF NOTE IS SELECTED
vel = 80; // Optionnal calc based en vel
MIDI_SetNote(take, j, sel, muted, start, end, chan, pitch, vel); // SET NOTE J
); // END IF NOTE IS SELECTED
j += 1; // INCREMENT
); // END OF LOOP
UpdateArrange();
ha-ha! I get it
Code:
-- ...
function bool_to_num(bool)
if bool == true then return 1 elseif bool == false then return 0 end
end
-- ///////////////////////////////////////////////////
r.MIDIEditor_LastFocused_OnCommand(40006, 0) -- Ctrl+A
-- ///////////////////////////////////////////////////
take = r.MIDIEditor_GetTake(r.MIDIEditor_GetActive())
-- ...
Last edited by semiono; 05-31-2022 at 12:43 PM.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:00 AM.
|