{-# Language DeriveFunctor #-}
module Csound.Typed.Gui.Widget(
    -- * Panels
    panel, keyPanel, tabs, keyTabs, panels,
    keyPanels, panelBy, keyPanelBy, tabsBy, keyTabsBy,

    -- * Types
    Input, Output, Inner,
    noInput, noOutput, noInner,
    Widget, widget, Source, source, Sink, sink, Display, display, SinkSource, sinkSource, sourceSlice, sinkSlice,
    mapSource, mapGuiSource, mhor, mver, msca,

    -- * Widgets
    count, countSig, joy, knob, roller, slider, sliderBank, numeric, meter, box,
    button, butBank, butBankSig, butBank1, butBankSig1, toggle, toggleSig,
    setNumeric,
    setToggle, setToggleSig, setKnob, setSlider,
    -- * Transformers
    setTitle,
    -- * Keyboard
    KeyEvt(..), Key(..), keyIn
) where

import Control.Arrow
import Control.Monad
import Control.Monad.Trans.Class

import Data.Boolean
import Data.Text (Text)
import Data.Text qualified as Text

import Csound.Dynamic hiding (int, when1)
import qualified Csound.Typed.GlobalState.Elements as C

import Csound.Typed.Gui.Gui
import Csound.Typed.GlobalState
import Csound.Typed.Types hiding (whens)
import Csound.Typed.InnerOpcodes

-- | Renders a list of panels.
panels :: [Gui] -> SE ()
panels :: [Gui] -> SE ()
panels = (Gui -> SE ()) -> [Gui] -> SE ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Gui -> SE ()
panel

-- | Renders a list of panels. Panels are sensitive to keyboard events.
keyPanels :: [Gui] -> SE ()
keyPanels :: [Gui] -> SE ()
keyPanels = (Gui -> SE ()) -> [Gui] -> SE ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Gui -> SE ()
keyPanel

-- | Renders the GUI elements on the window. Rectangle is calculated
-- automatically (window doesn't listens for keyboard events).
panel :: Gui -> SE ()
panel :: Gui -> SE ()
panel = Bool -> Gui -> SE ()
genPanel Bool
False

-- | Renders the GUI elements on the window. Rectangle is calculated
-- automatically (window listens for keyboard events).
keyPanel :: Gui -> SE ()
keyPanel :: Gui -> SE ()
keyPanel = Bool -> Gui -> SE ()
genPanel Bool
True

genPanel :: Bool -> Gui -> SE ()
genPanel :: Bool -> Gui -> SE ()
genPanel Bool
isKeybd Gui
g = GE () -> SE ()
forall a. GE a -> SE a
geToSe (GE () -> SE ()) -> GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ Panel -> GE ()
saveGuiRoot (Panel -> GE ()) -> Panel -> GE ()
forall a b. (a -> b) -> a -> b
$ Win -> Bool -> Panel
Single (Text -> Maybe Rect -> Gui -> Win
Win Text
"" Maybe Rect
forall a. Maybe a
Nothing Gui
g) Bool
isKeybd

-- | Renders the GUI elements with tabs. Rectangles are calculated
-- automatically.
tabs :: [(Text, Gui)] -> SE ()
tabs :: [(Text, Gui)] -> SE ()
tabs = Bool -> [(Text, Gui)] -> SE ()
genTabs Bool
False

-- | Renders the GUI elements with tabs. Rectangles are calculated
-- automatically.
keyTabs :: [(Text, Gui)] -> SE ()
keyTabs :: [(Text, Gui)] -> SE ()
keyTabs = Bool -> [(Text, Gui)] -> SE ()
genTabs Bool
True

genTabs :: Bool -> [(Text, Gui)] -> SE ()
genTabs :: Bool -> [(Text, Gui)] -> SE ()
genTabs Bool
isKey [(Text, Gui)]
xs = GE () -> SE ()
forall a. GE a -> SE a
geToSe (GE () -> SE ()) -> GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ Panel -> GE ()
saveGuiRoot (Panel -> GE ()) -> Panel -> GE ()
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Rect -> [Win] -> Bool -> Panel
Tabs Text
"" Maybe Rect
forall a. Maybe a
Nothing (((Text, Gui) -> Win) -> [(Text, Gui)] -> [Win]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Text
title, Gui
gui) -> Text -> Maybe Rect -> Gui -> Win
Win Text
title Maybe Rect
forall a. Maybe a
Nothing Gui
gui) [(Text, Gui)]
xs) Bool
isKey

-- | Renders the GUI elements on the window. We can specify the window title
-- and rectangle of the window.
panelBy :: Text -> Maybe Rect -> Gui -> SE ()
panelBy :: Text -> Maybe Rect -> Gui -> SE ()
panelBy = Bool -> Text -> Maybe Rect -> Gui -> SE ()
genPanelBy Bool
False

-- | Renders the GUI elements on the window. We can specify the window title
-- and rectangle of the window. Panesls are sensitive to keyboard events.
keyPanelBy :: Text -> Maybe Rect -> Gui -> SE ()
keyPanelBy :: Text -> Maybe Rect -> Gui -> SE ()
keyPanelBy = Bool -> Text -> Maybe Rect -> Gui -> SE ()
genPanelBy Bool
True

genPanelBy :: Bool -> Text -> Maybe Rect -> Gui -> SE ()
genPanelBy :: Bool -> Text -> Maybe Rect -> Gui -> SE ()
genPanelBy Bool
isKeybd Text
title Maybe Rect
mrect Gui
gui = GE () -> SE ()
forall a. GE a -> SE a
geToSe (GE () -> SE ()) -> GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ Panel -> GE ()
saveGuiRoot (Panel -> GE ()) -> Panel -> GE ()
forall a b. (a -> b) -> a -> b
$ Win -> Bool -> Panel
Single (Text -> Maybe Rect -> Gui -> Win
Win Text
title Maybe Rect
mrect Gui
gui) Bool
isKeybd

-- | Renders the GUI elements with tabs. We can specify the window title and
-- rectangles for all tabs and for the main window.
tabsBy :: Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
tabsBy :: Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
tabsBy = Bool -> Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
genTabsBy Bool
False

-- | Renders the GUI elements with tabs. We can specify the window title and
-- rectangles for all tabs and for the main window. Tabs are sensitive to keyboard events.
keyTabsBy :: Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
keyTabsBy :: Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
keyTabsBy = Bool -> Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
genTabsBy Bool
True

genTabsBy :: Bool -> Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
genTabsBy :: Bool -> Text -> Maybe Rect -> [(Text, Maybe Rect, Gui)] -> SE ()
genTabsBy Bool
isKeybd Text
title Maybe Rect
mrect [(Text, Maybe Rect, Gui)]
gui = GE () -> SE ()
forall a. GE a -> SE a
geToSe (GE () -> SE ()) -> GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ Panel -> GE ()
saveGuiRoot (Panel -> GE ()) -> Panel -> GE ()
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Rect -> [Win] -> Bool -> Panel
Tabs Text
title Maybe Rect
mrect (((Text, Maybe Rect, Gui) -> Win)
-> [(Text, Maybe Rect, Gui)] -> [Win]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Text
a, Maybe Rect
b, Gui
c) -> Text -> Maybe Rect -> Gui -> Win
Win Text
a Maybe Rect
b Gui
c) [(Text, Maybe Rect, Gui)]
gui) Bool
isKeybd

-- | Widgets that produce something has inputs.
type Input  a = a

-- | Widgets that consume something has outputs.
type Output a = a -> SE ()

-- | Widgets that just do something inside them or have an inner state.
type Inner    = SE ()

-- | A value for widgets that consume nothing.
noOutput :: Output ()
noOutput :: Output ()
noOutput = Output ()
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return

-- | A value for widgets that produce nothing.
noInput :: Input ()
noInput :: ()
noInput  = ()

-- | A value for stateless widgets.
noInner :: Inner
noInner :: SE ()
noInner = Output ()
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | A widget consists of visible element (Gui), value consumer (Output)
-- and producer (Input) and an inner state (Inner).
type Widget a b = SE (Gui, Output a, Input b, Inner)

