Skip to content

Commit

Permalink
Merge branch 'main' into cycseq
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu authored May 11, 2023
2 parents ac0ca49 + 7c04314 commit e176524
Show file tree
Hide file tree
Showing 24 changed files with 795 additions and 625 deletions.
119 changes: 37 additions & 82 deletions BootTidal.hs
Original file line number Diff line number Diff line change
@@ -1,88 +1,43 @@
:set -fno-warn-orphans
:set -XMultiParamTypeClasses
:set -XOverloadedStrings
:set prompt ""

import Sound.Tidal.Context

import System.IO (hSetEncoding, stdout, utf8)
hSetEncoding stdout utf8


let config = defaultConfig {cVerbose = True, cFrameTimespan = 1/20}
oscmap = [(superdirtTarget {oLatency = 0.1}, [superdirtShape])]

tidal <- startStream config oscmap

tidal <- startTidal (superdirtTarget {oLatency = 0.05, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cVerbose = True, cFrameTimespan = 1/20})

:{
let only = (hush >>)
p = streamReplace tidal
hush = streamHush tidal
panic = do hush
once $ sound "superpanic"
list = streamList tidal
mute = streamMute tidal
unmute = streamUnmute tidal
unmuteAll = streamUnmuteAll tidal
unsoloAll = streamUnsoloAll tidal
solo = streamSolo tidal
unsolo = streamUnsolo tidal
once = streamOnce tidal
first = streamFirst tidal
asap = once
nudgeAll = streamNudgeAll tidal
all = streamAll tidal
resetCycles = streamResetCycles tidal
setCycle = streamSetCycle tidal
setcps = asap . cps
getcps = streamGetcps tidal
getnow = streamGetnow tidal
-- xfade i = transition tidal True (Sound.Tidal.Transition.xfadeIn 4) i
-- xfadeIn i t = transition tidal True (Sound.Tidal.Transition.xfadeIn t) i
-- histpan i t = transition tidal True (Sound.Tidal.Transition.histpan t) i
-- wait i t = transition tidal True (Sound.Tidal.Transition.wait t) i
-- waitT i f t = transition tidal True (Sound.Tidal.Transition.waitT f t) i
-- jump i = transition tidal True (Sound.Tidal.Transition.jump) i
-- jumpIn i t = transition tidal True (Sound.Tidal.Transition.jumpIn t) i
-- jumpIn' i t = transition tidal True (Sound.Tidal.Transition.jumpIn' t) i
-- jumpMod i t = transition tidal True (Sound.Tidal.Transition.jumpMod t) i
-- jumpMod' i t p = transition tidal True (Sound.Tidal.Transition.jumpMod' t p) i
-- mortal i lifespan release = transition tidal True (Sound.Tidal.Transition.mortal lifespan release) i
-- interpolate i = transition tidal True (Sound.Tidal.Transition.interpolate) i
-- interpolateIn i t = transition tidal True (Sound.Tidal.Transition.interpolateIn t) i
-- clutch i = transition tidal True (Sound.Tidal.Transition.clutch) i
-- clutchIn i t = transition tidal True (Sound.Tidal.Transition.clutchIn t) i
-- anticipate i = transition tidal True (Sound.Tidal.Transition.anticipate) i
-- anticipateIn i t = transition tidal True (Sound.Tidal.Transition.anticipateIn t) i
-- forId i t = transition tidal False (Sound.Tidal.Transition.mortalOverlay t) i
d1 = p 1 . (|. orbit 0)
d2 = p 2 . (|. orbit 1)
d3 = p 3 . (|. orbit 2)
d4 = p 4 . (|. orbit 3)
d5 = p 5 . (|. orbit 4)
d6 = p 6 . (|. orbit 5)
d7 = p 7 . (|. orbit 6)
d8 = p 8 . (|. orbit 7)
d9 = p 9 . (|. orbit 8)
d10 = p 10 . (|. orbit 9)
d11 = p 11 . (|. orbit 10)
d12 = p 12 . (|. orbit 11)
d13 = p 13
d14 = p 14
d15 = p 15
d16 = p 16
:}

:{
let getState = streamGet tidal
setI = streamSetI tidal
setF = streamSetF tidal
setS = streamSetS tidal
setR = streamSetR tidal
setB = streamSetB tidal
:}
default (Signal String, Integer, Double)

