From ff7504b9b2dd0b4c13b9a7b86bc6988733a09316 Mon Sep 17 00:00:00 2001 From: eilseq Date: Tue, 11 Feb 2025 21:14:32 +0100 Subject: [PATCH 1/3] Create tidal-core package - refactore codebase in order to move Tidal core funcitonalities into dedicated package for dependency isolation and build optimization --- cabal.project | 2 +- src/Sound/Tidal/Stream/Process.hs | 1 + src/Sound/Tidal/Stream/Types.hs | 5 +- test/Test.hs | 22 ----- .../src}/Sound/Tidal/Bjorklund.hs | 0 {src => tidal-core/src}/Sound/Tidal/Chords.hs | 0 .../src}/Sound/Tidal/Control.hs | 2 +- {src => tidal-core/src}/Sound/Tidal/Core.hs | 0 {src => tidal-core/src}/Sound/Tidal/Params.hs | 0 .../src}/Sound/Tidal/ParseBP.hs | 0 .../src}/Sound/Tidal/Pattern.hs | 0 tidal-core/src/Sound/Tidal/Pattern/Types.hs | 4 + {src => tidal-core/src}/Sound/Tidal/Scales.hs | 0 {src => tidal-core/src}/Sound/Tidal/Show.hs | 0 {src => tidal-core/src}/Sound/Tidal/Simple.hs | 0 .../src}/Sound/Tidal/Stepwise.hs | 0 {src => tidal-core/src}/Sound/Tidal/Time.hs | 0 {src => tidal-core/src}/Sound/Tidal/UI.hs | 0 {src => tidal-core/src}/Sound/Tidal/Utils.hs | 0 .../test}/Sound/Tidal/ChordsTest.hs | 0 .../test}/Sound/Tidal/ControlTest.hs | 0 .../test}/Sound/Tidal/CoreTest.hs | 11 ++- .../test}/Sound/Tidal/ExceptionsTest.hs | 0 .../test}/Sound/Tidal/ParamsTest.hs | 0 .../test}/Sound/Tidal/ParseTest.hs | 0 .../test}/Sound/Tidal/PatternTest.hs | 0 .../test}/Sound/Tidal/ScalesTest.hs | 0 .../test}/Sound/Tidal/StepwiseTest.hs | 0 .../test}/Sound/Tidal/UITest.hs | 0 .../test}/Sound/Tidal/UtilsTest.hs | 0 tidal-core/test/Test.hs | 28 ++++++ tidal-core/test/TestUtils.hs | 71 +++++++++++++++ tidal-core/tidal-core.cabal | 86 +++++++++++++++++++ tidal-listener/tidal-listener.cabal | 1 + tidal-parse-ffi/tidal-parse-ffi.cabal | 4 +- tidal-parse/src/Sound/Tidal/Parse.hs | 85 +++++++++--------- .../test/Sound/Tidal/TidalParseTest.hs | 12 ++- tidal-parse/tidal-parse.cabal | 4 +- tidal.cabal | 29 +------ 39 files changed, 267 insertions(+), 100 deletions(-) rename {src => tidal-core/src}/Sound/Tidal/Bjorklund.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Chords.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Control.hs (99%) rename {src => tidal-core/src}/Sound/Tidal/Core.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Params.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/ParseBP.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Pattern.hs (100%) create mode 100644 tidal-core/src/Sound/Tidal/Pattern/Types.hs rename {src => tidal-core/src}/Sound/Tidal/Scales.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Show.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Simple.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Stepwise.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Time.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/UI.hs (100%) rename {src => tidal-core/src}/Sound/Tidal/Utils.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/ChordsTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/ControlTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/CoreTest.hs (97%) rename {test => tidal-core/test}/Sound/Tidal/ExceptionsTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/ParamsTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/ParseTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/PatternTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/ScalesTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/StepwiseTest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/UITest.hs (100%) rename {test => tidal-core/test}/Sound/Tidal/UtilsTest.hs (100%) create mode 100644 tidal-core/test/Test.hs create mode 100644 tidal-core/test/TestUtils.hs create mode 100644 tidal-core/tidal-core.cabal diff --git a/cabal.project b/cabal.project index 9e3717a0..773a55d6 100644 --- a/cabal.project +++ b/cabal.project @@ -1,2 +1,2 @@ tests: True -packages: ./ tidal-parse tidal-parse-ffi tidal-listener tidal-link +packages: ./ tidal-core tidal-parse tidal-parse-ffi tidal-listener tidal-link diff --git a/src/Sound/Tidal/Stream/Process.hs b/src/Sound/Tidal/Stream/Process.hs index 91e20c54..6d3319bd 100644 --- a/src/Sound/Tidal/Stream/Process.hs +++ b/src/Sound/Tidal/Stream/Process.hs @@ -43,6 +43,7 @@ import Sound.Tidal.ID import qualified Sound.Tidal.Link as Link import Sound.Tidal.Params (pS) import Sound.Tidal.Pattern +import Sound.Tidal.Pattern.Types import Sound.Tidal.Show () import Sound.Tidal.Stream.Target import Sound.Tidal.Stream.Types diff --git a/src/Sound/Tidal/Stream/Types.hs b/src/Sound/Tidal/Stream/Types.hs index 60dae6d8..e5e29a47 100644 --- a/src/Sound/Tidal/Stream/Types.hs +++ b/src/Sound/Tidal/Stream/Types.hs @@ -80,7 +80,4 @@ type PlayMap = Map.Map PatId PlayState -- tickArc :: Arc, -- tickNudge :: Double -- } --- deriving Show - -patternTimeID :: String -patternTimeID = "_t_pattern" +-- deriving Show \ No newline at end of file diff --git a/test/Test.hs b/test/Test.hs index 8f5e309a..f0ecbbe6 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1,30 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} -import Sound.Tidal.ChordsTest -import Sound.Tidal.ControlTest -import Sound.Tidal.CoreTest -import Sound.Tidal.ExceptionsTest -import Sound.Tidal.ParamsTest -import Sound.Tidal.ParseTest -import Sound.Tidal.PatternTest -import Sound.Tidal.ScalesTest -import Sound.Tidal.StepwiseTest import Sound.Tidal.StreamTest -import Sound.Tidal.UITest -import Sound.Tidal.UtilsTest import Test.Microspec main :: IO () main = microspec $ do - Sound.Tidal.CoreTest.run - Sound.Tidal.ParseTest.run - Sound.Tidal.ParamsTest.run - Sound.Tidal.PatternTest.run - Sound.Tidal.ControlTest.run - Sound.Tidal.ScalesTest.run - Sound.Tidal.ChordsTest.run - Sound.Tidal.StepwiseTest.run Sound.Tidal.StreamTest.run - Sound.Tidal.UITest.run - Sound.Tidal.UtilsTest.run - Sound.Tidal.ExceptionsTest.run diff --git a/src/Sound/Tidal/Bjorklund.hs b/tidal-core/src/Sound/Tidal/Bjorklund.hs similarity index 100% rename from src/Sound/Tidal/Bjorklund.hs rename to tidal-core/src/Sound/Tidal/Bjorklund.hs diff --git a/src/Sound/Tidal/Chords.hs b/tidal-core/src/Sound/Tidal/Chords.hs similarity index 100% rename from src/Sound/Tidal/Chords.hs rename to tidal-core/src/Sound/Tidal/Chords.hs diff --git a/src/Sound/Tidal/Control.hs b/tidal-core/src/Sound/Tidal/Control.hs similarity index 99% rename from src/Sound/Tidal/Control.hs rename to tidal-core/src/Sound/Tidal/Control.hs index b6c36cbe..ab3c60bf 100644 --- a/src/Sound/Tidal/Control.hs +++ b/tidal-core/src/Sound/Tidal/Control.hs @@ -43,7 +43,7 @@ import Sound.Tidal.Core ) import qualified Sound.Tidal.Params as P import Sound.Tidal.Pattern -import Sound.Tidal.Stream.Types (patternTimeID) +import Sound.Tidal.Pattern.Types (patternTimeID) import Sound.Tidal.UI (bite, _irand) import Prelude hiding ((*>), (<*)) diff --git a/src/Sound/Tidal/Core.hs b/tidal-core/src/Sound/Tidal/Core.hs similarity index 100% rename from src/Sound/Tidal/Core.hs rename to tidal-core/src/Sound/Tidal/Core.hs diff --git a/src/Sound/Tidal/Params.hs b/tidal-core/src/Sound/Tidal/Params.hs similarity index 100% rename from src/Sound/Tidal/Params.hs rename to tidal-core/src/Sound/Tidal/Params.hs diff --git a/src/Sound/Tidal/ParseBP.hs b/tidal-core/src/Sound/Tidal/ParseBP.hs similarity index 100% rename from src/Sound/Tidal/ParseBP.hs rename to tidal-core/src/Sound/Tidal/ParseBP.hs diff --git a/src/Sound/Tidal/Pattern.hs b/tidal-core/src/Sound/Tidal/Pattern.hs similarity index 100% rename from src/Sound/Tidal/Pattern.hs rename to tidal-core/src/Sound/Tidal/Pattern.hs diff --git a/tidal-core/src/Sound/Tidal/Pattern/Types.hs b/tidal-core/src/Sound/Tidal/Pattern/Types.hs new file mode 100644 index 00000000..b2a03f17 --- /dev/null +++ b/tidal-core/src/Sound/Tidal/Pattern/Types.hs @@ -0,0 +1,4 @@ +module Sound.Tidal.Pattern.Types where + +patternTimeID :: String +patternTimeID = "_t_pattern" diff --git a/src/Sound/Tidal/Scales.hs b/tidal-core/src/Sound/Tidal/Scales.hs similarity index 100% rename from src/Sound/Tidal/Scales.hs rename to tidal-core/src/Sound/Tidal/Scales.hs diff --git a/src/Sound/Tidal/Show.hs b/tidal-core/src/Sound/Tidal/Show.hs similarity index 100% rename from src/Sound/Tidal/Show.hs rename to tidal-core/src/Sound/Tidal/Show.hs diff --git a/src/Sound/Tidal/Simple.hs b/tidal-core/src/Sound/Tidal/Simple.hs similarity index 100% rename from src/Sound/Tidal/Simple.hs rename to tidal-core/src/Sound/Tidal/Simple.hs diff --git a/src/Sound/Tidal/Stepwise.hs b/tidal-core/src/Sound/Tidal/Stepwise.hs similarity index 100% rename from src/Sound/Tidal/Stepwise.hs rename to tidal-core/src/Sound/Tidal/Stepwise.hs diff --git a/src/Sound/Tidal/Time.hs b/tidal-core/src/Sound/Tidal/Time.hs similarity index 100% rename from src/Sound/Tidal/Time.hs rename to tidal-core/src/Sound/Tidal/Time.hs diff --git a/src/Sound/Tidal/UI.hs b/tidal-core/src/Sound/Tidal/UI.hs similarity index 100% rename from src/Sound/Tidal/UI.hs rename to tidal-core/src/Sound/Tidal/UI.hs diff --git a/src/Sound/Tidal/Utils.hs b/tidal-core/src/Sound/Tidal/Utils.hs similarity index 100% rename from src/Sound/Tidal/Utils.hs rename to tidal-core/src/Sound/Tidal/Utils.hs diff --git a/test/Sound/Tidal/ChordsTest.hs b/tidal-core/test/Sound/Tidal/ChordsTest.hs similarity index 100% rename from test/Sound/Tidal/ChordsTest.hs rename to tidal-core/test/Sound/Tidal/ChordsTest.hs diff --git a/test/Sound/Tidal/ControlTest.hs b/tidal-core/test/Sound/Tidal/ControlTest.hs similarity index 100% rename from test/Sound/Tidal/ControlTest.hs rename to tidal-core/test/Sound/Tidal/ControlTest.hs diff --git a/test/Sound/Tidal/CoreTest.hs b/tidal-core/test/Sound/Tidal/CoreTest.hs similarity index 97% rename from test/Sound/Tidal/CoreTest.hs rename to tidal-core/test/Sound/Tidal/CoreTest.hs index 5a9fc031..89bc0a06 100644 --- a/test/Sound/Tidal/CoreTest.hs +++ b/tidal-core/test/Sound/Tidal/CoreTest.hs @@ -5,7 +5,16 @@ module Sound.Tidal.CoreTest where import Data.List (sort) import qualified Data.Map as Map import Data.Ratio -import Sound.Tidal.Context +import Sound.Tidal.Control as C +import Sound.Tidal.Core as C +import Sound.Tidal.Params as C +import Sound.Tidal.ParseBP as C +import Sound.Tidal.Pattern as C +import Sound.Tidal.Scales as C +import Sound.Tidal.Show as C +import Sound.Tidal.Simple as C +import Sound.Tidal.Stepwise as C +import Sound.Tidal.UI as C import Test.Microspec import TestUtils import Prelude hiding ((*>), (<*)) diff --git a/test/Sound/Tidal/ExceptionsTest.hs b/tidal-core/test/Sound/Tidal/ExceptionsTest.hs similarity index 100% rename from test/Sound/Tidal/ExceptionsTest.hs rename to tidal-core/test/Sound/Tidal/ExceptionsTest.hs diff --git a/test/Sound/Tidal/ParamsTest.hs b/tidal-core/test/Sound/Tidal/ParamsTest.hs similarity index 100% rename from test/Sound/Tidal/ParamsTest.hs rename to tidal-core/test/Sound/Tidal/ParamsTest.hs diff --git a/test/Sound/Tidal/ParseTest.hs b/tidal-core/test/Sound/Tidal/ParseTest.hs similarity index 100% rename from test/Sound/Tidal/ParseTest.hs rename to tidal-core/test/Sound/Tidal/ParseTest.hs diff --git a/test/Sound/Tidal/PatternTest.hs b/tidal-core/test/Sound/Tidal/PatternTest.hs similarity index 100% rename from test/Sound/Tidal/PatternTest.hs rename to tidal-core/test/Sound/Tidal/PatternTest.hs diff --git a/test/Sound/Tidal/ScalesTest.hs b/tidal-core/test/Sound/Tidal/ScalesTest.hs similarity index 100% rename from test/Sound/Tidal/ScalesTest.hs rename to tidal-core/test/Sound/Tidal/ScalesTest.hs diff --git a/test/Sound/Tidal/StepwiseTest.hs b/tidal-core/test/Sound/Tidal/StepwiseTest.hs similarity index 100% rename from test/Sound/Tidal/StepwiseTest.hs rename to tidal-core/test/Sound/Tidal/StepwiseTest.hs diff --git a/test/Sound/Tidal/UITest.hs b/tidal-core/test/Sound/Tidal/UITest.hs similarity index 100% rename from test/Sound/Tidal/UITest.hs rename to tidal-core/test/Sound/Tidal/UITest.hs diff --git a/test/Sound/Tidal/UtilsTest.hs b/tidal-core/test/Sound/Tidal/UtilsTest.hs similarity index 100% rename from test/Sound/Tidal/UtilsTest.hs rename to tidal-core/test/Sound/Tidal/UtilsTest.hs diff --git a/tidal-core/test/Test.hs b/tidal-core/test/Test.hs new file mode 100644 index 00000000..1ec154b2 --- /dev/null +++ b/tidal-core/test/Test.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Sound.Tidal.ChordsTest +import Sound.Tidal.ControlTest +import Sound.Tidal.CoreTest +import Sound.Tidal.ExceptionsTest +import Sound.Tidal.ParamsTest +import Sound.Tidal.ParseTest +import Sound.Tidal.PatternTest +import Sound.Tidal.ScalesTest +import Sound.Tidal.StepwiseTest +import Sound.Tidal.UITest +import Sound.Tidal.UtilsTest +import Test.Microspec + +main :: IO () +main = microspec $ do + Sound.Tidal.CoreTest.run + Sound.Tidal.ParseTest.run + Sound.Tidal.ParamsTest.run + Sound.Tidal.PatternTest.run + Sound.Tidal.ControlTest.run + Sound.Tidal.ScalesTest.run + Sound.Tidal.ChordsTest.run + Sound.Tidal.StepwiseTest.run + Sound.Tidal.UITest.run + Sound.Tidal.UtilsTest.run + Sound.Tidal.ExceptionsTest.run diff --git a/tidal-core/test/TestUtils.hs b/tidal-core/test/TestUtils.hs new file mode 100644 index 00000000..74f43cc4 --- /dev/null +++ b/tidal-core/test/TestUtils.hs @@ -0,0 +1,71 @@ +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeSynonymInstances #-} + +module TestUtils where + +import Data.List (sort) +import qualified Data.Map.Strict as Map +import Data.Ratio as C +import Sound.Tidal.Control as C +import Sound.Tidal.Core as C +import Sound.Tidal.Params as C +import Sound.Tidal.ParseBP as C +import Sound.Tidal.Pattern as C +import Sound.Tidal.Scales as C +import Sound.Tidal.Show as C +import Sound.Tidal.Simple as C +import Sound.Tidal.Stepwise as C +import Sound.Tidal.UI as C +import Prelude hiding ((*>), (<*)) + +import Test.Microspec +import Prelude hiding ((*>), (<*)) + +class TolerantEq a where + (~==) :: a -> a -> Bool + +instance TolerantEq Double where + a ~== b = abs (a - b) < 0.000001 + +instance TolerantEq Value where + (VS a) ~== (VS b) = a == b + (VI a) ~== (VI b) = a == b + (VR a) ~== (VR b) = a == b + (VF a) ~== (VF b) = abs (a - b) < 0.000001 + _ ~== _ = False + +instance (TolerantEq a) => TolerantEq [a] where + as ~== bs = (length as == length bs) && all (uncurry (~==)) (zip as bs) + +instance TolerantEq ValueMap where + a ~== b = Map.differenceWith (\a' b' -> if a' ~== b' then Nothing else Just a') a b == Map.empty + +instance TolerantEq (Event ValueMap) where + (Event _ w p x) ~== (Event _ w' p' x') = w == w' && p == p' && x ~== x' + +-- | Compare the events of two patterns using the given arc +compareP :: (Ord a, Show a) => Arc -> Pattern a -> Pattern a -> Property +compareP a p p' = + sort (queryArc (stripContext p) a) + `shouldBe` sort (queryArc (stripContext p') a) + +-- | Like @compareP@, but tries to 'defragment' the events +comparePD :: (Ord a, Show a) => Arc -> Pattern a -> Pattern a -> Property +comparePD a p p' = + sort (defragParts $ queryArc (stripContext p) a) + `shouldBe` sort (defragParts $ queryArc (stripContext p') a) + +-- | Like @compareP@, but for control patterns, with some tolerance for floating point error +compareTol :: Arc -> ControlPattern -> ControlPattern -> Bool +compareTol a p p' = sort (queryArc (stripContext p) a) ~== sort (queryArc (stripContext p') a) + +-- | Utility to create a pattern from a String +ps :: String -> Pattern String +ps = parseBP_E + +stripContext :: Pattern a -> Pattern a +stripContext = setContext $ Context [] + +firstCycleValues :: Pattern a -> [a] +firstCycleValues pat = map value $ queryArc pat (Arc 0 1) \ No newline at end of file diff --git a/tidal-core/tidal-core.cabal b/tidal-core/tidal-core.cabal new file mode 100644 index 00000000..53fc4e64 --- /dev/null +++ b/tidal-core/tidal-core.cabal @@ -0,0 +1,86 @@ +cabal-version: 2.0 + +name: tidal-core +version: 1.10.0 + +homepage: http://tidalcycles.org/ +license: GPL-3 +license-file: LICENSE + +extra-source-files: + README.md + CHANGELOG.md + tidal.el + +category: Sound +build-type: Simple + +tested-with: + GHC == 8.6.5, + GHC == 8.8.4, + GHC == 8.10.7, + GHC == 9.0.2, + GHC == 9.4.8, + GHC == 9.8.2 + +library + ghc-options: -Wall + hs-source-dirs: src + default-language: Haskell2010 + + exposed-modules: + Sound.Tidal.Bjorklund + Sound.Tidal.Chords + Sound.Tidal.Control + Sound.Tidal.Core + Sound.Tidal.Params + Sound.Tidal.ParseBP + Sound.Tidal.Pattern + Sound.Tidal.Pattern.Types + Sound.Tidal.Scales + Sound.Tidal.Show + Sound.Tidal.Simple + Sound.Tidal.Stepwise + Sound.Tidal.Time + Sound.Tidal.UI + Sound.Tidal.Utils + + build-depends: + base >=4.8 && <5, + containers <0.8, + colour <2.4, + text <2.2, + parsec >=3.1.12 && <3.2, + deepseq >=1.1.0.0 + +test-suite tests + type: exitcode-stdio-1.0 + main-is: Test.hs + hs-source-dirs: test + ghc-options: -Wall + default-language: Haskell2010 + + other-modules: + Sound.Tidal.ControlTest + Sound.Tidal.CoreTest + Sound.Tidal.ParamsTest + Sound.Tidal.ParseTest + Sound.Tidal.PatternTest + Sound.Tidal.ScalesTest + Sound.Tidal.ChordsTest + Sound.Tidal.StepwiseTest + Sound.Tidal.UITest + Sound.Tidal.UtilsTest + Sound.Tidal.ExceptionsTest + TestUtils + + build-depends: + base >=4 && <5, + microspec >=0.2.0.1, + containers, + tidal-core, + deepseq + +source-repository head + type: git + location: https://github.com/tidalcycles/Tidal diff --git a/tidal-listener/tidal-listener.cabal b/tidal-listener/tidal-listener.cabal index 992d500c..14735ffd 100644 --- a/tidal-listener/tidal-listener.cabal +++ b/tidal-listener/tidal-listener.cabal @@ -26,6 +26,7 @@ library deepseq, optparse-applicative, tidal >= 1.10 && < 1.11, + tidal-core, hosc >= 0.21 && < 0.22, hint, network diff --git a/tidal-parse-ffi/tidal-parse-ffi.cabal b/tidal-parse-ffi/tidal-parse-ffi.cabal index 8e3906ba..fce24667 100644 --- a/tidal-parse-ffi/tidal-parse-ffi.cabal +++ b/tidal-parse-ffi/tidal-parse-ffi.cabal @@ -19,7 +19,7 @@ library base , containers , tidal-parse - , tidal + , tidal-core , aeson , bytestring , vector @@ -35,7 +35,7 @@ test-suite tests , containers , tidal-parse-ffi , tidal-parse - , tidal + , tidal-core , aeson , bytestring , HUnit diff --git a/tidal-parse/src/Sound/Tidal/Parse.hs b/tidal-parse/src/Sound/Tidal/Parse.hs index 4a5aea52..e381dadd 100644 --- a/tidal-parse/src/Sound/Tidal/Parse.hs +++ b/tidal-parse/src/Sound/Tidal/Parse.hs @@ -13,22 +13,25 @@ import Data.Char import Data.List (dropWhileEnd) import qualified Data.Text import Language.Haskellish as Haskellish -import qualified Sound.Tidal.Chords as T -import Sound.Tidal.Context - ( ControlPattern, - Enumerable, - Pattern, - Time, - ValueMap, - ) -import qualified Sound.Tidal.Context as T + +import Sound.Tidal.ParseBP (Enumerable, Parseable, parseBP) + +import Sound.Tidal.UI as T +import Sound.Tidal.Chords as T +import Sound.Tidal.Control as T +import Sound.Tidal.Core as T +import Sound.Tidal.Params as T +import Sound.Tidal.Pattern as T +import Sound.Tidal.Scales as T +import Sound.Tidal.Simple as T + import Sound.Tidal.Parse.TH type H = Haskellish () -- This is depended upon by Estuary, and changes to its type will cause problems downstream for Estuary. parseTidal :: String -> Either String ControlPattern -parseTidal x = if x' == [] then (return T.silence) else r +parseTidal x = if x' == [] then (return silence) else r where x' = dropWhileEnd isSpace $ dropWhile isSpace $ Haskellish.removeComments x r = bimap showSyntaxError fst $ Haskellish.parseAndRun parser () x @@ -59,8 +62,8 @@ instance Parse Time where instance Parse Double where parser = (fromIntegral <$> integer) <|> (realToFrac <$> rational) "expected literal Double" -instance Parse T.Note where - parser = (T.Note . fromIntegral <$> integer) <|> (T.Note . realToFrac <$> rational) "expected literal Note" +instance Parse Note where + parser = (Note . fromIntegral <$> integer) <|> (Note . realToFrac <$> rational) "expected literal Note" instance Parse String where parser = @@ -84,7 +87,7 @@ instance Parse [Time] where parser = numList instance Parse [Double] where parser = numList -instance Parse [T.Note] where parser = numList +instance Parse [Note] where parser = numList instance {-# OVERLAPPABLE #-} (Parse a) => Parse [a] where parser = list parser @@ -147,13 +150,13 @@ chords = ) instance Parse ValueMap where - parser = empty + parser = Control.Applicative.empty instance Parse ControlPattern where parser = (parser :: H (Pattern String -> ControlPattern)) <*!> parser <|> (parser :: H (Pattern Double -> ControlPattern)) <*!> parser - <|> (parser :: H (Pattern T.Note -> ControlPattern)) <*!> parser + <|> (parser :: H (Pattern Note -> ControlPattern)) <*!> parser <|> (parser :: H (Pattern Int -> ControlPattern)) <*!> parser <|> listCp_cp <*!> parser <|> genericPatternExpressions @@ -171,7 +174,7 @@ genericPatternExpressions = <|> list_p <*!> parser <|> tupleADouble_p <*!> parser <|> listTupleStringTransformation_p <*!> parser - <|> silence + <|> parseSilence listTupleStringTransformation_p :: forall a. (Parse (Pattern a), Parse (Pattern a -> Pattern a)) => H ([(String, Pattern a -> Pattern a)] -> Pattern a) listTupleStringTransformation_p = listTupleStringPattern_listTupleStringTransformation_p <*!> parser @@ -197,12 +200,12 @@ fractionalPatternExpressions = <|> pInt_pFractionalA <*!> parser <|> pDouble_pFractionalA <*!> parser -silence :: H (Pattern a) -silence = $(fromTidal "silence") -- ie. T.silence <$ reserved "silence", see Sound.Tidal.Parse.TH +parseSilence :: H (Pattern a) +parseSilence = $(fromTidal "silence") -- ie. silence <$ reserved "silence", see Sound.Tidal.Parse.TH instance Parse (Pattern Bool) where parser = - parseBP + haskellishParseBP <|> (parser :: H (Pattern String -> Pattern Bool)) <*!> parser <|> (parser :: H (Pattern Int -> Pattern Bool)) <*!> parser <|> genericPatternExpressions @@ -210,7 +213,7 @@ instance Parse (Pattern Bool) where instance Parse (Pattern String) where parser = - parseBP + haskellishParseBP <|> genericPatternExpressions <|> (parser :: H (Pattern Int -> Pattern String)) <*!> parser <|> (parser :: H (String -> Pattern String)) <*!> parser @@ -218,22 +221,22 @@ instance Parse (Pattern String) where <*!> parser "expected Pattern String" -parseBP :: (Enumerable a, T.Parseable a) => H (Pattern a) -parseBP = do +haskellishParseBP :: (Enumerable a, Parseable a) => H (Pattern a) +haskellishParseBP = do (b, _) <- Haskellish.span - p <- T.parseBP <$> string + p <- parseBP <$> string case p of Left e -> throwError $ Data.Text.pack $ show e Right p' -> do - return $ T.withContext (updateContext b) p' + return $ withContext (updateContext b) p' where - updateContext (dx, dy) c@T.Context {T.contextPosition = poss} = - c {T.contextPosition = map (\((bx, by), (ex, ey)) -> ((bx + dx, by + dy), (ex + dx, ey + dy))) poss} + updateContext (dx, dy) c@Context {contextPosition = poss} = + c {contextPosition = map (\((bx, by), (ex, ey)) -> ((bx + dx, by + dy), (ex + dx, ey + dy))) poss} instance Parse (Pattern Int) where parser = pure . fromIntegral <$> integer - <|> parseBP + <|> haskellishParseBP <|> genericPatternExpressions <|> numPatternExpressions "expected Pattern Int" @@ -241,7 +244,7 @@ instance Parse (Pattern Int) where instance Parse (Pattern Integer) where parser = pure <$> integer - <|> parseBP + <|> haskellishParseBP <|> genericPatternExpressions <|> numPatternExpressions "expected Pattern Integer" @@ -250,7 +253,7 @@ instance Parse (Pattern Double) where parser = pure . fromIntegral <$> integer <|> pure . realToFrac <$> rational - <|> parseBP + <|> haskellishParseBP <|> genericPatternExpressions <|> numPatternExpressions <|> fractionalPatternExpressions @@ -268,11 +271,11 @@ instance Parse (Pattern Double) where <|> $(fromTidalList (fmap (\x -> "in" ++ show x) ([0 .. 127] :: [Int]))) "expected Pattern Double" -instance Parse (Pattern T.Note) where +instance Parse (Pattern Note) where parser = pure . fromIntegral <$> integer <|> pure . realToFrac <$> rational - <|> parseBP + <|> haskellishParseBP <|> genericPatternExpressions <|> numPatternExpressions <|> fractionalPatternExpressions @@ -282,7 +285,7 @@ instance Parse (Pattern Time) where parser = pure . fromIntegral <$> integer <|> pure <$> rational - <|> parseBP + <|> haskellishParseBP <|> genericPatternExpressions <|> numPatternExpressions <|> fractionalPatternExpressions @@ -343,7 +346,7 @@ instance Parse (Pattern Double -> Pattern Double) where <|> $(fromTidal "perlin2") "expected Pattern Double -> Pattern Double" -instance Parse (Pattern T.Note -> Pattern T.Note) where +instance Parse (Pattern Note -> Pattern Note) where parser = genericTransformations <|> numTransformations <|> floatingTransformations <|> ordTransformations "expected Pattern Note -> Pattern Note" genericTransformations :: forall a. (Parse (Pattern a), Parse (Pattern a -> Pattern a), Parse (Pattern a -> Pattern a -> Pattern a), Parse ((Pattern a -> Pattern a) -> Pattern a -> Pattern a), Parse ([Pattern a -> Pattern a] -> Pattern a -> Pattern a)) => H (Pattern a -> Pattern a) @@ -464,12 +467,12 @@ instance Parse (Pattern Int -> Pattern Bool) where <|> pA_pB <|> a_patternB -instance Parse (Pattern T.Note -> ControlPattern) where +instance Parse (Pattern Note -> ControlPattern) where parser = $(fromTidal "up") <|> $(fromTidal "n") <|> $(fromTidal "note") - <|> (parser :: H (String -> Pattern T.Note -> ControlPattern)) <*!> parser + <|> (parser :: H (String -> Pattern Note -> ControlPattern)) <*!> parser <|> pA_pB <|> a_patternB @@ -606,7 +609,7 @@ instance Parse (Pattern Double -> Pattern Double -> Pattern Double) where <|> pDouble_p_p "expected Pattern Double -> Pattern Double -> Pattern Double" -instance Parse (Pattern T.Note -> Pattern T.Note -> Pattern T.Note) where +instance Parse (Pattern Note -> Pattern Note -> Pattern Note) where parser = genericBinaryPatternFunctions <|> numMergeOperator @@ -624,7 +627,7 @@ instance Parse (ControlPattern -> ControlPattern -> ControlPattern) where <*!> parser "expected ControlPattern -> ControlPattern -> ControlPattern" -genericBinaryPatternFunctions :: (T.Unionable a) => H (Pattern a -> Pattern a -> Pattern a) +genericBinaryPatternFunctions :: (Unionable a) => H (Pattern a -> Pattern a -> Pattern a) genericBinaryPatternFunctions = $(fromTidal "overlay") <|> $(fromTidal "append") @@ -639,7 +642,7 @@ genericBinaryPatternFunctions = <|> (parser :: H (Pattern Bool -> Pattern a -> Pattern a -> Pattern a)) <*!> parser <|> constParser -unionableMergeOperator :: (T.Unionable a) => H (Pattern a -> Pattern a -> Pattern a) +unionableMergeOperator :: (Unionable a) => H (Pattern a -> Pattern a -> Pattern a) unionableMergeOperator = $(fromTidal "#") <|> $(fromTidal "|>|") @@ -666,7 +669,7 @@ numMergeOperator = <|> $(fromHaskell "*") <|> $(fromHaskell "-") -realMergeOperator :: (T.Moddable a) => H (Pattern a -> Pattern a -> Pattern a) +realMergeOperator :: (Moddable a) => H (Pattern a -> Pattern a -> Pattern a) realMergeOperator = $(fromTidal "|%|") <|> $(fromTidal "|%") @@ -835,7 +838,7 @@ instance Parse ((Pattern Time -> Pattern Time) -> Pattern Time -> Pattern Time) instance Parse ((Pattern Double -> Pattern Double) -> Pattern Double -> Pattern Double) where parser = genericAppliedTransformations -instance Parse ((Pattern T.Note -> Pattern T.Note) -> Pattern T.Note -> Pattern T.Note) where +instance Parse ((Pattern Note -> Pattern Note) -> Pattern Note -> Pattern Note) where parser = genericAppliedTransformations genericAppliedTransformations :: H ((Pattern a -> Pattern a) -> Pattern a -> Pattern a) @@ -865,7 +868,7 @@ instance Parse ([a] -> Pattern Int -> Pattern a) where instance Parse (String -> Pattern Double -> ControlPattern) where parser = $(fromTidal "pF") -instance Parse (String -> Pattern T.Note -> ControlPattern) where +instance Parse (String -> Pattern Note -> ControlPattern) where parser = $(fromTidal "pN") instance Parse (String -> Pattern Int -> ControlPattern) where diff --git a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs index ec60b1bd..7ab41f37 100644 --- a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs +++ b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs @@ -4,9 +4,19 @@ module Sound.Tidal.TidalParseTest where import Data.Either import qualified Data.Map.Strict as Map + import Sound.Tidal.Chords as Tidal -import Sound.Tidal.Context as Tidal +import Sound.Tidal.Control as Tidal +import Sound.Tidal.Core as Tidal +import Sound.Tidal.Params as Tidal +import Sound.Tidal.Pattern as Tidal +import Sound.Tidal.UI as Tidal + import Sound.Tidal.Parse +import Sound.Tidal.Scales () +import Sound.Tidal.Show () +import Sound.Tidal.Simple () + import Test.Microspec hiding (run) stripContext :: Pattern a -> Pattern a diff --git a/tidal-parse/tidal-parse.cabal b/tidal-parse/tidal-parse.cabal index db82bb9f..04f106a2 100644 --- a/tidal-parse/tidal-parse.cabal +++ b/tidal-parse/tidal-parse.cabal @@ -30,7 +30,7 @@ library Build-depends: base >=4.8 && <5 - , tidal >= 1.10 && <1.11 + , tidal-core , transformers >= 0.5 && < 0.7 , template-haskell , haskellish >= 0.3.2 && < 0.4 @@ -53,7 +53,7 @@ test-suite tests , microspec >= 0.2.0.1 , containers < 0.8 , tidal-parse - , tidal + , tidal-core source-repository head type: git diff --git a/tidal.cabal b/tidal.cabal index b51c7318..d0b4883a 100644 --- a/tidal.cabal +++ b/tidal.cabal @@ -27,22 +27,12 @@ library autogen-modules: Paths_tidal - Exposed-modules: Sound.Tidal.Bjorklund + Exposed-modules: Sound.Tidal.Boot - Sound.Tidal.Chords - Sound.Tidal.Control Sound.Tidal.Context - Sound.Tidal.Core Sound.Tidal.ID - Sound.Tidal.Params - Sound.Tidal.ParseBP - Sound.Tidal.Pattern - Sound.Tidal.Scales Sound.Tidal.Safe.Context Sound.Tidal.Safe.Boot - Sound.Tidal.Show - Sound.Tidal.Simple - Sound.Tidal.Stepwise Sound.Tidal.Stream Sound.Tidal.Stream.Config Sound.Tidal.Stream.Listen @@ -51,10 +41,7 @@ library Sound.Tidal.Stream.Target Sound.Tidal.Stream.Types Sound.Tidal.Stream.UI - Sound.Tidal.Time Sound.Tidal.Transition - Sound.Tidal.UI - Sound.Tidal.Utils Sound.Tidal.Version Paths_tidal Build-depends: @@ -74,6 +61,7 @@ library , exceptions < 0.11 , mtl >= 2.2 && < 2.4 , tidal-link >= 1.1 && < 1.2 + , tidal-core test-suite tests type: exitcode-stdio-1.0 @@ -81,18 +69,8 @@ test-suite tests hs-source-dirs: test ghc-options: -Wall - other-modules: Sound.Tidal.ControlTest - Sound.Tidal.CoreTest - Sound.Tidal.ParamsTest - Sound.Tidal.ParseTest - Sound.Tidal.PatternTest - Sound.Tidal.ScalesTest - Sound.Tidal.ChordsTest - Sound.Tidal.StepwiseTest + other-modules: Sound.Tidal.StreamTest - Sound.Tidal.UITest - Sound.Tidal.UtilsTest - Sound.Tidal.ExceptionsTest TestUtils build-depends: base >=4 && <5, @@ -101,6 +79,7 @@ test-suite tests containers, parsec, tidal, + tidal-core, deepseq default-language: Haskell2010 From 20a0500a76ac5c5e1bf09c1ca306cfc34790ad2a Mon Sep 17 00:00:00 2001 From: eilseq Date: Sun, 16 Feb 2025 16:37:47 +0100 Subject: [PATCH 2/3] Update CI, Config and Doc files - Update Stack files - Update NIX pipeline - Update Cabal files - Update Ormolu Job in CI --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++--------------- flake.nix | 3 +++ stack.yaml | 11 +++++----- tidal-core/tidal-core.cabal | 6 ------ tidal.cabal | 12 ++++++++--- 5 files changed, 43 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24ce023d..ad2b582d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,20 +77,29 @@ jobs: - name: test run: cabal v2-test ${{ matrix.versions.args }} --enable-tests --enable-benchmarks all - ormolu: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: haskell-actions/run-ormolu@v17 - with: - mode: inplace - pattern: | - src/**/*.hs - tidal-link/src/**/*.hs - tidal-parse/src/**/*.hs - tidal-listener/src/**/*.hs - - name: apply ormolu formatting - uses: stefanzweifel/git-auto-commit-action@v4 - if: ${{ always() }} - with: - commit_message: automated ormolu reformatting +ormolu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Detect and switch to current branch + run: | + BRANCH_NAME=$(git branch --show-current || echo "${{ github.ref_name }}") + git checkout "$BRANCH_NAME" + + - uses: haskell-actions/run-ormolu@v17 + with: + mode: inplace + pattern: | + src/**/*.hs + tidal-core/src/**/*.hs + tidal-link/src/**/*.hs + tidal-parse/src/**/*.hs + tidal-listener/src/**/*.hs + + - name: apply ormolu formatting + uses: stefanzweifel/git-auto-commit-action@v4 + if: ${{ always() }} + with: + commit_message: automated ormolu reformatting + branch: ${{ github.head_ref || github.ref_name }} diff --git a/flake.nix b/flake.nix index 636329c8..70b77ba0 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,7 @@ Packages are included for: - tidal + - tidal-core - tidal-link - tidal-listener - tidal-parse @@ -45,6 +46,7 @@ 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-core = ./tidal-core; tidal-link = ./tidal-link; tidal-listener = ./tidal-listener; tidal-parse = ./tidal-parse; @@ -53,6 +55,7 @@ tidal-ghc = pkgs.haskellPackages.ghcWithPackages (hpkgs: [project.tidal]); in { tidal = project.tidal; + tidal-core = project.tidal-core; tidal-link = project.tidal-link; tidal-listener = project.tidal-listener; tidal-parse = project.tidal-parse; diff --git a/stack.yaml b/stack.yaml index b62d2df8..a5d98f5b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,13 +1,12 @@ resolver: lts-22.8 packages: - - '.' - - 'tidal-parse' - - 'tidal-listener' - - 'tidal-link' + - "." + - "tidal-core" + - "tidal-parse" + - "tidal-listener" + - "tidal-link" extra-deps: - hosc-0.21 - haskellish-0.3.2.2 - - diff --git a/tidal-core/tidal-core.cabal b/tidal-core/tidal-core.cabal index 53fc4e64..05145deb 100644 --- a/tidal-core/tidal-core.cabal +++ b/tidal-core/tidal-core.cabal @@ -5,12 +5,6 @@ version: 1.10.0 homepage: http://tidalcycles.org/ license: GPL-3 -license-file: LICENSE - -extra-source-files: - README.md - CHANGELOG.md - tidal.el category: Sound build-type: Simple diff --git a/tidal.cabal b/tidal.cabal index d0b4883a..81bd2ec4 100644 --- a/tidal.cabal +++ b/tidal.cabal @@ -90,7 +90,9 @@ test-suite dontcrash main-is: dontcrash.hs hs-source-dirs: test build-depends: base, - tidal + tidal, + tidal-core + default-language: Haskell2010 benchmark bench-speed @@ -104,7 +106,9 @@ benchmark bench-speed build-depends: base >=4 && <5, criterion >=1.6.3.0, - tidal + tidal, + tidal-core + ghc-options: -Wall default-language: Haskell2010 @@ -118,7 +122,9 @@ benchmark bench-memory build-depends: base >=4 && <5, weigh, - tidal + tidal, + tidal-core + ghc-options: -Wall default-language: Haskell2010 From d07b02631ffcbb60b15ccb8b6fc4c6148b3fec9e Mon Sep 17 00:00:00 2001 From: Alex McLean Date: Wed, 19 Feb 2025 08:30:50 +0000 Subject: [PATCH 3/3] Specify tidal-core version --- tidal.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidal.cabal b/tidal.cabal index 81bd2ec4..2f4ab74c 100644 --- a/tidal.cabal +++ b/tidal.cabal @@ -61,7 +61,7 @@ library , exceptions < 0.11 , mtl >= 2.2 && < 2.4 , tidal-link >= 1.1 && < 1.2 - , tidal-core + , tidal-core == 1.10.0 test-suite tests type: exitcode-stdio-1.0