If you name the tracks as "AAA-1", "AAA-3", and "AAA-2", and export multiple WAV files based on tracks, then the file names will be (respectively): AAA-1.wav, AAA-3.wav, and AAA-2.wav, but because the metadata "track number" tag just increments from "1", the metadata track numbers will still be 1, 2 and 3 respectively, because that was the order of the tracks in the project.
Yes, I this is a good strategy to avoid naming collisions - i.e. putting a unique number into the file name.
This still doesn't really address the issue though. Audacity must be checking for unique label/track names BEFORE it starts writing the file because, according to your example, it only appends a number if it detects a collision. But, if we tell it specifically to ALWAYS put a number into the file name by checking the 'Numbering before label name/track name" option, Audacity doesn't need to do any checking what-so-ever because the resulting filename is guaranteed to be unique (unless... see below).
The question then becomes, where do we get that sequence number from? Clearly, Audacity is getting it from a loop counter; my argument is that it should come from the output track index as stored in the metadata.
Here is my reasoning:
First the scenario that I am trying to 'clean up'. We record an LP, side one is saved as Project A; side two is Project B. The LP tracks are labeled. For the sake of the discussion lets suppose that the first LP track on BOTH sides is labeled 'AAA' and there are 5 track/labels on each side.
1) We export multiple Project A into FolderZ with numbering ON.
=> So FolderZ now contains 5 files, the first one has the name 1_AAA.wav.
2) Now we export multiple Project B into the same FolderZ with numbering ON.
=> and we have a name collision error when the Side 2 label 1_AAA.wav file is attempted.
Notice that the user has NO WAY to avoid this collision name because the sequence number is generated from an internal loop counter of some sort.
On the other hand, and the point I'm trying to make is, the user DOES have control over the metadata track index, because Audacity gives the user the chance to modify the metadata before it writes it to the file, and it does this for all track/label metadata sets before it begins to write any of the files.
If the metadata track index was used instead of an internal sequence number the scenario would shake out like this:
3) We export multiple Project A into FolderZ with numbering ON.
=> Just as before FolderZ now contains 5 files, the first one has the name 1_AAA.wav.
=> This is identical to item (1) above
4) Now we export multiple Project B into the same FolderZ with numbering ON
=> If the user did nothing, we would get the same name collision as before, because the metadata track number starts at 1 each time.
=> This is identical to item (2) above since the user did nothing to chance the default metadata track index.
However, we CAN change that metadata track number before Audacity begins to write the files. So instead:
5) Now we export multiple Project B into the same FolderZ with numbering ON.
=> Audacity presents us with the Metadata edit form, once for each track/label it is going to export
=> As each edit form is presented, we change the track number to '6', '7', '8', '9', '10, each in turn
=> Audacity uses the track number for the file name and Side 2 label 6_AAA.wav is written and there is no name collision.
This is the specific reason that I refer to the current situation as 'incorrect output' even though I fully realize it is the designed result. The design, as coded, is GUARANTEED to produce a name collision in the scenario as presented, even though the design is specifically supposed to avoid that problem - as described by you in your reply.
Furthermore, as an end user, I expect to have control over the output file name as much as practical - and this suggestion does just that.
Finally, the implementation should be quite simple, I think, (though of course I am not looking at your code), I am not suggesting that you 'turn off' the collision detector code at all. Rather I suggest that before you check for file name collisions, however you do it, you add another step if the user has asked for file numbering, simply prepend the metadata track index to the file name instead of the loop counter.