Welcome Guest

Pages: 1
Action flow
UKenGBPostJanuary 26, 2021, 05:58
Advanced
Posts: 57
Registered:
April 30, 2020, 09:36
Normal topicAction flow

I need to process the selected files/tracks to make desired changes to each. Normally I would simply 'Force Grouped Execution' to accomplish this. But…

In this case there are several steps that only need to be done once, prior to then running through each track. If everything runs 'Grouped', all the setup steps will be repeated (doing exactly the same thing) for every track which is horribly inefficient - especially if any setup steps are slow..

So I need to be able to execute a few steps once, then run the rest of the steps on each selected track.

Currently I have action 'D being Run by actions 'A', 'B' or 'C', each of which simply sets a variable to control which field(s) 'D' works on. Each is set 'Grouped', which works, but calling 'A', 'B' or 'C' for every track is inefficient.

So if I execute 'A', 'B' and 'C' 'Stepwise' and Run 'D' 'Grouped', will that achieve what I need. Will 'A', 'B' or 'C' run once, but then 'D' executes for each track? If not, how can I force that?

2MR2PostJanuary 26, 2021, 10:39
Avatar photo
Administrator
Posts: 2419
Registered:
August 23, 2012, 19:27
Normal topicAction flow

Every action starts stepwise. Calling a grouped action executes as you would expect and immediately returns to the previous execution state when it finishes running for all selected files.

Think of it this way. If you have three selected files:

