Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

various experiments

  • Loading branch information...
commit 7aa2905d390480f6bbf8c16f6b4f32fc860a5dc9 1 parent 5270938
@yaxu authored
Showing with 17 additions and 4 deletions.
  1. +14 −2 Parse.hs
  2. +3 −2 Stream.hs
View
16 Parse.hs
@@ -13,6 +13,15 @@ import Data.Colour.SRGB
import GHC.Exts( IsString(..) )
+class (Pattern p) => ParseablePattern p where
+ parsePattern :: Parseable a => String -> p a
+
+instance ParseablePattern Sequence where
+ parsePattern = p
+
+instance ParseablePattern Signal where
+ parsePattern = toSignal . p
+
class Parseable a where
p :: String -> Sequence a
@@ -33,8 +42,11 @@ type ColourD = Colour Double
instance Parseable ColourD where
p = parseRhythm pColour
-instance (Parseable a) => IsString (Sequence a) where
- fromString = p
+instance (ParseablePattern p, Parseable a) => IsString (p a) where
+ fromString = parsePattern
+
+--instance (Parseable a, Pattern p) => IsString (p a) where
+-- fromString = p :: String -> p a
lexer = P.makeTokenParser haskellDef
braces = P.braces lexer
View
5 Stream.hs
@@ -11,6 +11,7 @@ import Control.Concurrent.MVar
import Pattern
import Data.Ratio
--import Control.Exception
+import Parse
import qualified Data.Map as Map
@@ -118,7 +119,7 @@ onTick s shape patternM change ticks
catch (mapM_ (send s) messages) (\msg -> putStrLn $ "oops " ++ show msg)
return ()
-make :: Pattern p => (a -> Datum) -> OscShape -> String -> p a -> (p OscMap)
+make :: ParseablePattern p => (a -> Datum) -> OscShape -> String -> p a -> (p OscMap)
make toOsc s nm p = fmap (\x -> Map.singleton nParam (defaultV x)) p
where nParam = param s nm
defaultV a = Just $ toOsc a
@@ -132,7 +133,7 @@ param :: OscShape -> String -> Param
param shape n = head $ filter (\x -> name x == n) (params shape)
-- Merge any pattern with a sequence
-merge :: Pattern p => OscSequence -> p OscMap -> OscSequence
+merge :: ParseablePattern p => OscSequence -> p OscMap -> OscSequence
merge x y = Map.union <$> x <~> y
infixr 1 ~~
Please sign in to comment.
Something went wrong with that request. Please try again.