Struct, variables and mininotation

The idea I have in mind is the following: suppose you start with a very simple rhythmic structure defined using struct and some mininotation:

d1 $ struct "1!3 1@3 1@2" $ s "bd"

and later you want to parameterise the number of kick samples at the beginning of the pattern.
To begin with, it could be generated by irand.

In my mind, it should look like this:

do
    setF "kickStut" $ irand 16
    d1 $ struct "1!^kickStut 1@3 1@2" $ s "p_bd"

but of course, it does not work.

What am I doing wrong?

1 Like

I think it's just that the mininotation doesn't (yet) support patterns in the argument after !, just numbers. While I don't think it's exactly the same, you could get something similar to what you're trying to do with

setB "kick" $ fast (irand 16) "t"
d1 $ struct "^kick 1@3 1@2" $ s "bd"
4 Likes

Thank you @bgold!
Two follow-up questions:

  1. I do understand setB "kick" $ fast (irand 16) but not the "t": what does it mean in the context?
  2. how about variables: can I use normal variables inside the mininotation?

When using struct t=1 f=0 (which stands for true and false) since struct accepts booleans

Thank you @Francesco_Corvi, what I mean is: what is "t": is it Pattern, or string or?

It is a Pattern of booleans.

Yeah, oops I mixed notation a bit there. Technically struct uses Pattern Bool, but you can represent booleans using "1 0 0 1" or "t f f t" and often Haskell will figure out that the first should be Bool rather than Int.

And as far as variables in the mininotation - I think it just comes down to that since a variable is a Pattern, you can use it anywhere in the mininotation that Patterns are accepted. So d1 $ s "bd(^foo, 8)" works (assuming "foo" has been set somewhere) because the Euclidean stuff accepts Patterns.

I think the places in mininotation that don't take patterns are after _, @, !, or ?

Thank you for the explanation @bgold and @Francesco_Corvi !
I asked because I sometimes inspect the pattern and if I write:

tidal> putStrLn . show $ fast 2 $ s "bd"

I know I will get:

(0>½)|s: "bd"
(½>1)|s: "bd"

and when I tried this:

tidal> putStrLn . show $ fast 2 "t"

I got an error:

<interactive>:2:26: error:
    • No instance for (Enumerable ()) arising from the literal ‘"t"’
    • In the second argument of ‘fast’, namely ‘"t"’
      In the second argument of ‘($)’, namely ‘fast 2 "t"’
      In the expression: putStrLn . show $ fast 2 "t"

but then I realised how stupid I am, because I have to explicitly set that "t" is Pattern Bool!

tidal> putStrLn . show $ fast 2 ("t" :: Pattern Bool)
(0>½)|True
(½>1)|True

and it works as expected :smile:


It seems very much the case here, as I am not able to figure out how to use it - using brackets does not solve the problem and I get a complaint from the compiler :confused:
Perhaps a future option @yaxu?

Yes, definitely worth creating an issue for these.. I'm not sure how tricky this would be to fix, one of those things that might take five minutes, or five days..

1 Like

@yaxu just did it :slight_smile:

1 Like