Old 07-15-2016, 11:30 AM   #41
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,145
Default

Quote:
Originally Posted by spk77 View Post
Can we pass functions with parameters to "reaper.defer" function? Like this: reaper.defer(main(false))?
That would call main() over and over again. Try this:
Code:
reaper.defer(function() main(false) end)

Last edited by cfillion; 07-15-2016 at 11:38 AM.
cfillion is offline   Reply With Quote
Old 07-15-2016, 11:36 AM   #42
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by cfillion View Post
This would only call main() over and over again. Try this:
Code:
reaper.defer(function() main(false) end)
That was it, thanks! I'm going to add this "delayed undo" to all my "adjust x via mousewheel" -scripts
spk77 is offline   Reply With Quote
Old 08-16-2016, 06:10 AM   #43
lowellben
Human being with feelings
 
lowellben's Avatar
 
Join Date: Aug 2010
Location: They put me in a home.
Posts: 3,340
Default

Quote:
Originally Posted by spk77 View Post
That was it, thanks! I'm going to add this "delayed undo" to all my "adjust x via mousewheel" -scripts
Somewhat related bug, fyi:

"...volume envelope point at mouse cursor via mousewheel.lua:1: unexpected symbol near '/'"

when I try to use your script spk77_Adjust volume envelope point at mouse cursor via mousewheel.lua

This script appears to not be working. Thanks!
__________________
47.8% of statistics are made up.
lowellben is offline   Reply With Quote
Old 08-16-2016, 06:57 AM   #44
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,826
Default

Quote:
Originally Posted by spk77 View Post
That was it, thanks! I'm going to add this "delayed undo" to all my "adjust x via mousewheel" -scripts
@spk77
Could you add undo to these ones?
MoveUp envelope points.lua
MoveDown envelope points.lua
Compress envelope points.lua
Expand envelope points.lua
by the way, I found a bug in those, when selecting all points, the first one, at time 0.0, wasn't moved,
I changed this (in red) and it works now, but I'm not sure why.

Code:
for i=1,env_point_count do
      value = ({get_env_point(env, i-1)})[3]
      selected = ({get_env_point(env, i-1)})[6]
      if selected then
        e_i[c] = i-1
        e_v[c] = value
        c = c+1
        sel_points = sel_points + 1
        sum = sum + value
      end
    end
heda is offline   Reply With Quote
Old 05-20-2020, 03:26 PM   #45
Triode
Human being with feelings
 
Triode's Avatar
 
Join Date: Jan 2012
Posts: 690
Default

Does anyone know if there's a way of doing a time delay undo like this in a lua script?


Quote:
Originally Posted by Justin View Post
Here's a version of the script that waits to process undo until after mouse tweaking has finished:
Code:
function VAL2DB(x)(
  x < 0.0000000298023223876953125 ? -150 : max(-150, log(x)* 8.6858896380650365530225783783321);  
);
function DB2VAL(x) ( exp((x)*0.11512925464970228420089957273422 ));
 
want_item = 1; // set to 0 for take volume rather than item volume

function run(first) (
  val=cnt=tr=0;
  get_action_context(#foo,0,0, mode, res, val)||first ? (
    pc=time_precise();
    val != 0 ? loop(GetNumTracks(),
      trh = GetTrack(0,tr);
      idx=0;
      loop(GetTrackNumMediaItems(trh),
        item = GetTrackMediaItem(trh,idx);
        IsMediaItemSelected(item) && (want_item || (tk = GetActiveTake(item))) ? (
          vol = want_item ? GetMediaItemInfo_Value(item,"D_VOL") : GetMediaItemTakeInfo_Value(tk,"D_VOL");
          ph = vol < 0.0;
          vol = DB2VAL(VAL2DB(abs(vol)) + (val > 0 ? 0.5 : -0.5));      
          want_item ? SetMediaItemInfo_Value(item,"D_VOL",vol) : SetMediaItemTakeInfo_Value(tk,"D_VOL",ph ? -vol : vol);      
          cnt+=1;
          z=1;
        );
        idx+=1
      );
      tr+=1
    );
    cnt != 0 ? UpdateTimeline();
  );
  time_precise() < pc+1 ? defer("run(0)") : Undo_OnStateChange("Adjust Item Volume"); 
);

run(1);
__________________
Brush and Beater Drums Online: www.outoftheboxdrums.co.uk
Triode 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 06:26 AM.


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