-- | A consumer of the values.
type Sink   a = SE (Gui, Output a)

-- | A producer of the values.
type Source a = SE (Gui, Input a)

type SinkSource a = SE (Gui, Output a, Input a)

-- | A static element. We can only look at it.
type Display  = SE Gui

-- | A handy function for transforming the value of producers.
mapSource :: (a -> b) -> Source a -> Source b
mapSource :: forall a b. (a -> b) -> Source a -> Source b
mapSource a -> b
f Source a
x = ((Gui, a) -> (Gui, b)) -> Source a -> SE (Gui, b)
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> (Gui, a) -> (Gui, b)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second a -> b
f) Source a
x

-- | A handy function for transforming the GUIs of producers.
mapGuiSource :: (Gui -> Gui) -> Source a -> Source a
mapGuiSource :: forall a. (Gui -> Gui) -> Source a -> Source a
mapGuiSource Gui -> Gui
f Source a
x = ((Gui, a) -> (Gui, a)) -> Source a -> Source a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Gui
gui, a
ins) -> (Gui -> Gui
f Gui
gui, a
ins)) Source a
x

mGroup :: Monoid a => ([Gui] -> Gui) -> [Source a] -> Source a
mGroup :: forall a. Monoid a => ([Gui] -> Gui) -> [Source a] -> Source a
mGroup [Gui] -> Gui
guiGroup [Source a]
as = do
    ([Gui]
gs, [a]
fs) <- ([(Gui, a)] -> ([Gui], [a])) -> SE [(Gui, a)] -> SE ([Gui], [a])
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Gui, a)] -> ([Gui], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip (SE [(Gui, a)] -> SE ([Gui], [a]))
-> SE [(Gui, a)] -> SE ([Gui], [a])
forall a b. (a -> b) -> a -> b
$ [Source a] -> SE [(Gui, a)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [Source a]
as
    (Gui, a) -> Source a
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Gui] -> Gui
guiGroup [Gui]
gs, [a] -> a
forall a. Monoid a => [a] -> a
mconcat [a]
fs)

-- | Horizontal grouping of widgets that can produce monoidal values.
mhor :: Monoid a => [Source a] -> Source a
mhor :: forall a. Monoid a => [Source a] -> Source a
mhor = ([Gui] -> Gui) -> [Source a] -> Source a
forall a. Monoid a => ([Gui] -> Gui) -> [Source a] -> Source a
mGroup [Gui] -> Gui
hor

-- | Vertical grouping of widgets that can produce monoidal values.
mver :: Monoid a => [Source a] -> Source a
mver :: forall a. Monoid a => [Source a] -> Source a
mver = ([Gui] -> Gui) -> [Source a] -> Source a
forall a. Monoid a => ([Gui] -> Gui) -> [Source a] -> Source a
mGroup [Gui] -> Gui
ver

-- | Scaling of widgets that can produce values.
msca :: Double -> Source a -> Source a
msca :: forall a. Double -> Source a -> Source a
msca Double
d = (Gui -> Gui) -> Source (Input a) -> Source (Input a)
forall a. (Gui -> Gui) -> Source a -> Source a
mapGuiSource (Double -> Gui -> Gui
sca Double
d)

-- | A widget constructor.
widget :: SE (Gui, Output a, Input b, Inner) -> Widget a b
widget :: forall a b.
SE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
widget SE (Gui, Output a, Input b, SE ())
x = (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
forall a b. (Gui, Output a, Input b, SE ()) -> Widget a (Input b)
go ((Gui, Output a, Input b, SE ())
 -> SE (Gui, Output a, Input b, SE ()))
-> SE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< SE (Gui, Output a, Input b, SE ())
x
    where
        go :: (Gui, Output a, Input b, Inner) -> Widget a b
        go :: forall a b. (Gui, Output a, Input b, SE ()) -> Widget a (Input b)
go (Gui
gui, Output a
outs, Input b
ins, SE ()
inner) = GE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
forall a. GE a -> SE a
geToSe (GE (Gui, Output a, Input b, SE ())
 -> SE (Gui, Output a, Input b, SE ()))
-> GE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
forall a b. (a -> b) -> a -> b
$ do
            GuiHandle
handle <- GE GuiHandle
newGuiHandle
            GuiNode -> DepT GE () -> GE ()
appendToGui (Gui -> GuiHandle -> GuiNode
GuiNode Gui
gui GuiHandle
handle) (SE () -> DepT GE ()
forall a. SE a -> Dep a
unSE SE ()
inner)
            (Gui, Output a, Input b, SE ())
-> GE (Gui, Output a, Input b, SE ())
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (GuiHandle -> Gui
fromGuiHandle GuiHandle
handle, Output a
outs, Input b
ins, SE ()
inner)

-- | A producer constructor.
source :: SE (Gui, Input a) -> Source a
source :: forall a. SE (Gui, Input a) -> SE (Gui, Input a)
source SE (Gui, Input a)
x = ((Gui, Output (), Input a, SE ()) -> (Gui, Input a))
-> SE (Gui, Output (), Input a, SE ()) -> SE (Gui, Input a)
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Output (), Input a, SE ()) -> (Gui, Input a)
forall {a} {b} {b} {d}. (a, b, b, d) -> (a, b)
select (SE (Gui, Output (), Input a, SE ()) -> SE (Gui, Input a))
-> SE (Gui, Output (), Input a, SE ()) -> SE (Gui, Input a)
forall a b. (a -> b) -> a -> b
$ SE (Gui, Output (), Input a, SE ())
-> SE (Gui, Output (), Input a, SE ())
forall a b.
SE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
widget (SE (Gui, Output (), Input a, SE ())
 -> SE (Gui, Output (), Input a, SE ()))
-> SE (Gui, Output (), Input a, SE ())
-> SE (Gui, Output (), Input a, SE ())
forall a b. (a -> b) -> a -> b
$ ((Gui, Input a) -> (Gui, Output (), Input a, SE ()))
-> SE (Gui, Input a) -> SE (Gui, Output (), Input a, SE ())
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Input a) -> (Gui, Output (), Input a, SE ())
forall {a} {c}. (a, c) -> (a, Output (), c, SE ())
append SE (Gui, Input a)
x
    where
        select :: (a, b, b, d) -> (a, b)
select (a
g, b
_, b
i, d
_) = (a
g, b
i)
        append :: (a, c) -> (a, Output (), c, SE ())
append (a
g, c
i) = (a
g, Output ()
noOutput, c
i, SE ()
noInner)

-- | A consumer constructor.
sink :: SE (Gui, Output a) -> Sink a
sink :: forall a. SE (Gui, Output a) -> SE (Gui, Output a)
sink SE (Gui, Output a)
x = ((Gui, Output a, (), SE ()) -> (Gui, Output a))
-> SE (Gui, Output a, (), SE ()) -> SE (Gui, Output a)
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Output a, (), SE ()) -> (Gui, Output a)
forall {a} {b} {c} {d}. (a, b, c, d) -> (a, b)
select (SE (Gui, Output a, (), SE ()) -> SE (Gui, Output a))
-> SE (Gui, Output a, (), SE ()) -> SE (Gui, Output a)
forall a b. (a -> b) -> a -> b
$ SE (Gui, Output a, (), SE ()) -> SE (Gui, Output a, (), SE ())
forall a b.
SE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
widget (SE (Gui, Output a, (), SE ()) -> SE (Gui, Output a, (), SE ()))
-> SE (Gui, Output a, (), SE ()) -> SE (Gui, Output a, (), SE ())
forall a b. (a -> b) -> a -> b
$ ((Gui, Output a) -> (Gui, Output a, (), SE ()))
-> SE (Gui, Output a) -> SE (Gui, Output a, (), SE ())
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Output a) -> (Gui, Output a, (), SE ())
forall {a} {b}. (a, b) -> (a, b, (), SE ())
append SE (Gui, Output a)
x
    where
        select :: (a, b, c, d) -> (a, b)
