Old 04-07-2017, 03:56 PM   #1
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default Track/item name manipulation (lua script)

Hello!

A new little script, inspired by spk77's python script: Manipulate track names

For the creation of the buttons and the mouse handling I have used spk77's code and I have used a Lokasenna function too. So, big thanks to both of them!

The script is here:
Track name manipulation

I would like some help from more experienced users: at the moment the script does not create any undo points. I would like undo points to be created under these two circumstances:
a) when the user exits the program
b) if the user changes track selection

How could this be accomplished?

EDIT: See post #4 for the final version


You may now find amagalma_Track Name Manipulation and amagalma_Item Name Manipulation in ReaPack.


Both scripts got replaced by the script amagalma_Track-Item Name Manipulation


Last edited by amagalma; 07-15-2017 at 07:53 AM.
amagalma is offline   Reply With Quote
Old 04-07-2017, 05:45 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,550
Default

I haven't tried it, but you could do:

1) reaper.Undo_BeginBlock() when the script starts.

2) A function to see if the track selection has changed*, and then the following in Main():
Code:
if did_tracks_change then
  reaper.Undo_EndBlock("Track name manipulator", 0)
  reaper.Undo_BeginBlock()
end
3) reaper.Undo_EndBlock() as an else section for when gfx.getchar comes back as -1.

----------

* I had to do this in my "track selection follows item selection" script. Here's (I think) all you need:
Code:
local num_tracks
local sel_tracks = {}

-- *Very* limited for error checking, types, etc
-- Only use it if you know your tables will work
local function compare_tables(t1, t2)
  if #t1 ~= #t2 then return false end
  for k, v in pairs(t1) do
    if v ~= t2[k] then return false end
  end
  return true
end


-- In Main()

	-- Get the number of selected tracks
	num_tracks = reaper.CountSelectedTracks( 0 )

	-- Grab their MediaTracks into a table
	local cur_tracks = {}
	for i = 1, num_tracks do
		cur_tracks[i] = reaper.GetSelectedTrack( 0, i - 1)
	end

	-- See if the current and stored track selections match
	if not compare_tables(sel_tracks, cur_tracks) then

		-- User changed the track selection
		sel_tracks = cur_tracks

		reaper.Undo_EndBlock("Track name manipulator", 0)
		reaper.Undo_BeginBlock()
		
	end
Checking all of the tracks on every loop might be pretty rough for the script's CPU usage, so you may want to use a timing function to only run that block every 500ms or something.
Lokasenna is offline   Reply With Quote
Old 04-08-2017, 02:51 AM   #3
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

Thank you Lokasenna for your help!

3) reaper.Undo_OnStateChangeEx("Track name manipulation", 1, -1) without a reaper.Undo_BeginBlock() seems to do the trick better. Making-an-Undo-point-when-exiting "problem" solved!

I am going to try what you suggest for the track selection change undo creation point "problem".

Edit: Hmm.. I can't get it to work properly.. I get "reascript: Run" in the Undo list instead of named Undos...
Edit2: I am getting there.. I had to avoid UndoBegin... I'll update in a bit the code..

Last edited by amagalma; 04-08-2017 at 06:59 AM.
amagalma is offline   Reply With Quote
Old 04-08-2017, 05:58 AM   #4
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

Manipulate track names (prefix, suffix, trim start, trim end, uppercase, lowercase, swap case, capitalize, titlecase, replace, strip leading & trailing whitespaces).

Undo points are created only if track names have been changed when you close the script or if track names have been changed when you change track selection.

Track Names Manipulation

available in ReaPack
amagalma is offline   Reply With Quote
Old 04-13-2017, 12:53 AM   #5
Gianfini
Human being with feelings
 
Join Date: Jan 2015
Posts: 647
Default

Great Job! That was strongly needed.

To make it really good there are few missing points I suggest

Basic version
- UNDO is key here, a small error and you get lots of tracks modified, and cannot get back to clean version
- There should be an option to add progressive numbering (in the beginning or at the end after suffix). It should have the number of digit option, start number, whether using numbers or letters

Advanced version (name building mode)
- possibility to build the naming from scratch, adding prefix, suffix, fixed text, progressive numbering and possibility to use old name as wildcard, building a mockup and committing all changes at once at the end. Preview of first 3-5 tracks should be available to see what you get.
For example Prefix=Snare, Suffix =" - mic ", Progressive numbering two digits, $track at the end: could result in "Snare - mic 01 AKG" "Snare - mic 02 SM57" "Snare - mic 03 SM58" (where AKG, SM57, SM58 were the original track names).
- possibility to add other wildcard in the building mode such as $item_name (first item), $channel_number, etc.

g
Gianfini is offline   Reply With Quote
Old 04-13-2017, 05:07 AM   #6
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

Thanks!

Undo is already implemented. If you make a mistake just close the script and undo the last action!

I'll add at some point the progressive numbering. done!

For the rest, although they are very cool ideas, I do not have the time/knowledge to implement...

Edit: I added the progressive numbering ability. The update should be available later in ReaPack

Last edited by amagalma; 04-13-2017 at 07:34 AM.
amagalma is offline   Reply With Quote
Old 04-13-2017, 12:15 PM   #7
Gianfini
Human being with feelings
 
Join Date: Jan 2015
Posts: 647
Default

Quote:
Originally Posted by amagalma View Post
Thanks!

Undo is already implemented. If you make a mistake just close the script and undo the last action!

I'll add at some point the progressive numbering. done!

For the rest, although they are very cool ideas, I do not have the time/knowledge to implement...

Edit: I added the progressive numbering ability. The update should be available later in ReaPack
thanks!
Gianfini is offline   Reply With Quote
Old 07-11-2017, 05:46 PM   #8
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

In ReaPack you may now find amagalma_Item Name Manipulation, the sister script that deals with item names.
amagalma is offline   Reply With Quote
Old 07-15-2017, 07:54 AM   #9
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

Both scripts got replaced by the script amagalma_Track-Item Name Manipulation

amagalma is offline   Reply With Quote
Old 07-18-2017, 07:07 AM   #10
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,217
Default

handy thanks much!
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is offline   Reply With Quote
Old 07-28-2017, 02:36 PM   #11
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

You're welcome
amagalma is offline   Reply With Quote
Old 07-28-2017, 02:37 PM   #12
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

Update: v1.1 (2017-07-28)

- Fixed crash when dealing with empty items
- Changed color scheme
- Added Clear button (clears all names)
- Added Keep button (trims names and keeps only the number of characters defined)
amagalma is offline   Reply With Quote
Old 10-06-2017, 08:48 AM   #13
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,383
Default

Just a "first usage" report.

Got a project for mixing where all tracks are named "Songtitle - ..." which I find redundant seeing on the tracknames (when importing and Reaper autonames the tracks according to the filenames) and the items.

Fired up your script, "Replace" "Songtitle -" with nothing, bam, gone.

Until now I used Batch rename utility for such tasks but being able to do it directly in Reaper is nice.

Very useful script, thank you.
nofish is offline   Reply With Quote
Old 10-06-2017, 09:49 AM   #14
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,595
Default

You are welcome!

Check v2 co-authored by Gianfini and me, it has some extra functionality and looks a lot better!
amagalma 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 10:41 PM.


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