ReaScripts: Notes and references.. (share here..)

Discussion in 'Reaper' started by Futurewine, May 6, 2021.

  1. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    This thread is about sharing notes and references to ReaScript. Feel free to write tutor here if you like, much appreciated :shalom:. #happyscripting ~

    Latest: --->

     
    Last edited: May 13, 2021
    • Like Like x 2
    • Interesting Interesting x 2
    • List
  2.  
  3. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    References: The Configuration-Variables
    https://mespotin.uber.space/Ultraschall/Reaper_Config_Variables.html

    How to manipulate (using lua by example):
    Originally Posted by nofish: https://forums.cockos.com/showpost.php?p=2240152&postcount=2
    PHP:
    -- QUERY
    state 
    reaper.SNM_GetIntConfigVar("projshowgrid", -666)&-- bitwise AND, query bitreturns 4/non zero if enabledif disabled

    -- TOGGLE
    -- toggleOK reaper.SNM_SetIntConfigVar("projshowgrid"reaper.SNM_GetIntConfigVar("projshowgrid", -666)~4) -- bitwise NOT XOR (exclusive OR), flip bit

    -- ENABLE
    -- enableOK reaper.SNM_SetIntConfigVar("projshowgrid"reaper.SNM_GetIntConfigVar("projshowgrid", -666)|4) -- bitwise OR, set bit

    -- DISABLE
    -- disableOK reaper.SNM_SetIntConfigVar("projshowgrid", (reaper.SNM_GetIntConfigVar("projshowgrid", -666)&(~4))) -- bitwise AND NOTclear bit
    Note for writing in EEL script:

    :shalom:
     
    Last edited: May 7, 2021
  4. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    File reading in EEL2 (example)
    Originally Posted by spk77: https://forum.cockos.com/showpost.php?p=1348960&postcount=2
    PHP:
    function msg_s(m)
    (
      
    ShowConsoleMsg(m);
      
    //ShowConsoleMsg("\n");
    );

    function 
    read_lines(file_name)
    (
      (
    file fopen(file_name"r")) ? (
        while(
    feof(file) == 0) ( // feof(file) returns nonzero if the file fp is at the end of file.
          
    fgets(file#line); // read the file line by line
          #lines += #line;
        
    );
        
    fclose(file);
        
    msg_s(#lines);
      
    );
    );

    file_name "C:/EEL scripts/Read lines test.txt"// edit this line (it seems that backslashes don't work in "file_name")
    read_lines(file_name);
     
    Last edited: May 7, 2021
  5. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    Formula: Convert db to val, val to db (LUA):
    originally posted by spk77: https://forum.cockos.com/showpost.php?p=1608719&postcount=6
    PHP:
    val_to_dB = function(val) return 20*math.log(val10end
    dB_to_val 
    = function(dB_val) return 10^(dB_val/20end

    -- test
    some_dB_val 
    val_to_dB(2) -- should be ~6.02 dB
    some_dB_val_to_val 
    dB_to_val(some_dB_val) -- should be "2"
     
  6. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
  7. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    EEL2 Template: ReaImGui: ReaScript binding for Dear ImGui
    credits: cfillion : https://forum.cockos.com/showthread.php?t=250419

    notes: hell i've no idea yet how to use thos extension.. the example here is a simplified result from ~studying~ the example script from: Script: ReaImGui_Hello World.eel (included in reapack download.. search: reapack imgui or visit forum link for more infos.. :shalom:)

    PHP:
    // EEL2 Template: ReaImGui
    // REAPER 6.24 or newer only!

    FLT_MIN 0.0001// 1.17549e-38

    ctx ImGui_CreateContext("Hello World!"500420);

    function 
    update() (
      
    viewport ImGui_GetMainViewport(ctx);
     
      
    ImGui_Viewport_GetPos(viewportxy);
      
    ImGui_SetNextWindowPos(ctxxy);
     
      
    ImGui_Viewport_GetSize(viewportwh);
      
    ImGui_SetNextWindowSize(ctxwh);
     
      
    ImGui_Begin(ctx"main"0ImGui_WindowFlags_NoDecoration()) ? (

        
    // ========== Start stuffing your GUIs here.. ========== //

        
    ImGui_Text(ctx"Hello World!");

        
    // ========== End stuffing your GUIs here.. ========== //

      
    );
     
      
    ImGui_End(ctx);
    );

    function 
    loop() (
      
    ImGui_IsCloseRequested(ctx) ?
        
    ImGui_DestroyContext(ctx) : (
        
    update();
        
    defer("loop()");
      )
    );

    defer("loop()");
    [​IMG]
     
    Last edited: May 7, 2021
  8. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    Hellyea buddy! i demystified this.. have fun :shalom:

    Python Example: ReaImGui: ReaScript (by Futurewine)

    reference and credits: cfilion: https://github.com/cfillion/reaimgui/blob/master/examples/track_manager.py

    PHP:
    sys.path.append(RPR_GetResourcePath() + "/Scripts/ReaTeam Extensions/API")

    from imgui_python import *

    FLT_MIN 1.17549e-38

    def init
    ():
        global 
    ctxviewport
        ctx 
    ImGui_CreateContext("Hello World"320240)[0]
        
    viewport ImGui_GetMainViewport(ctx)
        
    loop()
      
    def loop():
        if 
    ImGui_IsCloseRequested(ctx):
            
    ImGui_DestroyContext(ctx)
            return

        
    _xImGui_Viewport_GetPos(viewport)
        
    ImGui_SetNextWindowPos(ctxxy)
        
    _wImGui_Viewport_GetSize(viewport)
        
    ImGui_SetNextWindowSize(ctxwh)
      
        
    ImGui_Begin(ctx"main"NoneImGui_WindowFlags_NoDecoration())

        
    ### START add ImGui widget from here.. ###
        
    if ImGui_Button(ctx"Play/Stop")[0]:
            
    RPR_Main_OnCommand(400440)
        
    ### STOP add ImGui widget from here.. ###

        
    ImGui_End(ctx)

        
    RPR_defer("loop()")

    RPR_defer("init()")
    [​IMG]

    :shalom::shalom::shalom:

     
    • Interesting Interesting x 1
    • Useful Useful x 1
    • List
  9. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    get floating window by its title via script.. (lua example)
    originally posted by Edgemeal : https://forum.cockos.com/showpost.php?p=2365993&postcount=3

    PHP:
    -- Toggle video window full screen.lua
    local hwnd 
    reaper.BR_Win32_FindWindowEx("0""0""0""Video Window"falsetrue)
    if 
    hwnd then reaper.BR_Win32_SendMessage(hwnd0x20300end -- WM_LBUTTONDBLCLK 0x203
     
  10. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    Best Answer
    Scripting templates/examples: How to get and manipulate TCP, Media Items, Project Markers (EEL2)
    originally posted by X-Raym : https://github.com/ReaTeam/ReaScripts-Templates/blob/master/Templates/X-Raym_Template.eel
    notes: more examples/templates including Lua and Python here: https://github.com/ReaTeam/ReaScripts-Templates/tree/master/Templates

    PHP:
    /**
     * ReaScript Name: Template Title (match file name without extension and author)
     * Description: A template script for REAPER ReaScript.
     * Instructions: Here is how to use it. (optional)
     * Author: X-Raym
     * Author URI: http://extremraym.com
     * Repository: GitHub > X-Raym > EEL Scripts for Cockos REAPER
     * Repository URI: https://github.com/X-Raym/REAPER-EEL-Scripts
     * File URI: https://github.com/X-Raym/REAPER-EEL-Scripts/scriptName.eel
     * Licence: GPL v3
     * Forum Thread: Script: Script name
     * Forum Thread URI: http://forum.cockos.com/***.html
     * REAPER: 4.76
     * Extensions: SWS/S&M 2.6.0 (optional)
     * Version: 1.3.2
    */
     
    /**
     * Changelog:
     * v1.3.2 (2015-03-14)
         # more infos for items loop
     * v1.3.1 (2015-02-20)
         # loops takes bug fix
     * v1.3 (2015-02-19)
        + Instructions header field
        + Get and Set parameters for items
        + Get and Set parameters for takes
     * v1.2.1 (2015-02-17)
        # loops indentation
     * v1.2 (2015-02-13)
        + Items, Takes, Tracks, Regions and FX loops
        # Underscore variables
     * v1.1 (2015-02-15)
        + Basic scripts actions template
     * v1.0 (2015-01-09)
        + Initial Release
        + New functions
        - Deleted functions
        # Updated functions
     */

    // ----- DEBUGGING ====>
    @import ../Functions/X-Raym_Functions console debug messages.eel

    debug 
    1// 0 => No console. 1 => Display console messages for debugging.
    clean 1// 0 => No console cleaning before every script execution. 1 => Console cleaning before every script execution.

    msg_clean();
    // <==== DEBUGGING -----

    function main() // local (i, j, item, take, track)
    (
        
    Undo_BeginBlock(); // Begining of the undo block. Leave it at the top of your main function.

        // YOUR CODE BELOW

        // LOOP THROUGH SELECTED ITEMS
        /*
        selected_items_count = CountSelectedMediaItems(0);
        
        i = 0; // INITIALIZE loop through selected items
        loop(selected_items_count, (item = GetSelectedMediaItem(0, i)) ? (
                // GET INFOS
                value_get = GetMediaItemInfo_Value(item, "D_VOL"); // Get the value of a the parameter
                B_MUTE : bool * to muted state
                B_LOOPSRC : bool * to loop source
                B_ALLTAKESPLAY : bool * to all takes play
                B_UISEL : bool * to ui selected
                C_BEATATTACHMODE : char * to one char of beat attached mode, -1=def, 0=time, 1=allbeats, 2=beatsosonly
                C_LOCK : char * to one char of lock flags (&1 is locked, currently)
                D_VOL : double * of item volume (volume bar)
                D_POSITION : double * of item position (seconds)
                D_LENGTH : double * of item length (seconds)
                D_SNAPOFFSET : double * of item snap offset (seconds)
                D_FADEINLEN : double * of item fade in length (manual, seconds)
                D_FADEOUTLEN : double * of item fade out length (manual, seconds)
                D_FADEINLEN_AUTO : double * of item autofade in length (seconds, -1 for no autofade set)
                D_FADEOUTLEN_AUTO : double * of item autofade out length (seconds, -1 for no autofade set)
                C_FADEINSHAPE : int * to fadein shape, 0=linear, ...
                C_FADEOUTSHAPE : int * to fadeout shape
                I_GROUPID : int * to group ID (0 = no group)
                I_LASTY : int * to last y position in track (readonly)
                I_LASTH : int * to last height in track (readonly)
                I_CUSTOMCOLOR : int * : custom color, windows standard color order (i.e. RGB(r,g,b)|0x100000). if you do not |0x100000, then it will not be used (though will store the color anyway)
                I_CURTAKE : int * to active take
                IP_ITEMNUMBER : int, item number within the track (read-only, returns the item number directly)
                F_FREEMODE_Y : float * to free mode y position (0..1)
                F_FREEMODE_H : float * to free mode height (0..1)
                
                // MODIFY INFOS
                value_set = value_get; // Prepare value output
                
                // SET INFOS
                SetMediaItemInfo_Value(item, "D_VOL", value_set); // Set the value to the parameter
            ); // ENDIF inside loop selected items
            i += 1; // INCREMENT loop through selected items
        ); // ENDLOOP through selected items
        */

        // LOOP THROUGH SELECTED TAKES
        /*
        selected_items_count = CountSelectedMediaItems(0);

        i = 0; // INITIALIZE loop through selected items
        loop(selected_items_count, (item = GetSelectedMediaItem(0, i)) ? (
                (take = GetActiveTake(item)) ? (
                    // GET INFOS
                    value_get = GetMediaItemTakeInfo_Value(take, "D_VOL"); // Get the value of a the parameter
                    // "D_VOL"
                    // "D_PAN"
                    // "D_PLAYRATE"
                    // "D_PITCH", Ge
                    // "I_CHANMODE"
                    // "D_STARTOFFS"
                    // "D_PANLAW"
                    // MODIFY INFOS
                    value_set = value_get; // Prepare value output
                    // SET INFOS
                    SetMediaItemTakeInfo_Value(take, "D_VOL", value_set); // Set the value to the parameter
                ); // ENDIF active take
            ); // ENDIF inside loop selected items
            i += 1; // INCREMENT loop through selected items
        ); // ENDLOOP through selected items
        */

        // LOOP TRHOUGH SELECTED TRACKS
        /*
        selected_tracks_count = CountSelectedTracks(0);

        i = 0; // INITIALIZE loop through selected tracks
        loop(selected_tracks_count, (track = GetSelectedTrack(0, i)) ? (
                // ACTIONS
            ); // ENDIF inside loop
            i += 1; // INCREMENT loop through selected tracks
        ); // ENDLOOP through selected tracks


        // LOOP THROUGH REGIONS
        /*
        i = 0; // INITIALIZE loop through regions

        while (EnumProjectMarkers(i, is_region, region_start, region_end, #name, region_id)) (   
            is_region === 1 ? (
                // ACTIONS   
            );
            i += 1; // INCREMENT loop through regions
        ); // ENDWHILE loop through regions
        */


        // LOOP TRHOUGH FX - by HeDa
        /*
        tracks_count = CountTracks(0);

        i=0; // INITIALIZE track loop
        loop (tracks_count, // loop for all tracks
                
            track = GetTrack(0, i);    // which track
            track_FX_count = TrackFX_GetCount(tracki); // count number of FX instances on the track
            
            i=0; // INITIALIZE FX loop
            loop (track_FX_count,    // loop for all FX instances on each track
                // ACTIONS
                i+=1; // INCREMENT FX loop                       
            ); // ENDLOOP FX loop
            
            i+=1; // INCREMENT tracks loop
        ); // ENDLOOP tracks loop
        */

        // YOUR CODE ABOVE

        
    Undo_EndBlock("My action"0); // End of the undo block. Leave it at the bottom of your main function.
    );

    msg_start(); // Display characters in the console to show you the begining of the script execution.

    main(); // Execute your main function

    UpdateArrange(); // Update the arrangement (often needed)

    msg_end(); // Display characters in the console to show you the end of the script execution.
     
  11. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    haa i forgot things.. 1 year later this thread just saved my life.. awsome forum :shalom::shalom:
     
    • Winner Winner x 1
    • Love it! Love it! x 1
    • List
  12. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    How to define an array of strings in eel?
    thanks to amagalma for question and Justin for answer, ref: https://forums.cockos.com/showthread.php?t=189265


    PHP:
    array = 10000// this is in EEL normal-memory, not string space -- need to make sure it doesn't collide with other memory your script uses

    mem_set_values(array, "dog""cat""mouse");
    ...
    gfx_drawstr(array[x]);
     
  13. Futurewine

    Futurewine Audiosexual

    Joined:
    Oct 4, 2017
    Messages:
    885
    Likes Received:
    558
    Location:
    Sound City Labs
    might save this formula here.. originally think-tank from mine just now.. :shalom:

    so the title is.. Get time by measure.. ? (something like that..)
    PHP:
        measure 25
        qn 
    = ((measure 4) - 4) - RPR_TimeMap_timeToQN(RPR_GetProjectTimeOffset(00))
        
    time RPR_TimeMap_QNToTime(qn)

        
    # example use case..
        
    RPR_SetEditCurPos(time00)
     
Loading...
Loading...