select (a
g, b
o, c
_, d
_) = (a
g, b
o)
        append :: (a, b) -> (a, b, (), SE ())
append (a
g, b
o) = (a
g, b
o, ()
noInput, SE ()
noInner)

sinkSource :: SE (Gui, Output a, Input a) -> SinkSource a
sinkSource :: forall a. SE (Gui, Output a, a) -> SE (Gui, Output a, a)
sinkSource SE (Gui, Output a, a)
x = ((Gui, Output a, a, SE ()) -> (Gui, Output a, a))
-> SE (Gui, Output a, a, SE ()) -> SE (Gui, Output a, a)
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Output a, a, SE ()) -> (Gui, Output a, a)
forall {a} {b} {c} {d}. (a, b, c, d) -> (a, b, c)
select (SE (Gui, Output a, a, SE ()) -> SE (Gui, Output a, a))
-> SE (Gui, Output a, a, SE ()) -> SE (Gui, Output a, a)
forall a b. (a -> b) -> a -> b
$ SE (Gui, Output a, a, SE ()) -> SE (Gui, Output a, a, SE ())
forall a b.
SE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
widget (SE (Gui, Output a, a, SE ()) -> SE (Gui, Output a, a, SE ()))
-> SE (Gui, Output a, a, SE ()) -> SE (Gui, Output a, a, SE ())
forall a b. (a -> b) -> a -> b
$ ((Gui, Output a, a) -> (Gui, Output a, a, SE ()))
-> SE (Gui, Output a, a) -> SE (Gui, Output a, a, SE ())
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Output a, a) -> (Gui, Output a, a, SE ())
forall {a} {b} {c}. (a, b, c) -> (a, b, c, SE ())
append SE (Gui, Output a, a)
x
    where
        select :: (a, b, c, d) -> (a, b, c)
select (a
g, b
o, c
i, d
_) = (a
g, b
o, c
i)
        append :: (a, b, c) -> (a, b, c, SE ())
append (a
g, b
o, c
i) = (a
g, b
o, c
i, SE ()
noInner)

-- | A display constructor.
display :: SE Gui -> Display
display :: SE Gui -> SE Gui
display SE Gui
x = ((Gui, Output (), (), SE ()) -> Gui)
-> SE (Gui, Output (), (), SE ()) -> SE Gui
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Gui, Output (), (), SE ()) -> Gui
forall {a} {b} {c} {d}. (a, b, c, d) -> a
select (SE (Gui, Output (), (), SE ()) -> SE Gui)
-> SE (Gui, Output (), (), SE ()) -> SE Gui
forall a b. (a -> b) -> a -> b
$ SE (Gui, Output (), (), SE ()) -> SE (Gui, Output (), (), SE ())
forall a b.
SE (Gui, Output a, Input b, SE ())
-> SE (Gui, Output a, Input b, SE ())
widget (SE (Gui, Output (), (), SE ()) -> SE (Gui, Output (), (), SE ()))
-> SE (Gui, Output (), (), SE ()) -> SE (Gui, Output (), (), SE ())
forall a b. (a -> b) -> a -> b
$ (Gui -> (Gui, Output (), (), SE ()))
-> SE Gui -> SE (Gui, Output (), (), SE ())
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Gui -> (Gui, Output (), (), SE ())
forall {a}. a -> (a, Output (), (), SE ())
append SE Gui
x
    where
        select :: (a, b, c, d) -> a
select (a
g, b
_, c
_, d
_) = a
g
        append :: a -> (a, Output (), (), SE ())
append a
g = (a
g, Output ()
noOutput, ()
noInput, SE ()
noInner)

-----------------------------------------------------------------------------
-- primitive elements

-- | Appends a title to a group of widgets.
setTitle :: Text -> Gui -> SE Gui
setTitle :: Text -> Gui -> SE Gui
setTitle Text
name Gui
g
    | Text -> Bool
Text.null Text
name = Gui -> SE Gui
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return Gui
g
    | Bool
otherwise = do
        Gui
gTitle <- Text -> SE Gui
box Text
name
        Gui -> SE Gui
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Gui -> SE Gui) -> Gui -> SE Gui
forall a b. (a -> b) -> a -> b
$ [Gui] -> Gui
ver [Double -> Gui -> Gui
sca Double
0.01 Gui
gTitle, Gui
g]

setSourceTitle :: Text -> Source a -> Source a
setSourceTitle :: forall a. Text -> Source a -> Source a
setSourceTitle Text
name Source a
ma = Source a -> Source a
forall a. SE (Gui, Input a) -> SE (Gui, Input a)
source (Source a -> Source a) -> Source a -> Source a
forall a b. (a -> b) -> a -> b
$ do
    (Gui
gui, a
val) <- Source a
ma
    Gui
newGui <- Text -> Gui -> SE Gui
setTitle Text
name Gui
gui
    (Gui, a) -> Source a
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Gui
newGui, a
val)

setLabelSource :: Text -> Source a -> Source a
setLabelSource :: forall a. Text -> Source a -> Source a
setLabelSource Text
a
    | Text -> Bool
Text.null Text
a    = Source a -> Source a
forall a. a -> a
id
    | Bool
otherwise = ((Gui, a) -> (Gui, a)) -> Source a -> Source a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Gui -> Gui) -> (Gui, a) -> (Gui, a)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Gui -> Gui) -> (Gui, a) -> (Gui, a))
-> (Gui -> Gui) -> (Gui, a) -> (Gui, a)
forall a b. (a -> b) -> a -> b
$ Text -> Gui -> Gui
setLabel Text
a)

setLabelSink :: Text -> Sink a -> Sink a
setLabelSink :: forall a. Text -> Sink a -> Sink a
setLabelSink Text
a
    | Text -> Bool
Text.null Text
a = Sink a -> Sink a
forall a. a -> a
id
    | Bool
otherwise = ((Gui, Output a) -> (Gui, Output a)) -> Sink a -> Sink a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Gui -> Gui) -> (Gui, Output a) -> (Gui, Output a)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Gui -> Gui) -> (Gui, Output a) -> (Gui, Output a))
-> (Gui -> Gui) -> (Gui, Output a) -> (Gui, Output a)
forall a b. (a -> b) -> a -> b
$ Text -> Gui -> Gui
setLabel Text
a)

setLabelSnkSource :: Text -> SinkSource a -> SinkSource a
setLabelSnkSource :: forall a. Text -> SinkSource a -> SinkSource a
setLabelSnkSource Text
a
    | Text -> Bool
Text.null Text
a = SinkSource a -> SinkSource a
forall a. a -> a
id
    | Bool
otherwise   = ((Gui, Output a, a) -> (Gui, Output a, a))
-> SinkSource a -> SinkSource a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Gui
x, Output a
y, a
z) -> (Text -> Gui -> Gui
setLabel Text
a Gui
x, Output a
y, a
z))

singleOut :: Maybe Double -> Elem -> Source Sig
singleOut :: Maybe Double -> Elem -> Source Sig
singleOut Maybe Double
v0 Elem
el = GE (Gui, Sig) -> Source Sig
forall a. GE a -> SE a
geToSe (GE (Gui, Sig) -> Source Sig) -> GE (Gui, Sig) -> Source Sig
forall a b. (a -> b) -> a -> b
$ do
    (Var
var, GuiHandle
handle) <- GE (Var, GuiHandle)
newGuiVar
    let handleVar :: Var
handleVar = GuiHandle -> Var
guiHandleToVar GuiHandle
handle
        inits :: [InitMe]
inits = [InitMe] -> (Double -> [InitMe]) -> Maybe Double -> [InitMe]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (InitMe -> [InitMe]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (InitMe -> [InitMe]) -> (Double -> InitMe) -> Double -> [InitMe]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Double -> InitMe
InitMe Var
handleVar) Maybe Double
v0
        gui :: Gui