-- Import all the boot functions and aliases.
import Sound.Tidal.Boot

-- Create a Tidal Stream with the default settings.
-- Use 'mkTidalWith' to customize these settings.
tidalInst <- mkTidal

-- This orphan instance makes the boot aliases work!
-- It has to go after you define 'tidalInst'.
instance Tidally where tidal = tidalInst

-- You can add your own aliases in this file. Here are some examples:
-- :{
-- let xfade i = transition tidal True (Sound.Tidal.Transition.xfadeIn 4) i
-- xfadeIn i t = transition tidal True (Sound.Tidal.Transition.xfadeIn t) i
-- histpan i t = transition tidal True (Sound.Tidal.Transition.histpan t) i
-- wait i t = transition tidal True (Sound.Tidal.Transition.wait t) i
-- waitT i f t = transition tidal True (Sound.Tidal.Transition.waitT f t) i
-- jump i = transition tidal True (Sound.Tidal.Transition.jump) i
-- jumpIn i t = transition tidal True (Sound.Tidal.Transition.jumpIn t) i
-- jumpIn' i t = transition tidal True (Sound.Tidal.Transition.jumpIn' t) i
-- jumpMod i t = transition tidal True (Sound.Tidal.Transition.jumpMod t) i
-- jumpMod' i t p = transition tidal True (Sound.Tidal.Transition.jumpMod' t p) i
-- mortal i lifespan release = transition tidal True (Sound.Tidal.Transition.mortal lifespan release) i
-- interpolate i = transition tidal True (Sound.Tidal.Transition.interpolate) i
-- interpolateIn i t = transition tidal True (Sound.Tidal.Transition.interpolateIn t) i
-- clutch i = transition tidal True (Sound.Tidal.Transition.clutch) i
-- clutchIn i t = transition tidal True (Sound.Tidal.Transition.clutchIn t) i
-- anticipate i = transition tidal True (Sound.Tidal.Transition.anticipate) i
-- anticipateIn i t = transition tidal True (Sound.Tidal.Transition.anticipateIn t) i
-- forId i t = transition tidal False (Sound.Tidal.Transition.mortalOverlay t) i
-- :}

:set -fwarn-orphans
:set prompt "tidal> "
:set prompt-cont ""

default (Signal String, Integer, Double)
28 changes: 14 additions & 14 deletions bin/generate-params.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
-- This can be run with e.g.:
-- runhaskell generate-params.hs > ../src/Sound/Tidal/Params.hs

import Data.List
import Data.Function
import System.IO
import Data.Function
import Data.List
import System.IO

toType :: String -> String
toType "s" = "Signal String"
toType "f" = "Signal Double"
toType "i" = "Signal Int"
toType "note" = "Signal Note"
toType "s" = "Signal String"
toType "f" = "Signal Double"
toType "i" = "Signal Int"
toType "note" = "Signal Note"
toType "[word8]" = "Signal [Word8]"

toFunc :: String -> String
toFunc "s" = "pS"
toFunc "f" = "pF"
toFunc "i" = "pI"
toFunc "note" = "pN"
toFunc "s" = "pS"
toFunc "f" = "pF"
toFunc "i" = "pI"
toFunc "note" = "pN"
toFunc "[word8]" = "pX"

main :: IO ()
Expand Down Expand Up @@ -52,11 +52,11 @@ controls = intercalate "\n" $ map fs $ sortBy (compare `on` (\(_,x,_) -> x)) gen
counters _ _ = ""
bus (t,name,desc) | elem name nobus = concat [
name, "bus :: Signal Int -> ", toType t, " -> ControlSignal\n",
name, "bus _ _ = error $ \"Control parameter '" ++ name ++ "' can't be sent to a bus.\"\n"
name, "bus _ _ = error \"Control parameter '" ++ name ++ "' can't be sent to a bus.\"\n"
]
| otherwise =
| otherwise =
concat [name, "bus :: Signal Int -> ", toType t, " -> ControlSignal\n",
name, "bus busid pat = (", toFunc t, " \"", name, "\" pat) # (pI \"^", name, "\" busid)\n",
name, "bus busid pat = ", toFunc t, " \"", name, "\" pat # pI \"^", name, "\" busid\n",
name, "recv :: Signal Int -> ControlSignal\n",
name, "recv busid = pI \"^", name, "\" busid\n"
]
Expand Down
32 changes: 16 additions & 16 deletions bin/params-header.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ module Sound.Tidal.Params where
along with this library. If not, see <http://www.gnu.org/licenses/>.
-}

