Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Sound/Tidal/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import Foreign
import Foreign.C.Types
import System.IO (hPutStrLn, stderr)

import qualified Sound.OSC.FD as O
import qualified Sound.Osc.Fd as O
import qualified Sound.Osc.Time.Timeout as O
import qualified Network.Socket as N

import Sound.Tidal.Config
Expand All @@ -45,7 +46,6 @@ import Sound.Tidal.Params (pS)
import Sound.Tidal.Pattern
import qualified Sound.Tidal.Tempo as T
import Sound.Tidal.Utils ((!!!))
-- import qualified Sound.OSC.Datum as O
import Data.List (sortOn)
import System.Random (getStdRandom, randomR)
import Sound.Tidal.Show ()
Expand All @@ -59,15 +59,15 @@ data Stream = Stream {sConfig :: Config,
sStateMV :: MVar ValueMap,
-- sOutput :: MVar ControlPattern,
sLink :: Link.AbletonLink,
sListen :: Maybe O.UDP,
sListen :: Maybe O.Udp,
sPMapMV :: MVar PlayMap,
sActionsMV :: MVar [T.TempoAction],
sGlobalFMV :: MVar (ControlPattern -> ControlPattern),
sCxs :: [Cx]
}

data Cx = Cx {cxTarget :: Target,
cxUDP :: O.UDP,
cxUDP :: O.Udp,
cxOSCs :: [OSC],
cxAddr :: N.AddrInfo,
cxBusAddr :: Maybe N.AddrInfo
Expand Down Expand Up @@ -256,13 +256,13 @@ sendHandshakes stream = mapM_ sendHandshake $ filter (oHandshake . cxTarget) (sC
else
hPutStrLn stderr "Can't handshake with SuperCollider without control port."

sendO :: Bool -> (Maybe O.UDP) -> Cx -> O.Message -> IO ()
sendO :: Bool -> (Maybe O.Udp) -> Cx -> O.Message -> IO ()
sendO isBusMsg (Just listen) cx msg = O.sendTo listen (O.Packet_Message msg) (N.addrAddress addr)
where addr | isBusMsg && isJust (cxBusAddr cx) = fromJust $ cxBusAddr cx
| otherwise = cxAddr cx
sendO _ Nothing cx msg = O.sendMessage (cxUDP cx) msg

sendBndl :: Bool -> (Maybe O.UDP) -> Cx -> O.Bundle -> IO ()
sendBndl :: Bool -> (Maybe O.Udp) -> Cx -> O.Bundle -> IO ()
sendBndl isBusMsg (Just listen) cx bndl = O.sendTo listen (O.Packet_Bundle bndl) (N.addrAddress addr)
where addr | isBusMsg && isJust (cxBusAddr cx) = fromJust $ cxBusAddr cx
| otherwise = cxAddr cx
Expand Down Expand Up @@ -546,7 +546,7 @@ setPreviousPatternOrSilence stream =
-- Send events early using timestamp in the OSC bundle - used by Superdirt
-- Send events early by adding timestamp to the OSC message - used by Dirt
-- Send events live by delaying the thread
send :: Maybe O.UDP -> Cx -> Double -> Double -> (Double, Bool, O.Message) -> IO ()
send :: Maybe O.Udp -> Cx -> Double -> Double -> (Double, Bool, O.Message) -> IO ()
send listen cx latency extraLatency (time, isBusMsg, m)
| oSchedule target == Pre BundleStamp = sendBndl isBusMsg listen cx $ O.Bundle timeWithLatency [m]
| oSchedule target == Pre MessageStamp = sendO isBusMsg listen cx $ addtime m
Expand All @@ -555,7 +555,7 @@ send listen cx latency extraLatency (time, isBusMsg, m)
sendO isBusMsg listen cx m
return ()
where addtime (O.Message mpath params) = O.Message mpath ((O.int32 sec):((O.int32 usec):params))
ut = O.ntpr_to_ut timeWithLatency
ut = O.ntpr_to_posix timeWithLatency
sec :: Int
sec = floor ut
usec :: Int
Expand Down Expand Up @@ -659,7 +659,7 @@ streamSetB = streamSet
streamSetR :: Stream -> String -> Pattern Rational -> IO ()
streamSetR = streamSet

openListener :: Config -> IO (Maybe O.UDP)
openListener :: Config -> IO (Maybe O.Udp)
openListener c
| cCtrlListen c = catchAny run (\_ -> do verbose c "That port isn't available, perhaps another Tidal instance is already listening on that port?"
return Nothing
Expand Down Expand Up @@ -693,16 +693,16 @@ ctrlResponder waits c (stream@(Stream {sListen = Just sock}))
return ()
where
bufferIndices [] = []
bufferIndices (x:xs') | x == (O.ASCII_String $ O.ascii "&controlBusIndices") = catMaybes $ takeWhile isJust $ map O.datum_integral xs'
bufferIndices (x:xs') | x == (O.AsciiString $ O.ascii "&controlBusIndices") = catMaybes $ takeWhile isJust $ map O.datum_integral xs'
| otherwise = bufferIndices xs'
-- External controller commands
act (O.Message "/ctrl" (O.Int32 k:v:[]))
= act (O.Message "/ctrl" [O.string $ show k,v])
act (O.Message "/ctrl" (O.ASCII_String k:v@(O.Float _):[]))
act (O.Message "/ctrl" (O.AsciiString k:v@(O.Float _):[]))
= add (O.ascii_to_string k) (VF (fromJust $ O.datum_floating v))
act (O.Message "/ctrl" (O.ASCII_String k:O.ASCII_String v:[]))
act (O.Message "/ctrl" (O.AsciiString k:O.AsciiString v:[]))
= add (O.ascii_to_string k) (VS (O.ascii_to_string v))
act (O.Message "/ctrl" (O.ASCII_String k:O.Int32 v:[]))
act (O.Message "/ctrl" (O.AsciiString k:O.Int32 v:[]))
= add (O.ascii_to_string k) (VI (fromIntegral v))
-- Stream playback commands
act (O.Message "/mute" (k:[]))
Expand All @@ -729,7 +729,7 @@ ctrlResponder waits c (stream@(Stream {sListen = Just sock}))
putMVar (sStateMV stream) $ Map.insert k v sMap
return ()
withID :: O.Datum -> (ID -> IO ()) -> IO ()
withID (O.ASCII_String k) func = func $ (ID . O.ascii_to_string) k
withID (O.AsciiString k) func = func $ (ID . O.ascii_to_string) k
withID (O.Int32 k) func = func $ (ID . show) k
withID _ _ = return ()
ctrlResponder _ _ _ = return ()
Expand Down
4 changes: 2 additions & 2 deletions src/Sound/Tidal/Tempo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Sound.Tidal.Tempo where

import Control.Concurrent.MVar
import qualified Sound.Tidal.Pattern as P
import qualified Sound.OSC.FD as O
import qualified Sound.Osc.Fd as O
import Control.Concurrent (forkIO, ThreadId, threadDelay)
import Control.Monad (when)
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -39,7 +39,7 @@ import Sound.Tidal.StreamTypes
along with this library. If not, see <http://www.gnu.org/licenses/>.
-}

instance Show O.UDP where
instance Show O.Udp where
show _ = "-unshowable-"

type TransitionMapper = P.Time -> [P.ControlPattern] -> P.ControlPattern
Expand Down
4 changes: 2 additions & 2 deletions test/Sound/Tidal/StreamTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Sound.Tidal.StreamTest where
import Test.Microspec
import Sound.Tidal.Stream
import Sound.Tidal.Pattern
import qualified Sound.OSC.FD as O
import qualified Sound.Osc.Fd as O
import qualified Data.Map.Strict as M

run :: Microspec ()
Expand Down Expand Up @@ -33,4 +33,4 @@ run =
it "should work for params with fallback expressions" $ do
getString (M.singleton "s" (VS "sn")) "s=bd" `shouldBe` Just "sn"
it "should work for missing params with fallback expressions" $ do
getString M.empty "s=bd" `shouldBe` Just "bd"
getString M.empty "s=bd" `shouldBe` Just "bd"
6 changes: 3 additions & 3 deletions tidal-listener/src/Sound/Tidal/Listener.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Sound.Tidal.ID
import qualified Sound.Tidal.Context as T
import Sound.Tidal.Hint
import Sound.Tidal.Listener.Config
import Sound.OSC.FD as O
import Sound.Osc.Fd as O
import Control.Concurrent
import Control.Concurrent.MVar
import qualified Network.Socket as N
Expand All @@ -21,7 +21,7 @@ https://github.com/tidalcycles/tidal-listener/wiki

data State = State {sIn :: MVar String,
sOut :: MVar Response,
sLocal :: UDP,
sLocal :: Udp,
sRemote :: N.SockAddr,
sStream :: T.Stream
}
Expand Down Expand Up @@ -80,7 +80,7 @@ startHint = do mIn <- newEmptyMVar
getcps st = streamGetcps (sStream st)

act :: State -> Maybe O.Message -> IO State
act st (Just (Message "/code" [ASCII_String a_ident, ASCII_String a_code])) =
act st (Just (Message "/code" [AsciiString a_ident, AsciiString a_code])) =
do let ident = ID $ ascii_to_string a_ident
code = ascii_to_string a_code
putMVar (sIn st) code
Expand Down
4 changes: 2 additions & 2 deletions tidal-listener/tidal-listener.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ library
Sound.Tidal.Hint
build-depends: base,
data-default,
tidal >=1.7.1,
hosc,
tidal ==1.9.3,
hosc >= 0.20 && < 0.21,
hint,
network
default-language: Haskell2010
Expand Down
4 changes: 2 additions & 2 deletions tidal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ library
base >=4.8 && <5
, containers < 0.7
, colour < 2.4
, hosc >= 0.17 && < 0.20
, hosc >= 0.20 && < 0.21
, text < 2.1
, parsec >= 3.1.12 && < 3.2
, network < 3.2
Expand Down Expand Up @@ -90,7 +90,7 @@ test-suite tests
build-depends:
base ==4.*
, microspec >= 0.2.0.1
, hosc >= 0.17 && < 0.20
, hosc >= 0.20 && < 0.21
, containers
, parsec
, tidal
Expand Down