Old 10-09-2020, 11:39 AM   #1
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default "Track Tags" Lua Module

Hello reapers,

I finally decided to make a humble contribution to this amazing collection of scripts and reaper facilities of all you folks! It's the first time, so it's also kind of an experiment for me and I very much appreciate your feedback (with regard to all aspects of this post).

It is a module of lua functions which allows to add tags (single tags or key-value-pairs to a track's SWS notes and to read/write them. It requires another small module in which I collected some utility functions. The track tags aim to provide a way to "intelligently" mark tracks and attach information to them, which can be accessed and reacted to via code.

The idea is to include the module in other scripts and use its functions from there. I created some very basic scripts with which more complex custom actions can be built.

Currently, your Scripts folder needs to contain a subfolder called "LC" into which the lua files need to be copied.

Below is a MWE. The source file is fully documented (is there a recommended way to provide a list of available functions?).

Code:
lc = require "Scripts.LC.LCm_Utility"
tt = require "Scripts.LC.LCm_Track Tags"

local track = reaper.GetSelectedTrack(0,0)

-- add single valued tag to temporary tag list
tt.addSingle("IAmATag")
-- add key-value pair tag to temporary tag list
tt.addPair("answer", 42)
-- store these tags within the track's notes
tt.setTagString(track)
This code will add the following tag string to the track's notes:

Code:
{tags:IAmATag|answer:42}
Note that any existing tag string in the track's notes is overwritten, because it was not read before writing.

This very tag string could now be read, adapted and saved again:

Code:
lc = require "Scripts.LC.LCm_Utility"
tt = require "Scripts.LC.LCm_Track Tags"

local track = reaper.GetSelectedTrack(0,0)

-- load track tags
tt.getTagString(track)

-- check single tag
if tt.hasSingle("IAmATag") then
  lc.msg("This track says IAmATag!")
end
-- modify value of key, if it exists
if tt.hasKey("answer") then
  tt.setValue("answer", 666)
end
-- update tag string
tt.setTagString(track)

Exemplary utility scripts may be:
  • LC_Add tag (single) to selected tracks.lua
  • LC_Delete tags of selected tracks.lua
  • LC_Select all tracks with tag (single).lua

A custom action (which I use to display only tracks with a given tag) could be:
  • SWS: Show all tracks
  • LC_Select all tracks with tag (single).lua
  • SWS: Toggle (invert) track selection
  • SWS: Toggle selected track(s) visible in MCP
  • SWS: Toggle selected track(s) visible in TCP
  • Unselect all tracks

I'm looking forward to your feedback.

Cheers,
Lukas
Attached Files
File Type: lua LC_Add tag (single) to selected tracks.lua (478 Bytes, 74 views)
File Type: lua LC_Delete tags of selected tracks.lua (366 Bytes, 74 views)
File Type: lua LC_Select all tracks with tag (single).lua (524 Bytes, 74 views)
File Type: lua LCm_Track tags.lua (8.5 KB, 76 views)
File Type: lua LCm_Utility.lua (4.0 KB, 75 views)
LuCsa is offline   Reply With Quote
Old 10-20-2020, 12:03 PM   #2
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default

Hey folks!

I just wanted to humbly bump this thread and ask, whether it received no posts because I provided a solution for which there is no problem, or if there is something technical that makes it unattractive to use. In the first case, good! If the second applies I'd appreciate feedback on how to improve my contribution!

Thanks and cheers,
Lukas
LuCsa is offline   Reply With Quote
Old 10-21-2020, 03:33 AM   #3
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

Hey LuCsa, I haven't tried your scripts yet, but I can certainly see one use for them. For example, when I want to show/hide tracks, there are some scripts which can easily show/hide eg Bass tracks or Vocal tracks, however one of the problems with most or all of them is that you can't select one group of tracks (eg Bass) and then also add another selection to that (eg drums).

Your tag solution could work quite nicely with show/hide tracks if it could search for multiple tags (eg drums & bass), or failing that, the tags 'bass' and 'drum and bass' could be added to say the bass track, and the latter also to the drum track, this would enable you to show the drums and bass tracks.

In any event, it could work well with orchestration tracks (eg woodwind, cellos, violins, brass) - the tag 'Orchestra' could be assigned, and then you could show all the Orchestra tracks.

So I think there is a lot of potential in what you have done, and the use of tags is usually quite helpful in most scenarios.
dahya is offline   Reply With Quote
Old 10-21-2020, 09:09 AM   #4
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

LuCsa, I did as you state, created an LC folder and put the script files in there, but get the following error when trying to run the 'add tag' action:


...sa Scripts\LC\LC_Add tag (single) to selected tracks.lua:1: module 'Scripts.LC.LCm_Utility' not found:
no field package.preload['Scripts.LC.LCm_Utility']
no file 'C:\Program Files\REAPER (x64)\lua\Scripts\LC\LCm_Utility.lua'
no file 'C:\Program Files\REAPER (x64)\lua\Scripts\LC\LCm_Utility\init.lua'
no file 'C:\Program Files\REAPER (x64)\Scripts\LC\LCm_Utility.lua'
no file 'C:\Program Files\REAPER (x64)\Scripts\LC\LCm_Utility\init.lua'
no file 'C:\Program Files\REAPER (x64)\..\share\lua\5.3\Scripts\LC\LCm_Utility.lua'
no file 'C:\Program Files\REAPER (x64)\..\share\lua\5.3\Scripts\LC\LCm_Utility\init .lua'
no file '.\Scripts\LC\LCm_Utility.lua'
no file '.\Scripts\LC\LCm_Utility\init.lua'
no file 'C:\Program Files\REAPER (x64)\Scripts\LC\LCm_Utility.dll'
no file 'C:\Program Files\REAPER (x64)\..\lib\lua\5.3\Scripts\LC\LCm_Utility.dll'
no file 'C:\Program Files\REAPER (x64)\loadall.dll'
no file '.\Scripts\LC\LCm_Utility.dll'
no file 'C:\Program Files\REAPER (x64)\Scripts.dll'
no file 'C:\Program Files\REAPER (x64)\..\lib\lua\5.3\Scripts.dll'
no file 'C:\Program Files\REAPER (x64)\loadall.dll'
no file '.\Scripts.dll'



Please advise how to fix this error?
dahya is offline   Reply With Quote
Old 10-21-2020, 02:00 PM   #5
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default

Hi Dahya,

thanks for your feedback. :-)

