Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - karbock

Pages: 1 ... 12 13 1415 16 ... 23
196
Tips and Tricks / Re: BBCeditor (forum post edit tool)
« on: February 19, 2023, 05:38:34 PM »
Forum-friendly colour sets

As mentioned above by hiccup, the forum post editor features a preselection of 9 colours. Two alternative sets are also shown here. The first one features colours having predefined names in BBcode. All the sets are suitable with both the light and the dark theme.

Forum's setAlternative set 1Alternative set 2
Colour typeHex. codeN/AColour typeHex. codeBBcode colour nameColour typeHex. codeN/A
██ bluecolor=#0093F8██ bluecolor=#6495EDcolor=CornFlowerBlue██ bluecolor=#208CF3
██ browncolor=#9E6F00██ browncolor=#D2691Ecolor=Chocolate██ browncolor=#8F7200
██ cyancolor=#40C2B9██ cyancolor=#20B2AAcolor=LightSeaGreen██ cyancolor=#40C2B9
██ graycolor=#8F8F8F██ graycolor=#778899color=LightSlateGray██ graycolor=#8A8A8A
██ greencolor=#00A300██ greencolor=#32CD32color=LimeGreen██ greencolor=#14A31B
██ khakicolor=#BFAD00██ khakicolor=#DAA520color=GoldenRod██ khakicolor=#BFAD00
██ orangecolor=#EE8200██ orangecolor=#FF8C00color=DarkOrange██ orangecolor=#DB720F
██ redcolor=#FC0003██ redcolor=#FF6347color=Tomato██ redcolor=#DE201D
██ violetcolor=#CD78D6██ violetcolor=#DA70D6color=Orchid██ violetcolor=#A852F2

Usage:
  • Alternative colour set 1:
    Colourise your text by specifying either the matching hexadecimal code or the BBcode colour name.
  • Forum's colour set and Alternative set 2:
    Colourise your text by specifying the hexadecimal code only.
A full list of the 141 predefined colours + transparent is available here  (with explanations).

197
Improved:
* No more condition on AlbumArtist
* $Count used to identify multiple-composer albums instead

Split up:
* the solution with 7 virtual tags (but easy to maintain)
* the solution with 3 virtual tags (but difficult to maintain), with aggregated formulas


Updated:
* list of composer names in v.Composer.Short

198
From my library:
Pau Casals / Enric Casals
Franz Schubert / Heinz  Schubert
Thanks for your contribution! I'll add them to the next update (coming soon...)

199
Improved:
  • Work name:
    The work is shown IF it is present AND the track count for the combination <Album>+<Work> differs from the track count for <Album>.
  • Composer name:
    The given names are generally removed. Exceptions:
    • Couperin, Marcello, Pachelbel, Scarlatti: given names kept
    • Bach: given names removed only for Johann Sebastian
    • Haydn: given name removed only for Joseph
    • Mendelssohn: given name removed only for Felix
    • Mozart: given names removed only for Wolfgang Amadeus

200
Added:
* \p{P}
* \p{S}
* \uFFFF
* some resources
* TOC

Modified:
* titles and structure

201
Improved:
* The variable parts of the symbols stand out

202
Changes:
    • Removed v.Str.Default, v.Chk.Grouping
    • Simplified v.SubGrouping.Header
    • Reduced the number of virtual tags
    • Added Pachelbel to v.Composer.Short

203
I don't understand what you are saying here.
(I'll take a drink, maybe that helps)
You could use a cuppa. :D I've just had one (Yes, weekend!)
To rephrase my previous post: I'm going to prepare an addition about Unicode in RegExes. Stay tuned.

204
Added:
* $_ with example
* $& with example

205
@boroda:

a{3,}: well spotted, I was just thinking: 'have I already mentioned it?'
a{,3}: not tested in MB so far, and not sure it's available in many regex parsers outside MB (doesn't exist in Perl), thus I'll propose a{0,3}, which is standard.
Just an example: https://stackoverflow.com/questions/22079519/why-isnt-the-x-at-most-n-times-regex-quantifier-included-in-java-in-the-x

@hiccup:

* https://regex101.com/: added, thanks!
* Unicode support: already considered when preparing the original post, I'll select the crème de la crème + external reference for those who wish extended documentation.
* $_: I had tested it, but didn't consider it (rightly or wrongly) as crucial in the first version. Added, example to come.
* An anecdote about Patrick McGoohan (who played the prisoner in the series): he was chosen only years later to play the warden in 'Escape from Alcatraz' (1979), based on true events.

206
Tips and Tricks / Re: Regular Expressions: coding, examples, exercises
« on: February 10, 2023, 08:55:31 PM »
Added:
* Backreferences

