Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex support in Auto Color for track, marker, region name filters #1291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Color/Autocolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "../SnM/SnM_Util.h"
#include "../reaper/localize.h"
#include "WDL/projectcontext.h"
#include <regex>

#define PRI_UP_MSG 0x10000
#define PRI_DOWN_MSG 0x10001
Expand Down Expand Up @@ -86,6 +87,8 @@ static bool g_bAIEnabled = false;
static bool g_bALEnabled = false;
static WDL_String g_ACIni;
static int s_ignore_update;
static const char g_cRegexPrefix = '$'; // Filter should start with that prefix to be treated as regex
static const auto g_bmRegexOptions = std::regex_constants::extended | std::regex_constants::icase | std::regex_constants::collate;


// Register to marker/region updates
Expand Down Expand Up @@ -812,8 +815,20 @@ void ApplyColorRuleToTrack(SWS_RuleItem* rule, bool bDoColors, bool bDoIcons, bo
else // Check for name match
{
char* cName = (char*)GetSetMediaTrackInfo(tr, "P_NAME", NULL);
if (cName && stristr(cName, rule->m_str_filter.Get()))
bMatch = true;
if (cName){
if (stristr(cName, rule->m_str_filter.Get())){
// Exact match
bMatch = true;
}
else if (strlen(rule->m_str_filter.Get()) > 1 && (rule->m_str_filter.Get())[0] == g_cRegexPrefix){
// Regex pattern match
const char* sUserPattern = (char*) rule->m_str_filter.Get() + 1; // Chopping the prefix
std::regex reUserPattern(sUserPattern, g_bmRegexOptions);

if (std::regex_match(cName, reUserPattern))
bMatch = true;
}
}
}
}
else if (strcmp(rule->m_str_filter.Get(), cFilterTypes[AC_MASTER]) == 0)
Expand Down Expand Up @@ -1064,6 +1079,7 @@ void ApplyColorRuleToMarkerRegion(SWS_RuleItem* _rule, int _flags)
int x=0, num, color;
bool isRgn;
const char* name;
const bool isRegex = (strlen(_rule->m_str_filter.Get()) > 1) && ((_rule->m_str_filter.Get())[0] == g_cRegexPrefix);

PreventUIRefresh(1);
if(_rule->m_type & _flags)
Expand All @@ -1072,6 +1088,7 @@ void ApplyColorRuleToMarkerRegion(SWS_RuleItem* _rule, int _flags)
{
if ((!strcmp(cFilterTypes[AC_RGNANY], _rule->m_str_filter.Get()) ||
(!strcmp(cFilterTypes[AC_RGNUNNAMED], _rule->m_str_filter.Get()) && (!name || !*name)) ||
(name && isRegex && std::regex_match(name, std::regex((char*)_rule->m_str_filter.Get() + 1, g_bmRegexOptions))) ||
(name && stristr(name, _rule->m_str_filter.Get())))
&&
((_flags&AC_REGION && isRgn && _rule->m_type==AC_REGION) ||
Expand Down
3 changes: 3 additions & 0 deletions whatsnew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Global notes: (Issue 1170)
+Internal tweaks (more efficient load/save)
+Additionally to saving when project is saved, can be saved via notes window context menu (global notes are stored in <REAPER resource path>/SWS_global notes.txt)

Auto color/icon/layout:
+Add regex patterns support in name filters for more flexible filtering. Filters beginning with "$" sign (e.g. "$((gtr)|(guitar)).*lead") are now treated as regular expressions. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04|Extended POSIX| grammar is used, case-insensitive.

Linux:
+Added official Linux ARM builds (32-bit and 64-bit)
+Enable media file tagging features
Expand Down