gui = ElemOuts -> [InitMe] -> Elem -> Gui
fromElem [Var
var, Var
handleVar] [InitMe]
inits Elem
el
    GuiNode -> DepT GE () -> GE ()
appendToGui (Gui -> GuiHandle -> GuiNode
GuiNode Gui
gui GuiHandle
handle) (SE () -> DepT GE ()
forall a. SE a -> Dep a
unSE SE ()
noInner)
    (Gui, Sig) -> GE (Gui, Sig)
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (GuiHandle -> Gui
fromGuiHandle GuiHandle
handle, Var -> Sig
readSig Var
var)

singleIn :: (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> Sink Sig
singleIn :: (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> Sink Sig
singleIn GuiHandle -> Output Sig
outs Maybe Double
v0 Elem
el = GE (Gui, Output Sig) -> Sink Sig
forall a. GE a -> SE a
geToSe (GE (Gui, Output Sig) -> Sink Sig)
-> GE (Gui, Output Sig) -> Sink Sig
forall a b. (a -> b) -> a -> b
$ do
    (Var
var, GuiHandle
handle) <- GE (Var, GuiHandle)
newGuiVar
    let handleVar :: Var
handleVar = GuiHandle -> Var
guiHandleToVar GuiHandle
handle
        inits :: [InitMe]
inits = [InitMe] -> (Double -> [InitMe]) -> Maybe Double -> [InitMe]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (InitMe -> [InitMe]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (InitMe -> [InitMe]) -> (Double -> InitMe) -> Double -> [InitMe]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Double -> InitMe
InitMe Var
handleVar) Maybe Double
v0
        gui :: Gui
gui = ElemOuts -> [InitMe] -> Elem -> Gui
fromElem [Var
var, Var
handleVar] [InitMe]
inits Elem
el
    GuiNode -> DepT GE () -> GE ()
appendToGui (Gui -> GuiHandle -> GuiNode
GuiNode Gui
gui GuiHandle
handle) (SE () -> DepT GE ()
forall a. SE a -> Dep a
unSE SE ()
noInner)
    (Gui, Output Sig) -> GE (Gui, Output Sig)
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (GuiHandle -> Gui
fromGuiHandle GuiHandle
handle, GuiHandle -> Output Sig
outs GuiHandle
handle)

singleInOut :: (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> SinkSource Sig
singleInOut :: (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> SinkSource Sig
singleInOut GuiHandle -> Output Sig
outs Maybe Double
v0 Elem
el = GE (Gui, Output Sig, Sig) -> SinkSource Sig
forall a. GE a -> SE a
geToSe (GE (Gui, Output Sig, Sig) -> SinkSource Sig)
-> GE (Gui, Output Sig, Sig) -> SinkSource Sig
forall a b. (a -> b) -> a -> b
$ do
    (Var
var, GuiHandle
handle) <- GE (Var, GuiHandle)
newGuiVar
    let handleVar :: Var
handleVar = GuiHandle -> Var
guiHandleToVar GuiHandle
handle
        inits :: [InitMe]
inits = [InitMe] -> (Double -> [InitMe]) -> Maybe Double -> [InitMe]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (InitMe -> [InitMe]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (InitMe -> [InitMe]) -> (Double -> InitMe) -> Double -> [InitMe]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Double -> InitMe
InitMe Var
handleVar) Maybe Double
v0
        gui :: Gui
gui = ElemOuts -> [InitMe] -> Elem -> Gui
fromElem [Var
var, Var
handleVar] [InitMe]
inits Elem
el
    GuiNode -> DepT GE () -> GE ()
appendToGui (Gui -> GuiHandle -> GuiNode
GuiNode Gui
gui GuiHandle
handle) (SE () -> DepT GE ()
forall a. SE a -> Dep a
unSE SE ()
noInner)
    (Gui, Output Sig, Sig) -> GE (Gui, Output Sig, Sig)
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (GuiHandle -> Gui
fromGuiHandle GuiHandle
handle, GuiHandle -> Output Sig
outs GuiHandle
handle, Var -> Sig
readSig Var
var)

-- | A variance on the function 'Csound.Gui.Widget.count', but it produces
-- a signal of piecewise constant function.
countSig :: ValDiap -> ValStep -> Maybe ValStep -> Double -> Source Sig
countSig :: ValDiap -> Double -> Maybe Double -> Double -> Source Sig
countSig ValDiap
diap Double
step1 Maybe Double
mValStep2 Double
v0 = Maybe Double -> Elem -> Source Sig
singleOut (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> Source Sig) -> Elem -> Source Sig
forall a b. (a -> b) -> a -> b
$ ValDiap -> Double -> Maybe Double -> Elem
Count ValDiap
diap Double
step1 Maybe Double
mValStep2

-- | Allows the user to increase/decrease a value with mouse
-- clicks on a corresponding arrow button. Output is an event stream that contains
-- values when counter changes.
--
-- > count diapason fineValStep maybeCoarseValStep initValue
--
-- doc: http://www.csounds.com/manual/html/FLcount.html
count :: ValDiap -> ValStep -> Maybe ValStep -> Double -> Source (Evt D)
count :: ValDiap -> Double -> Maybe Double -> Double -> Source (Evt D)
count ValDiap
diap Double
step1 Maybe Double
mValStep2 Double
v0 = (Sig -> Evt D) -> Source Sig -> Source (Evt D)
forall a b. (a -> b) -> Source a -> Source b
mapSource Sig -> Evt D
snaps (Source Sig -> Source (Evt D)) -> Source Sig -> Source (Evt D)
forall a b. (a -> b) -> a -> b
$ ValDiap -> Double -> Maybe Double -> Double -> Source Sig
countSig ValDiap
diap Double
step1 Maybe Double
mValStep2 Double
v0

-- | It is a squared area that allows the user to modify two output values
-- at the same time. It acts like a joystick.
--
-- > joy valueSpanX valueSpanY (initX, initY)
--
-- doc: <http://www.csounds.com/manual/html/FLjoy.html>
joy :: ValSpan -> ValSpan -> (Double, Double) -> Source (Sig, Sig)
joy :: ValSpan -> ValSpan -> (Double, Double) -> Source (Sig, Sig)
joy ValSpan
sp1 ValSpan
sp2 (Double
x, Double
y) = GE (Gui, (Sig, Sig)) -> Source (Sig, Sig)
forall a. GE a -> SE a
geToSe (GE (Gui, (Sig, Sig)) -> Source (Sig, Sig))
-> GE (Gui, (Sig, Sig)) -> Source (Sig, Sig)
forall a b. (a -> b) -> a -> b
$ do
    (Var
var1, GuiHandle
handle1) <- GE (Var, GuiHandle)
newGuiVar
    (Var
var2, GuiHandle
handle2) <- GE (Var, GuiHandle)
newGuiVar
    let handleVar1 :: Var
handleVar1 = GuiHandle -> Var
guiHandleToVar GuiHandle
handle1
        handleVar2 :: Var
handleVar2 = GuiHandle -> Var
guiHandleToVar GuiHandle
handle2
        outs :: ElemOuts
outs  = [Var
var1, Var
var2, Var
handleVar1, Var
handleVar2]
        inits :: [InitMe]
inits = [Var -> Double -> InitMe
InitMe Var
handleVar1 Double
x, Var -> Double -> InitMe
InitMe Var
handleVar2 Double
y]
        gui :: Gui
gui   = ElemOuts -> [InitMe] -> Elem -> Gui
fromElem ElemOuts
outs [InitMe]
inits (ValSpan -> ValSpan -> Elem
Joy ValSpan
sp1 ValSpan
sp2)
    GuiNode -> DepT GE () -> GE ()
appendToGui (Gui -> GuiHandle -> GuiNode
GuiNode Gui
gui GuiHandle
handle1) (SE () -> DepT GE ()
forall a. SE a -> Dep a
unSE SE ()
noInner)
    (Gui, (Sig, Sig)) -> GE (Gui, (Sig, Sig))
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return ( GuiHandle -> Gui
fromGuiHandle GuiHandle
handle1, (Var -> Sig
readSig Var
var1, Var -> Sig
readSig Var
var2))

-- | A FLTK widget opcode that creates a knob.
--
-- > knob valueSpan initValue
--
-- doc: <http://www.csounds.com/manual/html/FLknob.html>
knob :: Text -> ValSpan -> Double -> Source Sig
knob :: Text -> ValSpan -> Double -> Source Sig
knob Text
name ValSpan
sp Double
v0 = Text -> Source Sig -> Source Sig
forall a. Text -> Source a -> Source a
setLabelSource Text
name (Source Sig -> Source Sig) -> Source Sig -> Source Sig
forall a b. (a -> b) -> a -> b
$ Maybe Double -> Elem -> Source Sig
singleOut (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> Source Sig) -> Elem -> Source Sig
forall a b. (a -> b) -> a -> b
$ ValSpan -> Elem
Knob ValSpan
sp

-- | FLroller is a sort of knob, but put transversally.
--
-- > roller valueSpan step initVal
--
-- doc: <http://www.csounds.com/manual/html/FLroller.html>
roller :: Text -> ValSpan -> ValStep -> Double -> Source Sig
roller :: Text -> ValSpan -> Double -> Double -> Source Sig
roller Text
name ValSpan
sp Double
step Double
v0 = Text -> Source Sig -> Source Sig
forall a. Text -> Source a -> Source a
setLabelSource Text
name (Source Sig -> Source Sig) -> Source Sig -> Source Sig
forall a b. (a -> b) -> a -> b
$ Maybe Double -> Elem -> Source Sig
singleOut (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> Source Sig) -> Elem -> Source Sig
forall a b. (a -> b) -> a -> b
$ ValSpan -> Double -> Elem
Roller ValSpan
sp Double
step

-- | FLslider puts a slider into the corresponding container.
--
-- > slider valueSpan initVal
--
-- doc: <http://www.csounds.com/manual/html/FLslider.html>
slider :: Text -> ValSpan -> Double -> Source Sig
slider :: Text -> ValSpan -> Double -> Source Sig
slider Text
name ValSpan
sp Double
v0 = Text -> Source Sig -> Source Sig
forall a. Text -> Source a -> Source a
setLabelSource Text
name (Source Sig -> Source Sig) -> Source Sig -> Source Sig
forall a b. (a -> b) -> a -> b
$ Maybe Double -> Elem -> Source Sig
singleOut (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> Source Sig) -> Elem -> Source Sig
forall a b. (a -> b) -> a -> b
$ ValSpan -> Elem
Slider ValSpan
sp

-- | Constructs a list of linear unit sliders (ranges in [0, 1]). It takes a list
-- of init values.
sliderBank :: Text -> [Double] -> Source [Sig]
sliderBank :: Text -> [Double] -> Source [Sig]
sliderBank Text
name [Double]
ds = Source [Sig] -> Source [Sig]
forall a. SE (Gui, Input a) -> SE (Gui, Input a)
source (Source [Sig] -> Source [Sig]) -> Source [Sig] -> Source [Sig]
forall a b. (a -> b) -> a -> b
$ do
    ([Gui]
gs, [Sig]
vs) <- ([(Gui, Sig)] -> ([Gui], [Sig]))
-> SE [(Gui, Sig)] -> SE ([Gui], [Sig])
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Gui, Sig)] -> ([Gui], [Sig])
forall a b. [(a, b)] -> ([a], [b])
unzip (SE [(Gui, Sig)] -> SE ([Gui], [Sig]))
-> SE [(Gui, Sig)] -> SE ([Gui], [Sig])
forall a b. (a -> b) -> a -> b
$ (Int -> Double -> Source Sig)
-> [Int] -> [Double] -> SE [(Gui, Sig)]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (\Int
n Double
d -> Text -> ValSpan -> Double -> Source Sig
slider (String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Int -> String
forall a. Show a => a -> String
show Int
n) ValSpan
uspan Double
d) [(Int
1::Int) ..] [Double]
ds
    Gui
gui <- Text -> Gui -> SE Gui
setTitle Text
name  (Gui -> SE Gui) -> Gui -> SE Gui
forall a b. (a -> b) -> a -> b
$ [Gui] -> Gui
hor [Gui]
gs
    (Gui, [Sig]) -> Source [Sig]
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Gui
gui, [Sig]
vs)

-- | numeric (originally FLtext in the Csound) allows the user to modify
-- a parameter value by directly typing it into a text field.
--
-- > numeric diapason step initValue
--
-- doc: <http://www.csounds.com/manual/html/FLtext.html>
numeric :: Text -> ValDiap -> ValStep -> Double -> Source Sig
numeric :: Text -> ValDiap -> Double -> Double -> Source Sig
numeric Text
name ValDiap
diap Double
step Double
v0 = Text -> Source Sig -> Source Sig
forall a. Text -> Source a -> Source a
setLabelSource Text
name (Source Sig -> Source Sig) -> Source Sig -> Source Sig
forall a b. (a -> b) -> a -> b
$ Maybe Double -> Elem -> Source Sig
singleOut (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> Source Sig) -> Elem -> Source Sig
forall a b. (a -> b) -> a -> b
$ ValDiap -> Double -> Elem
Text ValDiap
diap Double
step

-- | A FLTK widget that displays text inside of a box.
-- If the text is longer than 255 characters the text
-- is split on several parts (Csound limitations).
--
-- > box text
--
-- doc: <http://www.csounds.com/manual/html/FLbox.html>
box :: Text -> Display
box :: Text -> SE Gui
box Text
label
    | Text -> Int
Text.length Text
label Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
lim = Text -> SE Gui
rawBox Text
label
    | Bool
otherwise               = ([Gui] -> Gui) -> SE [Gui] -> SE Gui
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Gui -> Gui
padding Int
0 (Gui -> Gui) -> ([Gui] -> Gui) -> [Gui] -> Gui
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Gui] -> Gui
ver) (SE [Gui] -> SE Gui) -> SE [Gui] -> SE Gui
forall a b. (a -> b) -> a -> b
$ (Text -> SE Gui) -> [Text] -> SE [Gui]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Text -> SE Gui
rawBox ([Text] -> SE [Gui]) -> [Text] -> SE [Gui]
forall a b. (a -> b) -> a -> b
$ Int -> Text -> [Text]
parts Int
lim Text
label
    where
        parts :: Int -> Text -> [Text]
