Old 07-31-2021, 04:36 PM   #1
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,232
Default stripping and saving parts of a take name?

i have this line that gets the name of a take in a script:
Code:
local Take_Name = reaper.GetTakeName( Take )
the way i use this, it returns an entire file name, such as "example_file.wav."

i'd like to use part of the file name and strip out the rest, then later use the stripped out part. more specifically, i want to come up with:

Code:
example_file
and
Code:
.wav
as separate variables so that i can create:

Code:
example_file_DENOISED.wav
i assume i need to assign three variables:

Code:
prefix=
append=
suffix=
in order to return:

Code:
example_file
_DENOISED
.wav
no idea how to extract "example_file" and ".wav" though.

thanks for guidance,
babag
babag is offline   Reply With Quote
Old 07-31-2021, 09:56 PM   #2
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

prefix=Take_Name:match('(.+)_[^_%.]+%.%w+')
append=Take_Name:match('.+(_[^_%.]+)%.%w+')
suffix=Take_Name:match('.+_[^_%.]+(%.%w+)')
dsyrock is offline   Reply With Quote
Old 07-31-2021, 10:57 PM   #3
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 2,232
Default

thanks, dsyrock. much appreciated.

i'm a complete moron when it comes to this stuff (no offense to morons intended as they're undoubtedly smarter than me about this stuff) but i couldn't get what you posted to work for me.

here's some code i cobbled together from things i found around the intertubes. you'll see how i tried to incorporate what you posted. if you comment out the current regex stuff and uncomment yours it didn't seem to work. the way i have it here, based on things i found floating around the web, did give me the expected result. i have no idea how i might get bitten on the butt by using this in real world situations so any fixes are welcome. here's what i have so far:
Code:
function Msg(variable)
    reaper.ShowConsoleMsg(tostring(variable).."\n")
end

function GetFilePrefix(url)
  return url:match "([^/]$-([^.]+))" -- To match before the .
  --return url:match('(.+)_[^_%.]+%.%w+') -- dsyrock
end

function GetFileExtension(url)
  return url:match "[^.]+$" -- To match after the .
  --return url:match('.+_[^_%.]+(%.%w+)') -- dsyrock
end

function PARSE_TAKE_NAME ()
    reaper.PreventUIRefresh(1)
    reaper.Undo_BeginBlock()

    local num_sel =  reaper.CountSelectedMediaItems( 0 )
    
    for i = 0, num_sel - 1 do
        local item        =  reaper.GetSelectedMediaItem(0, i )
        local take        =  reaper.GetActiveTake( item )
        retval, tk_name   =  reaper.GetSetMediaItemTakeInfo_String( take, "P_NAME", "", 0 )
        tk_name_pre       =  GetFilePrefix( tk_name )
        tk_name_append    =  "_PROCESSED"
        tk_name_ext       =  GetFileExtension( tk_name )
        
        new_tk_name       =  ( tk_name_pre .. tk_name_append .. "." .. tk_name_ext  )
        
        Msg( tk_name )
        Msg( tk_name_pre )
        Msg( tk_name_ext )
        Msg( new_tk_name )
   
    end

    reaper.PreventUIRefresh(-1)
    reaper.UpdateArrange()
    reaper.Undo_EndBlock("Parse take name", -1)
end

PARSE_TAKE_NAME ()
thanks again,
babag

Last edited by babag; 07-31-2021 at 11:06 PM.
babag 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 11:54 PM.


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