Giter Site home page Giter Site logo

vivid's People

Contributors

lpil avatar vivid-synth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vivid's Issues

How to reset an envelope?

EDIT: Solved! See first comment, below this initial post.

Hi Tom!

(If there's a better place than the Github issues for me to ask questions, please let me know and I'll happily comply.)

I must not understand how envelopes work. I thought that an envelope would reset when it receives a gate=0 value, but that doesn't seem to be happening.

Below is a synth called syn with a single parameter, "start". "start" is consumed by an envGen that causes the signal to fade in. It works initially -- when you first create the voice, it does indeed fade in. I expected setting "start" to 0 would then cause the envelope to reset to 0, making the voice disappear suddenly, i.e. "pop out". But instead it has no effect.

syn :: SynthDef '["start"] = (
  sd (toI $ 1 :: I "start") $
    do
      sig <- sinOsc (freq_ 440) ~* 0.05
             ~* ( envGen_wGate              -- To fade in.
                  (V::V "start")
                  1                         -- Time scale = 1 second.
                  (env 0 [(1,1)] Curve_Lin) -- Start at 0 and ramp up to 1
                                            -- over the course of 1 second.
                  DoNothing )
      out 0 [sig,sig]
  )

s <- synth syn ()      -- It fades in.
set s (0 :: I "start") -- Why doesn't it pop (not fade) out?
set s (1 :: I "start") -- At this point I expected it to fade in again,
                       -- but of course it can't because it never popped out.
free s

What have I misunderstood?

Thanks again for all your help!

Envelope documentation

A million years ago on an extinct mailing list (Haskell Art), you gave me an example of how to use envelopes. Yesterday I discovered it works like a charm. I've tweaked it a little and added comments. It might make a good piece of documentation to add somewhere, maybe at the top of Vivid.Envelopes.

