Go Back   Cockos Incorporated Forums > REAPER Forums > JSFX and ReaScript Discussion

Reply
 
Thread Tools Display Modes
Old 02-16-2015, 10:56 AM   #1
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default ReaScript: Template Script, Header and Loops & ReaScript Updater Idea (step 1)

Hi !

I want to share with you a script template file I coded for scripting in REAPER. I build this for two main reasons:
  • Helping beginners with a script model they can duplicate and easily use. It has a lot of comments that maybe for newbies, and for people who will look at your code.
  • Being able to create scripts quickly. Indeed, the script contains the most common loops (selected items, takes, tracks...), I need, already in place with indispensable functions (updateArrange, undo blocks...) and integration with my debug console script, very handy for creating scripts.
Propose a standardized header, with all the scripts infos, to allow possible future great things, such as an automatic script updater extension (I have thinking a lot about how it would be possible and I will share you the results of my research on that very soon - note: there is hope, and have some concrete ideas about it).

My template code part (below the header) is defined by:
  • Tabulation indentation (i find them more convenient to use)
  • variables_with_underscores, to be quickly identify variables and functions (reaper functions are CamelCasedBased).
You may not agree with this conventions, that's ok, we all have our code habits, I will not tell you how to code. But if all of us could use a common header, it could open doors of a eventual script updated extension.

The header is based on the normalized WordPress (most used CMS in the world) plugin header, and contains international ISO 8601 standard date format, which is very easily scannable by regex, for any eventual ReaScript updater extensions. This is basically how WordPress works for telling you that a installed plugin need an updated: just scanning the header regulary and compare it to a database. This is a trusting working model of header. :P

Because script are individuals files, they must contain all infos that will be potentially needed for scanning, so I added even more infos that there is in a WordPress plugin header. This is how it look like with my personal infos for example.

Code:
/**
 * ReaScript Name: Template (match file name without extension and author)
 * Description: A template script for REAPER ReaScript.
 * Instructions: Here how to use it.
 * Screenshot: Here is a link.
 * Notes: Here some infos.
 * Category: Here some infos.
 * Author: X-Raym
 * Author URl: http://extremraym.com
 * Repository: GitHub > X-Raym > EEL Scripts for Cockos REAPER
 * Repository URl: https://github.com/X-Raym/REAPER-EEL-Scripts
 * File URl: https://github.com/X-Raym/REAPER-EEL-Scripts/scriptName.eel
 * Licence: GPL v3
 * Forum Thread: 
 * Forum Thread URl: http://forum.cockos.com/***.html
 * Version: 1.0
 * REAPER: 4.76
 * Extensions: SWS/S&M 2.6.0
 */
EDIT 2015-12-08 : minimum fileds are ReaScript Name, Author, and Version
This will be used by the script downloader by cfillion
Q about Cockos politics to third-party libraries - Cockos Confederated Forums

I think it is pretty complete, most of software extensions manager don't have all that fields.
We could easily imagine this infos parsed by a local script manager. There is all what is needed for auto-update the script (name, version checker, url...).
Script format could be determined by file extension.

