Skip to content

Commit

Permalink
modulated range notations added; oscillator names all shortened to th…
Browse files Browse the repository at this point in the history
…ree letters
  • Loading branch information
dktr0 committed Nov 29, 2018
1 parent e431f19 commit b15af73
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
Punctual.jsexe
punctual.jsexe
.DS_Store
dist
dist-*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -4,4 +4,4 @@ build:
stack build

install:
cp -Rf $$(stack path --local-install-root)/bin/Punctual.jsexe .
cp -Rf $$(stack path --local-install-root)/bin/punctual.jsexe .
45 changes: 42 additions & 3 deletions Sound/Punctual/Parser.hs
Expand Up @@ -69,7 +69,6 @@ punctualParser :: GenParser Char a [Expression]
punctualParser = do
whiteSpace
x <- expression `sepBy` reservedOp ";"
eof
return x

runPunctualParser :: String -> Either ParseError [Expression]
Expand All @@ -90,6 +89,7 @@ productOfGraphs = chainl1 simpleGraph (reservedOp "*" >> return Product)
simpleGraph :: GenParser Char a Graph
simpleGraph = choice [
parens graphParser,
try $ modulatedRange,
Constant <$> extent,
reserved "noise" >> return Noise,
reserved "pink" >> return Pink,
Expand All @@ -99,12 +99,51 @@ simpleGraph = choice [
FromTarget <$> lexeme identifier
]

-- x <> 440 +- 2% { sine 0.5 }
-- x <> 440 +- 10 { sine 0.5 }
-- x <> 430 .. 450 { sine 0.5 }

modulatedRange :: GenParser Char a Graph
modulatedRange = do
(a,b) <- rangeParser
m <- braces simpleGraph
return $ Sum (average a b) (Product (Product (difference b a) (Constant 0.5)) m)

average :: Graph -> Graph -> Graph
average x y = Product (Sum x y) (Constant 0.5)

rangeParser :: GenParser Char a (Graph,Graph)
rangeParser = choice [
try $ do
x <- Constant <$> extent
reservedOp "+-"
y <- Constant <$> extentPercent
let y' = Product x y
return (difference x y',Sum x y'),
try $ do
x <- Constant <$> extent
reservedOp "+-"
y <- Constant <$> extent
return (difference x y,Sum x y),
try $ do
x <- Constant <$> extent
reservedOp ".."
y <- Constant <$> extent
return (x,y),
try $ do
x <- Constant <$> extent
return (Constant 0,x)
]

difference :: Graph -> Graph -> Graph
difference x y = Sum x (Product y (Constant (-1)))

oscillators :: GenParser Char a Graph
oscillators = choice [
Sine <$> (reserved "sine" >> simpleGraph),
Sine <$> (reserved "sin" >> simpleGraph),
Tri <$> (reserved "tri" >> simpleGraph),
Saw <$> (reserved "saw" >> simpleGraph),
Square <$> (reserved "square" >> simpleGraph)
Square <$> (reserved "sqr" >> simpleGraph)
]

filters :: GenParser Char a Graph
Expand Down
4 changes: 2 additions & 2 deletions Sound/Punctual/Token.hs
Expand Up @@ -13,8 +13,8 @@ tokenParser = P.makeTokenParser $ P.LanguageDef {
P.identLetter = alphaNum <|> char '_',
P.opStart = oneOf "+*:@<>~=%",
P.opLetter = oneOf "+*:@<>~=%",
P.reservedNames = ["c","s","ms","db","sine","tri","saw","square","noise","pink","lpf","hpf","adsr","mix"],
P.reservedOpNames = ["+","*",":","@","<>","~","=","%",";"],
P.reservedNames = ["c","s","ms","db","sin","tri","saw","sqr","noise","pink","lpf","hpf","mix"],
P.reservedOpNames = ["+","*",":","@","<>","~","=","%",";","+-",".."],
P.caseSensitive = False
}

Expand Down

0 comments on commit b15af73

Please sign in to comment.