diff --git a/src/Sound/Tidal/Control.hs b/src/Sound/Tidal/Control.hs index fe9843799..705b2a3ad 100644 --- a/src/Sound/Tidal/Control.hs +++ b/src/Sound/Tidal/Control.hs @@ -98,7 +98,7 @@ _chop n = withEvents (concatMap chopEvent) -- begin and end values by the old difference (end-begin), and -- add the old begin chomp :: Context -> ControlMap -> Int -> (Int, (Arc, Arc)) -> Event ControlMap - chomp c v n' (i, (w,p')) = Event c (Just w) p' (Map.insert "begin" (VF b' Nothing) $ Map.insert "end" (VF e' Nothing) v) + chomp c v n' (i, (w,p')) = Event c (Just w) p' (Map.insert "begin" (VF b') $ Map.insert "end" (VF e') v) where b = fromMaybe 0 $ do v' <- Map.lookup "begin" v getF v' e = fromMaybe 1 $ do v' <- Map.lookup "end" v @@ -150,7 +150,7 @@ _striate n p = fastcat $ map offset [0 .. n-1] where offset i = mergePlayRange (fromIntegral i / fromIntegral n, fromIntegral (i+1) / fromIntegral n) <$> p mergePlayRange :: (Double, Double) -> ControlMap -> ControlMap -mergePlayRange (b,e) cm = Map.insert "begin" (VF ((b*d')+b') Nothing) $ Map.insert "end" (VF ((e*d')+b') Nothing) cm +mergePlayRange (b,e) cm = Map.insert "begin" (VF ((b*d')+b')) $ Map.insert "end" (VF ((e*d')+b')) cm where b' = fromMaybe 0 $ Map.lookup "begin" cm >>= getF e' = fromMaybe 1 $ Map.lookup "end" cm >>= getF d' = e' - b' @@ -285,7 +285,7 @@ randslice = tParam $ \n p -> innerJoin $ (\i -> _slice n i p) <$> _irand n _splice :: Int -> Pattern Int -> ControlPattern -> Pattern (Map.Map String Value) _splice bits ipat pat = withEvent f (slice (pure bits) ipat pat) # P.unit (pure "c") - where f ev = ev {value = Map.insert "speed" (VF d Nothing) (value ev)} + where f ev = ev {value = Map.insert "speed" (VF d) (value ev)} where d = sz / (fromRational $ (wholeStop ev) - (wholeStart ev)) sz = 1/(fromIntegral bits) diff --git a/src/Sound/Tidal/Params.hs b/src/Sound/Tidal/Params.hs index bce1950fe..1b0b566ef 100644 --- a/src/Sound/Tidal/Params.hs +++ b/src/Sound/Tidal/Params.hs @@ -35,14 +35,14 @@ grp fs p = splitby <$> p mF :: String -> String -> ControlMap mF name v = fromMaybe Map.empty $ do f <- readMaybe v - return $ Map.singleton name (VF f Nothing) + return $ Map.singleton name (VF f) mI :: String -> String -> ControlMap mI name v = fromMaybe Map.empty $ do i <- readMaybe v - return $ Map.singleton name (VI i Nothing) + return $ Map.singleton name (VI i) mS :: String -> String -> ControlMap -mS name v = Map.singleton name (VS v Nothing) +mS name v = Map.singleton name (VS v) -- | Grouped params @@ -61,26 +61,26 @@ nrpn = grp [mI "nrpn", mI "val"] -- | Singular params pF :: String -> Pattern Double -> ControlPattern -pF name = fmap (Map.singleton name . (flip VF) Nothing) +pF name = fmap (Map.singleton name . VF) pI :: String -> Pattern Int -> ControlPattern -pI name = fmap (Map.singleton name . (flip VI) Nothing) +pI name = fmap (Map.singleton name . VI) pB :: String -> Pattern Bool -> ControlPattern -pB name = fmap (Map.singleton name . (flip VB) Nothing) +pB name = fmap (Map.singleton name . VB) pR :: String -> Pattern Rational -> ControlPattern -pR name = fmap (Map.singleton name . (flip VR) Nothing) +pR name = fmap (Map.singleton name . VR) -- | params for note pN :: String -> Pattern Note -> ControlPattern -pN name = fmap (Map.singleton name . (flip VN) Nothing) +pN name = fmap (Map.singleton name . VN) pS :: String -> Pattern String -> ControlPattern -pS name = fmap (Map.singleton name . (flip VS) Nothing) +pS name = fmap (Map.singleton name . VS) pX :: String -> Pattern [Word8] -> ControlPattern -pX name = fmap (Map.singleton name . (flip VX) Nothing) +pX name = fmap (Map.singleton name . VX) -- | patterns for internal sound routing toArg :: Pattern String -> ControlPattern diff --git a/src/Sound/Tidal/Pattern.hs b/src/Sound/Tidal/Pattern.hs index f327e9b70..eb1e63e08 100644 --- a/src/Sound/Tidal/Pattern.hs +++ b/src/Sound/Tidal/Pattern.hs @@ -36,7 +36,6 @@ import Data.Maybe (isJust, fromJust, catMaybes, mapMaybe) import Data.Typeable (Typeable) import Control.DeepSeq (NFData) import Data.Word (Word8) -import Sound.Tidal.Utils (matchMaybe) ------------------------------------------------------------------------ -- * Types @@ -276,13 +275,13 @@ type Query a = (State -> [Event a]) data Pattern a = Pattern {query :: Query a} deriving Generic -data Value = VS { svalue :: String, vbus :: Maybe Int } - | VF { fvalue :: Double, vbus :: Maybe Int } - | VN { nvalue :: Note, vbus :: Maybe Int } - | VR { rvalue :: Rational, vbus :: Maybe Int } - | VI { ivalue :: Int, vbus :: Maybe Int } - | VB { bvalue :: Bool, vbus :: Maybe Int } - | VX { xvalue :: [Word8], vbus :: Maybe Int } -- Used for OSC 'blobs' +data Value = VS { svalue :: String } + | VF { fvalue :: Double } + | VN { nvalue :: Note } + | VR { rvalue :: Rational } + | VI { ivalue :: Int } + | VB { bvalue :: Bool } + | VX { xvalue :: [Word8] } -- Used for OSC 'blobs' deriving (Typeable, Data, Generic) class Valuable a where @@ -291,70 +290,70 @@ class Valuable a where instance NFData Value instance Valuable String where - toValue a = VS a Nothing + toValue a = VS a instance Valuable Double where - toValue a = VF a Nothing + toValue a = VF a instance Valuable Rational where - toValue a = VR a Nothing + toValue a = VR a instance Valuable Int where - toValue a = VI a Nothing + toValue a = VI a instance Valuable Bool where - toValue a = VB a Nothing + toValue a = VB a instance Valuable [Word8] where - toValue a = VX a Nothing + toValue a = VX a instance Eq Value where - (VS x _) == (VS y _) = x == y - (VB x _) == (VB y _) = x == y - (VF x _) == (VF y _) = x == y - (VI x _) == (VI y _) = x == y - (VN x _) == (VN y _) = x == y - (VR x _) == (VR y _) = x == y - (VX x _) == (VX y _) = x == y + (VS x) == (VS y) = x == y + (VB x) == (VB y) = x == y + (VF x) == (VF y) = x == y + (VI x) == (VI y) = x == y + (VN x) == (VN y) = x == y + (VR x) == (VR y) = x == y + (VX x) == (VX y) = x == y - (VF x _) == (VI y _) = x == fromIntegral y - (VI y _) == (VF x _) = x == fromIntegral y + (VF x) == (VI y) = x == fromIntegral y + (VI y) == (VF x) = x == fromIntegral y - (VF x _) == (VR y _) = toRational x == y - (VR y _) == (VF x _) = toRational x == y - (VI x _) == (VR y _) = toRational x == y - (VR y _) == (VI x _) = toRational x == y + (VF x) == (VR y) = toRational x == y + (VR y) == (VF x) = toRational x == y + (VI x) == (VR y) = toRational x == y + (VR y) == (VI x) = toRational x == y _ == _ = False instance Ord Value where - compare (VS x _) (VS y _) = compare x y - compare (VB x _) (VB y _) = compare x y - compare (VF x _) (VF y _) = compare x y - compare (VN x _) (VN y _) = compare (unNote x) (unNote y) - compare (VI x _) (VI y _) = compare x y - compare (VR x _) (VR y _) = compare x y - compare (VX x _) (VX y _) = compare x y + compare (VS x) (VS y) = compare x y + compare (VB x) (VB y) = compare x y + compare (VF x) (VF y) = compare x y + compare (VN x) (VN y) = compare (unNote x) (unNote y) + compare (VI x) (VI y) = compare x y + compare (VR x) (VR y) = compare x y + compare (VX x) (VX y) = compare x y - compare (VS _ _) _ = LT - compare _ (VS _ _) = GT - compare (VB _ _) _ = LT - compare _ (VB _ _) = GT - compare (VX _ _) _ = LT - compare _ (VX _ _) = GT + compare (VS _) _ = LT + compare _ (VS _) = GT + compare (VB _) _ = LT + compare _ (VB _) = GT + compare (VX _) _ = LT + compare _ (VX _) = GT - compare (VF x _) (VI y _) = compare x (fromIntegral y) - compare (VI x _) (VF y _) = compare (fromIntegral x) y + compare (VF x) (VI y) = compare x (fromIntegral y) + compare (VI x) (VF y) = compare (fromIntegral x) y - compare (VR x _) (VI y _) = compare x (fromIntegral y) - compare (VI x _) (VR y _) = compare (fromIntegral x) y + compare (VR x) (VI y) = compare x (fromIntegral y) + compare (VI x) (VR y) = compare (fromIntegral x) y - compare (VF x _) (VR y _) = compare x (fromRational y) - compare (VR x _) (VF y _) = compare (fromRational x) y + compare (VF x) (VR y) = compare x (fromRational y) + compare (VR x) (VF y) = compare (fromRational x) y - compare (VN x _) (VI y _) = compare x (fromIntegral y) - compare (VI x _) (VN y _) = compare (fromIntegral x) y + compare (VN x) (VI y) = compare x (fromIntegral y) + compare (VI x) (VN y) = compare (fromIntegral x) y - compare (VN x _) (VR y _) = compare (unNote x) (fromRational y) - compare (VR x _) (VN y _) = compare (fromRational x) (unNote y) + compare (VN x) (VR y) = compare (unNote x) (fromRational y) + compare (VR x) (VN y) = compare (fromRational x) (unNote y) - compare (VF x _) (VN y _) = compare x (unNote y) - compare (VN x _) (VF y _) = compare (unNote x) y + compare (VF x) (VN y) = compare x (unNote y) + compare (VN x) (VF y) = compare (unNote x) y type StateMap = Map.Map String (Pattern Value) @@ -510,10 +509,10 @@ class TolerantEq a where (~==) :: a -> a -> Bool 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 + (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 ControlMap where @@ -612,13 +611,13 @@ instance Num ControlMap where negate = (applyFIS negate negate id <$>) (+) = Map.unionWith (fNum2 (+) (+)) (*) = Map.unionWith (fNum2 (*) (*)) - fromInteger i = Map.singleton "n" $ VI (fromInteger i) Nothing + fromInteger i = Map.singleton "n" $ VI (fromInteger i) signum = (applyFIS signum signum id <$>) abs = (applyFIS abs abs id <$>) instance Fractional ControlMap where recip = fmap (applyFIS recip id id) - fromRational r = Map.singleton "speed" $ VF (fromRational r) Nothing + fromRational r = Map.singleton "speed" $ VF (fromRational r) ------------------------------------------------------------------------ -- * Internal functions @@ -676,52 +675,52 @@ withPart f = withEvent (\(Event c w p v) -> Event c w (f p) v) -- | Apply one of three functions to a Value, depending on its type applyFIS :: (Double -> Double) -> (Int -> Int) -> (String -> String) -> Value -> Value -applyFIS f _ _ (VF f' b) = VF (f f') b -applyFIS f _ _ (VN (Note f') b) = VN (Note $ f f') b -applyFIS _ f _ (VI i b) = VI (f i) b -applyFIS _ _ f (VS s b) = VS (f s) b +applyFIS f _ _ (VF f') = VF (f f') +applyFIS f _ _ (VN (Note f')) = VN (Note $ f f') +applyFIS _ f _ (VI i) = VI (f i) +applyFIS _ _ f (VS s) = VS (f s) applyFIS _ _ _ v = v -- | Apply one of two functions to a pair of Values, depending on their types (int -- or float; strings and rationals are ignored) fNum2 :: (Int -> Int -> Int) -> (Double -> Double -> Double) -> Value -> Value -> Value -fNum2 fInt _ (VI a abus) (VI b bbus) = VI (fInt a b) (matchMaybe abus bbus) -fNum2 _ fFloat (VF a abus) (VF b bbus) = VF (fFloat a b) (matchMaybe abus bbus) -fNum2 _ fFloat (VN (Note a) abus) (VN (Note b) bbus) = VN (Note $ fFloat a b) (matchMaybe abus bbus) -fNum2 _ fFloat (VI a abus) (VF b bbus) = VF (fFloat (fromIntegral a) b) (matchMaybe abus bbus) -fNum2 _ fFloat (VF a abus) (VI b bbus) = VF (fFloat a (fromIntegral b)) (matchMaybe abus bbus) +fNum2 fInt _ (VI a) (VI b) = VI (fInt a b) +fNum2 _ fFloat (VF a) (VF b) = VF (fFloat a b) +fNum2 _ fFloat (VN (Note a)) (VN (Note b)) = VN (Note $ fFloat a b) +fNum2 _ fFloat (VI a) (VF b) = VF (fFloat (fromIntegral a) b) +fNum2 _ fFloat (VF a) (VI b) = VF (fFloat a (fromIntegral b)) fNum2 _ _ x _ = x getI :: Value -> Maybe Int -getI (VI i _) = Just i -getI (VR x _) = Just $ floor x -getI (VF x _) = Just $ floor x +getI (VI i) = Just i +getI (VR x) = Just $ floor x +getI (VF x) = Just $ floor x getI _ = Nothing getF :: Value -> Maybe Double -getF (VF f _) = Just f -getF (VR x _) = Just $ fromRational x -getF (VI x _) = Just $ fromIntegral x +getF (VF f) = Just f +getF (VR x) = Just $ fromRational x +getF (VI x) = Just $ fromIntegral x getF _ = Nothing getN :: Value -> Maybe Note -getN (VF f _) = Just $ Note f -getN (VR x _) = Just $ Note $ fromRational x -getN (VI x _) = Just $ Note $ fromIntegral x +getN (VF f) = Just $ Note f +getN (VR x) = Just $ Note $ fromRational x +getN (VI x) = Just $ Note $ fromIntegral x getN _ = Nothing getS :: Value -> Maybe String -getS (VS s _) = Just s +getS (VS s) = Just s getS _ = Nothing getB :: Value -> Maybe Bool -getB (VB b _) = Just b +getB (VB b) = Just b getB _ = Nothing getR :: Value -> Maybe Rational -getR (VR r _) = Just r -getR (VF x _) = Just $ toRational x -getR (VI x _) = Just $ toRational x +getR (VR r) = Just r +getR (VF x) = Just $ toRational x +getR (VI x) = Just $ toRational x getR _ = Nothing @@ -749,7 +748,7 @@ extractR :: String -> ControlPattern -> Pattern Rational extractR = _extract getR getBlob :: Value -> Maybe [Word8] -getBlob (VX xs _) = Just xs +getBlob (VX xs) = Just xs getBlob _ = Nothing compressArc :: Arc -> Pattern a -> Pattern a @@ -837,7 +836,3 @@ matchManyToOne f pa pb = pa {query = q} where as' = as $ start $ wholeOrPart ex as s = query pa $ fQuery s fQuery s = st {arc = Arc s s} - --- Set the bus for values within a control pattern -dial :: Int -> ControlPattern -> ControlPattern -dial i = fmap (fmap (\v -> v {vbus = Just i})) diff --git a/src/Sound/Tidal/Show.hs b/src/Sound/Tidal/Show.hs index 485de910d..acd4f7c12 100644 --- a/src/Sound/Tidal/Show.hs +++ b/src/Sound/Tidal/Show.hs @@ -64,17 +64,13 @@ instance Show Context where show (Context cs) = show cs instance Show Value where - show (VS s bus) = showbus bus $ ('"':s) ++ "\"" - show (VI i bus) = showbus bus $ show i - show (VF f bus) = showbus bus $ show f ++ "f" - show (VN n bus) = showbus bus $ show n ++ "n" - show (VR r bus) = showbus bus $ show r ++ "r" - show (VB b bus) = showbus bus $ show b - show (VX xs bus) = showbus bus $ show xs - -showbus :: Maybe Int -> String -> String -showbus Nothing s = s -showbus (Just i) s = s ++ "(" ++ show i ++ ")" + show (VS s) = ('"':s) ++ "\"" + show (VI i) = show i + show (VF f) = show f ++ "f" + show (VN n) = show n ++ "n" + show (VR r) = show r ++ "r" + show (VB b) = show b + show (VX xs) = show xs instance {-# OVERLAPPING #-} Show ControlMap where show m = intercalate ", " $ map (\(name, v) -> name ++ ": " ++ show v) $ Map.toList m diff --git a/src/Sound/Tidal/Stream.hs b/src/Sound/Tidal/Stream.hs index fc905a5b2..c0cc97705 100644 --- a/src/Sound/Tidal/Stream.hs +++ b/src/Sound/Tidal/Stream.hs @@ -111,17 +111,17 @@ type PlayMap = Map.Map PatId PlayState sDefault :: String -> Maybe Value -sDefault x = Just $ VS x Nothing +sDefault x = Just $ VS x fDefault :: Double -> Maybe Value -fDefault x = Just $ VF x Nothing +fDefault x = Just $ VF x rDefault :: Rational -> Maybe Value -rDefault x = Just $ VR x Nothing +rDefault x = Just $ VR x iDefault :: Int -> Maybe Value -iDefault x = Just $ VI x Nothing +iDefault x = Just $ VI x bDefault :: Bool -> Maybe Value -bDefault x = Just $ VB x Nothing +bDefault x = Just $ VB x xDefault :: [Word8] -> Maybe Value -xDefault x = Just $ VX x Nothing +xDefault x = Just $ VX x required :: Maybe Value required = Nothing @@ -249,26 +249,24 @@ startTidal target config = startStream config [(target, [superdirtShape])] startMulti :: [Target] -> Config -> IO () startMulti _ _ = hPutStrLn stderr $ "startMulti has been removed, please check the latest documentation on tidalcycles.org" -toDatum :: [Int] -> Value -> O.Datum -toDatum _ (VF x Nothing) = O.float x -toDatum _ (VI x Nothing) = O.int32 x -toDatum _ (VS x Nothing) = O.string x -toDatum _ (VR x Nothing) = O.float $ ((fromRational x) :: Double) -toDatum _ (VB True Nothing) = O.int32 (1 :: Int) -toDatum _ (VB False Nothing) = O.int32 (0 :: Int) -toDatum _ (VX xs Nothing) = O.Blob $ O.blob_pack xs -toDatum [] v = O.string ('c':(show $ (fromJust $ vbus v))) -toDatum busses v = O.string ('c':(show $ busses !!! (fromJust $ vbus v))) - -toData :: [Int] -> OSC -> Event ControlMap -> Maybe [O.Datum] -toData busses (OSC {args = ArgList as}) e = fmap (fmap (toDatum busses)) $ sequence $ map (\(n,v) -> Map.lookup n (value e) <|> v) as -toData busses (OSC {args = Named rqrd}) e - | hasRequired rqrd = Just $ concatMap (\(n,v) -> [O.string n, toDatum busses v]) $ Map.toList $ value e +toDatum :: Value -> O.Datum +toDatum (VF x) = O.float x +toDatum (VI x) = O.int32 x +toDatum (VS x) = O.string x +toDatum (VR x) = O.float $ ((fromRational x) :: Double) +toDatum (VB True) = O.int32 (1 :: Int) +toDatum (VB False) = O.int32 (0 :: Int) +toDatum (VX xs) = O.Blob $ O.blob_pack xs + +toData :: OSC -> Event ControlMap -> Maybe [O.Datum] +toData (OSC {args = ArgList as}) e = fmap (fmap (toDatum)) $ sequence $ map (\(n,v) -> Map.lookup n (value e) <|> v) as +toData (OSC {args = Named rqrd}) e + | hasRequired rqrd = Just $ concatMap (\(n,v) -> [O.string n, toDatum v]) $ Map.toList $ value e | otherwise = Nothing where hasRequired [] = True hasRequired xs = null $ filter (not . (`elem` ks)) xs ks = Map.keys (value e) -toData _ _ _ = Nothing +toData _ _ = Nothing substitutePath :: String -> ControlMap -> Maybe String substitutePath str cm = parse str @@ -285,13 +283,13 @@ substitutePath str cm = parse str getString :: ControlMap -> String -> Maybe String getString cm s = defaultValue $ simpleShow <$> Map.lookup s cm where simpleShow :: Value -> String - simpleShow (VS str _) = str - simpleShow (VI i _) = show i - simpleShow (VF f _) = show f - simpleShow (VN n _) = show n - simpleShow (VR r _) = show r - simpleShow (VB b _) = show b - simpleShow (VX xs _) = show xs + simpleShow (VS str) = str + simpleShow (VI i) = show i + simpleShow (VF f) = show f + simpleShow (VN n) = show n + simpleShow (VR r) = show r + simpleShow (VB b) = show b + simpleShow (VX xs) = show xs (_, dflt) = break (== '=') s defaultValue :: Maybe String -> Maybe String defaultValue Nothing | null dflt = Nothing @@ -308,8 +306,11 @@ playStack pMap = stack $ map pattern active toOSC :: Double -> [Int] -> Event ControlMap -> T.Tempo -> OSC -> [(Double, Bool, O.Message)] toOSC latency busses e tempo osc@(OSC _ _) = catMaybes (playmsg:busmsgs) - where playmsg | eventHasOnset e = do vs <- toData busses osc addExtra - mungedPath <- substitutePath (path osc) (value e) + where (busmap, playmap) = Map.partitionWithKey (\k _ -> null k || head k /= '^') $ value e + -- swap in bus ids where needed + playmap' = Map.union (Map.mapKeys tail $ Map.map (\(VI i) -> VS ('c':(show i))) busmap) playmap + playmsg | eventHasOnset e = do vs <- toData osc addExtra + mungedPath <- substitutePath (path osc) playmap' return (ts, False, -- bus message ? O.Message mungedPath vs @@ -318,24 +319,24 @@ toOSC latency busses e tempo osc@(OSC _ _) toBus n | null busses = n | otherwise = busses !!! n busmsgs = map - (\v -> do b <- toBus <$> vbus v - return $ (tsPart, - True, -- bus message ? - O.Message "/c_set" [O.int32 b, toDatum busses $ v {vbus = Nothing}] - ) + (\(('^':k), (VI b)) -> do v <- Map.lookup k playmap + return $ (tsPart, + True, -- bus message ? + O.Message "/c_set" [O.int32 b, toDatum v] + ) ) - (Map.elems $ value e) + (Map.toList busmap) onPart = sched tempo $ start $ part e on = sched tempo $ start $ wholeOrPart e off = sched tempo $ stop $ wholeOrPart e delta = off - on -- If there is already cps in the event, the union will preserve that. addExtra = (\v -> (Map.union v extra)) <$> e - extra = Map.fromList [("cps", (VF (T.cps tempo) Nothing)), - ("delta", VF delta Nothing), - ("cycle", VF (fromRational $ start $ wholeOrPart e) Nothing) + extra = Map.fromList [("cps", (VF (T.cps tempo))), + ("delta", VF delta), + ("cycle", VF (fromRational $ start $ wholeOrPart e)) ] - nudge = fromJust $ getF $ fromMaybe (VF 0 Nothing) $ Map.lookup "nudge" $ value e + nudge = fromJust $ getF $ fromMaybe (VF 0) $ Map.lookup "nudge" $ value e ts = on + nudge + latency tsPart = onPart + nudge + latency @@ -351,11 +352,11 @@ toOSC latency _ e tempo (OSCContext oscpath) delta = off - on cyc :: Double cyc = fromRational $ start $ wholeOrPart e - nudge = fromJust $ getF $ fromMaybe (VF 0 Nothing) $ Map.lookup "nudge" $ value e + nudge = fromJust $ getF $ fromMaybe (VF 0) $ Map.lookup "nudge" $ value e ts = on + nudge + latency doCps :: MVar T.Tempo -> (Double, Maybe Value) -> IO () -doCps tempoMV (d, Just (VF cps Nothing)) = +doCps tempoMV (d, Just (VF cps)) = do _ <- forkIO $ do threadDelay $ floor $ d * 1000000 -- hack to stop things from stopping ! -- TODO is this still needed? @@ -436,7 +437,7 @@ doTick fake stream st = | otherwise = patstack frameEnd = snd $ T.nowTimespan st -- add cps to state - sMap' = Map.insert "_cps" (pure $ VF (T.cps tempo) Nothing) sMap + sMap' = Map.insert "_cps" (pure $ VF (T.cps tempo)) sMap --filterOns = filter eventHasOnset extraLatency | fake = 0 | otherwise = cFrameTimespan config + T.nudged tempo @@ -524,7 +525,7 @@ streamReplace s k !pat now <- O.time let cyc = T.timeToCycles tempo now putMVar (sInput s) $ - Map.insert ("_t_all") (pure $ VR cyc Nothing) $ Map.insert ("_t_" ++ show k) (pure $ VR cyc Nothing) input + Map.insert ("_t_all") (pure $ VR cyc) $ Map.insert ("_t_" ++ show k) (pure $ VR cyc) input -- update the pattern itself pMap <- seq x $ takeMVar $ sPMapMV s let playState = updatePS $ Map.lookup (show k) pMap @@ -627,11 +628,11 @@ ctrlResponder (stream@(Stream {sListen = Just sock})) = do ms <- O.recvMessages act (O.Message x (O.Int32 k:v:[])) = act (O.Message x [O.string $ show k,v]) act (O.Message _ (O.ASCII_String k:v@(O.Float _):[])) - = add (O.ascii_to_string k) (VF (fromJust $ O.datum_floating v) Nothing) + = add (O.ascii_to_string k) (VF (fromJust $ O.datum_floating v)) act (O.Message _ (O.ASCII_String k:O.ASCII_String v:[])) - = add (O.ascii_to_string k) (VS (O.ascii_to_string v) Nothing) + = add (O.ascii_to_string k) (VS (O.ascii_to_string v)) act (O.Message _ (O.ASCII_String k:O.Int32 v:[])) - = add (O.ascii_to_string k) (VI (fromIntegral v) Nothing) + = add (O.ascii_to_string k) (VI (fromIntegral v)) act m = hPutStrLn stderr $ "Unhandled OSC: " ++ show m add :: String -> Value -> IO () add k v = do sMap <- takeMVar (sInput stream) diff --git a/src/Sound/Tidal/UI.hs b/src/Sound/Tidal/UI.hs index ec393dcb4..d40724ace 100644 --- a/src/Sound/Tidal/UI.hs +++ b/src/Sound/Tidal/UI.hs @@ -1723,10 +1723,10 @@ contrastRange -> ControlPattern -> Pattern a contrastRange = contrastBy f - where f (VI s _, VI e _) (VI v _) = v >= s && v <= e - f (VF s _, VF e _) (VF v _) = v >= s && v <= e - f (VN s _, VN e _) (VN v _) = v >= s && v <= e - f (VS s _, VS e _) (VS v _) = v == s && v == e + where f (VI s, VI e) (VI v) = v >= s && v <= e + f (VF s, VF e) (VF v) = v >= s && v <= e + f (VN s, VN e) (VN v) = v >= s && v <= e + f (VS s, VS e) (VS v) = v == s && v == e f _ _ = False -- | Like @contrast@, but one function is given, and applied to events with matching controls.