-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
345 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,83 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
-- {-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Minipat.Dirt.Eval | ||
( liveEvalPat | ||
, liveEvalSoundPat | ||
) | ||
-- ( liveEvalPat | ||
-- , liveEvalSoundPat | ||
-- , liveEvalNotePat | ||
-- ) | ||
where | ||
|
||
import Dahdit.Midi.Osc (Datum (..), DatumType (..)) | ||
import Data.Map.Strict qualified as Map | ||
import Data.Text (Text) | ||
import Data.Void (Void) | ||
import Looksee (intP, sciP) | ||
import Minipat.Ast (Ident (..), Pattern (..), Select (..)) | ||
import Minipat.Dirt.Osc (Attrs) | ||
import Minipat.Eval (EvalEnv (..), evalPat) | ||
import Minipat.Interp (InterpEnv (..), InterpErr (..), forbidInterpEnv) | ||
import Minipat.Parser (P, identP) | ||
|
||
datumP :: DatumType -> P Datum | ||
datumP = \case | ||
DatumTypeInt32 -> fmap (DatumInt32 . fromInteger) intP | ||
DatumTypeInt64 -> fmap (DatumInt64 . fromInteger) intP | ||
DatumTypeFloat -> fmap (DatumFloat . realToFrac) sciP | ||
DatumTypeDouble -> fmap (DatumDouble . realToFrac) sciP | ||
DatumTypeString -> fmap (DatumString . unIdent) identP | ||
dt -> fail ("Datum type is not parseable: " <> show dt) | ||
|
||
forbidEvalEnv :: DatumType -> EvalEnv e Datum | ||
forbidEvalEnv dt = EvalEnv forbidInterpEnv (datumP dt) | ||
|
||
liveEvalPat :: (Pattern f) => DatumType -> Text -> f Datum | ||
liveEvalPat dt txt = either (pure patEmpty) id (evalPat @_ @Void (forbidEvalEnv dt) txt) | ||
|
||
data SoundSelectErr = SoundSelectErr | ||
deriving stock (Eq, Ord, Show) | ||
|
||
soundSelFn :: (Pattern f) => Select -> f Attrs -> Either (InterpErr SoundSelectErr) (f Attrs) | ||
soundSelFn sel attrs = | ||
case sel of | ||
SelectSample n -> Right (fmap (Map.insert "note" (DatumInt32 (fromIntegral n))) attrs) | ||
_ -> Left (InterpErrEmbed SoundSelectErr) | ||
|
||
soundProjFn :: Ident -> Attrs | ||
soundProjFn = Map.singleton "sound" . DatumString . unIdent | ||
|
||
soundInterpEnv :: InterpEnv SoundSelectErr Ident Attrs | ||
soundInterpEnv = InterpEnv soundSelFn soundProjFn | ||
|
||
soundEvalEnv :: EvalEnv SoundSelectErr Attrs | ||
soundEvalEnv = EvalEnv soundInterpEnv identP | ||
|
||
liveEvalSoundPat :: (Pattern f) => Text -> f Attrs | ||
liveEvalSoundPat txt = either (pure patEmpty) id (evalPat soundEvalEnv txt) | ||
-- import Control.Exception (Exception) | ||
-- import Dahdit.Midi.Osc (Datum (..), DatumType (..)) | ||
-- import Data.Map.Strict qualified as Map | ||
-- import Data.Text (Text) | ||
-- import Data.Void (Void) | ||
-- import Looksee (intP, sciP) | ||
-- import Minipat.Ast (Ident (..), Pattern (..), Select (..)) | ||
-- import Minipat.Dirt.Notes (LinNote) | ||
-- import Minipat.Dirt.Osc (Attrs) | ||
-- import Minipat.Eval (evalPat) | ||
-- import Minipat.Interp (InterpErr (..)) | ||
-- import Minipat.Parser (P, identP) | ||
-- | ||
-- datumP :: DatumType -> P Datum | ||
-- datumP = \case | ||
-- DatumTypeInt32 -> fmap (DatumInt32 . fromInteger) intP | ||
-- DatumTypeInt64 -> fmap (DatumInt64 . fromInteger) intP | ||
-- DatumTypeFloat -> fmap (DatumFloat . realToFrac) sciP | ||
-- DatumTypeDouble -> fmap (DatumDouble . realToFrac) sciP | ||
-- DatumTypeString -> fmap (DatumString . unIdent) identP | ||
-- dt -> fail ("Datum type is not parseable: " <> show dt) | ||
-- | ||
-- forbidEvalEnv :: DatumType -> EvalEnv e Datum | ||
-- forbidEvalEnv dt = EvalEnv forbidInterpEnv (datumP dt) | ||
-- | ||
-- liveEvalPat :: (Pattern f) => DatumType -> Text -> f Datum | ||
-- liveEvalPat dt txt = either (pure patEmpty) id (evalPat @_ @Void (forbidEvalEnv dt) txt) | ||
-- | ||
-- data SoundSelectErr = SoundSelectErr | ||
-- deriving stock (Eq, Ord, Show) | ||
-- | ||
-- instance Exception SoundSelectErr | ||
-- | ||
-- soundSel :: (Pattern f) => Select -> f Attrs -> Either (InterpErr SoundSelectErr) (f Attrs) | ||
-- soundSel sel attrs = | ||
-- case sel of | ||
-- SelectSample n -> Right (fmap (Map.insert "note" (DatumInt32 (fromIntegral n))) attrs) | ||
-- _ -> Left (InterpErrEmbed SoundSelectErr) | ||
-- | ||
-- soundProj :: Ident -> Attrs | ||
-- soundProj = Map.singleton "sound" . DatumString . unIdent | ||
-- | ||
-- soundInterpEnv :: InterpEnv SoundSelectErr Ident Attrs | ||
-- soundInterpEnv = InterpEnv soundSel soundProj | ||
-- | ||
-- soundEvalEnv :: EvalEnv SoundSelectErr Attrs | ||
-- soundEvalEnv = EvalEnv soundInterpEnv identP | ||
-- | ||
-- -- TODO parse sound with note selector here instead of having it in the grammar | ||
-- liveEvalSoundPat :: (Pattern f) => Text -> f Attrs | ||
-- liveEvalSoundPat txt = either (pure patEmpty) id (evalPat soundEvalEnv txt) | ||
-- | ||
-- noteProjFn :: Integer -> Attrs | ||
-- noteProjFn = Map.singleton "note" . DatumInt32 . fromInteger | ||
-- | ||
-- data NoteErr = NoteErr | ||
-- deriving stock (Eq, Ord, Show) | ||
-- | ||
-- instance Exception NoteErr | ||
-- | ||
-- linNoteP :: P LinNote | ||
-- linNoteP = error "TODO" | ||
-- | ||
-- noteProj :: LinNote -> Attrs | ||
-- noteProj = error "TODO" | ||
-- | ||
-- noteInterpEnv :: InterpEnv NoteErr LinNote Attrs | ||
-- noteInterpEnv = InterpEnv forbidSel noteProj | ||
-- | ||
-- noteEvalEnv :: EvalEnv NoteErr Attrs | ||
-- noteEvalEnv = EvalEnv noteInterpEnv linNoteP | ||
-- | ||
-- liveEvalNotePat :: (Pattern f) => Text -> f Attrs | ||
-- liveEvalNotePat txt = either (pure patEmpty) id (evalPat noteEvalEnv txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.