About the error - I'm not too savy about Lua modules yet. Did you try to load only LCm_Utility.lua and LCm_Track Tags.lua first? Those are the essential ones. The others just use the track tags functions.

Maybe someone of the more knowledgeable Lua programmers can chime in and help? I've got my scripts in an "LC" subfolder of script and can import them as given in my example codes... :-/
LuCsa is offline   Reply With Quote
Old 10-21-2020, 02:19 PM   #6
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

Quote:
Originally Posted by LuCsa View Post
Hi Dahya,

thanks for your feedback. :-)

About the error - I'm not too savy about Lua modules yet. Did you try to load only LCm_Utility.lua and LCm_Track Tags.lua first? Those are the essential ones. The others just use the track tags functions.

Maybe someone of the more knowledgeable Lua programmers can chime in and help? I've got my scripts in an "LC" subfolder of script and can import them as given in my example codes... :-/
Earlier on I only ran the LC_Add tag (single) to selected tracks script first and got this error.

After seeing your message here, I ran the LCm_Utility script, then the LCm_Track Tags, and after running the latter I got a similar error.

I'm just a beginner with regards to Lua programming too. I think it's to do with the LC_Add tag (single) to selected tracks not being able to find the utility script, so it's probably something to do with the path, but I'm not familiar with LUA to fix it yet.
dahya is offline   Reply With Quote
Old 10-23-2020, 10:10 AM   #7
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default

Hmm, strange...

The dependency is Utility <-- Track Tags <-- all other files

Maybe this thread helps us? Although there is a difference between dofile and require. According to another thread, the way I put it into the scripts should work.

Are you sure you have put the scripts into your Reaper installation's Script folder and subfolder: ".../Scripts/LC"

Maybe someone else could check if s/he has the same problem?

Cheers

Last edited by LuCsa; 10-25-2020 at 03:53 AM.
LuCsa is offline   Reply With Quote
Old 10-23-2020, 10:21 AM   #8
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

Quote:
Originally Posted by LuCsa View Post
Hmm, strange...

The dependency is Utility <-- Track Tags <-- all other files

Maybe https://forums.cockos.com/showthread.php?t=224972 thread helps us? Although there is a difference between dofile and require. According to another thread, the way I put it into the scripts should work.

Are you sure you have put the scripts into your Reaper installation's Script folder and subfolder: ".../Scripts/LC"

Maybe someone else could check if s/he has the same problem?

Cheers
All here:

...\AppData\Roaming\REAPER\Scripts\LC\LC_Add tag (single) to selected tracks.lua
...\AppData\Roaming\REAPER\Scripts\LC\LC_Delete tags of selected tracks.lua
...\AppData\Roaming\REAPER\Scripts\LC\LC_Select all tracks with tag (single).lua
...\AppData\Roaming\REAPER\Scripts\LC\LCm_Track tags.lua
...\AppData\Roaming\REAPER\Scripts\LCm_Utility.lua

and still get the error.
dahya is offline   Reply With Quote
Old 10-23-2020, 11:18 AM   #9
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default

Hi!

