Old 03-01-2017, 07:31 AM   #1
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,490
Default Pro Tools "Show/hide Clip Gain Line" (Start+Shift+Hyphen) equivalent

Hello!

I created this script to show/hide all take volume envelopes in project (like Shift+Start+- in Protools does). I think I am doing something wrong with the External States.. Could you have a look and tell me what is wrong?

Thanks!

Code:
function Show_All_Take_VolEnvelope(show)
  local(item_cnt, item_idx, item, take_idx, take_cnt, take, VolEnv, BR_Env,
        BR_Env, active,visible,armed, inLane,laneHeight, 
        defShape, minVal,maxVal,centerVal, type, faderScaling)   
(
  Main_OnCommand(NamedCommandLookup("_SWS_SAVEALLSELITEMS1"), 0); // save current item selection
  SelectAllMediaItems(0, 1);
  item_cnt = CountSelectedMediaItems(0);
  item_idx=0;
  loop(item_cnt,
      item = GetSelectedMediaItem(0, item_idx);
      take_cnt = CountTakes(item);
      take_idx = 0;
      loop(take_cnt,
          take = GetMediaItemTake(item, take_idx);
          VolEnv = GetTakeEnvelopeByName(take,"Volume");
          VolEnv ? (
                  BR_Env = extension_api("BR_EnvAlloc", VolEnv, 0);
                  extension_api("BR_EnvGetProperties", BR_Env, active,visible,armed, inLane,laneHeight, 
                                defShape, minVal,maxVal,centerVal, type, faderScaling);
                  extension_api("BR_EnvSetProperties", BR_Env, active, show, armed, inLane,laneHeight, 
                                defShape, faderScaling);
                  extension_api("BR_EnvFree", BR_Env, 1);   
                   ) : (  // create VolEnv if it does not exist
            Main_OnCommand(40289, 0); // unselect all items
            SetMediaItemSelected(item, 1);
            Main_OnCommand(NamedCommandLookup("_S&M_TAKEENV1"), 0);     
                       );
          take_idx += 1;
      );
      item_idx+=1;
  );
  Main_OnCommand(NamedCommandLookup("_SWS_RESTALLSELITEMS1"), 0); // restore item selection
  match("%s", show, #show);
  SetExtState("MyScript", "Show all take vol envelopes", #show, 0);
);

// LOGIC
PreventUIRefresh(1);
HasState = HasExtState("MyScript", "Show all take vol envelopes");
HasState == 0 ? Show_All_Take_VolEnvelope(1) : (
                GetExtState(#retval, "MyScript", "Show all take vol envelopes");
                match("%d", #retval, retval);
                retval == 0 ? Show_All_Take_VolEnvelope(1) : Show_All_Take_VolEnvelope(0);
                                               ); 
PreventUIRefresh(-1);
function NoUndo()(abs(0)); defer("NoUndo()");
EDIT: See post #7

Last edited by amagalma; 04-10-2017 at 02:57 AM.
amagalma is offline   Reply With Quote
Old 03-01-2017, 10:12 AM   #2
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,490
Default

edited:

Code:
function Show_All_Take_VolEnvelope(show)
  local(item_cnt, item_idx, item, take_idx, take_cnt, take, VolEnv, BR_Env,
        BR_Env, active,visible,armed, inLane,laneHeight, 
        defShape, minVal,maxVal,centerVal, type, faderScaling)   
(
  Main_OnCommand(NamedCommandLookup("_SWS_SAVEALLSELITEMS1"), 0); // save current item selection
  SelectAllMediaItems(0, 1);
  item_cnt = CountSelectedMediaItems(0);
  item_idx=0;
  loop(item_cnt,
      item = GetSelectedMediaItem(0, item_idx);
      take_cnt = CountTakes(item);
      take_idx = 0;
      loop(take_cnt,
          take = GetMediaItemTake(item, take_idx);
          VolEnv = GetTakeEnvelopeByName(take,"Volume");
          VolEnv ? (
                  BR_Env = extension_api("BR_EnvAlloc", VolEnv, 0);
                  extension_api("BR_EnvGetProperties", BR_Env, active,visible,armed, inLane,laneHeight, 
                                defShape, minVal,maxVal,centerVal, type, faderScaling);
                  extension_api("BR_EnvSetProperties", BR_Env, active, show, armed, inLane,laneHeight, 
                                defShape, faderScaling);
                  extension_api("BR_EnvFree", BR_Env, 1);   
                   ) : (  // create VolEnv if it does not exist
            Main_OnCommand(40289, 0); // unselect all items
            SetMediaItemSelected(item, 1);
            Main_OnCommand(NamedCommandLookup("_S&M_TAKEENV1"), 0);     
                       );
          take_idx += 1;
      );
      item_idx+=1;
  );
  Main_OnCommand(NamedCommandLookup("_SWS_RESTALLSELITEMS1"), 0); // restore item selection
  show = sprintf(#, "%d", show);
  SetExtState("MyScript", "Show all take vol envelopes", show, 0);
);

// LOGIC
PreventUIRefresh(1);
HasState = HasExtState("MyScript", "Show all take vol envelopes");
HasState == 0 ? Show_All_Take_VolEnvelope(1) : (
                GetExtState(#retval, "MyScript", "Show all take vol envelopes");
                match("%d", #retval, retval);
                retval == 0 ? Show_All_Take_VolEnvelope(1) : Show_All_Take_VolEnvelope(0);
                                               ); 
PreventUIRefresh(-1);
function NoUndo()(abs(0)); defer("NoUndo()");
It works now but "Select all items" and "Restore saved selected item(s)" appear in my Undo list. What can I do so that there is nothing added in the Undo list?

Thanks!

Last edited by amagalma; 03-01-2017 at 10:19 AM.
amagalma is offline   Reply With Quote
Old 03-01-2017, 12:17 PM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,966
Default

Hi !

THanks for sharing !

You should not use BR SWS slots for that, cause it may override a user made selection, and a script should not have "side effects".

You can simply save selected items at scripts start

https://github.com/ReaTeam/ReaScript...%20editing.lua

and restore them later

https://github.com/ReaTeam/ReaScript...plate.lua#L268

Feel free to adapt this code so that it fit your script :P
X-Raym is offline   Reply With Quote
Old 03-01-2017, 03:42 PM   #4
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,490
Default

Thank you X-Raym for your help!

I use eel. So, if I am not wrong the script to save the selected items, would be something like this:
Code:
function SaveSelectedItems(table)
(
sel_items = CountSelectedMediaItems(0);
i=0;
  loop(sel_items,
       table[i] = GetSelectedMediaItem(0, i);    
       i+=1;
  );
);
But I have no idea how to restore the selection. What is the equivalent code in eel of your lua code?
amagalma is offline   Reply With Quote
Old 03-01-2017, 03:57 PM   #5
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,490
Default

Is it like this? :

Code:
function RestoreSelectedItems(table)
(
Main_OnCommand(40289,0); // unselect all items
i=0;
  loop(sel_items,
      SetMediaItemSelected(table[i], 1);
      i+=1;
  );
);
amagalma is offline   Reply With Quote
Old 03-01-2017, 04:01 PM   #6
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,490
Default

I added them into my script and they seem to work.. But it does not solve the undo problem...

Current code is:
Code:
function SaveSelectedItems(table)
(
sel_items = CountSelectedMediaItems(0);
i=0;
  loop(sel_items,
      table[i] = GetSelectedMediaItem(0, i);    
      i+=1;
  );
);

function RestoreSelectedItems(table)
(
Main_OnCommand(40289,0); // unselect all items
i=0;
  loop(sel_items,
      SetMediaItemSelected(table[i], 1);
      i+=1;
  );
);


function Show_All_Take_VolEnvelope(show)
  local(item_cnt, item_idx, item, take_idx, take_cnt, take, VolEnv, BR_Env,
        BR_Env, active,visible,armed, inLane,laneHeight, 
        defShape, minVal,maxVal,centerVal, type, faderScaling)   
(
Undo_BeginBlock();
  SaveSelectedItems(table); // save current item selection
  SelectAllMediaItems(0, 1);
  item_cnt = CountSelectedMediaItems(0);
  item_idx=0;
  loop(item_cnt,
      item = GetSelectedMediaItem(0, item_idx);
      take_cnt = CountTakes(item);
      take_idx = 0;
      loop(take_cnt,
          take = GetMediaItemTake(item, take_idx);
          VolEnv = GetTakeEnvelopeByName(take,"Volume");
          VolEnv ? (
                  BR_Env = extension_api("BR_EnvAlloc", VolEnv, 0);
                  extension_api("BR_EnvGetProperties", BR_Env, active,visible,armed, inLane,laneHeight, 
                                defShape, minVal,maxVal,centerVal, type, faderScaling);
                  extension_api("BR_EnvSetProperties", BR_Env, active, show, armed, inLane,laneHeight, 
                                defShape, faderScaling);
                  extension_api("BR_EnvFree", BR_Env, 1);   
                   ) : (  // create VolEnv if it does not exist
            Main_OnCommand(40289, 0); // unselect all items
            SetMediaItemSelected(item, 1);
            Main_OnCommand(NamedCommandLookup("_S&M_TAKEENV1"), 0);     
                       );
          take_idx += 1;
      );
      item_idx+=1;
  );
  RestoreSelectedItems(table); // restore item selection
  show = sprintf(#, "%d", show);
  SetExtState("Myscript", "Show all take vol envelopes", show, 0);
Undo_EndBlock("Toggle show all take vol envelopes", -1);
);

function Main()
(
HasState = HasExtState("Myscript", "Show all take vol envelopes");
HasState == 0 ? Show_All_Take_VolEnvelope(1) : (
                GetExtState(#retval, "Myscript", "Show all take vol envelopes");
                match("%d", #retval, retval);
                retval == 0 ? Show_All_Take_VolEnvelope(1) : Show_All_Take_VolEnvelope(0);
                                             ); 
);

PreventUIRefresh(1);
Main();
function NoUndo()(abs(0)); defer("NoUndo()");
PreventUIRefresh(-1);
Any ideas?

Last edited by amagalma; 03-01-2017 at 04:12 PM.
amagalma is offline   Reply With Quote
Old 04-10-2017, 02:53 AM   #7
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,490
Default

Forget all the code above!

If anyone needs the Pro Tools "Show/hide Clip Gain Line" equivalent for Reaper, look for amagalma_Toggle take volume envelope visible for all takes of all items in project in ReaPack.
amagalma 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 04:50 PM.


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