{-# LANGUAGE DataKinds, ExtendedDefaultRules #-}

import Vivid

main :: IO ()
main = do
   s <- synth foo ()
   wait 1
   putStrLn "Now we fade in!"
   set s (1 ::I "gate")
   wait 4 -- because the envelope below lasts 1+2+1 seconds
   free s

e :: EnvLiterally '["gate"]
e = env 0 -- The level to start at.
  [ -- These are (level, time in seconds to reach that level) pairs.
    (1, 1) 
  , (1, 2) -- Since the last level was also 1, this pair causes
  -- the envelope to stay at 1 for 2 seconds after reaching it.
  , (0, 1)]
  Curve_Lin

-- This has a default gate of 0, so the envelope doesn't trigger when
-- the voice is created; rather, the user must send a positive gate value
-- to trigger it. (If they then send another 0, they gain the opportunity
-- to retrigger it with another positive gate value.)
-- If instead the default was 1, then the user would not need to send
-- the initial gate value separately (but they could still send 0
-- to make it ready to retrigger).
foo :: SynthDef '["gate"]
foo = sd (0 ::I "gate") $ do
   e' <- envGen_wGate (V::V "gate") 1 e DoNothing
   s <- sinOsc (freq_ 440) ~* e'
   out 0 [s,s]

I made it work in stack, after simplifying the code very slightly

I added a stack.yaml file with a single line:

resolver: lts-11.15

Then I stripped all the bounds from the .cabal file. After that I could run stack setup.

But stack ghci was giving me type errors, until I made the following changes to one file:

diff --git a/Vivid/SynthDef/FromUA.hs b/Vivid/SynthDef/FromUA.hs
index 98d614a..8e1b6b3 100644
--- a/Vivid/SynthDef/FromUA.hs
+++ b/Vivid/SynthDef/FromUA.hs
@@ -103,9 +103,9 @@ instance FromUA (NoDefaults args0) where
    fromUA _ = return []
 
 instance FromUA (UA a args0) where
-   type UAsArgs (UA a sdArgs) = '[a]
-   type SDBodyArgs (UA a args) = args
-   fromUA :: UA a args -> SDBody (UA a args) [(String, Signal)]
+   type UAsArgs (UA a args0) = '[a]
+   type SDBodyArgs (UA a args0) = args0
+   fromUA :: UA a args0 -> SDBody (UA a args0) [(String, Signal)]
    fromUA (UA x) = do
       y <- x
       return [(symbolVal (Proxy::Proxy a), y)]

And now I can run the examples!

I would submit a pull request but I don't actually know what the meaning of my changes to FromUA are, so I can't be sure I did something desirable.

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

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?

running readme example on stackage lts-16.23

Hi

When trying to run the readme example in Stackage LTS-16.23 (close to the lastest) I get the errors below.

The stack project I used is available here. To reproduce after cloning the repo do stack build.

Building all executables for `try-vivid' once. After a successful build of all of them, only specified executables will be rebuilt.
try-vivid> configure (exe)
Configuring try-vivid-0.1.0.0...
try-vivid> build (exe)
Preprocessing executable 'try-vivid-exe' for try-vivid-0.1.0.0..
Building executable 'try-vivid-exe' for try-vivid-0.1.0.0..
[1 of 2] Compiling Main

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:12:15: error:
    • Ambiguous type variable ‘i1’ arising from a use of ‘~*’
      prevents the constraint ‘(ToSig i1 '["note"])’ from being solved.
      Probable fix: use a type annotation to specify what ‘i1’ should be.
      These potential instances exist:
        instance ToSig Int16 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int32 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int64 args -- Defined in ‘Vivid.SynthDef.ToSig’
        ...plus 9 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘(~+)’, namely
        ‘sinOsc (freq_ 5) ? KR ~* 10’
      In a stmt of a 'do' block:
        wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
   |
12 |     wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:12:15: error:
    • Ambiguous type variable ‘i10’ arising from a use of ‘~+’
      prevents the constraint ‘(ToSig i10 '["note"])’ from being solved.
      Probable fix: use a type annotation to specify what ‘i10’ should be.
      These potential instances exist:
        instance ToSig Int16 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int32 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int64 args -- Defined in ‘Vivid.SynthDef.ToSig’
        ...plus 9 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block:
        wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
      In the expression:
        sd (0 :: I "note")
          $ do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
               s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
               out 0 [s, s]
   |
12 |     wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:12:23: error:
    • Ambiguous type variable ‘s0’ arising from a use of ‘freq_’
      prevents the constraint ‘(ToSig s0 '["note"])’ from being solved.
      Probable fix: use a type annotation to specify what ‘s0’ should be.
      These potential instances exist:
        instance ToSig Int16 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int32 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int64 args -- Defined in ‘Vivid.SynthDef.ToSig’
        ...plus 9 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘sinOsc’, namely ‘(freq_ 5)’
      In the first argument of ‘(?)’, namely ‘sinOsc (freq_ 5)’
      In the first argument of ‘(~*)’, namely ‘sinOsc (freq_ 5) ? KR’
   |
12 |     wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |                       ^^^^^^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:12:29: error:
    • Ambiguous type variable ‘s0’ arising from the literal ‘5’
      prevents the constraint ‘(Num s0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘s0’ should be.
      These potential instances exist:
        instance Num Int16 -- Defined in ‘GHC.Int’
        instance Num Int32 -- Defined in ‘GHC.Int’
        instance Num Int64 -- Defined in ‘GHC.Int’
        ...plus 7 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘freq_’, namely ‘5’
      In the first argument of ‘sinOsc’, namely ‘(freq_ 5)’
      In the first argument of ‘(?)’, namely ‘sinOsc (freq_ 5)’
   |
12 |     wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |                             ^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:12:40: error:
    • Ambiguous type variable ‘i1’ arising from the literal ‘10’
      prevents the constraint ‘(Num i1)’ from being solved.
      Probable fix: use a type annotation to specify what ‘i1’ should be.
      These potential instances exist:
        instance Num Int16 -- Defined in ‘GHC.Int’
        instance Num Int32 -- Defined in ‘GHC.Int’
        instance Num Int64 -- Defined in ‘GHC.Int’
        ...plus 7 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the second argument of ‘(~*)’, namely ‘10’
      In the first argument of ‘(~+)’, namely
        ‘sinOsc (freq_ 5) ? KR ~* 10’
      In a stmt of a 'do' block:
        wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |
12 |     wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |                                        ^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:12:46: error:
    • Ambiguous type variable ‘i10’ arising from the literal ‘10’
      prevents the constraint ‘(Num i10)’ from being solved.
      Probable fix: use a type annotation to specify what ‘i10’ should be.
      These potential instances exist:
        instance Num Int16 -- Defined in ‘GHC.Int’
        instance Num Int32 -- Defined in ‘GHC.Int’
        instance Num Int64 -- Defined in ‘GHC.Int’
        ...plus 7 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the second argument of ‘(~+)’, namely ‘10’
      In a stmt of a 'do' block:
        wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
   |
12 |     wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
   |                                              ^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:13:10: error:
    • Ambiguous type variable ‘i00’ arising from the literal ‘0.1’
      prevents the constraint ‘(Fractional i00)’ from being solved.
      Probable fix: use a type annotation to specify what ‘i00’ should be.
      These potential instances exist:
        instance GHC.TypeLits.KnownSymbol s => Fractional (I s)
          -- Defined in ‘Vivid.SynthDef.TypesafeArgs’
        instance Fractional Double -- Defined in ‘GHC.Float’
        instance Fractional Float -- Defined in ‘GHC.Float’
        ...plus two instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘(~*)’, namely ‘0.1’
      In a stmt of a 'do' block:
        s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
   |
13 |     s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V::V "note") ~+ wobble)
   |          ^^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:13:10: error:
    • Ambiguous type variable ‘i00’ arising from a use of ‘~*’
      prevents the constraint ‘(ToSig i00 '["note"])’ from being solved.
      Probable fix: use a type annotation to specify what ‘i00’ should be.
      These potential instances exist:
        instance ToSig Int16 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int32 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int64 args -- Defined in ‘Vivid.SynthDef.ToSig’
        ...plus 9 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block:
        s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
      In the expression:
        sd (0 :: I "note")
          $ do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
               s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
               out 0 [s, s]
   |
13 |     s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V::V "note") ~+ wobble)
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:14:5: error:
    • Ambiguous type variable ‘busNum0’ arising from a use of ‘out’
      prevents the constraint ‘(ToSig
                                  busNum0 '["note"])’ from being solved.
      Probable fix: use a type annotation to specify what ‘busNum0’ should be.
      These potential instances exist:
        instance ToSig Int16 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int32 args -- Defined in ‘Vivid.SynthDef.ToSig’
        instance ToSig Int64 args -- Defined in ‘Vivid.SynthDef.ToSig’
        ...plus 9 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block: out 0 [s, s]
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
      In the expression:
        sd (0 :: I "note")
          $ do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
               s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
               out 0 [s, s]
   |
14 |     out 0 [s,s]
   |     ^^^^^^^^^^^

/home/miguel/Development/Haskell/projects/misc/try-vivid-hsc3/Main.hs:14:9: error:
    • Ambiguous type variable ‘busNum0’ arising from the literal ‘0’
      prevents the constraint ‘(Num busNum0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘busNum0’ should be.
      These potential instances exist:
        instance Num Int16 -- Defined in ‘GHC.Int’
        instance Num Int32 -- Defined in ‘GHC.Int’
        instance Num Int64 -- Defined in ‘GHC.Int’
        ...plus 7 others
        ...plus 7 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘out’, namely ‘0’
      In a stmt of a 'do' block: out 0 [s, s]
      In the second argument of ‘($)’, namely
        ‘do wobble <- sinOsc (freq_ 5) ? KR ~* 10 ~+ 10
            s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V :: V "note") ~+ wobble)
            out 0 [s, s]’
   |
14 |     out 0 [s,s]
   |         ^

--  While building package try-vivid-0.1.0.0 (scroll up to its section to see the error) using:
      /home/miguel/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.4 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0 build exe:try-vivid-exe --ghc-options ""
    Process exited with code: ExitFailure 1

Is it possible to combine messages to call `set` only once?

set has this type:

  (VividAction m, Subset (InnerVars params) sdArgs,
   VarList params) =>
  Synth sdArgs -> params -> m ()
        -- Defined in ‘Vivid.Actions’

Suppose I've got two tuples that satisfy the necessary conditions on params in that type. Is there a way to combine them, so that I only need to call set once?

I ask because I'm using a synth with 31 parameters (and counting ...), and I maintain a map from strings to floats to represent its state. For every such (string,float) pair, I currently have to send it in a separate call to set. I'm getting dropped notes, hung notes and other glitches, and it seems possible that message bandwidth is the problem.

How can I play the example?

• Couldn't match type ‘transformers-0.5.2.0:Control.Monad.Trans.State.Lazy.StateT
                             (Timestamp, Vivid.Actions.NRT.Maximum Timestamp,
                              containers-0.5.10.2:Data.Map.Internal.Map
                                Timestamp [Either ByteString vivid-osc-0.3.0.0:Vivid.OSC.OSC])
                             IO’
                     with ‘IO’
      Expected type: IO ()
        Actual type: NRT ()
    • In a stmt of a 'do' block: playSong
      In the expression:
        do putStrLn "Simplest:"
           playSong
           putStrLn "With precise timing:"

I'm currently getting the above error

Getting Vivid to work with Tidal and SuperDirt

I tried to get Vivid and Tidal + SuperDirt working together based on this post:

http://lurk.org/groups/haskell-art/messages/topic/46bqOK1iOsiMy0fgOWMZa4

import Vivid

let (freq,_) = pI "freq" (Just 440)

defineSD $ sdNamed "foooo" () $ do
   s <- sinOsc (freq_ 440)
   out 0 [s, s]

d1 $ sound "foooo" # freq "400"

But it's not recognised by SuperDirt:

no synth or sample named 'foooo' could be found.
instrument not found: nil
[ "#bundle", 15955788339759360291, 
  [ 12, 1003, 1 ],
  [ 12, 1002, 1 ],
  [ "/g_new", 1103, 1, 2 ],
  [ "/s_new", "dirt_gate2", -1, 1, 1103, "in", 18, "out", 20, "amp", 0.4, "sample", 0, "sustain", 0.999, "fadeInTime", 0, "fadeTime", 0.001 ]
]

Most SuperDirt synths have this kind of format:

(
SynthDef(\foo, { |out, freq = 440|
	blah blah blah
	OffsetOut.ar(out, DirtPan.ar(sound, ~dirt.numChannels, pan, env))
}).add
);

So maybe it's the difference in output destination that's causing the issue?

Would love to get this to work! Thanks for making Vivid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.