Quote:
...\AppData\Roaming\REAPER\Scripts\LCm_Utility.lua
must also go into ".../Scripts/LC/"!

Cheers!
LuCsa is offline   Reply With Quote
Old 10-23-2020, 11:54 AM   #10
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

Quote:
Originally Posted by LuCsa View Post
Hi!

must also go into ".../Scripts/LC/"!

Cheers!
Sorry, that was a typo by me, all of those files are in the same folder, in ...\Reaper\Scripts\LC\
dahya is offline   Reply With Quote
Old 10-24-2020, 02:03 PM   #11
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default

Strange...that would have been too easy, though.
Maybe someone more knowledgeable will chime in here...
LuCsa is offline   Reply With Quote
Old 10-24-2020, 03:41 PM   #12
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

Hi LuCsa, I believe that I have fixed your scripts (attached) as follows:

I'm not a LUA programmer (I tend to copy/paste from other scripts !), but the clue was in the error as it couldn't find the utility script. So I found the answer from this post:

https://forums.cockos.com/showpost.p...2&postcount=10

I think thanks go to cfillion and kenm for this solution.

So there was a few changes I made in the scripts:

1. Added the code as stated above:

local path = ({reaper.get_action_context()})[2]:match('^.+[\\//]')
package.path = path .. "?.lua"

2. Stripped out any folder references to the files in the require statements, and just use the filename (as I guess the above script finds the current folder) so this:

lc = require "Scripts.LC.LCm_Utility"

now becomes this:

lc = require "LCm_Utility"

3. Added the following as a comment in the Script: LC_Select all tracks with tag (single).lua - you can un-comment if you want the script to only show tracks with those tags:

-- reaper.Main_OnCommand(reaper.NamedCommandLookup("_ SWSTL_SHOWEX"), 0) -- SWS: Show selected track(s), hide others

Also, I suggest that you have a look at the following thread where spk77 has already implemented a track tag script:

https://forum.cockos.com/showthread.php?t=203446
Attached Files
File Type: lua LC_Add tag (single) to selected tracks.lua (555 Bytes, 59 views)
File Type: lua LC_Delete tags of selected tracks.lua (443 Bytes, 59 views)
File Type: lua LC_Select all tracks with tag (single).lua (719 Bytes, 54 views)
File Type: lua LCm_Track tags.lua (8.6 KB, 69 views)
File Type: lua LCm_Utility.lua (4.0 KB, 62 views)
dahya is offline   Reply With Quote
Old 10-25-2020, 04:13 AM   #13
LuCsa
Human being with feelings
 
Join Date: Aug 2016
Posts: 87
Default

Hi Dahya!

First of all: I appreciate your efforts to get this working.

Quote:
Originally Posted by dahya View Post
Hi LuCsa, I believe that I have fixed your scripts (attached) as follows:

I'm not a LUA programmer (I tend to copy/paste from other scripts !), but the clue was in the error as it couldn't find the utility script. So I found the answer from this post:

https://forums.cockos.com/showpost.p...2&postcount=10

I think thanks go to cfillion and kenm for this solution.

So there was a few changes I made in the scripts:

1. Added the code as stated above:

local path = ({reaper.get_action_context()})[2]:match('^.+[\\//]')
package.path = path .. "?.lua"

2. Stripped out any folder references to the files in the require statements, and just use the filename (as I guess the above script finds the current folder) so this:

lc = require "Scripts.LC.LCm_Utility"

now becomes this:

lc = require "LCm_Utility"
Awesome! This is what I also found in the (broken) link I provided above, thanks for checking and trying that out!
Quote:
Also, I suggest that you have a look at the following thread where spk77 has already implemented a track tag script:
https://forum.cockos.com/showthread.php?t=203446
I am aware of that awesome tool! Didn't check it out in action yet, though. My own track tag thing is way below what spk77's solution does, of course. I used this to get into some script programming again and wanted a very simple solution with some basic "API" for some further usage inside other scripts.

Thanks again for digging into this - and let me know, if you find it useful for your own purposes.

Cheers,
Lukas
LuCsa is offline   Reply With Quote
Old 10-25-2020, 06:02 AM   #14
dahya
Human being with feelings
 
Join Date: Oct 2019
Posts: 232
Default

Quote:
Originally Posted by LuCsa View Post
Hi Dahya!

First of all: I appreciate your efforts to get this working.
That's ok, it's nice to be able to delve a little into Lua programming, which I'd like to do more of if/when I have time.

One thing I forgot to mention is that all the scripts should now be placed in the same folder.

With reference to the script by spk77, you may want to expand on how your script might be different, or list the different use case scenarios for your scripts (I appreciate you've already given some examples), else people would just go with spk77's script as it has a lot more functionality.
dahya 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 12:30 PM.


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