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(a)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(a)we.lurk.org
To unsubscribe send an email to livecode-leave(a)we.lurk.org