@hiccup:
Still looking for an answer to nr. 6...
"I'm not a number, I'm a free man!"

207
Tips and Tricks / Re: Regular Expressions: coding, examples, exercises
« on: February 10, 2023, 06:26:15 PM »
This is impressive and beautifully done. A great addition to Tips & Tricks!
I learned some new things, and am surely going to make good use of a favorites shortcut for it.
(...)
7. Awesome work. I have thought about doing something like this also, but I wasn't up to the task and gave up on it, but I think you nailed it.
(...)
And I have some comments ;-) :
A jong  ;) , thanks for your kind words and your keen eye!

1. it should say 'not followed by...'
1b. And maybe add the terms: lookahead and lookbehind to that part?
(maybe give them their own 'Lookarounds' header, instead of having them under 'Groups'?)
Okee!

2. + 3.
There is (as often) more than one way to say it. I don't mind changing if you think it sounds clearer.

4. ma{2,3}n matches: maan, maaan
has a leftover 'n' behind {2,3} that shouldn't be there
The suffixed n is not too much, since it's present in maan and maaan. Here, "a{2,3}" is both prefixed and suffixed.
ma{2,3}n matches: maan, maaan
I can add some formatting, as in the line above, but you have already experienced how unreadable a BBcode text can get for its author...

5. I believe those should be round brackets, not curly ones.
Sure thing. And I feel relieved that the RegEx Welfare Society didn't suit me... :)

6. Not all of the above need to/should be escaped in that case, right?
A first draft, since the answer is not obvious, as you mentioned:
between "[...]", I don't escape special characters except: [  ]  -
But as for capturing groups in general, I'll check in my Perl bible and perform some tests.

Besides, I liked the 'newbee' spelling: it fits very nicely in the context.  ;)

208
Tips and Tricks / Regular Expressions: coding, examples, testing resources
« on: February 09, 2023, 07:37:58 PM »
A Review of Regular Expressions

Table of contents

(1) Their use in MusicBee
(2) Characters
(3) Groups
(4) Other symbols
(5) External resources


(1) Their use in MusicBee


(1a) Purposes

A regular expression (RegEx) is a pattern used in comparison with any tag content for:
  • match tests
  • substring extractions
  • replacements


(1b) Virtual tag functions using RegExes

Function and syntaxPurposeIF <tag> matches RegEx,
returns:
ELSE,
returns:
$IsMatch(<tag>,RegEx)checks if the RegEx is present anywhere in the tagTF
$RxReplace(<tag>,RegEx,new)global string replacement<tag> content with each occurrence of RegEx replaced by the new replacement stringthe unmodified <tag> content
$RxMatch(<tag>,RegEx)first matching portionfirst portion of the tag matching the RegExa void string
$RxSplit(<tag>,RegEx,n)nth delimited sectionnth section of the <tag> content split up by using RegEx as delimiterthe unmodified <tag> content

Notes for the functions presented above:
  • use double quotes around the RegEx string or new replacement string if they include special characters such as comma, round bracket, angle bracket, single quote, i.e.:
    , ( ) < > '
  • the match test is case-insensitive by default ("x" matches both x and X)
    -> See "(4d) Case-sensitive matches";
  • the tag itself is not modified in the audio track nor in MusicBee's library.


(1c) Overview of RegEx symbols

RegEx symbols include: constituents, quantifiers, anchors and grouping marks.
  • Each RegEx constituent can be
    - a single character: literal, or belonging to a set/range, or
    - a group: several characters between rounded brackets (parentheses).
  • Any constituent is optionally followed by a quantifier, indicating how many times it must be present.
  • Anchors can be added to the RegEx to specify positions or boundaries.
  • You can specify whether the match must be case-sensitive, and for which RegEx portion.



(2) Characters


(2a) Literal characters and custom character classes

SymbolMeaning
aliteral character 'a'
All characters match themselves literally,
except those having special meaning in a RegEx:
. + * ? ^ $ ( ) [ ] { } | \
See also next table "(2c) Literal characters, backslashed".
[aeiou]any character in the set
[^aeiou]any character not in the set
[a-z]any character in the range
[^a-z]any character not in the range
.any character, except new line
[.]character '.'
\uFFFFUnicode (utf16) character with hex. code 'FFFF'



(2b) Pre-defined character classes (Unicode)

Backslash + lowercase letter = positive class.
Backslash + UPPERCASE  letter = negative class (any character not in the positive class).

SymbolMeaning
\wa word character: letter, digit, connector (hyphen, underscore)
\Wa non-word character
\da digit
\Da non-digit character
\sa white space character (including: space, tab, vertical tab, linefeed)
\Sa non-space character
\p{P}any punctuation character, such as:
. , ' ‘ " “ - - : ;
\P{P}any non-punctuation character
\p{S}any symbol character (currency, math, ...)
\P{S}any non-symbol character



(2c) Literal characters, backslashed

To match a character that has special meaning in regular expressions, precede it by a backslash.

SymbolMeaning
\.
\[   \]
The character after the backslash:
. [ ]
Meaning without \: see "(2a) Custom character classes".
\+   \*   \?
\{   \}
The character after the backslash:
+ * ? { }
Meaning without \: see "(4a) Quantifiers".
\(   \)
\|
The character after the backslash:
( ) |
Meaning without \: see "(3) Groups".
\^   \$The character after the backslash:
^ $
Meaning without \: see "(4c) Anchors".
\\a backslash



(2d) Combining characters within a RegEx

You can place single characters side-by-side as you wish.

SymbolMeaning
foobarliteral string 'foobar'
[a-z][0-9]any letter, immediately followed by any digit => matches a3, b0, c9, …



(3) Groups

A group is a series of contiguous single characters, defined by enclosing the string in rounded brackets (parentheses).
A group serves to:
  • store the result of the matching group in an indexed memory (1, 2, 3, …)
  • store the result of the matching group in a named memory
  • define the scope of the next quantifier (see "(4a) Quantifiers" below)
  • specify different options
The contents of the indexed/names memories can then be used in the replacement string (with RxReplace).
See "(3c) Substitutions" below.



(3a) Group types

SymbolGroup typeMeaning
(SubRegEx)indexed group, capturingTreats SubRegEx as a group and places the matching string in an indexed memory.
Each group of the whole RegEx is assigned an incremented number, starting from 1.
See "(3c) Substitutions" below.
(?:SubRegEx)non-capturing groupTreats SubRegEx as a group, without placing the matching string in an indexed memory.
Useful if you simply want to apply a quantifier to the group.
(?<alias>SubRegEx)named group, capturingThe matching string is stored in a named memory instead of an indexed one.
See "(3c) Substitutions" below.
(choice1|choice2|...)option group, capturingMatches any of the choices, and stores the matching string in an indexed memory.
Example:
    • (Bach|Mozart) matches 'Bach' and 'Mozart'
(?:choice1|choice2|...)option group, non-capturingMatches any of the choices, without storing the matching string in an indexed memory.



(3b) Lookarounds

'Lookarounds' are special groups used to define the context: what immediately precedes or follows.

SymbolLookaround typeMeaning
a(?=suffix)positive lookaheadMatches 'a' followed by 'suffix',
without including 'suffix' itself in the matching string.
a(?!suffix)negative lookaheadMatches 'a' not followed by 'suffix',
without including 'suffix' itself in the matching string.
(?<=prefix)apositive lookbehindMatches 'a' preceded by 'prefix',
without including 'prefix' itself in the matching string.
(?<!prefix)anegative lookbehindMatches 'a' not preceded by 'prefix',
without including 'prefix' itself in the matching string.



(3c) Substitutions (in the replacement string)

A substitution is the use of an indexed or named memory (capturing group) in the replacement string of $RxReplace.

In the examples below, <MyTag> contains 'FooBar'.

SymbolMeaningExample
$nindexed group n$RxReplace(<MyTag>,"(.{3})(.{3})","$2,$1")
-> 'Bar,Foo'
$`the substring before the match$RxReplace(<MyTag>,"a","$`")
-> 'FooBFooBr'
$'the substring after the match$RxReplace(<MyTag>,"a","$'")
-> 'FooBrr'
$+the last indexed memory$RxReplace(<MyTag>,"^(.{3})(.{3})(?:.*)$","$+")
-> 'Bar'
${alias}the content of stored memory alias
See: (?<alias>SubRegEx) in "(3) Groups"
$RxReplace(<MyTag>,"(?<First>.{3})(?<Second>.{3})","${Second}")
-> 'Bar'
$&the matching string$RxReplace(<MyTag>,"[aeiou]{2}","[$&]")
-> 'F[oo]Bar'
$_the whole input string$RxReplace(<MyTag>,"[aeiou]{2}","[$_]")
-> 'F[FooBar]Bar'



(3d) Backreferences (in the RegEx)

A backreference is the use of an indexed or named memory (capturing group) in the very RegEx where the memory is defined, thus not in the replacement string.

SymbolMeaningExample
\nindexed group n"(.)\1" matches a character followed by its repetition, such as:
aa, bb, cc, …

"(.)(.)\2\1" matches two characters followed by their repetition in mirror, such as:
ABBA, elle, otto, ...
\k<alias>named group alias"(?<one>.)\k<one>" matches a character followed by its repetition, such as:
aa, bb, cc, …

