Name Pattern Based on Template

Forums

I needed this functionality and I've managed to implement it... at least almost completely.
The code isn't elegant, but it gets the job done.

WHAT DOES IT DO?

1- Date Pattern: Predefines the new session title based on a pattern that accepts date and time values.

2- Automatic Session Properties: This is an optional feature. Since the template can now predefine the title, and previously predefining the working directory, it's possible to directly assign session properties without the window appearing. In other words, it works as if it were a pre-existing session.

HOW DOES IT WORK?
Templates now have a new `name-pattern` property.

Accepts the following commands/patterns:

%ON: Indicates that the pattern is active
%OK: Automatic session properties

%y: Year 00
%m: Month 00
%d: Day 00
%H: Hour 00
%M: Minute 00

For example: %ON %OK %y-%m-%d_%H:%M Improvisations > 26-04-04_16:43 Improvisations

To save a pattern in the template, you can enter it as the session name before saving it as a .qtt file.

However, it's more convenient to edit the template with a text editor:
<session version="Qtractor 1.5.12" name-pattern="%ON %OK %y-%m-%d_%H:%M Improvisations">

__ USE CASES

1_ Creativity first, then definition

Work without interruptions. There's no need to configure or think about names that don't yet make sense for sessions that might not be worth saving.

1 You configure Qtractor as .qtz.

2 In the template:

Pattern: "%ON %OK noNameYet" // Active + Automatic Properties
Directory: "path/toMy/projects/.tmp"

You open it, enjoy it, save it, or not. All the junk stays in the .tmp file, which you clean up from time to time... or not.

2_ Study

If you're studying a piece or a technique, each session will automatically have a time pattern so you can track its progress.
They are all saved in the same working directory.
In this case, .qtr is a more suitable format.

Pattern: "%ON %y-%m-%d Lesson 00" // Active
Directory: "path/toMy/projects/PianoStudio"

We'll only have to change the lesson numbering.

3_ Improvisations

Date pattern, but this time it works better with qtz .tmp and %OK...

etc...

__ DOESN'T WORK: In %OK mode, it doesn't recognize the automatic directory option in Qtractor; I haven't been able to get it working. In normal mode (having to accept properties), it does work.

__ SHARING

In case it's useful to someone else. Implementing this properly would involve adding a "Template Configuration" button to Qtractor Options. It would open a window where the user could configure %ON and %OK with checkboxes without entering code, a text line to edit the pattern and directory, a pattern preview, a code list... In short, a crazy work.

Regards

File attachments
Permalink

My intention was simply to share the utility and make it accessible somewhere. Perhaps someone else will find it useful, or perhaps not. I don't know if it's a utility of general interest or not.

I know that if you see value in something like this, you would implement it properly.

I lost access to GitHub a long time ago, so I can't share it there.

Regarding the code, I just realized that it's not necessary to process the pattern twice (it can be done in session and then saved for sessionForm) and that I can include option.h in session.cpp to access the automatic directory options.

If I improve it and you don't mind, I'll share it here again.

Permalink

1. The code has been optimized.

2. AutoSessionDir should no depend on Qtractor's configuration if it's: %OK (auto accept session properties).
It now has its own option: %OK/DIR.

_ Options & Patterns:

%ON: Active naming patterns.
%OK: Automatically accepts session properties based on the pattern.
%OK/DIR: Automatically accepts session properties based on the pattern and also creates a session directory based on the pattern.

%y: Year 00
%m: Month 00
%d: Day 00
%H: Hour 00
%M: Minute 00

_ Other notes: This is an advanced feature, therefore it doesn't require a UI, only documentation.

File attachments
Permalink

I'd use a 4 digit year because it improves readability of the filenames and add %S as a 2 digit second.

Four-digit year:
%Y (2026), I considered this unnecessary because the pattern is already there.

It would be: 20%y. Of course, what if we're still alive in the year 3500? Why not?

It would be: 35%y.

Seconds:
%S, I considered this unnecessary because it's highly unlikely that less than a minute will pass between sessions.
(Remember that templates are applied when opening, not when saving. This functionality is not for scheduling backups, but it is for what a template should be used for: preconfiguring the session. It has always been possible to preconfigure the "recording" session directory from the template; with this functionality, you can also preconfigure the session name.)

