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

Reply
 
Thread Tools Display Modes
Old 09-15-2013, 01:46 PM   #1
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default ReaScript: Rename tracks to source file name - keep trailing digits

This one was missing (Reaper drops the last digits when importing tracks)

Rename tracks to (active)take source filename (without file extension) and keep trailing digits:



Code:
# Rename tracks to take source filename (without file extension)
# take = first item's active take

from reaper_python import *
from contextlib import contextmanager
import os

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

with undoable("Rename tracks to source file name"):

    def msg(m):
        RPR_ShowConsoleMsg(m)

    def renameToSourceFileName():
        trackCount = RPR_CountSelectedTracks(0)

        if trackCount < 1:
            msg("")
            msg("Select tracks first")
            return

        for i in range(trackCount):
            trackId = RPR_GetSelectedTrack(0, i)
            itemCount = RPR_CountTrackMediaItems(trackId)
            if itemCount == 0:
                continue

            itemId = RPR_GetTrackMediaItem(trackId, 0)   # get id from first item in track
            takeId = RPR_GetActiveTake(itemId)  # get id from active take in item
            takeSource = RPR_GetMediaItemTake_Source(takeId)
            fullPath = str(RPR_GetMediaSourceFileName(takeSource, "", 512)[1])

            if fullPath == "":  # ignore in-project MIDI
                continue

            fileName = os.path.split(fullPath)[-1][:-4]   # get filename and remove file extension

            RPR_GetSetMediaTrackInfo_String(trackId, "P_NAME", fileName, 1)

    renameToSourceFileName()
spk77 is offline   Reply With Quote
Old 03-06-2014, 12:38 AM   #2
matthewjumpsoffbuildings
Human being with feelings
 
Join Date: Mar 2013
Posts: 463
Default

thanks, this is useful
matthewjumpsoffbuildings is offline   Reply With Quote
Old 08-21-2014, 07:41 AM   #3
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

EEL version is here (this was requested):
  • unzip to your computer
  • download from the Action List

https://stash.reaper.fm/21561/Set%20t...tension%29.zip



Edit/Zip updated: If the first item on a track is "In-project MIDI item" -> the script uses "active take name" for renaming the track.

Last edited by spk77; 08-21-2014 at 11:34 AM.
spk77 is offline   Reply With Quote
Old 08-21-2014, 07:58 AM   #4
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,924
Default

Quote:
Originally Posted by spk77 View Post
EEL version is here (this was requested):
  • unzip to your computer
  • download from the Action List

https://stash.reaper.fm/21561/Set%20t...tension%29.zip

Nice one spk77, I'll add that to the cache


>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is online now   Reply With Quote
Old 08-21-2014, 09:16 AM   #5
luiso
Human being with feelings
 
luiso's Avatar
 
Join Date: Sep 2013
Location: La Habana, Cuba
Posts: 79
Default spk77, your PM inbox is full...

Sorry, the .py works just fine, but i was testing it on midi items!!!
then i opened it and saw a line that made think about the source files,
I thought it takes the name from the active take, but it is from the souce file
could you make another that renames the tracks from the Active Take Name, so it
could also rename Midi tracks, that would be the best tool ever!!!

This is my ideal workflow
1. import audio and midi to reaper
2. apply my track templates via sws resources window
3. run your script to get the names back!!!

cool ehh... fast mix setup... greetings...

PS: thanks for the EEL !!!
do you program this things on a rocket??? that was fast!!!
luiso is offline   Reply With Quote
Old 08-21-2014, 10:23 AM   #6
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by luiso View Post
Sorry, the .py works just fine, but i was testing it on midi items!!!
then i opened it and saw a line that made think about the source files,
I thought it takes the name from the active take, but it is from the souce file
could you make another that renames the tracks from the Active Take Name, so it
could also rename Midi tracks, that would be the best tool ever!!!

This is my ideal workflow
1. import audio and midi to reaper
2. apply my track templates via sws resources window
3. run your script to get the names back!!!

cool ehh... fast mix setup... greetings...

PS: thanks for the EEL !!!
do you program this things on a rocket??? that was fast!!!

Hi,
Yes, in-project MIDI doesn't have a source file (MIDI event info is "integrated" into RPP files). It should be quite easy to modify it so that it takes the names from active takes. I'll modify it and post it here
spk77 is offline   Reply With Quote
Old 08-21-2014, 10:52 AM   #7
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