parts Int
n Text
xs
            | Text -> Int
Text.length Text
xs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n = [Text
xs]
            | Bool
otherwise     = Text
a Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: Int -> Text -> [Text]
parts Int
n Text
b
            where (Text
a, Text
b) = Int -> Text -> (Text, Text)
Text.splitAt Int
n Text
xs
        lim :: Int
lim = Int
255

rawBox :: Text -> Display
rawBox :: Text -> SE Gui
rawBox Text
label = GE Gui -> SE Gui
forall a. GE a -> SE a
geToSe (GE Gui -> SE Gui) -> GE Gui -> SE Gui
forall a b. (a -> b) -> a -> b
$ do
    (Var
_, GuiHandle
handle) <- GE (Var, GuiHandle)
newGuiVar
    let gui :: Gui
gui = ElemOuts -> [InitMe] -> Elem -> Gui
fromElem [GuiHandle -> Var
guiHandleToVar GuiHandle
handle] [] (Text -> Elem
Box Text
label)
    GuiNode -> DepT GE () -> GE ()
appendToGui (Gui -> GuiHandle -> GuiNode
GuiNode Gui
gui GuiHandle
handle) (SE () -> DepT GE ()
forall a. SE a -> Dep a
unSE SE ()
noInner)
    Gui -> GE Gui
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Gui -> GE Gui) -> Gui -> GE Gui
forall a b. (a -> b) -> a -> b
$ GuiHandle -> Gui
fromGuiHandle GuiHandle
handle

