filter if sequence of chars is matched | how to in bach (without regexp)

Discussions, advice, bug reports and much more about the "bach" environment.
Post Reply
sydy
Posts: 155
Joined: Tue Mar 21, 2017 1:34 pm

filter if sequence of chars is matched | how to in bach (without regexp)

Post by sydy » Mon Sep 09, 2019 3:45 pm

Hy,

I'm want to filter out patterns whenever they contain a predefined sequence of characters or numbers.
Stupidly, I couldn't figure out how to do this without regexp.

I'd like to stay inside the bach.dataflow (avoid the @out t in the middle of the algorithm) and make the condition dynamically changeable.

Does somebody know how to do this with bach?

Here's an eg. of how I do it with regexp. (see copy compressed)

Patterns to check [ 3 3 3 4 ] [ 1 4 4 4 ] [ 2 4 2 3 ] [ 1 4 4 1 ]
bach.sieve
lambda condition

regexp "(3 3 3|4 4 4)"
IF pattern contains sequence of "3 3 3" OR "4 4 4" (substrings matched)
THEN filter it out (send 0 to bach.sieve)
ELSE (unmatched) (send 1 to bach.sieve) pass it through

Result of bach.sieve
0 0 [ 2 4 2 3 ] [ 1 4 4 1 ]

Thanks for any comments.
m

<pre><code>
----------begin_max5_patcher----------
836.3oc0WsziSCCD9b5uBqbBjJQ9Qdxo8xh.IDWfaaWUkl5s0qRrCINkhV1+
6LwNk1RSoY2MHAJpMcF+X72m+7LtOLwwcgZKu1E8VzMHGmGl33Xb05voy1ws
HcaVdZsoatYphBtT6N01lluUa7+g2gJS0ZdkDkoj5TgrFUy+ZCWlwQp6PybY
H3YlKBop.KeD7Lycl7Ku+5OgtSjCCEIzHUidl75O94qgoqtt0idckpY05cQL
WH4YpFoIrrNmxlBXf4bsYQh67BKnr0B4p4U7LsEjrvXO7TDwOn8EMh09xOxC
itsaPhkF7nVb+aX9t6megb2zSZ883jIseMcfzlj+MXFOg0Vjls16t7TMh31K
THmGJTruAJDCFBMFT5AHwNM5uWxsCv0sOPRS5GjcNqS2vWNG5HD24vFbkXQi
1JYb9EVcb2vqpEJILEK3UsMFiw3XSiFlZL4qRUkNMGcEfOjteZidYZyGadgi
F.uMsMxxU8yeQ+KxeE755zU7SHvmgLKl4EE.TDlXHr3mqNi1KOQGQvge5fKH
x6.rk7LwFgMZX6LB+J9J91RHu4qLoQ+gI84qm41OhCtr7OxJ+aA6Pj+G8oOJ
HYzRUdtc2aPFnC.+VXUQPFJv7aJ7lBsr2OAc6twWVwqgBVoZ3307iJdPeppE
hg57sT1yVrD82VqXSRVIjmI4H9RHjPMGxCImfvCfg++akMpE7MbzUP+WxK0q
AMxU4oEKVldtZuzKwSwlJuTbx.OC0apidoQ1AX2LJy0d9sKpYVWs9OlPpUMU
Y6hamfCseosjWqERywgC5Cw1mdo7gFGx.hi+HDGHUCbb+B3gMRAhcg.0VV6E
GH5P1hRFi.QGnVXO+loxUU1VwdTFgEQC7SvjjPbLLWdA3f3XJKfl3SHQgstn
PJjCNLTHVVpfrQcxWZByi1Vz0lHkEl3E1mcTWdVlWmwKUdxdYX+HX5G0BTRX
bHMxO.mDiYIzdc8mXhP6kOCr.2O1dQqiMGcZ.PH4Rh5QQqkL.9dmx+j7cokk
cEGLgoMHPp96saGwSMlBo0zTPCthzFwt9a6PZEj2VCIsapLKL2sg1pVtEpkv
+TsQzcGE.dPHMkQjov8OJSsHwTsYxiS9I72b7cJ
-----------end_max5_patcher-----------
</code></pre>

