Using markovPat for chords

hey friends! I've been experimenting with bgold 's awesome markovPat .. trying to figure out how to use it with chords.

It works great with single notes or sounds;

this works fine:

p "bass" $  n (fmap ([0,4,7,11]!!) $ markovPat 32 1 [[4,1,0,0], [1,0,0.5,0.25], [1,0,0.5,0.25], [1,0,0,0]]) # thru

as does this:

p "drums" $ loopFirst $ (9 ~>) $ s (fmap (["bd", "808hh", "808ohh", "808sd", "~"]!!)
               $ markovPat 16 2
               [[2,4,1,0.5,3,0.5], -- bd
                [3,8,1,1,0.1,0.1], -- hh
                [3,7,0,0,2,1], -- ohh
                [1,0,0,0,0.2,0.8], -- sd
                [1,0.5,0.1,0,0.8,0.8], --rest
                [2,3,1,1,0.5,0.8] -- cvb
               ]) # cut 89

but this does not:

d1 $ n (fmap (["c'maj","e'min","a'min"]!!) $ markovPat 8 1 [[3,5,2], [4,4,2], [0,1,0]]) # thru

(thru is midi output)

I get an error like this:

<interactive>:21270:16: error:
    β€’ No instance for (Data.String.IsString Double)
        arising from the literal β€˜"c'maj"’
    β€’ In the expression: "c'maj"
      In the first argument of β€˜(!!)’, namely
        β€˜["c'maj", "e'min", "a'min"]’
      In the first argument of β€˜fmap’, namely
        β€˜(["c'maj", "e'min", "a'min"] !!)’

any ideas? thanks!

1 Like

Here, 0,4, .. are numbers:

n (fmap ([0,4,7,11]!!) $ ...

there, "c'maj" etc. are patterns:

n (fmap (["c'maj","e'min","a'min"]!!) $ ..

Your program has this value and type (using a smaller example)

(fmap (["c'maj","d" :: Pattern Note] !!) $ run 2)
(0>Β½)|(0>1)|Note {unNote = 0.0}
(0>1)|Note {unNote = 4.0}
(0>1)|Note {unNote = 7.0}
(Β½>1)|(0>1)|Note {unNote = 2.0}
it :: Pattern (Pattern Note)

so you need one of the join operators (and I always confuse them) but perhaps

n $ unwrap (fmap (["c'maj","d" :: Pattern Note] !!) $ run 2)
(0>Β½)|n: Note {unNote = 0.0}n
(0>Β½)|n: Note {unNote = 4.0}n
(0>Β½)|n: Note {unNote = 7.0}n
(Β½>1)|n: Note {unNote = 2.0}n
it :: ControlPattern

The examples from the documentation (https://tidalcycles.org/markovPat) use s where you want n, and the types are different

n :: Pattern Note -> ControlPattern
s :: Pattern String -> ControlPattern

Since s accepts any string, we risk running into this

s (fmap (["[bd,sn]", "cp", "arpy" ]!!) $ markovPat 8 1 [[3,5,2], [4,4,2], [0,1,0]])
(0>β…›)|s: "cp"
(β…›>ΒΌ)|s: "[bd,sn]"  <== wrong
...

I think the more expressive type of n is good (it turns a run-time error into a compile-time error).