String -> Pattern Double?

Could someone please tell me if there is a simple hack to convert a string to a Pattern Double for use in expressions such as Gain. I have some code which does algorithmic replacement of strings in Pattern String. This uses parseBP_E which handles a string input. I haven't been able to do a similar process so that I can modify a string and then pass it to gain. Something like this:

let {g1::String;
    g1 = "[1 0.7]" }

d1 $ sound "[hh*16]" #  gain g1 --"[1 0.7]"

But that, you know, works. Any advice would be greatly appreciated. :-]

This works for me:

d1 $ sound "[hh*16]" # gain (parseBP_E g1)

Brilliant! Hacked on that for a couple of hours and couldn't get it to work. Thought I tried that permutation, but alas no. Thought I had a type problem but actually was using functional application in the wrong place ( gain $ parseBP_E ... ). Duh. I see now that gain is part of a parsed statement and not a function. So needed to force the evaluation with parenthesis. I think my adversarial relationship with the Haskell strong typing system has induced a state of learned helplessness.

For the record, here's the working example:

import qualified Data.Text as R
let {tstRpl::String->String->String->String;
      tstRpl  a b c = R.unpack $ R.replace (R.pack a) (R.pack b)  (R.pack c)}
d1 $ sound "hh*16" # gain  (parseBP_E $ tstRpl "$0" "3" "[1 0.5]*$0")

Awesome! Thanks!!! If you have any suggestions of a simpler Haskell string replace, that would be awesome too.

Also if you could convince my daughter to apply to Sheffield. :-]

You could use this feature instead:

-- set rational value
setR "foo" 3 

d1 $ sound "hh*16" # gain "[1 0.5]*[^foo]"

Perfect. Thanks!

1 Like