Action 'A' processes every statement for all selected files in parallel.
'A' runs 'D' grouped.
'D' is run in its entirety for each of the three files. (Three complete executions of 'D'.
Control returns to 'A' where it again processes every statement for all three files in parallel.

Many times slices of code which you are running grouped can more effectively be handled by constraining which files are executed. As an example say you want to look for Title fields which start with 'The the'. You want to remove the extra 'the' and if and only if the condition was met you want to rename the files:

1: Test if the Title field starts with "The the " case insensitive (Set result and Variable 0)
2: Ignore files where Variable 0 is false
3: if true
4: Replace prefix of "The the" in the Title field with "The·"
5: Rename Files (My Template) *** The template does not exist
6: Restore Initial Set of Files
7: endif

Line 1 tests all selected files to see if the Title field starts with 'the the'. For every file Variable 0 is set to true (1) or false (0). This is a single test. If you have 10 files selected it is processed once as opposed to ten times if running grouped.

Line 2 constrains the set of selected files to those which have a value of true in Variable 0. Yate always requires that at least one file is available stepwise. For this reason if 'no files' satisfy the condition nothing is modified. For that reason it is critical that you always test if the statement worked.

Line 3 tests if the previous statement worked. If true, at least one file met the required condition.

Line 4 replaces the text only on those files which met the criteria.

Line 5 renames those files and only those files which met the criteria.

Line 6 restores the initial set of files so that subsequent statements outside the if-endif construct will again have all of the initially selected files available.

Regardless as to how many files were selected, the above code will only run once. If you take out statements 2 and 6 and run the sequence grouped it will work the same. However if you have 100 files selected it will execute 500 statements as opposed to 7.

There are times where ignoring files is simply too cumbersome as what you might want to execute is too complicated as it contains numerous flow control sequences. In cases such as these you can still limit the number of calls which take place. Assume that an empty Genre field requires that you perform a variety of functions which must be run grouped:

1: Test if the Genre field is empty (Set result and Variable 0)
2: Run inline action 'Fix empty Genres' grouped if Variable 0 is true
3:
4: Start Fix empty Genres
5: ' Do whatever you wish

Line 1 sets Variable 0 to true if Genre is empty, otherwise false
Line 2 executes inline action 'Fix empty Genres' grouped for each file which has an empty genre. The action called does not have to be inline. Inline actions are a good way to keep code snippets contained in the same file where they have no real value to be stored in a separate action 'file'.

The 'variable test' feature on Run statements and the statements in the File Availability category allow for a number of different scenarios to limit the number of statements that are executed.

Hopefully this helps.

UKenGBPostJanuary 26, 2021, 15:37
Advanced
Posts: 57
Registered:
April 30, 2020, 09:36
Normal topicAction flow

I'll have to study this tomorrow. I cannot get my head around what 'Stepwise' actually means.

"…processes every statement for all selected files in parallel."

Does that mean it runs each statement over all files and then moves on to the next statement and runs that on all files and so on for each statement?

It's a programming mode with which I am unfamiliar and totally contrary to how I would normally expect a script/program to execute.

What I actually want to achieve is slightly different from what I explained. In fact I want 'A', 'B' or 'C' to execute once and run 'D' which executes once and runs 'E' grouped and hence on every selected file.

This keeps together everything related and avoids duplication of code. So 'A', 'B' and 'C' set the name of the field to work on, then 'D' sets up some other variables required by 'A', 'B' and 'C' but only needs to be done once. Then 'E' does the work on each file/track.

Is it possible to execute some initial lines in an action once, but then execute the rest of the action's statements in Grouped mode, so on each track/file? I rather think not but wondered if it might in fact be possible and avoid have too many 'Run Action' statements and separate files.

What about ' Constrain Execution to a Single File statement'? Could I use that to ensure that the containing action only ran once?

2MR2PostJanuary 26, 2021, 16:22
Avatar photo
Administrator
Posts: 2419
Registered:
August 23, 2012, 19:27
Normal topicAction flow

Does that mean it runs each statement over all files and then moves on to the next statement and runs that on all files and so on for each statement?

Effectively yes. Think about a silly example where you want to clear the Title field. If you do a Clear Title stepwise it does the operation for each selected file. From a programmers point of view they happen in parallel as any one statement is indivisible. The interpreter is smart enough to avoid looping over each file when it is not necessary. For example when you set a named variable there is no need to loop over the files.

It's a programming mode with which I am unfamiliar and totally contrary to how I would normally expect a script/program to execute.

True but Yate needed the concept of multiple inputs at a time, otherwise everything would be grouped and extremely slow.

What I actually want to achieve is slightly different from what I explained. In fact I want 'A', 'B' or 'C' to execute once and run 'D' which executes once and runs 'E' grouped and hence on every selected file.

This keeps together everything related and avoids duplication of code. So 'A', 'B' and 'C' set the name of the field to work on, then 'D' sets up some other variables required by 'A', 'B' and 'C' but only needs to be done once. Then 'E' does the work on each file/track.

Simply create a new action so that you can reuse the code. In the new action do the following:

Run action A
Run action B
Run action C
Run action D and inside D ... Run action E grouped

Is it possible to execute some initial lines in an action once, but then execute the rest of the action's statements in Grouped mode, so on each track/file? I rather think not but wondered if it might in fact be possible and avoid have too many 'Run Action' statements and separate files.

Inline actions are no different than separate actions except that they live in the same 'file'. Any 'separate' or inline action can be run grouped. The only way to change the execution mode is via a call to another action (inline or otherwise). Once an action is run grouped everything it does or calls is also grouped. The best thing about inline actions is that you can embed code snippets which do not require separate files. The bulk of the actions on the web resources page use inline actions unless separate actions are required for reusability reasons.

What about ' Constrain Execution to a Single File statement'? Could I use that to ensure that the containing action only ran once?

Constrain Execution to a single file will not work for you as it ensures that only a single file is selected. It is typically used when you're designing an action which does not use loaded files and you essentially do not want to process whatever is loaded. There are lots of actions on the resources web page which use this. For example the Audio File Health Check 'repair' action which dynamically loads files.

UKenGBPostJanuary 27, 2021, 06:26
Advanced
Posts: 57
Registered:
April 30, 2020, 09:36
Normal topicAction flow

OK, getting there. 🙂

'A', 'B' and 'C' simply set a named variable to the name of the field/tag on which the rest will operate ('A' sets it to 'Composer', 'B' to 'Artist', 'C' to 'Album Artist'), so whichever one is run (from the menu) determines what field will be checked/modified etc and only one of them will be run to start the process and obviously needs to run just once. Running again will make no difference, but just wastes time. So only 2 statements required, 'Set' the named variable and 'Run' the common action(s)

'D' then contains some common code. It will again only set named variables and nothing to do with any tracks/files.

'E' contains the statements to execute for each track/file and therefore MUST be Run Grouped.

So I'm thinking that if I want to work on the 'Composer' field, 'A' is run 'Stepwise', sets the variable, Runs 'D' 'Stepwise' and then Runs 'E' 'Grouped'. Would that mean 'A' and 'D would only run once but 'E' would execute for each track/file?

What about if 'A' Runs 'D' (both 'Stepwise') and 'D' Runs 'E' 'Grouped'. Would that be the same as above?

2MR2PostJanuary 27, 2021, 08:55
Avatar photo
Administrator
Posts: 2419
Registered:
August 23, 2012, 19:27
Normal topicAction flow

So I'm thinking that if I want to work on the 'Composer' field, 'A' is run 'Stepwise', sets the variable, Runs 'D' 'Stepwise' and then Runs 'E' 'Grouped'. Would that mean 'A' and 'D would only run once but 'E' would execute for each track/file?

Yes. Each statement in A and in D will only execute once. E will execute in its entirety repeatably for each track. Note, there is no way to force an action to run stepwise. If A is running stepwise and D is run (without specifying grouped), D will run stepwise. The 'grouped' option is what modifies the normal flow.

What about if 'A' Runs 'D' (both 'Stepwise') and 'D' Runs 'E' 'Grouped'. Would that be the same as above?

Yes it seems to me that the two questions are identical. Stepwise always leads to stepwise unless grouped is specified. When a 'grouped' action finishes execution it restores the previous execution mode.

Think of grouped as 'an action runs in its entirety before proceeding to the next file'.

UKenGBPostFebruary 1, 2021, 06:08
Advanced
Posts: 57
Registered:
April 30, 2020, 09:36
Normal topicAction flow

Seems to all be working now although it was a bit complicated working out the nested loops.

Thanks for support, as always.

2MR2PostFebruary 1, 2021, 07:31
Avatar photo
Administrator
Posts: 2419
Registered:
August 23, 2012, 19:27
Normal topicAction flow

Glad it's working.

Pages: 1
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.061 seconds.