Skip to content

Commit

Permalink
Move internal server control to separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kersten committed Jun 6, 2012
1 parent 2378ea6 commit 3d01b0e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Sound/SC3/Server/Monad.hs
Expand Up @@ -60,7 +60,7 @@ import Sound.SC3.Server.Command (notify)
import Sound.SC3.Server.Connection (Connection)
import qualified Sound.SC3.Server.Connection as C
import Sound.SC3.Server.Notification (Notification, synced)
import Sound.SC3.Server.Options (ServerOptions)
import Sound.SC3.Server.Process.Options (ServerOptions)
import Sound.SC3.Server.State ( BufferId, BufferIdAllocator
, BusId, BusIdAllocator
, NodeId, NodeIdAllocator
Expand Down
4 changes: 2 additions & 2 deletions Sound/SC3/Server/Monad/Command.hs
Expand Up @@ -78,6 +78,7 @@ import Control.Arrow (first)
import Control.Failure (Failure, failure)
import Control.Monad (liftM)
import Control.Monad.IO.Class (MonadIO)
import Sound.OpenSoundControl (OSC(..))
import Sound.SC3 (Rate(..), UGen)
import qualified Sound.SC3.Server.Allocator.Range as Range
import Sound.SC3.Server.Monad hiding (sync, unsafeSync)
Expand All @@ -89,8 +90,7 @@ import Sound.SC3.Server.Command (AddAction(..), PrintLevel(..))
import qualified Sound.SC3.Server.Command as C
import qualified Sound.SC3.Server.Command.Completion as C
import qualified Sound.SC3.Server.Notification as N
import Sound.SC3.Server.Options (ServerOptions(..))
import Sound.OpenSoundControl (OSC(..))
import Sound.SC3.Server.Process.Options (ServerOptions(..))

-- ====================================================================
-- Utils
Expand Down
@@ -1,21 +1,18 @@
module Sound.SC3.Server.Process.Monad (
module Sound.SC3.Server.Monad.Process (
withSynth
, withDefaultSynth
, withInternal
, withDefaultInternal
-- * Re-exported for convenience
, module Sound.SC3.Server.Options
, module Sound.SC3.Server.Process.Options
, OutputHandler(..)
, defaultOutputHandler
) where

import qualified Sound.SC3.Server.Connection as Conn
import qualified Sound.SC3.Server.Internal as Process
import Sound.SC3.Server.Monad (Server)
import qualified Sound.SC3.Server.Monad as Server
import Sound.SC3.Server.Options
import Sound.SC3.Server.Process (OutputHandler(..), defaultOutputHandler)
import qualified Sound.SC3.Server.Process as Process
import Sound.SC3.Server.Process.Options

withSynth :: ServerOptions -> RTOptions -> OutputHandler -> Server a -> IO a
withSynth serverOptions rtOptions outputHandler action =
Expand All @@ -27,14 +24,3 @@ withSynth serverOptions rtOptions outputHandler action =

withDefaultSynth :: Server a -> IO a
withDefaultSynth = withSynth defaultServerOptions defaultRTOptions defaultOutputHandler

withInternal :: ServerOptions -> RTOptions -> OutputHandler -> Server a -> IO a
withInternal serverOptions rtOptions outputHandler action =
Process.withInternal
serverOptions
rtOptions
outputHandler
$ \t -> Conn.open t >>= Server.runServer action serverOptions

withDefaultInternal :: Server a -> IO a
withDefaultInternal = withInternal defaultServerOptions defaultRTOptions defaultOutputHandler
2 changes: 1 addition & 1 deletion Sound/SC3/Server/State.hs
Expand Up @@ -33,7 +33,7 @@ import qualified Sound.SC3.Server.Allocator.BlockAllocator.FirstFit as FirstFitA
import qualified Sound.SC3.Server.Allocator.SetAllocator as SetAllocator
import qualified Sound.SC3.Server.Allocator.SimpleAllocator as SimpleAllocator
import qualified Sound.SC3.Server.Allocator.Wrapped as Wrapped
import Sound.SC3.Server.Options (ServerOptions(..))
import Sound.SC3.Server.Process.Options (ServerOptions(..))

-- | Synchronisation barrier id.
newtype SyncId = SyncId Int32 deriving (Bounded, Enum, Eq, Integral, NFData, Num, Ord, Real, Show)
Expand Down
9 changes: 6 additions & 3 deletions examples/hello.hs
@@ -1,8 +1,10 @@
import Control.Monad.IO.Class (liftIO)
import Sound.SC3.Server.Process.Monad
import Sound.SC3.UGen
import Sound.SC3.Server.Monad
import Sound.SC3.Server.Monad.Command
-- You need the hsc3-server-internal package in order to use the internal server
--import Sound.SC3.Server.Monad.Process.Internal (withDefaultInternal)
import Sound.SC3.Server.Monad.Process (withDefaultSynth)
import Sound.SC3.Server.Monad.Request ((!>), async, extract, whenDone)
import Sound.SC3.Server.Notification
import Sound.OpenSoundControl (immediately)
Expand All @@ -20,8 +22,9 @@ statusLoop = do
pauseThread 1
statusLoop

--run = withDefaultSynth
run = withDefaultInternal
-- You need the hsc3-server-internal package in order to use the internal server
--run = withDefaultInternal
run = withDefaultSynth

latency = 0.03

Expand Down
9 changes: 6 additions & 3 deletions examples/sine-grains.hs
@@ -1,10 +1,12 @@
import Control.Concurrent.MVar
import Control.Monad (void, when)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Sound.SC3.Server.Process.Monad
import Sound.SC3.UGen
import Sound.SC3.Server.Monad
import Sound.SC3.Server.Monad.Command
-- You need the hsc3-server-internal package in order to use the internal server
--import Sound.SC3.Server.Monad.Process.Internal (withDefaultInternal)
import Sound.SC3.Server.Monad.Process (withDefaultSynth)
import Sound.SC3.Server.Monad.Request
import Sound.SC3.Server.Notification
import Sound.OpenSoundControl (immediately)
Expand Down Expand Up @@ -43,8 +45,9 @@ grainLoop quit synthDef delta sustain t = do
b <- keepRunning quit
when b $ grainLoop quit synthDef delta sustain t'

{-run = withDefaultSynth-}
run = withDefaultInternal
-- You need the hsc3-server-internal package in order to use the internal server
--run = withDefaultInternal
run = withDefaultSynth

latency = 0.03

Expand Down
2 changes: 1 addition & 1 deletion hsc3-server.cabal
Expand Up @@ -37,9 +37,9 @@ Library
Sound.SC3.Server.Connection.ListenerMap.List
Sound.SC3.Server.Monad
Sound.SC3.Server.Monad.Command
Sound.SC3.Server.Monad.Process
Sound.SC3.Server.Monad.Request
Sound.SC3.Server.Notification
Sound.SC3.Server.Process.Monad
Sound.SC3.Server.State
Other-Modules:
Sound.SC3.Server.Allocator.BlockAllocator.FreeList
Expand Down

0 comments on commit 3d01b0e

Please sign in to comment.