-- | A FLTK widget opcode that creates a button.
--
-- > button text
--
-- doc: <http://www.csounds.com/manual/html/FLbutton.html>
button :: Text -> Source (Evt Unit)
button :: Text -> Source (Evt Unit)
button Text
name = Text -> Source (Evt Unit) -> Source (Evt Unit)
forall a. Text -> Source a -> Source a
setLabelSource Text
name (Source (Evt Unit) -> Source (Evt Unit))
-> Source (Evt Unit) -> Source (Evt Unit)
forall a b. (a -> b) -> a -> b
$ Source (Evt Unit) -> Source (Evt Unit)
forall a. SE (Gui, Input a) -> SE (Gui, Input a)
source (Source (Evt Unit) -> Source (Evt Unit))
-> Source (Evt Unit) -> Source (Evt Unit)
forall a b. (a -> b) -> a -> b
$ do
    Var
flag <- GE Var -> SE Var
forall a. GE a -> SE a
geToSe (GE Var -> SE Var) -> GE Var -> SE Var
forall a b. (a -> b) -> a -> b
$ UpdField Globals Var
forall a. UpdField Globals a
onGlobals UpdField Globals Var -> UpdField Globals Var
forall a b. (a -> b) -> a -> b
$ Rate -> E -> State Globals Var
C.newPersistentGlobalVar Rate
Kr E
0
    Var
flagChanged <- GE Var -> SE Var
forall a. GE a -> SE a
geToSe (GE Var -> SE Var) -> GE Var -> SE Var
forall a b. (a -> b) -> a -> b
$ UpdField Globals Var
forall a. UpdField Globals a
onGlobals UpdField Globals Var -> UpdField Globals Var
forall a b. (a -> b) -> a -> b
$ Rate -> E -> State Globals Var
C.newPersistentGlobalVar Rate
Kr E
0
    InstrId
instrId <- GE InstrId -> SE InstrId
forall a. GE a -> SE a
geToSe (GE InstrId -> SE InstrId) -> GE InstrId -> SE InstrId
forall a b. (a -> b) -> a -> b
$ SE () -> GE InstrId
saveInstr (SE () -> GE InstrId) -> SE () -> GE InstrId
forall a b. (a -> b) -> a -> b
$ Var -> SE ()
instr Var
flag
    GE () -> SE ()
forall a. GE a -> SE a
geToSe (GE () -> SE ()) -> GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ (InstrId -> GE ()
saveAlwaysOnInstr (InstrId -> GE ()) -> GE InstrId -> GE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ) (GE InstrId -> GE ()) -> GE InstrId -> GE ()
forall a b. (a -> b) -> a -> b
$ SE () -> GE InstrId
saveInstr (SE () -> GE InstrId) -> SE () -> GE InstrId
forall a b. (a -> b) -> a -> b
$ Var -> Var -> SE ()
instrCh Var
flag Var
flagChanged
    (Gui
g, Sig
_) <- Maybe Double -> Elem -> Source Sig
singleOut Maybe Double
forall a. Maybe a
Nothing (InstrId -> Elem
Button InstrId
instrId)
    Sig
val <- (GE E -> Sig) -> SE (GE E) -> SE Sig
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GE E -> Sig
forall a. Val a => GE E -> a
fromGE (SE (GE E) -> SE Sig) -> SE (GE E) -> SE Sig
forall a b. (a -> b) -> a -> b
$ Dep E -> SE (GE E)
forall a. Dep a -> SE (GE a)
fromDep (Dep E -> SE (GE E)) -> Dep E -> SE (GE E)
forall a b. (a -> b) -> a -> b
$ Var -> Dep E
forall (m :: * -> *). Monad m => Var -> DepT m E
readVar Var
flagChanged
    (Gui, Evt Unit) -> Source (Evt Unit)
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Gui
g, Sig -> Evt Unit
sigToEvt Sig
val)
    where
        instr :: Var -> SE ()
instr Var
ref = DepT GE () -> SE ()
forall a. Dep a -> SE a
SE (DepT GE () -> SE ()) -> DepT GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ do
            E
val <- Var -> Dep E
forall (m :: * -> *). Monad m => Var -> DepT m E
readVar Var
ref
            IfRate
-> [(E, DepT GE (CodeBlock E))]
-> DepT GE (CodeBlock E)
-> DepT GE ()
forall (m :: * -> *).
Monad m =>
IfRate
-> [(E, DepT m (CodeBlock E))] -> DepT m (CodeBlock E) -> DepT m ()
whens IfRate
IfKr
                [ (E
val E -> E -> E
forall bool. (bool ~ BooleanOf E) => E -> E -> bool
forall a bool. (EqB a, bool ~ BooleanOf a) => a -> a -> bool
==* E
0, DepT GE () -> DepT GE (CodeBlock E)
forall (m :: * -> *). Monad m => DepT m () -> DepT m (CodeBlock E)
toBlock (DepT GE () -> DepT GE (CodeBlock E))
-> DepT GE () -> DepT GE (CodeBlock E)
forall a b. (a -> b) -> a -> b
$ Var -> E -> DepT GE ()
forall (m :: * -> *). Monad m => Var -> E -> DepT m ()
writeVar Var
ref E
1)
                ] (DepT GE () -> DepT GE (CodeBlock E)
forall (m :: * -> *). Monad m => DepT m () -> DepT m (CodeBlock E)
toBlock (DepT GE () -> DepT GE (CodeBlock E))
-> DepT GE () -> DepT GE (CodeBlock E)
forall a b. (a -> b) -> a -> b
$ Var -> E -> DepT GE ()
forall (m :: * -> *). Monad m => Var -> E -> DepT m ()
writeVar Var
ref E
0)
            DepT GE ()
forall (m :: * -> *). Monad m => DepT m ()
turnoff

        instrCh :: Var -> Var -> SE ()
instrCh Var
ref Var
refCh = DepT GE () -> SE ()
forall a. Dep a -> SE a
SE (DepT GE () -> SE ()) -> DepT GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ do
            E
val <- Var -> Dep E
forall (m :: * -> *). Monad m => Var -> DepT m E
readVar Var
ref
            Var -> E -> DepT GE ()
forall (m :: * -> *). Monad m => Var -> E -> DepT m ()
writeVar Var
refCh (E -> E
C.changed E
val)

-- | A FLTK widget opcode that creates a toggle button.
--
-- > button text
--
-- doc: <http://www.csounds.com/manual/html/FLbutton.html>
toggle :: Text -> Bool -> Source (Evt D)
toggle :: Text -> Bool -> Source (Evt D)
toggle Text
name Bool
initVal = (Sig -> Evt D) -> Source Sig -> Source (Evt D)
forall a b. (a -> b) -> Source a -> Source b
mapSource Sig -> Evt D
snaps (Source Sig -> Source (Evt D)) -> Source Sig -> Source (Evt D)
forall a b. (a -> b) -> a -> b
$ Text -> Bool -> Source Sig
toggleSig Text
name Bool
initVal

-- | A variance on the function 'Csound.Gui.Widget.toggle', but it produces
-- a signal of piecewise constant function.
toggleSig :: Text -> Bool -> Source Sig
toggleSig :: Text -> Bool -> Source Sig
toggleSig Text
name Bool
initVal = Text -> Source Sig -> Source Sig
forall a. Text -> Source a -> Source a
setLabelSource Text
name (Source Sig -> Source Sig) -> Source Sig -> Source Sig
forall a b. (a -> b) -> a -> b
$ Maybe Double -> Elem -> Source Sig
singleOut (Bool -> Maybe Double
initToggle Bool
initVal) Elem
Toggle

initToggle :: Bool -> Maybe Double
initToggle :: Bool -> Maybe Double
initToggle Bool
a = if Bool
a then (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
1) else Maybe Double
forall a. Maybe a
Nothing

