-
-
Notifications
You must be signed in to change notification settings - Fork 253
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 variable interpolation to mini notation #530
Comments
I thought Template Haskell could help with this. Reading this (in particular "Writing ${alphaNum} interpolates the regex referred to by alphaNum into the larger regex validDotComMail'"): I did this: However the interpolation seems to be ignored:
results in:
|
Every time I've tried Template Haskell I've been stumped at how to use it properly, but that tutorial looks good so I'll take another look... |
Yes I don't find the documentation too clear! But looking a bit more closely, it seems the interpolation doesn't work until you make a I'd say it's not possible to turn a pattern into a q-expression, so this isn't going to work right now. I think this would be possible if #217 was done. I should also link in #375. |
One way to do it is with parser state (#217 may be related). I tried making a "toy" parser for Tidal that supported this, but the difficulty I run into is combining the stateful aspect with the generic type aspect. For example, if you're parsing a Pattern Double then the state (for interpolation) should also be Pattern Double, but combining this with the Euclidean parts (which are always Pattern Int) gets messy. I think maybe the Euclidean stuff needs to be isolated somehow. |
I read that regex tutorial a bit more carefully and managed to get the following proof of concept working on the
|
Here's the commit: It's only working with string patterns so far, I need to understand what's going on more.. But I think this is a really interesting proof of concept. |
Haven't been following this very closely - if this is using TH "on the fly", ie. during interpretation/performance, I would flag that it likely doesn't transfer to MiniTidal/GHCJS/the browser and could thus strongly impede the ability to give people a zero installation Tidal experience. It's worth considering the implications of particular implementation strategies for who ultimately gets to use it, I think. Apart from that particular (rather huge, IMO) implication, I would observe that - as something which is not type safe and which gives very cryptic feedback - TH is likely most suitable for managing the complexity of large compiled systems rather than for interpretation... |
If that's the case, we simply don't support interpolation in the mini notation in any interpreters without access to template Haskell,.. Potentially offer the same feature a different way (I guess this wouldn't be too tricky in MiniTidal). Using TH in this way adds type safety at compile time though, and I don't think it gives cryptic feedback - it just returns any parsec errors. In any case, TH aside, there are wider implications in expanding parseBP's AST to the whole of tidal, which I think will have some really interesting benefits including for systems like minitidal. |
It'd be nice to keep things "together" as much as possible. "Interpolation" (a variable system, basically) is such a significant feature that, once introduced, it could be hard to see a version of Tidal without as really connected to one with. I think you're right that the same feature could be offered a different way - I think my intuition is that there is a non-TH right might make it easier to offer this feature across different software delivery environments. By the way, have recently reworked MiniTidal using haskell-src-exts by the way, so it is now much easier to extend than previously. In terms of matching "classic Tidal" it is now mostly a matter of filling in missing operators and catching specific patterns of use. More about this elsewhere soon... That (MiniTidal haskell-src-exts rework) being the case, though, I have been thinking about the possibility of making MiniTidal match not a single ControlPattern but rather a whole Tidal "program" with the d1 d2 hush etc. This is somewhat connected to the original goal ("interpolation") of this issue in the sense that an example like this: x = "arpy*8" ...becomes something that will be possible (without on-the-fly TH) because we will be keeping a dictionary of things that have been defined anyway. I could well be missing something, but I have the sense that TH is being used as a way of getting a dictionary lookup without being responsible for a dictionary, which would beg the question, why not just have a dictionary? Thinking out loud... set :: String -> Pattern a -> IO () -- defines reusable patterns in MVar dictionaries that are available and statefully updated during parsing set "x" $ "arpy*8" let d1 = set "d1" |
Yes, there's already the control state dictionary for this sort of thing. I haven't quite worked out the interface for it but there's a working example in the #tidal-innards channel on talk.lurk.org As I said, the interesting part isn't really the TH bit but the AST bit of this change. It brings the mini notation together with the rest of tidal, so that
becomes possible |
Right... but from MiniTidal everything there is already possible! (edit: except the new $x obviously...) |
@yaxu what happens to the currently playing |
@bgold-cosmos here's how things actually look at the moment. It works really well..
This sets state via the same mechanism that external controllers set state, so running patterns will reflect changes. I think @dktr0 is right that we don't need TH, once everything goes via an AST we can use this state dictionary to embed patterns in each other. |
You can use dictionaries to embed patterns in each other now - doesn't have to wait for an AST refactor. |
I got something working using the state dictionary: e4034b7
Currently variables are prefixed with I'm resisting using the Otherwise, we're running out of keyboard characters fast.. No template haskell required.. and we already have an OSC interface for updating this state remotely, for free. (Hopefully that won't be used for griefing live performers..) |
Oh, that's an interesting way of doing it, I'll have some fun testing this out. Does this also mean that using the MIDI-OSC bridge, whatever's sent on CC# 11 could be used in the mininotation like this?
|
In theory yes, in practice that might need a tweak to the parser, as I think it won't like identifiers that begin with a number. |
I think I like the |
@bgold-cosmos it supports numeric ids now so midi input should be fine |
A continuation of discussion on this PR by @bgold-cosmos : #528
The text was updated successfully, but these errors were encountered: