Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 12-10-2017, 12:29 PM   #1
Etalon
Human being with feelings
 
Etalon's Avatar
 
Join Date: Aug 2014
Posts: 68
Default REQ: Stretch selected automation item right edge to time selection end

Well, the title says it all. I would like to load my saved automation items into the time selection, but the automation items only look for the start of the time selection and not how long the time selection is.
Including this in ReaPack would be great as well.
Thanks!
Etalon is offline   Reply With Quote
Old 12-10-2017, 10:14 PM   #2
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

This seems to work for your use case:



However, I don't consider it a good 'general situation' script as it would break if time selection start is not set to the beginning of the selected AI (it throughs an error currently when this happens).

So I'd refrain from putting it into ReaPack but leave it here for your use until someone hopefully does a better version.

Code:
function preventUndo()
end
reaper.defer(preventUndo)

timeSelStart, timeSelEnd = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
timeSelLength = timeSelEnd - timeSelStart

if timeSelLength > 0 then
  selEnv = reaper.GetSelectedTrackEnvelope(0)

  if selEnv ~= nil then
    AIcount = reaper.CountAutomationItems(selEnv)

    if AIcount > 0 then

      for i = 0, AIcount - 1 do
        isSel = reaper.GetSetAutomationItemInfo(selEnv, i, "D_UISEL", 0, false)

        if isSel ~= 0 then
          AIstart = reaper.GetSetAutomationItemInfo(selEnv, i, "D_POSITION", 0, false)
          
          if timeSelStart ~= AIstart then
            reaper.ShowMessageBox("Selected AI doesn't match Time selection start !", "Error", 0)
            return
          end

          AIlength = reaper.GetSetAutomationItemInfo(selEnv, i, "D_LENGTH", 0, false)
          AIplayrate =  reaper.GetSetAutomationItemInfo(selEnv, i, "D_PLAYRATE", 0, false)
          newAIplayrate = (AIlength / timeSelLength) * AIplayrate

          reaper.Undo_BeginBlock()
            reaper.GetSetAutomationItemInfo(selEnv, i, "D_LENGTH", timeSelLength, true)
            reaper.GetSetAutomationItemInfo(selEnv, i, "D_PLAYRATE", newAIplayrate, true)
          reaper.Undo_EndBlock("Script: Stretch AI right edge to time selection end", -1)

          break
        end

      end

    end

  end

end
nofish is offline   Reply With Quote
Old 12-10-2017, 10:40 PM   #3
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Take AI pos as Time selection start. Also it seems it needs to check is time selection ends after AI position. Nice script anyway, I would use it. At least it works as expected (not like AI envelope manipulation).
mpl is offline   Reply With Quote
Old 12-10-2017, 10:52 PM   #4
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Thanks.
Feel free to do the suggested modifications if you like, I'd appreciate it.

Otherwise I'll see if I can do it.
nofish is offline   Reply With Quote
Old 12-11-2017, 05:40 AM   #5
Etalon
Human being with feelings
 
Etalon's Avatar
 
Join Date: Aug 2014
Posts: 68
Default

Thank you nofish!
I've set this up to shift+double click on automation item and it works flawlessly!
That error may could be solved by moving the automation start to the time selection start first, but this is not crucial for me.
I've looked around, and there are not that many scripts or actions regarding automation items, like move automation item to edit cursor or time selection start etc.
Is it because AIs are a relatively new feature?
__________________
etalonbeats.com
Etalon is offline   Reply With Quote
Old 12-11-2017, 08:01 AM   #6
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

You're welcome.

Quote:
Originally Posted by Etalon View Post
Is it because AIs are a relatively new feature?
Probably this and that part of the AI API is currently broken.
This mainly concerns envelope manipulation though as mpl said, things like move AI... should also be possible currently I think, but didn't try yet.

I'm just starting to get into using AI's slowly myself, in fact this is my first script doing anything with AI's.
nofish is offline   Reply With Quote
Old 12-11-2017, 12:03 PM   #7
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Year it seems moving selected AIs to time selection start is a good idea, this is how I would do this script (almost same as nofish though):

Code:
  for key in pairs(reaper) do _G[key]=reaper[key]  end  
  
  function StretchAI()
    local timeSelStart, timeSelEnd = GetSet_LoopTimeRange(false, false, 0, 0, false)
    local timeSelLength = timeSelEnd - timeSelStart
    if timeSelLength < 0 then return end
    for i = 1, CountTracks(0) do 
      local tr = GetTrack(0,i-1)
      for ei = 1, CountTrackEnvelopes( tr ) do
        local env = GetTrackEnvelope( tr, ei-1 )
        for AIi = 1, CountAutomationItems(env) do
          isSel = GetSetAutomationItemInfo(env, AIi-1, "D_UISEL", 0, false)
          if isSel == 1 then  
            local AIpos = GetSetAutomationItemInfo(env, AIi-1, "D_POSITION", 0, false)
            local AIlen = GetSetAutomationItemInfo(env, AIi-1, "D_LENGTH", 0, false)
            local AIrate =  GetSetAutomationItemInfo(env, AIi-1, "D_PLAYRATE", 0, false)
            GetSetAutomationItemInfo(env, AIi-1, "D_POSITION", timeSelStart, true)
            GetSetAutomationItemInfo(env, AIi-1, "D_LENGTH", timeSelLength, true)
            GetSetAutomationItemInfo(env, AIi-1, "D_PLAYRATE", AIrate * AIlen/ timeSelLength  , true)
            Envelope_SortPointsEx(env, AIi-1)
          end
        end
      end
    end
  end
  
  defer(StretchAI)

Last edited by mpl; 12-11-2017 at 12:10 PM.
mpl is offline   Reply With Quote
Old 12-11-2017, 03:44 PM   #8
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

This is the better 'general use' version with also adjusting AI start, thanks mpl.

Will you put it in your ReaPack or should I do it ?

Nitpick:
- "if timeSelLength < 0 then return end"
I think should say "if timeSelLength == 0 then return end" as it would still run if there's no time selection at all and shrink the AI to minimum length.

Also thinking maybe an undo point should created (when it actually does stretch an AI) ?, not sure.
nofish is offline   Reply With Quote
Old 12-11-2017, 09:23 PM   #9
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Ah oops my fault.
First idea is yours so feel free to put it in your repo, I`m just more satisfied with all selected AI instead of only first selected AI on first selected envelope.

Last edited by mpl; 12-11-2017 at 11:09 PM.
mpl is offline   Reply With Quote
Old 12-12-2017, 08:27 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Noticed a quirk:



Happens in mine and your version in this condition. I guess it's because the AI env. edge points are not attached to the underlying env. when loading AI (may depend on some preference ?)
nofish is offline   Reply With Quote
Old 12-13-2017, 08:16 AM   #11
Vagelis
Human being with feelings
 
Vagelis's Avatar
 
Join Date: Oct 2017
Location: Larisa, Greece
Posts: 3,797
Default

Useful Script thanks!
Vagelis is offline   Reply With Quote
Old 12-13-2017, 01:08 PM   #12
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

@nofish, maybe you forget Envelope_SortPoints(Ex)() somewhere?
mpl is offline   Reply With Quote
Old 12-14-2017, 07:18 AM   #13
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

I also try with your version from above which does contain Envelope_SortPoints(Ex)(), same things happens. But not when I move the AI manually with mouse. Any idea why ?

nofish 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:17 AM.


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