-- | A FLTK widget opcode that creates a bank of buttons.
-- Result is (x, y) coordinate of the triggered button.
--
-- > butBank xNumOfButtons yNumOfButtons
--
-- doc: <http://www.csounds.com/manual/html/FLbutBank.html>
butBank :: Text -> Int -> Int -> (Int, Int) -> Source (Evt (D, D))
butBank :: Text -> Int -> Int -> (Int, Int) -> Source (Evt (D, D))
butBank Text
name Int
xn Int
yn (Int, Int)
inits = (Sig -> Evt (D, D)) -> Source Sig -> Source (Evt (D, D))
forall a b. (a -> b) -> Source a -> Source b
mapSource ((D -> (D, D)) -> Evt D -> Evt (D, D)
forall a b. (a -> b) -> Evt a -> Evt b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap D -> (D, D)
split2 (Evt D -> Evt (D, D)) -> (Sig -> Evt D) -> Sig -> Evt (D, D)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sig -> Evt D
snaps) (Source Sig -> Source (Evt (D, D)))
-> Source Sig -> Source (Evt (D, D))
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> (Int, Int) -> Source Sig
butBankSig1 Text
name Int
xn Int
yn (Int, Int)
inits
    where
        split2 :: D -> (D, D)
split2 D
a = (D -> D
forall a. SigOrD a => a -> a
floor' (D -> D) -> D -> D
forall a b. (a -> b) -> a -> b
$ D
a D -> D -> D
forall a. Fractional a => a -> a -> a
/ D
y, D -> D -> D
forall a. SigOrD a => a -> a -> a
mod' D
a D
x)
        x :: D
x = Int -> D
int Int
xn
        y :: D
y = Int -> D
int Int
yn

-- | A variance on the function 'Csound.Gui.Widget.butBank', but it produces
-- a signal of piecewise constant function.
-- Result is (x, y) coordinate of the triggered button.
butBankSig :: Text -> Int -> Int -> (Int, Int) -> Source (Sig, Sig)
butBankSig :: Text -> Int -> Int -> (Int, Int) -> Source (Sig, Sig)
butBankSig Text
name Int
xn Int
yn (Int, Int)
inits = (Sig -> (Sig, Sig)) -> Source Sig -> Source (Sig, Sig)
forall a b. (a -> b) -> Source a -> Source b
mapSource Sig -> (Sig, Sig)
split2 (Source Sig -> Source (Sig, Sig))
-> Source Sig -> Source (Sig, Sig)
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> (Int, Int) -> Source Sig
butBankSig1 Text
name Int
xn Int
yn (Int, Int)
inits
    where
        split2 :: Sig -> (Sig, Sig)
split2 Sig
a = (Sig -> Sig
forall a. SigOrD a => a -> a
floor' (Sig -> Sig) -> Sig -> Sig
forall a b. (a -> b) -> a -> b
$ Sig
a Sig -> Sig -> Sig
forall a. Fractional a => a -> a -> a
/ Sig
y, Sig -> Sig -> Sig
forall a. SigOrD a => a -> a -> a
mod' Sig
a Sig
x)
        x :: Sig
x = D -> Sig
sig (D -> Sig) -> D -> Sig
forall a b. (a -> b) -> a -> b
$ Int -> D
int Int
xn
        y :: Sig
y = D -> Sig
sig (D -> Sig) -> D -> Sig
forall a b. (a -> b) -> a -> b
$ Int -> D
int Int
yn

-- | A FLTK widget opcode that creates a bank of buttons.
--
-- > butBank xNumOfButtons yNumOfButtons
--
-- doc: <http://www.csounds.com/manual/html/FLbutBank.html>
butBank1 :: Text -> Int -> Int -> (Int, Int) -> Source (Evt D)
butBank1 :: Text -> Int -> Int -> (Int, Int) -> Source (Evt D)
butBank1 Text
name Int
xn Int
yn (Int, Int)
inits = (Sig -> Evt D) -> Source Sig -> Source (Evt D)
forall a b. (a -> b) -> Source a -> Source b
mapSource Sig -> Evt D
snaps (Source Sig -> Source (Evt D)) -> Source Sig -> Source (Evt D)
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> (Int, Int) -> Source Sig
butBankSig1 Text
name Int
xn Int
yn (Int, Int)
inits

butBankSig1 :: Text -> Int -> Int -> (Int, Int) -> Source Sig
butBankSig1 :: Text -> Int -> Int -> (Int, Int) -> Source Sig
butBankSig1 Text
name Int
xn Int
yn (Int
x0, Int
y0) = Text -> Source Sig -> Source Sig
forall a. Text -> Source a -> Source a
setSourceTitle Text
name (Source Sig -> Source Sig) -> Source Sig -> Source Sig
forall a b. (a -> b) -> a -> b
$ Maybe Double -> Elem -> Source Sig
singleOut (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
n) (Elem -> Source Sig) -> Elem -> Source Sig
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Elem
ButBank Int
xn Int
yn
    where n :: Double
n = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> Int -> Double
forall a b. (a -> b) -> a -> b
$ Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x0 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
yn