This one gets the names from the "active take(s) in first item(s) on selected track(s)"

https://stash.reaper.fm/21565/Set%20t...%29%20name.zip
spk77 is offline   Reply With Quote
Old 08-21-2014, 10:57 AM   #8
Breeder
Human being with feelings
 
Breeder's Avatar
 
Join Date: Nov 2010
Posts: 2,436
Default

The script that renames track to source name is nice but I agree with luiso that in case there is no source (i.e. MIDI items), it should just use take name.
Breeder is offline   Reply With Quote
Old 08-21-2014, 11:29 AM   #9
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Breeder View Post
The script that renames track to source name is nice but I agree with luiso that in case there is no source (i.e. MIDI items), it should just use take name.
Ok, now the script in post#3 should do that
spk77 is offline   Reply With Quote
Old 08-21-2014, 12:38 PM   #10
luiso
Human being with feelings
 
luiso's Avatar
 
Join Date: Sep 2013
Location: La Habana, Cuba
Posts: 79
Default spk77...

as i said, the best tool ever!!!
sorry for my language but, this is so fucking gooooooddddd
you just saved me from countless typing hours yhat i will
use for bears and girls :P
even if i edit the items and glue them, move others from other tracks, etc... the first one steel gives the name to the track!!!
this should be included by default man...
I will continue testing it and report to you
but so far.... REAL good ..... thanks again man
luiso is offline   Reply With Quote
Old 08-21-2014, 12:46 PM   #11
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by luiso View Post
as i said, the best tool ever!!!
sorry for my language but, this is so fucking gooooooddddd
you just saved me from countless typing hours yhat i will
use for bears and girls :P
even if i edit the items and glue them, move others from other tracks, etc... the first one steel gives the name to the track!!!
this should be included by default man...
I will continue testing it and report to you
but so far.... REAL good ..... thanks again man
Glad it worked!
spk77 is offline   Reply With Quote
Old 08-21-2014, 02:30 PM   #12
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,924
Default

Quote:
Originally Posted by luiso View Post
as i said, the best tool ever!!!
...
you just saved me from countless typing hours yhat i will
use for bears and girls :P
...

I'll never get to be an alpha male, they keep moving the goal-posts..!



>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is online now   Reply With Quote
Old 08-21-2014, 06:57 PM   #13
luiso
Human being with feelings
 
luiso's Avatar
 
Join Date: Sep 2013
Location: La Habana, Cuba
Posts: 79
Default Hi planetnine

"I'll never get to be an alpha male, they keep moving the goal-posts..! "

sorry man but my English is not so good to get the joke,
must be cause I wrote BEER wrong... but girls was OK...

>

.
luiso is offline   Reply With Quote
Old 08-22-2014, 02:02 AM   #14
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,924
Default

I realised afterwards it must be BEERS

I thought maybe wrestling BEARS was the latest masculine pursuit, I couldn't compete with that!


>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is online now   Reply With Quote
Old 08-22-2014, 07:53 AM   #15
luiso
Human being with feelings
 
luiso's Avatar
 
Join Date: Sep 2013
Location: La Habana, Cuba
Posts: 79
Default

"I thought maybe wrestling BEARS was the latest masculine pursuit, I couldn't compete with that!"

NO, NO... good music, BEERS and girls...
but now that i think about it, after some beers some mulata girls can turn wild and you have to gentle wrestle with them

cheer from the caribbean!!!!
luiso is offline   Reply With Quote
Old 05-07-2021, 04:48 AM   #16
ertugrulgul
Human being with feelings
 
Join Date: Jul 2014
Location: Turkey
Posts: 233
Default

Quote:
Originally Posted by spk77 View Post
EEL version is here (this was requested):
  • unzip to your computer
  • download from the Action List

https://stash.reaper.fm/21561/Set%20...tension%29.zip



Edit/Zip updated: If the first item on a track is "In-project MIDI item" -> the script uses "active take name" for renaming the track.
I couldn't managed to delete the file extension, how can I do that?

Last edited by ertugrulgul; 05-07-2021 at 04:59 AM.
ertugrulgul is offline   Reply With Quote
Old 12-17-2023, 11:18 AM   #17
magrotten
Human being with feelings
 
Join Date: Jun 2020
Posts: 7
Default

does anyone know if this can work with Selected Item rather than 1st item?
magrotten 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 03:50 AM.


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