Milliseconds:
%3N, which could be interesting because it can be used as a pseudo/pseudo random number generator.
I also ruled that out, because if you want to avoid repeating a name, a pattern (%m%d%H%M) is safer. It also provides temporal information and alphabetical order.

Anyway, if you need it, it's very easy to add these options to the patch. In qtractorSession.cpp, after line 2195, add:

PatternToName.replace("'%''S'", "ss"); // 00
PatternToName.replace("'%''3''N'", "zzz"); // 000

Because

#include <QDateTime>

was already present in qtractorSession.cpp and does the same thing.

I don't know the advantages or disadvantages of using one or the other.

Permalink

It seems to be the other way around; QDate only accepts dates, while QDateTime accepts both dates and times.

We can't directly use the QDateTime data format because it would then also process the letters between words that match the data formats.

For example, "Session default" would be interpreted as "Se35ion 7efpmulCEST".

That's why I proposed the standard bash format, so the user can explicitly mark with % which patterns (data formats) should be processed.

This means that each data format needs to be validated and converted, and for that, the code need to predefine which ones are accepted and include them.

It could accept them all; there aren't too many... but I decided on the ones that would actually be useful.

Regards

PS: I really think this functionality would be interesting and useful in general... but for that, a UI would be necessary. Not only because of "name-patter", but also because the template function would be strengthened.

1. This would clearly show that the directory in a template functions as the default directory for projects (it took me a while to figure this out).

2. Template properties could be easily edited without having to open a new session, save as, search to overwrite, etc.

3. And it would also have a naming pattern.

I don't think I'm capable of making the UI, and it doesn't make much sense for me to do it alone either.

But sharing ideas is fun :)

File attachments

We can't directly use the QDateTime data format because it would then also process the letters between words that match the data formats.

For example, "Session default" would be interpreted as "Se35ion 7efpmulCEST".

yes, I understand, but then as you're just dealing with date-time substitution it would be interesting to have the QDateTime::toString() segregated from a delimited string, say %DT{...} ?

fort instance, "Session default %DT{yyyy-MM-dd hh:mm:ss}" would lead to "Session default 2026-04-08 12:34:56" ?

seeya

Permalink

Reasons:

_ 1. So how do you handle the options: %ON, %OK, %OK/DIR?

_ 2. Ease of understanding and use for the user:

Handling curly braces is more complex and less understandable.

+ If you provide a phrase like: Available pattern %y %m %d %H %M.

The user will quickly understand it.

There is no possibility of user error. If they type the pattern, it will work; if not, it won't.

+ However: %DT{yyyy MM dd hh mm ss}.

This needs to be explained, or the user would end up doing things like:
%DT{yyyy MM dd hh mm ss My project},
%MyProject{yyyy MM dd hh mm ss},
%DT{yyyy}My project {MM dd hh mm ss},

_ 3. Interleaving pattern and text becomes more complicated.

_ 4. Creating a GUI would also be easier to program.

Implementing a small editor would be relatively simple with unary markers,
however, with curly braces...


(Clicking the button and/or clicking the options menu inserts the pattern into text)

_ 5. In the future, might want to include other patterns that isn't processed by QDateTime, but rather by its own processing.

Examples: Random alphanumeric, auto-incrementing number...

This isn't really a major drawback... it's just that the current mode already accounts for it.

- 1: Everything that isn't "Date" is processed.

- 2: It's deleted, leaving the result.

- 3: They are processed by QDateTime.

I've done a proof %rand, which generates a single-digit random number. If you want more digits, you just have to add more codes: %rand%rand%rand.

With the curly braces option at the end, you'd have to do something similar to do something similar to what already exists....

I think it's all drawbacks :).

Greetings

File attachments

Add new comment

The content of this field is kept private and will not be shown publicly.

Markdown

  • Parses markdown and converts it to HTML.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id> <img src alt height width> <strike> <pre> <p> <br>
  • Lines and paragraphs break automatically.

Filtered HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <b> <i> <pre> <img src alt height width> <strike>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
File attachments
Unlimited number of files can be uploaded to this field.
2 MB limit.
Allowed types: jpg jpeg gif png txt doc docx xls xlsx pdf ppt pps odt ods odp zip gz bz2 xz patch diff wav ogg flac ogv mp4 qtz.