From b7952eda85b07094ae7240c8a73ad4ac78cba445 Mon Sep 17 00:00:00 2001 From: sss-create <72546851@posteo.jp> Date: Wed, 15 Jan 2025 11:13:48 +0100 Subject: [PATCH 1/4] hosc-0.21 support --- tidal-listener/src/Sound/Tidal/Listener.hs | 77 +++++++++++----------- tidal-listener/tidal-listener.cabal | 5 +- tidal.cabal | 4 +- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/tidal-listener/src/Sound/Tidal/Listener.hs b/tidal-listener/src/Sound/Tidal/Listener.hs index db514fef6..b5dce5223 100644 --- a/tidal-listener/src/Sound/Tidal/Listener.hs +++ b/tidal-listener/src/Sound/Tidal/Listener.hs @@ -6,48 +6,51 @@ 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.Transport.Fd.Udp as UDP import Control.Concurrent import qualified Network.Socket as N -data State = State {sIn :: MVar InterpreterMessage, - sOut :: MVar InterpreterResponse, - sLocal :: Udp, - sRemote :: N.SockAddr, - sStream :: T.Stream - } +data State = State + { sIn :: MVar InterpreterMessage + , sOut :: MVar InterpreterResponse + , sLocal :: Udp + , sRemote :: N.SockAddr + , sStream :: T.Stream + } -- | Start Haskell interpreter, with input and output mutable variables to -- communicate with it listenWithConfig :: Config -> IO () listenWithConfig Config{..} = do - putStrLn $ "Starting Tidal Listener " ++ if noGHC then "without installed GHC" else "with installed GHC" - putStrLn $ "Listening for OSC commands on port " ++ show listenPort - putStrLn $ "Sending replies to port " ++ show replyPort + putStrLn $ "Starting Tidal Listener " ++ if noGHC then "without installed GHC" else "with installed GHC" + putStrLn $ "Listening for OSC commands on port " ++ show listenPort + putStrLn $ "Sending replies to port " ++ show replyPort - --start the stream - stream <- startListenerStream replyPort dirtPort + --start the stream + stream <- startListenerStream replyPort dirtPort - mIn <- newEmptyMVar - mOut <- newEmptyMVar + mIn <- newEmptyMVar + mOut <- newEmptyMVar - putStrLn "Starting tidal interpreter.. " - _ <- forkIO $ startHintJob True stream mIn mOut + putStrLn "Starting tidal interpreter.. " + _ <- forkIO $ startHintJob True stream mIn mOut - (remote_addr:_) <- N.getAddrInfo Nothing (Just "127.0.0.1") Nothing - local <- udpServer "127.0.0.1" listenPort + (remote_addr:_) <- N.getAddrInfo Nothing (Just "127.0.0.1") Nothing + let iOlocal = udpServer "127.0.0.1" listenPort + local <- iOlocal - let (N.SockAddrInet _ a) = N.addrAddress remote_addr - remote = N.SockAddrInet (fromIntegral replyPort) a - st = State mIn mOut local remote stream - loop st - where - loop st = - do -- wait for, read and act on OSC message - m <- recvMessage (sLocal st) - st' <- act st m - loop st' + + let (N.SockAddrInet _ a) = N.addrAddress remote_addr + remote = N.SockAddrInet (fromIntegral replyPort) a + st = State mIn mOut local remote stream + loop st + where + loop st = do + m <- O.recvMessage (sLocal st) + st' <- act st m + loop st' act :: State -> Maybe O.Message -> IO State @@ -59,9 +62,9 @@ act st (Just (Message "/eval" [AsciiString statement])) = do putMVar (sIn st) (MStat $ ascii_to_string statement) r <- takeMVar (sOut st) case r of - RStat (Just x) -> O.sendTo (sLocal st) (O.p_message "/eval/value" [string x]) (sRemote st) - RStat Nothing -> O.sendTo (sLocal st) (O.p_message "/eval/ok" []) (sRemote st) - RError e -> O.sendTo (sLocal st) (O.p_message "/eval/error" [string e]) (sRemote st) + RStat (Just x) -> UDP.sendTo (sLocal st) (O.p_message "/eval/value" [string x]) (sRemote st) + RStat Nothing -> UDP.sendTo (sLocal st) (O.p_message "/eval/ok" []) (sRemote st) + RError e -> UDP.sendTo (sLocal st) (O.p_message "/eval/error" [string e]) (sRemote st) _ -> return () return st @@ -70,8 +73,8 @@ act st (Just (Message "/type" [AsciiString expression])) = do putMVar (sIn st) (MType $ ascii_to_string expression) r <- takeMVar (sOut st) case r of - RType t -> O.sendTo (sLocal st) (O.p_message "/type/ok" [string t]) (sRemote st) - RError e -> O.sendTo (sLocal st) (O.p_message "/type/error" [string e]) (sRemote st) + RType t -> UDP.sendTo (sLocal st) (O.p_message "/type/ok" [string t]) (sRemote st) + RError e -> UDP.sendTo (sLocal st) (O.p_message "/type/error" [string e]) (sRemote st) _ -> return () return st @@ -79,21 +82,21 @@ act st (Just (Message "/load" [AsciiString path])) = do putMVar (sIn st) (MLoad $ ascii_to_string path) r <- takeMVar (sOut st) case r of - RStat (Just x) -> O.sendTo (sLocal st) (O.p_message "/load/value" [string x]) (sRemote st) --cannot happen - RStat Nothing -> O.sendTo (sLocal st) (O.p_message "/load/ok" []) (sRemote st) - RError e -> O.sendTo (sLocal st) (O.p_message "/load/error" [string e]) (sRemote st) + RStat (Just x) -> UDP.sendTo (sLocal st) (O.p_message "/load/value" [string x]) (sRemote st) --cannot happen + RStat Nothing -> UDP.sendTo (sLocal st) (O.p_message "/load/ok" []) (sRemote st) + RError e -> UDP.sendTo (sLocal st) (O.p_message "/load/error" [string e]) (sRemote st) _ -> return () return st -- test if the listener is responsive act st (Just (Message "/ping" [])) = - do O.sendTo (sLocal st) (O.p_message "/pong" []) (sRemote st) + do UDP.sendTo (sLocal st) (O.p_message "/pong" []) (sRemote st) return st -- get the current cps of the running stream act st (Just (Message "/cps" [])) = do cps <- streamGetCPS (sStream st) - O.sendTo (sLocal st) (O.p_message "/cps" [float cps]) (sRemote st) + UDP.sendTo (sLocal st) (O.p_message "/cps" [float cps]) (sRemote st) return st act st Nothing = do putStrLn "Not a message?" diff --git a/tidal-listener/tidal-listener.cabal b/tidal-listener/tidal-listener.cabal index c97a3f71e..992d500cb 100644 --- a/tidal-listener/tidal-listener.cabal +++ b/tidal-listener/tidal-listener.cabal @@ -1,5 +1,4 @@ -cabal-version: >=1.10 - +cabal-version: 2.0 name: tidal-listener version: 0.1.0.0 -- synopsis: @@ -27,7 +26,7 @@ library deepseq, optparse-applicative, tidal >= 1.10 && < 1.11, - hosc >= 0.20 && < 0.21, + hosc >= 0.21 && < 0.22, hint, network default-language: Haskell2010 diff --git a/tidal.cabal b/tidal.cabal index 6c06c3c27..bc7a9ef28 100644 --- a/tidal.cabal +++ b/tidal.cabal @@ -61,7 +61,7 @@ library base >=4.8 && <5 , containers < 0.8 , colour < 2.4 - , hosc >= 0.20 && < 0.21 + , hosc >= 0.21 && < 0.22 , text < 2.2 , parsec >= 3.1.12 && < 3.2 , network < 3.3 @@ -96,7 +96,7 @@ test-suite tests build-depends: base ==4.* , microspec >= 0.2.0.1 - , hosc >= 0.20 && < 0.21 + , hosc >= 0.21 && < 0.22 , containers , parsec , tidal From 314fbc489cc5973b285779fc3ace39c66e6f7d85 Mon Sep 17 00:00:00 2001 From: sss-create <72546851@posteo.jp> Date: Wed, 15 Jan 2025 11:32:29 +0100 Subject: [PATCH 2/4] added hosc-0.21 to stack.yaml --- stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index 7962e96b1..b62d2df8c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -7,7 +7,7 @@ packages: - 'tidal-link' extra-deps: - - hosc-0.20 + - hosc-0.21 - haskellish-0.3.2.2 From 7be28ed4299f57f1eddb901267c282de7ca42d9c Mon Sep 17 00:00:00 2001 From: sss-create <72546851@posteo.jp> Date: Thu, 16 Jan 2025 15:35:11 +0100 Subject: [PATCH 3/4] bump hosc in tidal-link --- tidal-link/tidal-link.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidal-link/tidal-link.cabal b/tidal-link/tidal-link.cabal index 28295c0d2..e29fa621a 100644 --- a/tidal-link/tidal-link.cabal +++ b/tidal-link/tidal-link.cabal @@ -33,7 +33,7 @@ library build-depends: base >=4.8 && <5, - hosc, + hosc >= 0.21 && <0.22, mtl, stm From 9e1c9912aae9d080c7e6385861204e4b9c96c032 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Sat, 18 Jan 2025 13:23:59 +1100 Subject: [PATCH 4/4] fix: Add `hosc` input to nix flake to support v0.21 Adds a flake input for `hosc` as 0.21 isn't yet on nixpkgs. Rather than waiting for a nixpkgs PR to update the stackage list, this overrides `hosc` package with the last v0.21 commit from the hosc repo. --- flake.lock | 30 ++++++++++++++++++++++++------ flake.nix | 6 ++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 1a7f8a0b6..97f844f44 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,29 @@ { "nodes": { + "hosc": { + "flake": false, + "locked": { + "lastModified": 1734661491, + "narHash": "sha256-ilu/WjulVrEtP+tBwTf2kughoziWhEm27MigkOm9F6c=", + "owner": "rd--", + "repo": "hosc", + "rev": "43bb2d07ff8d65cf9e51d1f5f96d0e6ffd6fe8fa", + "type": "github" + }, + "original": { + "owner": "rd--", + "repo": "hosc", + "rev": "43bb2d07ff8d65cf9e51d1f5f96d0e6ffd6fe8fa", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1730531603, - "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "lastModified": 1737062831, + "narHash": "sha256-Tbk1MZbtV2s5aG+iM99U8FqwxU/YNArMcWAv6clcsBc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d", + "rev": "5df43628fdf08d642be8ba5b3625a6c70731c19c", "type": "github" }, "original": { @@ -18,6 +35,7 @@ }, "root": { "inputs": { + "hosc": "hosc", "nixpkgs": "nixpkgs", "utils": "utils" } @@ -42,11 +60,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1687709756, - "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index fe2d0e36a..636329c8e 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,11 @@ inputs = { utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + # Manually include `hosc` at the `v0.21.0` + hosc = { + flake = false; + url = "github:rd--/hosc?rev=43bb2d07ff8d65cf9e51d1f5f96d0e6ffd6fe8fa"; + }; }; outputs = inputs: let @@ -38,6 +43,7 @@ mkPackages = pkgs: let project = pkgs.haskellPackages.extend (pkgs.haskell.lib.compose.packageSourceOverrides { + hosc = inputs.hosc; # Manually added as `hosc` 0.21 is not yet in nixpkgs. tidal = ./.; tidal-link = ./tidal-link; tidal-listener = ./tidal-listener;