Old 08-30-2018, 08:33 AM   #1
Travesty
Human being with feelings
 
Travesty's Avatar
 
Join Date: Nov 2014
Posts: 798
Default Script version of "Loop section of item source"

Hi, I need to alter the section checkbox in item properties, but I can't see a way to do it in the API using setmediaiteminfo_value or setmediaitemtakeinfo_value.

Does anyone know how this is set? I don't want to use the action, because it is a toggle, and I can't know the initial state.

Cheers
Travesty is offline   Reply With Quote
Old 08-30-2018, 09:05 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

It's tricky to change from scripts because the feature is internally implemented in Reaper by switching the take's PCM_source object between a normal audio file playback object and an object that can do the crossfaded looping (and reverse playback). I think you might need to attempt to manipulate the text based item/take state...(But I am not sure if that can be successfully used to switch the used PCM_source object type.)

Normal audio file playback objects look like this in the text chunk :
Code:
<SOURCE WAVE
        FILE "C:\MusicAudio\Lokakuu2018\ruler\harp_shred01.wav"
>
Section loop objects look like :

Code:
<SOURCE SECTION
        LENGTH 0.4657623069051
        STARTPOS 0.42799779553441
        OVERLAP 0.01
        <SOURCE WAVE
          FILE "C:\MusicAudio\Lokakuu2018\ruler\harp_shred01.wav"
        >
>
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 08-30-2018, 09:28 AM   #3
Travesty
Human being with feelings
 
Travesty's Avatar
 
Join Date: Nov 2014
Posts: 798
Default

Ah ok, is that something that can be accessed in lua? Is it done using reaper.SetItemStateChunk()?
Travesty is offline   Reply With Quote
Old 08-30-2018, 09:59 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by Travesty View Post
Ah ok, is that something that can be accessed in lua? Is it done using reaper.SetItemStateChunk()?
And GetItemStateChunk, because you need to of course keep the other old state too...I don't have the exact code to do the manipulation because I don't like using the text chunks and haven't worked much with them.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 08-31-2018, 10:50 AM   #5
Travesty
Human being with feelings
 
Travesty's Avatar
 
Join Date: Nov 2014
Posts: 798
Default

ok, thanks I'll try that
Travesty is offline   Reply With Quote
Old 08-31-2018, 12:03 PM   #6
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

There's also:
Code:
boolean retval, number offs, number len, boolean rev = reaper.PCM_Source_GetSectionInfo(PCM_source src)

If a section/reverse block, retrieves offset/len/reverse. return true if success
spk77 is offline   Reply With Quote
Old 06-11-2019, 08:56 AM   #7
Travesty
Human being with feelings
 
Travesty's Avatar
 
Join Date: Nov 2014
Posts: 798
Default

Just ended up here nearly a year later trying to solve the same issue again.

Thanks SPK77, that did the trick.

Code:
function ClearExistingSection()

  -- get item
    
    local item = reaper.GetSelectedMediaItem(0, 0)
    
  -- get item length
  
    if item ~= nil then
      local itemlen = reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )
      
  -- get take
  
      local take =  reaper.GetActiveTake(item)
      
  -- get source file
  
      if take ~= nil then
        src =  reaper.GetMediaItemTake_Source( take )

  -- get section info
      
    local retval, offs, len, rev = reaper.PCM_Source_GetSectionInfo( src )
      end
    end
    
    
    if retval == true then -- If section exists turn section off
      reaper.Main_OnCommand(40547,1,0)
  
    end
    
    

end


I needed to make sure that any previously existing sections were removed before adding a new one.

One thing to note, is that using reaper.Main_OnCommand(40547,1,0) twice in a row to disable the old and enable the new section didn't work. The effect would be that the section was removed, but a new one not added, presumably because the execution was too fast.

Moving the second reaper.Main_OnCommand(40547,1,0) to outside the function solved the issue.

Seems like a slight bug with the command.
Travesty 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 02:27 AM.


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