module Sound.SC3.Server.Process.Options (
Verbosity(..)
, ServerOptions(..)
, defaultServerOptions
, fromBuildDirectory
, fromPrefix
, fromApplicationBundle
, NetworkPort(..)
, defaultUDPPort
, defaultTCPPort
, RTOptions(..)
, onPort
, jackDeviceName
, withJackDeviceName
, defaultRTOptions
, defaultRTOptionsUDP
, defaultRTOptionsTCP
, NRTOptions(..)
, defaultNRTOptions
) where
import Data.Default (Default(..))
import Sound.SC3.Server.Enum
import System.FilePath ((</>))
data Verbosity =
Silent
| Quiet
| Normal
| Verbose
| VeryVerbose
| ExtremelyVerbose
deriving (Eq, Read, Show)
instance Enum Verbosity where
fromEnum Silent = 2
fromEnum Quiet = 1
fromEnum Normal = 0
fromEnum Verbose = 1
fromEnum VeryVerbose = 2
fromEnum ExtremelyVerbose = 3
toEnum (2) = Silent
toEnum (1) = Quiet
toEnum 0 = Normal
toEnum 1 = Verbose
toEnum 2 = VeryVerbose
toEnum 3 = ExtremelyVerbose
toEnum _ = error "Verbosity (toEnum): bad argument"
instance Default Verbosity where
def = Normal
data ServerOptions = ServerOptions {
serverProgram :: FilePath
, numberOfControlBusChannels :: Int
, numberOfAudioBusChannels :: Int
, numberOfInputBusChannels :: Int
, numberOfOutputBusChannels :: Int
, blockSize :: Int
, numberOfSampleBuffers :: Int
, maxNumberOfNodes :: Int
, maxNumberOfSynthDefs :: Int
, realtimeMemorySize :: Int
, numberOfWireBuffers :: Int
, numberOfRandomSeeds :: Int
, loadSynthDefs :: Bool
, verbosity :: Verbosity
, ugenPluginPath :: Maybe [FilePath]
, restrictedPath :: Maybe FilePath
} deriving (Eq, Show)
instance Default ServerOptions where
def = defaultServerOptions
defaultServerOptions :: ServerOptions
defaultServerOptions = ServerOptions {
serverProgram = "scsynth"
, numberOfControlBusChannels = 4096
, numberOfAudioBusChannels = 128
, numberOfInputBusChannels = 8
, numberOfOutputBusChannels = 8
, blockSize = 64
, numberOfSampleBuffers = 1024
, maxNumberOfNodes = 1024
, maxNumberOfSynthDefs = 1024
, realtimeMemorySize = 8192
, numberOfWireBuffers = 64
, numberOfRandomSeeds = 64
, loadSynthDefs = True
, verbosity = def
, ugenPluginPath = Nothing
, restrictedPath = Nothing
}
fromBuildDirectory :: FilePath -> ServerOptions -> ServerOptions
fromBuildDirectory dir options = options {
serverProgram = dir </> "server/scsynth/scsynth"
, ugenPluginPath = Just [ dir </> "server/plugins" ] }
fromPrefix :: FilePath -> ServerOptions -> ServerOptions
fromPrefix dir options = options {
serverProgram = dir </> "bin/scsynth"
, ugenPluginPath = Just [ dir </> "lib/SuperCollider/plugins" ] }
fromApplicationBundle :: FilePath -> ServerOptions -> ServerOptions
fromApplicationBundle dir options = options {
serverProgram = resources </> "scsynth"
, ugenPluginPath = Just [ resources </> "plugins" ] }
where resources = dir </> "Contents/Resources"
data NetworkPort =
UDPPort Int
| TCPPort Int
deriving (Eq, Show)
instance Default NetworkPort where
def = defaultUDPPort
defaultPortNumber :: Int
defaultPortNumber = 57110
defaultUDPPort :: NetworkPort
defaultUDPPort = UDPPort defaultPortNumber
defaultTCPPort :: NetworkPort
defaultTCPPort = TCPPort defaultPortNumber
data RTOptions = RTOptions {
networkPort :: NetworkPort
, useZeroconf :: Bool
, maxNumberOfLogins :: Int
, sessionPassword :: Maybe String
, hardwareDeviceName :: Maybe String
, hardwareBufferSize :: Int
, hardwareSampleRate :: Int
, inputStreamsEnabled :: Maybe Int
, outputStreamsEnabled :: Maybe Int
} deriving (Eq, Show)
instance Default RTOptions where
def = defaultRTOptions
defaultRTOptions :: RTOptions
defaultRTOptions = RTOptions {
networkPort = def
, useZeroconf = False
, maxNumberOfLogins = 16
, sessionPassword = Nothing
, hardwareDeviceName = Nothing
, hardwareBufferSize = 0
, hardwareSampleRate = 0
, inputStreamsEnabled = Nothing
, outputStreamsEnabled = Nothing
}
onPort :: NetworkPort -> RTOptions
onPort port = def { networkPort = port }
jackDeviceName ::
Maybe String
-> String
-> String
jackDeviceName = (++) . maybe "" ((++":"))
withJackDeviceName ::
Maybe String
-> String
-> RTOptions
-> RTOptions
withJackDeviceName serverName clientName options = options {
hardwareDeviceName = Just (jackDeviceName serverName clientName) }
defaultRTOptionsUDP :: RTOptions
defaultRTOptionsUDP = defaultRTOptions { networkPort = defaultUDPPort }
defaultRTOptionsTCP :: RTOptions
defaultRTOptionsTCP = defaultRTOptions { networkPort = defaultTCPPort }
data NRTOptions = NRTOptions {
inputFilePath :: Maybe FilePath
, outputFilePath :: FilePath
, outputSampleRate :: Int
, outputSoundFileFormat :: SoundFileFormat
, outputSampleFormat :: SampleFormat
} deriving (Eq, Show)
instance Default NRTOptions where
def = defaultNRTOptions
defaultNRTOptions :: NRTOptions
defaultNRTOptions = NRTOptions {
inputFilePath = Nothing
, outputFilePath = "output.wav"
, outputSampleRate = 44100
, outputSoundFileFormat = Wave
, outputSampleFormat = PcmInt16
}