-- |  FLtext that is sink shows current the value of a valuator in a text field.
setNumeric :: Text -> ValDiap -> ValStep -> Double -> Sink Sig
setNumeric :: Text -> ValDiap -> Double -> Double -> Sink Sig
setNumeric Text
name ValDiap
diap Double
step Double
v0 = Text -> Sink Sig -> Sink Sig
forall a. Text -> Sink a -> Sink a
setLabelSink Text
name (Sink Sig -> Sink Sig) -> Sink Sig -> Sink Sig
forall a b. (a -> b) -> a -> b
$ (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> Sink Sig
singleIn GuiHandle -> Output Sig
printk2 (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> Sink Sig) -> Elem -> Sink Sig
forall a b. (a -> b) -> a -> b
$ ValDiap -> Double -> Elem
Text ValDiap
diap Double
step

-- | A slider that serves as indicator. It consumes values instead of producing.
--
-- > meter valueSpan initValue
meter :: Text -> ValSpan -> Double -> Sink Sig
meter :: Text -> ValSpan -> Double -> Sink Sig
meter Text
name ValSpan
sp Double
v = Text -> Sink Sig -> Sink Sig
forall a. Text -> Sink a -> Sink a
setLabelSink Text
name (Sink Sig -> Sink Sig) -> Sink Sig -> Sink Sig
forall a b. (a -> b) -> a -> b
$ (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> Sink Sig
singleIn GuiHandle -> Output Sig
setVal (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v) (ValSpan -> Elem
Slider ValSpan
sp)

-------------------------------------------------------------
-- writeable widgets

setToggleSig :: Text -> Bool -> SinkSource Sig
setToggleSig :: Text -> Bool -> SinkSource Sig
setToggleSig Text
name Bool
initVal = Text -> SinkSource Sig -> SinkSource Sig
forall a. Text -> SinkSource a -> SinkSource a
setLabelSnkSource Text
name (SinkSource Sig -> SinkSource Sig)
-> SinkSource Sig -> SinkSource Sig
forall a b. (a -> b) -> a -> b
$ (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> SinkSource Sig
singleInOut GuiHandle -> Output Sig
setVal (Bool -> Maybe Double
initToggle Bool
initVal) Elem
Toggle

setToggle :: Text -> Bool -> SinkSource (Evt D)
setToggle :: Text -> Bool -> SinkSource (Evt D)
setToggle Text
name Bool
initVal = SinkSource (Evt D) -> SinkSource (Evt D)
forall a. SE (Gui, Output a, a) -> SE (Gui, Output a, a)
sinkSource (SinkSource (Evt D) -> SinkSource (Evt D))
-> SinkSource (Evt D) -> SinkSource (Evt D)
forall a b. (a -> b) -> a -> b
$ do
    (Gui
g, Output Sig
outs, Sig
ins) <- Text -> Bool -> SinkSource Sig
setToggleSig Text
name Bool
initVal
    let evtOuts :: Evt D -> SE ()
evtOuts Evt D
a = Output Sig
outs Output Sig -> SE Sig -> SE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Sig -> Evt Sig -> SE Sig
forall a. Tuple a => a -> Evt a -> SE a
stepper Sig
0 ((D -> Sig) -> Evt D -> Evt Sig
forall a b. (a -> b) -> Evt a -> Evt b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap D -> Sig
sig Evt D
a)
    (Gui, Evt D -> SE (), Evt D) -> SinkSource (Evt D)
forall a. a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return (Gui
g, Evt D -> SE ()
evtOuts, Sig -> Evt D
snaps Sig
ins)

setKnob :: Text -> ValSpan -> Double -> SinkSource Sig
setKnob :: Text -> ValSpan -> Double -> SinkSource Sig
setKnob Text
name ValSpan
sp Double
v0 = Text -> SinkSource Sig -> SinkSource Sig
forall a. Text -> SinkSource a -> SinkSource a
setLabelSnkSource Text
name (SinkSource Sig -> SinkSource Sig)
-> SinkSource Sig -> SinkSource Sig
forall a b. (a -> b) -> a -> b
$ (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> SinkSource Sig
singleInOut GuiHandle -> Output Sig
setVal' (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> SinkSource Sig) -> Elem -> SinkSource Sig
forall a b. (a -> b) -> a -> b
$ ValSpan -> Elem
Knob ValSpan
sp

setSlider :: Text -> ValSpan -> Double -> SinkSource Sig
setSlider :: Text -> ValSpan -> Double -> SinkSource Sig
setSlider Text
name ValSpan
sp Double
v0 = Text -> SinkSource Sig -> SinkSource Sig
forall a. Text -> SinkSource a -> SinkSource a
setLabelSnkSource Text
name (SinkSource Sig -> SinkSource Sig)
-> SinkSource Sig -> SinkSource Sig
forall a b. (a -> b) -> a -> b
$ (GuiHandle -> Output Sig) -> Maybe Double -> Elem -> SinkSource Sig
singleInOut GuiHandle -> Output Sig
setVal' (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v0) (Elem -> SinkSource Sig) -> Elem -> SinkSource Sig
forall a b. (a -> b) -> a -> b
$ ValSpan -> Elem
Slider ValSpan
sp

-------------------------------------------------------------
-- keyboard

-- | The stream of keyboard press/release events.
keyIn :: KeyEvt -> Evt Unit
keyIn :: KeyEvt -> Evt Unit
keyIn KeyEvt
evt = BoolSig -> Evt Unit
boolToEvt (BoolSig -> Evt Unit) -> BoolSig -> Evt Unit
forall a b. (a -> b) -> a -> b
$ Sig
asig Sig -> Sig -> BoolSig
forall bool. (bool ~ BooleanOf Sig) => Sig -> Sig -> bool
forall a bool. (EqB a, bool ~ BooleanOf a) => a -> a -> bool
==* Sig
1
    where asig :: Sig
asig = GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ (Var -> E) -> GE Var -> GE E
forall a b. (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Var -> E
readOnlyVar (GE Var -> GE E) -> GE Var -> GE E
forall a b. (a -> b) -> a -> b
$ KeyEvt -> GE Var
listenKeyEvt KeyEvt
evt

-- Outputs

readD :: Var -> SE D
readD :: Var -> SE D
readD Var
v = (E -> D) -> SE E -> SE D
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GE E -> D
D (GE E -> D) -> (E -> GE E) -> E -> D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE D) -> SE E -> SE D
forall a b. (a -> b) -> a -> b
$ Dep E -> SE E
forall a. Dep a -> SE a
SE (Dep E -> SE E) -> Dep E -> SE E
forall a b. (a -> b) -> a -> b
$ Var -> Dep E
forall (m :: * -> *). Monad m => Var -> DepT m E
readVar Var
v

readSig :: Var -> Sig
readSig :: Var -> Sig
readSig Var
v = GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return (E -> GE E) -> E -> GE E
forall a b. (a -> b) -> a -> b
$ Var -> E
readOnlyVar Var
v


refHandle :: GuiHandle -> SE D
refHandle :: GuiHandle -> SE D
refHandle GuiHandle
h = Var -> SE D
readD (GuiHandle -> Var
guiHandleToVar GuiHandle
h)

setVal :: GuiHandle -> Sig -> SE ()
setVal :: GuiHandle -> Output Sig
setVal GuiHandle
handle Sig
val = Sig -> Sig -> D -> SE ()
flSetVal ([Sig] -> Sig
changed [Sig
val]) Sig
val (D -> SE ()) -> SE D -> SE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GuiHandle -> SE D
refHandle GuiHandle
handle

printk2 :: GuiHandle -> Sig -> SE ()
printk2 :: GuiHandle -> Output Sig
printk2 GuiHandle
handle Sig
val = Sig -> D -> SE ()
flPrintk2 Sig
val (D -> SE ()) -> SE D -> SE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GuiHandle -> SE D
refHandle GuiHandle
handle

setVal' :: GuiHandle -> Sig -> SE ()
setVal' :: GuiHandle -> Output Sig
setVal' GuiHandle
handle Sig
val = Sig -> Sig -> D -> SE ()
flSetVal Sig
1 Sig
val (D -> SE ()) -> SE D -> SE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GuiHandle -> SE D
refHandle GuiHandle
handle


-------------------------------------------------------------
-- set gui value

flSetVal :: Sig -> Sig -> D -> SE ()
flSetVal :: Sig -> Sig -> D -> SE ()
flSetVal Sig
trig Sig
val D
handle = DepT GE () -> SE ()
forall a. Dep a -> SE a
SE (DepT GE () -> SE ()) -> DepT GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ (E -> DepT GE ()
forall (m :: * -> *). Monad m => E -> DepT m ()
depT_ (E -> DepT GE ()) -> Dep E -> DepT GE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> DepT GE ()) -> Dep E -> DepT GE ()
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E -> E
f (E -> E -> E -> E) -> GE E -> GE (E -> E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
trig GE (E -> E -> E) -> GE E -> GE (E -> E)
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
val GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> D -> GE E
forall a. Val a => a -> GE E
toGE D
handle
    where f :: E -> E -> E -> E
f E
a E
b E
c = Text -> Spec1 -> [E] -> E
opcs Text
"FLsetVal" [(Rate
Xr, [Rate
Kr, Rate
Kr, Rate
Ir])] [E
a, E
b, E
c]

flPrintk2 :: Sig -> D -> SE ()
flPrintk2 :: Sig -> D -> SE ()
flPrintk2 Sig
val D
handle = DepT GE () -> SE ()
forall a. Dep a -> SE a
SE (DepT GE () -> SE ()) -> DepT GE () -> SE ()
forall a b. (a -> b) -> a -> b
$ (E -> DepT GE ()
forall (m :: * -> *). Monad m => E -> DepT m ()
depT_ (E -> DepT GE ()) -> Dep E -> DepT GE ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) (Dep E -> DepT GE ()) -> Dep E -> DepT GE ()
forall a b. (a -> b) -> a -> b
$ GE E -> Dep E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> Dep E) -> GE E -> Dep E
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
forall a. Val a => a -> GE E
toGE Sig
val GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> D -> GE E
forall a. Val a => a -> GE E
toGE D
handle
    where f :: E -> E -> E
f E
a E
b = Text -> Spec1 -> [E] -> E
opcs Text
"FLprintk2" [(Rate
Xr, [Rate
Kr, Rate
Ir])] [E
a, E
b]

-----------------------------------------------------

sourceSlice :: SinkSource a -> Source a
sourceSlice :: forall a. SinkSource a -> Source a
sourceSlice = ((Gui, Output a, a) -> (Gui, a))
-> SE (Gui, Output a, a) -> SE (Gui, a)
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Gui
gui, Output a
_, a
a) -> (Gui
gui, a
a))

sinkSlice :: SinkSource a -> Sink a
sinkSlice :: forall a. SinkSource a -> Sink a
sinkSlice = ((Gui, Output a, a) -> (Gui, Output a))
-> SE (Gui, Output a, a) -> SE (Gui, Output a)
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Gui
gui, Output a
a, a
_) -> (Gui
gui, Output a
a))