vivid icon indicating copy to clipboard operation
vivid copied to clipboard

Represent a `[VarList]`? Convert a `Map String Float` to a `VarList`?

Open JeffreyBenjaminBrown opened this issue 3 years ago • 1 comments

In Montevideo I'm using maps from string to float to represent messages. This lets me represent arbitrary sequences of SuperCollider events, something I was unable to do using tuples because GHC is picky about their types.

But Vivid's set expects a VarList, which is a family of tuples:

set :: (Subset (InnerVars params) sdArgs, VividAction m,
    VarList params) =>
    Synth sdArgs -> params -> m ()

Currently my hack has been to extract a separate tuple for each key-value pair in the Map String Float, and set that tuple. But since the sequences I generate can be pretty complicated, that leads me to unbundle gobs of messages that really ought to be sent together.

The only solution I'm aware of would be to hard-code how to respond to every possible set of message keys. I'm using a synth with more than 33 parameters, so that would mean 2^30 = more than a billion definitions. I'm not even sure that would compile.

Can this be worked around?

JeffreyBenjaminBrown avatar Aug 02 '20 00:08 JeffreyBenjaminBrown

Maybe I can broaden the audience of this issue by noting that it's hard in Vivid even to represent a list of VarLists.

It turns out to be possible -- somehow, a year or two ago, I came up with the following:

data ScMsg' sdArgs where
  ScMsg' :: forall params sdArgs.
          ( Vivid.VarList params
          , Vivid.Subset (Vivid.InnerVars params) sdArgs)
       => params -> ScMsg' sdArgs

But that has the disadvantage that each ScMsg has "forgotten" its type. They can be used to set' a synth, but they cannot be analyzed, say, to convert a pattern in one parameter to a pattern in another.

JeffreyBenjaminBrown avatar Aug 02 '20 13:08 JeffreyBenjaminBrown