Below that, I also added the changelog part. This way, we could imagine that an updater script extension could display changelog as well. I used standard changelog symbols (+, -, #).
Code:
/**
 * Changelog:
 * v1.2 (2015-02-13)
    + Items, Takes, Tracks, Regions and FX loops
    # Underscore variables
 * v1.1 (2015-02-13)
    + Basic scripts actions template
 * v1.0 (2015-01-29)
    + Initial Release
    + New functions
    - Deleted functions
    # Updated functions
 */
My template is EEL only for now, it will be converted to LUA for v5, just as my console plugin.

As I already said, this could be the first and indispensable steps for building a powerful ReaScript Updater (more on this later). Indeed, from all resources that we can share for REAPER, scripts are what are the most commonly updated (except some themes). All REAPER users could benefit of it, and it could democratize scripts, and scripting.

I hope you will like the concept, and that you will be interested by following my call. Building a more interactive, modern and easy way to download scripts within REAPER start from the way we all wrote scripts. A common header structure may be all we need

In a future post, I will talk about the second step :P
Meanwhile, you may just find useful to have a header full of pre-filled metadatas, and basics functions already in place! This script updated thing is just a (non-negligible) bonus :P

I know it is ambitious, but with a common effort, I have the feeling that it could be possible, in a way or another.

Ideas are meant to be shared.
And so are ReaScripts !

Download links :
  • See my signature!
    The script is in folder Templates.

If you like it, it will probably be updated with more "basic loops" or "often used" functions.

Cheers !

Last edited by X-Raym; 12-10-2015 at 05:31 AM.
X-Raym is offline   Reply With Quote
Old 02-16-2015, 11:29 AM   #2
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,030
Default

I was already using some sort of your template
I like the idea of the basic loops template functions too.
heda is offline   Reply With Quote
Old 02-16-2015, 11:36 AM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@heda
Yeah, I noticed that
And you can see know that it is not just convenient, it can also become useful :P

We think about all sort of other basic loops: selected point envelope, trackFX etc...
I haven't prepare it yet, I will add things if requested :P
X-Raym is offline   Reply With Quote
Old 02-17-2015, 04:20 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

Any volunteer to convert it to convert it in Lua ? I don't know the basic loops in this language.
Could help every Lua learners :P

EDIT: @heda, I added your trackFX loop !

Last edited by X-Raym; 02-17-2015 at 05:06 AM.
X-Raym is offline   Reply With Quote
Old 02-19-2015, 11:39 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default v1.3 (2015-02-19)

Code:
 * Changelog:
 * v1.3 (2015-02-19)
    + Instructions header field
    + Get and Set parameters for items
    + Get and Set parameters for takes
If you find this get set useful, I will prepare them for tracks.

Instructions in header came from Heda's idea; nice one :P
X-Raym is offline   Reply With Quote
Old 02-27-2015, 06:29 AM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default LUA version

Thanks to heda and benf, I manage to transpose all functions to a LUA version of the template, for users who use REAPER v5 pre-releases.
It also uses the console debug functions which has been transposed to LUA too.
The download links are updated in the first post.

Cheers

Last edited by X-Raym; 02-27-2015 at 06:56 AM.
X-Raym is offline   Reply With Quote
Old 02-27-2015, 07:53 AM   #7
benf
Human being with feelings
 
benf's Avatar
 
Join Date: Oct 2008
Location: France
Posts: 2,061
Default

In lua, you can use :
Code:
reaper.ShowConsoleMsg(tostring(variable))
instead of :
Code:
str = string.format("%d", variable)
reaper.ShowConsoleMsg(str)
__________________
Listen and download my music on https://benest.bandcamp.com/
benf is offline   Reply With Quote
Old 02-27-2015, 08:13 AM   #8
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: City
Posts: 9,561
Default

Great stuff. This will certainly help with any script I'll be writing.

Thanks for the effort!
__________________
Dialogue/FX Editor & Re-Recording Mixer
Using Latch Preview
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 02-27-2015, 08:55 AM   #9
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@benf
You are right, It may be more efficient, but I keep it that ways for consistency with the EEL version, and I used %f and %X at some other part of the script.
But I may updated it if there is performance issue.

@airon
Thanks to you
You have some pretty advanced scripts already, it will be an honored if you used my template as base for some of them!

--
It is my second attempt in LUA, it could probably be optimized, but I try to make the thing right, using some LUA coding conventions I read in the official doc.
X-Raym is offline   Reply With Quote
Old 03-03-2015, 07:10 AM   #10
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default v1.4.1

I added some useful functions and code references for the LUA version.

Code:
 * Changelog:
 * v1.4.1 (2015-03-03)
     # EnumProjectMarkers3 for regions loop
 * v1.4 (2015-03-02)
     + Infos for track, take and items values
     + Restore view, loop, edit cursor and UI


Note: These restore functions need SWS.
X-Raym is offline   Reply With Quote
Old 03-03-2015, 07:15 AM   #11
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: brighton, uk
Posts: 12,273
Default

Thanks!
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 03-16-2015, 10:56 PM   #12
EpicSounds
Human being with feelings
 
EpicSounds's Avatar
 
Join Date: Jul 2009
Posts: 3,967
Default

Page Not found on all 4 links in OP.
__________________
REAPER Video Tutorials, Tips & Tricks and more at The REAPER Blog
EpicSounds is offline   Reply With Quote
Old 03-17-2015, 02:05 AM   #13
mim
Human being with feelings
 
Join Date: Mar 2009
Posts: 345
Default

Nice Idea!
Useful stuff for newbz!

Quote:
Originally Posted by EpicSounds View Post
Page Not found on all 4 links in OP.
One can find it,in the archive here :
http://extremraym.com/en/my-reaper-scripts/
mim is offline   Reply With Quote
Old 03-17-2015, 04:54 AM   #14
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@EpicSounds
Hi!

The link is in my signature!
I decided to change the way I share scripts. Individual links for every script is hard to manage, especially if the host/folder change, so now, they are all at the same place, and the link is no dependent of the post: it is simply my script link in my signature!

@mim
Thanks!
I'm about to make a video tutorial on how to use it!
X-Raym is offline   Reply With Quote
Old 04-14-2015, 04:43 PM   #15
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,030
Default

in template.lua
use this for the RestoreCursorPos()
It doesn't move the view.

Code:
-- RESTORE INITIAL CURSOR POS
function RestoreCursorPos()
	reaper.SetEditCurPos(init_cursor_pos, false, false)
end
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 04-14-2015, 11:43 PM   #16
jrp
Human being with feelings
 
Join Date: Nov 2014
Posts: 149
Default

Hey X-Raym,

Big thank you for all the effort!
Scripting is such a nice hobby, isn´t it? The article on your HP covering the new possibilities with v5 is also very nice!
So now let´s immagine something - and code it!
jrp is offline   Reply With Quote
Old 04-15-2015, 02:37 AM   #17
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@heda
Oh yes, it is not supposed to.
It just does cursor

Restore view is another module.
We have to use SWS REAPER action save/restore view for that now, but I plan to integrate a Lua version with future SWS API functions. (SaveView and RestoreView in the file doesn't work yet).
X-Raym is offline   Reply With Quote
Old 04-15-2015, 02:43 AM   #18
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@jrp
Many, thanks More articles will come soon ! Can't wait for v5 to come out.
Scripting is funny, totally ! It is like doing puzzle games, that are useful to solve :P

Do you have any script ideas you want to share ?
X-Raym is offline   Reply With Quote
Old 04-15-2015, 04:51 AM   #19
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,030
Default

@X-Raym, Sorry I didn't explain it well. I changed the code of that function. I mean, if you replace the function with the one I posted, it will work better by not moving the view.
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 04-15-2015, 05:11 AM   #20
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@heda
How could I missed this function.
I know I was looking for "Cursor" not for "Cur". !!

Thanks, it will be easier that way
X-Raym is offline   Reply With Quote
Old 05-07-2015, 05:00 PM   #21
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default 1.7

Thanks to the last SWS pre release 2.7.1 (and Breeder's work), I am happy to show my last Lua template version

Code:
 * Changelog:
 * v1.7 (2015-05-18)
     + Save/Restore view without calling the SWS "slot" functions.
 * v1.6 (2015-04-15)
     + Save/Restore functions without calling the SWS "slot" functions.
     # thanks to heda for the edit cursor restore
There is now functions to call/recall certain initial states (item selection, track selection, view, edit cursor, loop and time selection), without using the SWS actions, and so, without using your slots. It is now all integrated in the scripts...
... and in all my other scripts

Cheers !
X-Raym is offline   Reply With Quote
Old 08-23-2015, 04:55 AM   #22
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

One of the most time consuming part of scripting is the sharing part of the process (at least for me).

To manage my script pack on my website (with content displayed in a sortable responsibe table with lighbox for screenshot, and updates are displayed with a RSS file embed right in the page and triggered by any update in this table), I have to maintain a spreadsheet online, with all infos about scripts update.

Of course all infos came from the script header, but it is a bit boring to copy paste all this fields...

... So here it is, a script header parser !



It is still a long run before a script updater but it is a first step. A small one, but a step anyway :P
X-Raym is offline   Reply With Quote
Old 01-29-2016, 09:13 AM   #23
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

Templates have moved from my repo and can now be found on the ReaTeam-Templates repository.

I will soon create a template for each common cases (regions, markers, etc...) rather than a all purpose template, because I found it pretty confusing to have to delete all unnecessary code each times. Especially for beginners.

Meanwhile...
Hope it can be useful !
X-Raym is offline   Reply With Quote
Old 01-29-2016, 09:50 AM   #24
airon
Human being with feelings
 
airon's Avatar
 
Join Date: Aug 2006
Location: City
Posts: 9,561
Default

Thanks X-Raym. The template was a big help in getting me up and running.
__________________
Dialogue/FX Editor & Re-Recording Mixer
Using Latch Preview
"My ego comes pre-shrunk" - Randy Thom
airon is offline   Reply With Quote
Old 01-29-2016, 12:38 PM   #25
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,030
Default

the function UnselectAllTracks()

Maybe better just to use the action like this
reaper.Main_OnCommand("40297",0)

not really important
__________________
HeDaScripts for REAPER | VIP Donations

Last edited by heda; 01-29-2016 at 12:46 PM.
heda is offline   Reply With Quote
Old 01-29-2016, 01:36 PM   #26
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 3,952
Default

@heda
I think it was to avoid creating unwanted undo points. I did that long time ago and I didn't need to use it very often.

But sure, it can work with reaper.Main_OnCommand("40297",0) !
X-Raym 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 09:48 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.