danieleghisi
Site Admin
Posts: 1347
Joined: Fri Dec 03, 2010 1:25 pm

Re: filter if sequence of chars is matched | how to in bach (without regexp)

Post by danieleghisi » Mon Sep 09, 2019 9:05 pm

If all you need are matching sub-sequences, bach.find (and its reversed-inlet cousin bach.locate) are your friends (see patch below).
If you need regular expression on lllls, we don't have a tool for that yet, but I agree that it would be a nice idea to have a pattern matching object in the future.

<pre><code>
----------begin_max5_patcher----------
732.3ocyWssaiBCD8Y3qvhmyVYyk.YkpT+OphhLAustBLHvjlUU4eeGFCsa2
FBWBscUjBwWXN9LywyL4EaKm37ihJGxOI2Srrdw1xBmpYBq1wVNY7i6S4U31
bThmyiexYkYIs3nFmNlu+wat8VBsak7ZcpPq+cgvXcGoB1411UkI3aAV5Gtr
tWQUmIUvKg.41NYAWu+Qo5gckh8Ziob8VeCcEwMLp4wZWb.78qVGLjAdzRr1
Yq3GDI6.HACsiq0kx3Zsg7VuRVKmChxJYtBrQrnrYwHJkFgKdx1t66S1qV.G
VUcVu9KmUWvmQOqOiMrOyO.8YrA7YtyfnYhpJ9ChOvz9kDmkarMSUOD36YzC
T7wlaBtrdXA4FahbKZpbyOx8ylaWRf9KYpVTppSSunN87jMXtj0Gkmga9DDo
8PVMIlzOEi4pG5klal4UQlejIxFNPL0cgioY7BQpHibG7FIhB8iDF4tZ0yk7
BBa5g4n4l9lYRB4QGJL+8l+tuq926QfOaI26SfOamVhf0yzowL07F7pwRmGH
MeOWKlFG8l60eivHj9IvwdClDLZBQRHfB2GvXJ9aW3oKrxayyHSLXGNYGAFq
CCLdiu5XcQYSaGejF9SMQmgFLSyFC1xA8+31zjhCh2muLkmEmvmS9xy2tq2f
tQlIqIcJUEws3jJU+aO9HLMy+dORUdc49NFz0bN4MjRDUZohqAG+esol8395
dxjIE4fBpEwlNNg5adlievFTT+9QLZTWuoAsiHaOaHbzGa5HN1cb6pPJZL.Q
W.fZZKdPjZNMrqEn.iQtbHeyRPonuRJMnJNZAnj2X.JXgzcCEj7VhXzHvYIz
BiQcudgvYL9sqUxsdjR6qkOgiL+7RnCFBG+Ofio9CunnsZMBRCDPs2mxMksW
gCkJyPrK.mRwAY29CvY3kPYQMTSrtDOVNGWa5GwIKOo4enJaaEBHG.IVWWwg
18J3Fdfk+sOY+G.deTkF
-----------end_max5_patcher-----------
</code></pre>

sydy
Posts: 155
Joined: Tue Mar 21, 2017 1:34 pm

Re: filter if sequence of chars is matched | how to in bach (without regexp)

Post by sydy » Tue Sep 10, 2019 5:20 am

Thanks Daniele.

As always you got an elegant solution nearly on the fly.

Yes, matching patterns in substrings is a musically interesting tool – at least in my aesthetics. In that sense a regexp in Bach would be worth a future dev.

But for now here we go with a solution.

And, considering the Bach.eval possibilities I'm discovering now, there will be a lot of ways to engage much more complex sequences than this little example.

Have a very nice day.

M

Support Bach on Patreon!

Post Reply