Use contents of an output variable as current input

It might be nice also having something like PointFormat, where multiple format transformations to the current selection are needed before a final Say to output:

OutputTo "TEMP_LANGUAGE"
json_select "language"
SayFormat "$left(%_current%,2)"

OutputTo "LANGUAGE"
RegexpReplace "^.*" "%TEMP_LANGUAGE%"
SayFormat "$caps(%TEMP_LANGUAGE%)

I'd also vouch for PointAt to load in output buffers or %output% to the pointer as RegexpReplace "^.*" can be funny with certain characters if not escaped or replaced before-hand due to regex limitations.

I have this on my internal wish list

Use "output" and UseFormat "%output1%|$upper(%output2%)" are I think what you're also suggesting above.

Looks good! What’s the | for in UseFormat?

It's just text that would separate the contents of %output1% and %output2%. It's free-form and just serves as an example.

Ah, just for illustrative purposes, would be a bit much trying to process multiple outputs at once to be fair :face_exhaling: Also makes sense just having one command that would do the work of both ideas at once. ← Edit: Ignore this please. Got confused.

I'm not sure if we are having the same ideas about the feature. Can you elaborate a little on your last post?

Oh sorry, you’ve got the idea absolutely spot on. Use just seems redundant if UseFormat already does the job of loading an output into current input and uses format strings. ← Edit: Ignore this please. Got confused.

I was also just guessing the function of | as if it were for processing both %outputs% but that seems a bit much :sweat_smile:

OK, thanks for the extra explanation. I just wanted to be sure I wasn't missing anything and needed that extra bit of detail to follow your assumption about processing both outputs. :sweat_smile:

Yes, Use "output" would produce the same result as UseFormat "%output%", but the former can be implemented in a more performant way.

What to you think about the naming of the functions Use and UseFormat compared to PointAt and PointFormat? I feel that Use* is a little bit more direct.


I'm splitting this to a separate topic so that this suggestion can be tracked independently from the discussion about SayFormat.

I had thought of Point purely because it’s a pointer-based system and that’s how I got my head around learning it, but that’s only ever really referenced as such in the documentation: Developing Tag Sources – Mp3tag Documentation

Use does feel more appropriate given the point of a pointer is simply that’s what you use to manipulate data in its current input.

Current might be more to the point overall. I’ll leave it to a majority vote on what :laughing:

Now that I really think about it, UseFormat might actually have better utility not as a method for loading content into the current input, only to transform what’s currently inside it similarly to SayFormat. That would give far better purpose for Use as the opposite function of Say.

Apologies, realise I went round in a circle there. :smiling_face_with_tear: Two separate commands for two separate uses as I originally pitched in my first post.

Currently I use in my scripts the command:
regexpreplace "^.*" "text with %outputs% inside"
to copy the contents of one or more output buffers, optionally surrounded by arbitrary characters or strings, to the input buffer.

If this could be replaced one to one by the command
use "text with %outputs% inside",
the scripts would surely run faster, be easier to understand and not any more need escaping of special chracters for regular expression like the \ . Although it brings no new feature in, in my opinion this is enough benefit to be worth the effort.

A command useformat "string" seems to me to be not necessary, because its function would be already available with sayformat "string" and the new use "%output%".

This. Means its not just outputs that can be used but ANY string.

That’s where I got myself confused along the way because @Florian had the two named ideas under the same concept but really they would have completely different usecases.

Use strictly for loading into current input, UseFormat for transforming what is already in current input.

UseFormat means you don’t have to send SayFormat back and forth from temp outputs and current input if you need multiple commands to process the current input. SayFormat would then be the last step equivalent to SayRest.

The proposal

has raised the following question:

What result do we expect from the following command?

UseFormat "sort(%_current%)"

Should it append the sorted string at the end of the input buffer or clear the input buffer after it is read?
The current implementation of SayFormat lets me suspect, UseFormat would also append the sorted string to the end of the unsorted and that doesn't seem useful to me.

Maybe I wasn't clear in my initial description of the two proposed functions, let's try again.


The initial motivation was to use the contents of an output variable as the current input. This would make the current workaround using RegexpReplace "^.*" "%output%" obsolete.

The new function would replace the current input buffer, and would not emit anything to the current output.

I'd still go with two separate functions, one that serves as a counterpart to Say, and another that serves as a counterpart to SayFormat.

  1. Function Use S
    Example: Use "some text and %output%"
    (this is equivalent to what the current workaround with RegexpReplace "^.*" does, except for the need to escape)

  2. Function UseFormat S
    Example: UseFormat "some text and $sort(%_current%,-)"
    (this is something that isn't possible at the moment, only via SayFormat to a temporary output and then applying the RegexpReplace "^.*" workaround)

UseFormat “$replace(%_current%,text,string)”

would work just like

Replace “text" "string"

with the actual benefit being UseFormat could use most format strings, not just $replace().

Fair point though as all Say commands do append rather than alter an existing value. That being said - and at the risk of complicating it again :anxious_face_with_sweat: - unless there’s a need for an n parameter for Use and UseFormat to add newer content to the end of an existing current input similar to a Say command, it's simpler the two commands just replace existing content.

This looks about right!

Many thanks for the clarification. Now I'm looking forward to testing the new commands and comparing the performance gain against the old hacks.

...oh no. I do see the problem. What about:

UseFormat “$replace(moretext%_current%,text,string)”

Does "moretext" get added to the start?

Does it only accept %outputs%?

Or likely it just takes whatever text's given including %_current% if present then replaces all of current input? That would bring us back to UseFormat being a fancier Use! :sob:

But I guess that's the only complication. UseFormat would be commonly used with %_current% to manipulate mainly the current input anyway so it still means Use has a far more direct purpose. Again, SayFormat hasn't exactly replaced Say... yet. :face_with_peeking_eye:

Here is an internal test version with Use and UseFormat as described here.

https://download.mp3tag.de/support/998C7FB6-CA71-44C7-B92D-DF73372C4A3E-3-31-11-2/mp3tagv331k2-x64-setup.exe

Command Line and Position
Set "TEST" "hello world"
Use "test1" test1
Use "%TEST%" hello world
Use "123%TEST%456" 123hello world456
Use "%_current%" %_current%
Use "abc%_current%def" abc%_current%def
UseFormat "test2" test2
UseFormat "%TEST%" hello world
UseFormat "123%TEST%456" 123hello world456
UseFormat "%_current%" 123hello world456
UseFormat "abc%_current%def" abc123hello world456def
UseFormat "$upper(%_current%)" ABC123HELLO WORLD456DEF
UseFormat "$upper(moretext%_current%)" MORETEXTABC123HELLO WORLD456DEF

Works perfectly and as expected. Thank you very much!

Looking good! Thank you for trying the new commands and for sharing your findings.

My performance test shows that the new Use commmand is round about 20% faster than the corresponding Regexpreplace and everything I've tested works fine here.
Thank you for providing the new tools.