Skip to content

Commit

Permalink
fiddles
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Dec 11, 2012
1 parent db76aaf commit bd0b2a8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
7 changes: 5 additions & 2 deletions AdeSync.hs
@@ -1,18 +1,21 @@
import Sound.OpenSoundControl import Sound.OpenSoundControl
import Network.Netclock.Client import Network.Netclock.Client
import Control.Concurrent (threadDelay, forkIO)


tpb = 4 tpb = 4
address = "127.0.0.1" address = "127.0.0.1"


adeip = "192.168.1.3" adeip = "10.0.0.3"
adeport = 1777 adeport = 1777


main = clocked "adesync" address address tpb ot main = do putStrLn "start"
clocked "adesync" address address tpb ot


ot :: BpsChange -> Int -> IO () ot :: BpsChange -> Int -> IO ()
ot change tick = do putStrLn "tick" ot change tick = do putStrLn "tick"
ade <- openUDP adeip adeport ade <- openUDP adeip adeport
let m = Message "/PureEvents/Beat" [Int tick] let m = Message "/PureEvents/Beat" [Int tick]
threadDelay $ 1000000 `div` 18
send ade m send ade m
close ade close ade
return () return ()
Expand Down
5 changes: 3 additions & 2 deletions Dirt.hs
Expand Up @@ -50,11 +50,12 @@ accellerate = makeF dirt "accellerate"
sample :: String -> Int -> String sample :: String -> Int -> String
sample name n = name ++ "/" ++ (show n) sample name n = name ++ "/" ++ (show n)


striate :: OscSequence -> Int -> OscSequence striate :: Int -> OscSequence -> OscSequence
striate p n = cat $ map (\x -> off (fromIntegral x) p) [0 .. n-1] striate n p = cat $ map (\x -> off (fromIntegral x) p) [0 .. n-1]
where off i p = p ~~ begin (atom (fromIntegral i / fromIntegral n) :: Sequence Double) ~~ end (atom (fromIntegral (i+1) / fromIntegral n) :: Sequence Double) where off i p = p ~~ begin (atom (fromIntegral i / fromIntegral n) :: Sequence Double) ~~ end (atom (fromIntegral (i+1) / fromIntegral n) :: Sequence Double)


striateO :: OscSequence -> Int -> Double -> OscSequence striateO :: OscSequence -> Int -> Double -> OscSequence
striateO p n o = cat $ map (\x -> off (fromIntegral x) p) [0 .. n-1] striateO p n o = cat $ map (\x -> off (fromIntegral x) p) [0 .. n-1]
where off i p = p ~~ begin ((atom $ (fromIntegral i / fromIntegral n) + o) :: Sequence Double) ~~ end ((atom $ (fromIntegral (i+1) / fromIntegral n) + o) :: Sequence Double) where off i p = p ~~ begin ((atom $ (fromIntegral i / fromIntegral n) + o) :: Sequence Double) ~~ end ((atom $ (fromIntegral (i+1) / fromIntegral n) + o) :: Sequence Double)


metronome = slow 2 $ sound "[odx, [hh]*8]"
3 changes: 3 additions & 0 deletions Pattern.hs
Expand Up @@ -131,6 +131,9 @@ cat :: (Pattern p) => [p b] -> p b
cat ps = combine $ map (squash l) (zip [0..] ps) cat ps = combine $ map (squash l) (zip [0..] ps)
where l = length ps where l = length ps


slowcat :: (Pattern p) => [p b] -> p b
slowcat ps = slow (fromIntegral $ length ps) $ cat ps

listToPat :: Pattern p => [a] -> p a listToPat :: Pattern p => [a] -> p a
listToPat = cat . map atom listToPat = cat . map atom


