[livecode] Re: Vivid: How to pass synths around?

From: <amindfv_at_gmail.com>
Date: Tue, 3 Jul 2018 09:36:29 -0400

Hi Jeffrey -- I'm not sure why that's happening. "synth" should always return immediately, and never hang. The SC server is running normally?

Also a couple other quick tips:

  - You might want to add "midiCPS" to your freq arg, so that e.g. notes 45, 46, 47 are each a semitone apart, e.g.:

> (freq_ $ midiCPS (V::V "note"))


  - Since you're calling "readMVar", which is an IO action, you'll want to use "getTime" and "doScheduledAt" to pass around a precise time if you want sample-accurate timing. (Call "t <- getTime" the first time and then e.g. "addSecs 1 t")

Tom

> El 2 jul 2018, a las 23:36, Jeffrey Brown <jeffbrown.the_at_gmail.com> escribió:
>
> I want to create a synth, use it in an IO (), then stop that and use it in a different IO (). I'm close: The following code has the right type signatures, and it compiles:
>
> boop :: SynthDef '["note","amp"]
> boop = sd ( (0 ,0.1 )
> :: (I "note",I "amp")) $ do
> s1 <- (V::V "amp") ~* sinOsc (freq_ (V::V "note"))
> out 0 [s1, s1]
>
> loop :: (Elem "note" sdArgs)
> => MVar Bool -- changing this MVar to False will stop the loop
> -> Node sdArgs
> -> IO () -- would it be better if this was a VividAction?
> loop continue aSynth = do
> c <- readMVar continue
> if c
> then do set aSynth (toI 500 :: I "note")
> wait 0.1
> loop continue aSynth
> else return ()
>
> But in order to call "loop", I've got to give it a synth for its second argument. But if I call "a <- synth boop ()" in open code, I get stuck in some sort of loop:
>
> > a <- synth boop ()
> ^CInterrupted.
> > :t a
>
> <interactive>:1:1: error: Variable not in scope: a
> >
>
> --
> Jeff Brown | Jeffrey Benjamin Brown
> Website | Facebook | LinkedIn(spammy, so I often miss messages here) | Github
> _______________________________________________
> Livecode mailing list -- livecode_at_we.lurk.org
> To unsubscribe send an email to livecode-leave_at_we.lurk.org


_______________________________________________
Livecode mailing list -- livecode_at_we.lurk.org
To unsubscribe send an email to livecode-leave_at_we.lurk.org
Received on Tue Jul 03 2018 - 13:37:06 BST

This archive was generated by hypermail 2.4.0 : Sun Aug 20 2023 - 16:02:23 BST