"(?<one>.)(?<two>.)\k<two>\k<one>" matches two characters followed by their repetition in mirror, such as:
ABBA, elle, otto, …



(4) Other symbols


(4a) Quantifiers

A quantifier is placed after a character or a group to indicate how many times it must be repeated (contiguously).

SymbolMeaningExample
+one or moreba+r matches: bar, baar, baaar, …
but not: br
?zero or oneba?r matches: br, bar
but not: baar
*zero or moreba*r matches: br, bar, baar, …
{m,n}between m and n times (both inclusive)ba{2,3}r matches: baar, baaar
{m,}at least m timesba{2,}r matches: baar, baaar, baaaar, …
{0,n}at most n timesba{0,2}r matches: br, bar, baar

The examples above match repeated single characters.
Here is one for a repeated group:
"(the ){2}" matches a string containing "the the ".



(4b) Greedy and lazy quantifiers

By default, a constituent + quantifier matches the longest possible substring (= greedy behaviour). So as to specify that it must match the shortest possible substring (= lazy behaviour), simply add ? after the quantifier.

GreedyLazyMeaning
++?one or more
???zero or one
**?zero or more
{m,n}{m,n}?between m and n times (both inclusive)
{m,}{m,}?at least m times
{0,n}{0,n}?at most n times



(4c) Anchors

Anchors are special markers: instead of matching actual characters, they specify the position relative to the string boundaries or word boundaries.

SymbolMeaningExample
^at start of string"^A" matches "A" at the beginning of a string
$at end of string"bee$" matches "bee" at the end of a string
\bon word boundary"\bbee" matches words starting with bee, such as "beehive"
"bee\b" matches words ending with bee, such as "MusicBee"
\Bnot on word boundary"\Bbee\B" matches "bee" in "bumblebees"



(4d) Case-sensitive matches

All match checks are case-insensitive by default in MusicBee (unlike other applications).
  • To make a RegEx part case-sensitive, prefix it with (?-i).
    Thus, placing (?-i) at the very beginning makes the whole RegEx case-sensitive.
  • To switch back to case-insensitive, add (?i) to the RegEx before the concerned part.

SymbolMeaningExample
(?-i)case-sensitive:
applies to the RegEx part to its right
"(?-i)a" matches "a" but not "A"
(?i)case-insensitive:
applies to the RegEx part to its right
"(?-i)a(?i)a" matches "aA" but not "AA"



(5) External resources


(5a) Exercises

Auto-corrected exercises. You can see the result of your RegEx as you type it.

(5b) Testing pages


MusicBee relies on .NET to interpret RegExes. RegEx interpreters other than .NET may give slightly different results, and so far I have found only one testing site providing with the .NET RegEx flavour.

For building, testing, and debugging your RegExes (match tests, replacements),
use this site:
  • https://RegEx101.com/
    - Select «.NET (C#)» as RegEx engine (FLAVOR pane on the left).
    - To the right of the REGULAR EXPRESSION, set regex options "g" (global) and "i" (case-insensitive).

Other RegEx flavours:

PCRE = Perl-Compatible Regular Expression


(5c) Unicode character tables

Reference tables in PDF format:

(5d) Supported Unicode character classes

Microsoft .NET reference:

209
Great!
Thank you, Steven!

210
Context:
- audio track in M4A
- matching CUE sheet, for the sole purpose of skipping the leading silence (thus only 1 track defined)

Issue:
- CUE sheet not taken into account

Tried workaround:
- initial state = CUE sheet not recognised
- adding an arbitrary second track to the CUE
- rescanning the audio track in MB -> CUE sheet recognised
- removing the second track from the CUE
- rescanning the audio track
- CUE still taken into account, the track showing now the wished duration

MusicBee v3.5.8436 P (latest)
Windows 10 x64

Files (M4A + CUE):
https://drive.google.com/drive/folders/1PzZOQKTYo6Ij9FgAyFjm6lM8rrLhSYmh?usp=share_link

Not recognised CUE sheet:
Code
TITLE "Concert 01"
FILE "01 - Concert 01.m4a" M4A
TRACK 01 AUDIO
  TITLE "Концерт № 01 - Воспойте Господеви, воспойте песнь нову"
  INDEX 01 00:13:00

Recognised CUE sheet with DUMMY track:
Code
TITLE "Concert 01"
FILE "01 - Concert 01.m4a" M4A
TRACK 01 AUDIO
  TITLE "Концерт № 01 - Воспойте Господеви, воспойте песнь нову"
  INDEX 01 00:13:00
TRACK 02 AUDIO
  TITLE "DUMMY"
  INDEX 01 07:55:00

Pages: 1 ... 12 13 1415 16 ... 23