Expand Down
26 changes: 26 additions & 0 deletions Strategies.hs
@@ -0,0 +1,26 @@
{-# OPTIONS_GHC -XNoMonomorphismRestriction #-}

module Strategies where

import Pattern
import Dirt
import Data.Ratio
import Control.Applicative

echo n p = combine [p, n ~> p]
double f p = combine [p, f p]

-- every 4 (smash 4 [1, 2, 3]) $ sound "[odx sn/2 [~ odx] sn/3, [~ hh]*4]"

smash n xs p = cat $ map (\n -> slow n p') xs
where p' = striate n p

brak = every 2 (((1%4) <~) . (\x -> cat [x, silence]))

-- samples "jvbass [~ latibro] [jvbass [latibro jvbass]]" ((1%2) <~ slow 6 "[1 6 8 7 3]")
samples p p' = sample <$> p <*> p'





9 changes: 6 additions & 3 deletions Stream.hs
Expand Up @@ -3,6 +3,7 @@
module Stream where module Stream where


import Data.Maybe import Data.Maybe
import Sound.OSC.FD
import Sound.OpenSoundControl import Sound.OpenSoundControl
import Control.Applicative import Control.Applicative
import Network.Netclock.Client import Network.Netclock.Client
Expand Down Expand Up @@ -66,7 +67,7 @@ isSubset xs ys = all (\x -> elem x ys) xs


tpb = 1 tpb = 1


toMessage :: OscShape -> BpsChange -> Int -> (Double, OscMap) -> Maybe OSC toMessage :: OscShape -> BpsChange -> Int -> (Double, OscMap) -> Maybe Bundle
toMessage s change ticks (o, m) = toMessage s change ticks (o, m) =
do m' <- applyShape' s m do m' <- applyShape' s m
let beat = fromIntegral ticks / fromIntegral tpb let beat = fromIntegral ticks / fromIntegral tpb
Expand All @@ -79,7 +80,7 @@ toMessage s change ticks (o, m) =
usec = floor $ 1000000 * (logicalOnset - (fromIntegral sec)) usec = floor $ 1000000 * (logicalOnset - (fromIntegral sec))
oscdata = catMaybes $ mapMaybe (\x -> Map.lookup x m') (params s) oscdata = catMaybes $ mapMaybe (\x -> Map.lookup x m') (params s)
oscdata' = ((Int sec):(Int usec):oscdata) oscdata' = ((Int sec):(Int usec):oscdata)
osc | timestamp s = Message (path s) oscdata' osc | timestamp s = Bundle (immediately) [Message (path s) oscdata']
| otherwise = Bundle (UTCr logicalOnset) [Message (path s) oscdata] | otherwise = Bundle (UTCr logicalOnset) [Message (path s) oscdata]
return osc return osc


Expand Down Expand Up @@ -117,7 +118,7 @@ onTick s shape patternM change ticks
(seqToRelOnsets (a, Just b) p) (seqToRelOnsets (a, Just b) p)
--putStrLn $ (show a) ++ ", " ++ (show b) --putStrLn $ (show a) ++ ", " ++ (show b)
--putStrLn $ "tick " ++ show ticks ++ " = " ++ show messages --putStrLn $ "tick " ++ show ticks ++ " = " ++ show messages
catch (mapM_ (send s) messages) (\msg -> putStrLn $ "oops " ++ show msg) catch (mapM_ (sendOSC s) messages) (\msg -> putStrLn $ "oops " ++ show msg)
return () return ()


make :: ParseablePattern p => (a -> Datum) -> OscShape -> String -> p a -> (p OscMap) make :: ParseablePattern p => (a -> Datum) -> OscShape -> String -> p a -> (p OscMap)
Expand All @@ -143,9 +144,11 @@ merge' x y = Map.union <$> x <~> y
infixr 1 ~~ infixr 1 ~~
(~~) = merge (~~) = merge


infixr 1 |+|
(|+|) :: OscSequence -> OscSequence -> OscSequence (|+|) :: OscSequence -> OscSequence -> OscSequence
(|+|) = (~~) (|+|) = (~~)


infixr 1 |+~
(|+~) :: OscSequence -> OscSignal -> OscSequence (|+~) :: OscSequence -> OscSignal -> OscSequence
(|+~) = (~~) (|+~) = (~~)


0 comments on commit bd0b2a8

Please sign in to comment.