import qualified Data.Map.Strict as Map
import qualified Data.Map.Strict as Map

import Sound.Tidal.Types
import Sound.Tidal.Value
import Sound.Tidal.Pattern
import Sound.Tidal.Signal.Base
import Sound.Tidal.Signal.Compose ((#))
import Sound.Tidal.Pattern
import Sound.Tidal.Signal.Base
import Sound.Tidal.Signal.Compose ((#))
import Sound.Tidal.Types
import Sound.Tidal.Value
-- import Sound.Tidal.Core ((#))
import Sound.Tidal.Utils
import Data.Maybe (fromMaybe)
import Data.Word (Word8)
import Data.Fixed (mod')
import Data.Fixed (mod')
import Data.Maybe (fromMaybe)
import Data.Word (Word8)
import Sound.Tidal.Utils

-- | group multiple params into one
grp :: [String -> ValueMap] -> Signal String -> ControlSignal
Expand Down Expand Up @@ -64,7 +64,7 @@ pI name = fmap (Map.singleton name . VI)

pB :: String -> Signal Bool -> ControlSignal
pB name = fmap (Map.singleton name . VB)

pR :: String -> Signal Rational -> ControlSignal
pR name = fmap (Map.singleton name . VR)

Expand All @@ -80,14 +80,14 @@ pX name = fmap (Map.singleton name . VX)
pStateF :: String -> String -> (Maybe Double -> Double) -> ControlSignal
pStateF name sName update = pure $ Map.singleton name $ VState statef
where statef :: ValueMap -> (ValueMap, Value)
statef sMap = (Map.insert sName v sMap, v)
where v = VF $ update $ (Map.lookup sName sMap) >>= getF
statef sMap = (Map.insert sName v sMap, v)
where v = VF $ update $ Map.lookup sName sMap >>= getF

pStateList :: String -> String -> [Value] -> ControlSignal
pStateList name sName xs = pure $ Map.singleton name $ VState statef
where statef :: ValueMap -> (ValueMap, Value)
statef sMap = (Map.insert sName (VList $ tail looped) sMap, head looped)
where xs' = fromMaybe xs ((Map.lookup sName sMap) >>= getList)
statef sMap = (Map.insert sName (VList $ tail looped) sMap, head looped)
where xs' = fromMaybe xs (Map.lookup sName sMap >>= getList)
-- do this instead of a cycle, so it can get updated with the a list
looped | null xs' = xs
| otherwise = xs'
Expand Down Expand Up @@ -189,7 +189,7 @@ drumN "bt" = 84
drumN "ct" = 85
drumN "ms" = 86
drumN "os" = 87
drumN _ = 0
drumN _ = 0

-- Generated params

5 changes: 5 additions & 0 deletions example.tidal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This is an example file you can use to quickly test Tidal editor integration.

d1 $ s "bd sd bd [~ sd] bd sd bd*3 sd"

hush
6 changes: 3 additions & 3 deletions src/Sound/Tidal/Arc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ where
-- (c) Alex McLean 2022
-- Shared under the terms of the GNU Public License v. 3.0

import Sound.Tidal.Time
import Sound.Tidal.Types
import Sound.Tidal.Time
import Sound.Tidal.Types

-- | Returns the whole cycle arc that the given arc is in
timeToCycleArc :: Time -> Arc
Expand Down Expand Up @@ -52,7 +52,7 @@ splitArcs (Arc s e) | s == e = [Arc s e] -- support zero-width arcs
where splitArcs' (Arc s' e') | e' <= s' = []
| sam s' == sam e' = [Arc s' e']
| otherwise
= (Arc s' (nextSam s')):(splitArcs' (Arc (nextSam s') e'))
= Arc s' (nextSam s') : splitArcs' (Arc (nextSam s') e')


-- | Shifts a timearc to one of equal duration that starts within cycle zero.
Expand Down
Loading

0 comments on commit e176524

Please sign in to comment.