packages feed

mida 0.4.6 → 1.0.0

raw patch · 19 files changed

+239/−286 lines, 19 filesdep +aesondep +data-defaultdep +path-iodep −directorydep −temporarydep ~midadep ~transformers

Dependencies added: aeson, data-default, path-io, yaml

Dependencies removed: directory, temporary

Dependency ranges changed: mida, transformers

Files

CHANGELOG.md view
@@ -1,114 +1,120 @@-# History of changes+## MIDA 1.0.0 +* Use the `path-io` library.++* Use YAML files for configuration.++* Cosmetic changes in the interface.+ ## MIDA 0.4.6 -* support for Stack and other maintenance stuff;+* Support for Stack and other maintenance stuff; -* refactoring, more type-safe code and better libraries used.+* Refactoring, more type-safe code and better libraries used.  ## MIDA 0.4.5 -* various cosmetic changes;+* Various cosmetic changes; -* make the executable Cabal-installable.+* Make the executable Cabal-installable.  ## MIDA 0.4.4 -* cosmetic corrections in source code;+* Cosmetic corrections in source code; -* switch to better libraries.+* Switch to better libraries.  ## MIDA 0.4.3 -* various corrections and cosmetic changes;+* Various corrections and cosmetic changes; -* improved printing of syntax trees;+* Improved printing of syntax trees; -* allow more flexible looping expressions.+* Allow more flexible looping expressions.  ## MIDA 0.4.2 -* introduced simplifications on the level of internal language;+* Introduced simplifications on the level of internal language; -* changed default values of some parameters;+* Changed default values of some parameters; -* some characters have been replaced with pretty Unicode symbols;+* Some characters have been replaced with pretty Unicode symbols; -* improved manual.+* Improved manual.  ## MIDA 0.4.1 -* dramatically improved efficiency, now very long compositions can be+* Dramatically improved efficiency, now very long compositions can be   quickly rendered; -* lexer: changed style of comments, shell-like comments adopted;+* Lexer: changed style of comments, shell-like comments adopted; -* changed alias of notes: dièse is written now as `s` not as `#`, so middle+* Changed alias of notes: dièse is written now as `s` not as `#`, so middle   octave is: `c5`, `cs5`, `d5`, `ds5`, `e5`, etc.; -* now there are alias for all supported (in MIDI) pitches from 0 to 127,+* Now there are alias for all supported (in MIDI) pitches from 0 to 127,   that is: from `c0` to `g10` (alias `c10` -- `g10` added); -* changed alias of modulation signs, reason for such change is purely+* Changed alias of modulation signs, reason for such change is purely   technical -- all alias now are predefined definitions, rather than   syntactic sugar, so all alias must be valid identifiers; -* identifiers can contain underline sign (`_`);+* Identifiers can contain underline sign (`_`); -* arbitrary number of files can be specified for loading (from command line,+* Arbitrary number of files can be specified for loading (from command line,   as well as from interactive REPL); -* many purely technical changes that are difficult to explain concisely, but+* Many purely technical changes that are difficult to explain concisely, but   they should be mentioned, most important being addition of test suite and   ability to generate source files from syntax trees; -* added command line options: `--license` and `--version`.+* Added command line options: `--license` and `--version`.  ## MIDA 0.4.0 -* fixed bug in batch mode;+* Fixed bug in batch mode; -* added tab completion based on contents of current input line, including+* Added tab completion based on contents of current input line, including   completion of file names for some commands; -* detection and rejection of recursive definitions;+* Detection and rejection of recursive definitions; -* improved interface;+* Improved interface; -* wholly refactored (and sometimes rewritten) code (it's finally+* Wholly refactored (and sometimes rewritten) code (it's finally   sufficiently elegant); -* more intuitive logic of evaluation in some corner cases;+* More intuitive logic of evaluation in some corner cases; -* optional displaying of simplified principles (for debug and educational+* Optional displaying of simplified principles (for debug and educational   purposes); -* ability to set tempo and program for preview;+* Ability to set tempo and program for preview; -* improved documentation.+* Improved documentation.  ## MIDA 0.3.0 -* improved interface and parsing;+* Improved interface and parsing; -* added `:prv` and `:load` special commands;+* Added `:prv` and `:load` special commands; -* added additional parameters: modulation, breath, aftertouch, and pitch+* Added additional parameters: modulation, breath, aftertouch, and pitch   bend; -* fixed minor bugs.+* Fixed minor bugs.  ## MIDA 0.2.0 -* better command line experience: history, auto-completion and more;+* Better command line experience: history, auto-completion and more; -* fixed bug with infinite translation of scores that consist of elements+* Fixed bug with infinite translation of scores that consist of elements   which have zero duration; -* introduced conception of sections;+* Introduced conception of sections; -* all operations have become fully polymorphic.+* All operations have become fully polymorphic.  ## MIDA 0.1.0 -Initial release.+* Initial release.
README.md view
@@ -24,45 +24,30 @@  ## Installation -1. Install [Haskell Platform](https://www.haskell.org/platform/);-2. Install [Cabal](https://www.haskell.org/cabal/);-3. Download and untar git repository of MIDA, or clone it:+1. Install the [Haskell Tool Stack](http://haskellstack.org). +2. Add `~/.local/bin` directory to your `PATH`, like this:+    ```-   $ git clone https://github.com/mrkkrp/mida.git+   # in .bashrc or similar+   export PATH=$HOME/.local/bin:$PATH    ``` -4. Go to the root directory of the repository and execute:+3. Clone the repo, `cd` into it, and let `stack` do its thing:     ```-   $ cabal update-   $ cabal configure-   $ cabal install --only-dependencies-   $ cabal build-   # sh install.sh+   $ git clone https://github.com/mrkkrp/mida.git+   $ cd mida+   $ stack build --copy-bins    ``` -   or (if you use Stack):+4. Check it out:     ```-   $ stack build+   $ mida --version+   MIDA 1.0.0    ``` -5. Done (you can use `uninstall.sh` to uninstall the program).--Alternatively, instead of steps 3–5, you can just:--```-$ cabal install mida-```--In this case you will need to add `~/.cabal/bin` directory to your `PATH`:--```-# in .bashrc or similar-export PATH=$HOME/.cabal/bin:$PATH-```- ## Example  Here is a simple example of MIDA program that demonstrates syntax and@@ -100,6 +85,6 @@  ## License -Copyright © 2014, 2015 Mark Karpov+Copyright © 2014–2016 Mark Karpov  Distributed under GNU GPL, version 3.
mida.cabal view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell-Cabal; -*- -- -- Cabal config for MIDA. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software@@ -17,9 +16,9 @@ -- You should have received a copy of the GNU General Public License along -- with this program. If not, see <http://www.gnu.org/licenses/>. -name:                mida-version:             0.4.6-synopsis:            Language for algorithmic generation of MIDI files+name:                 mida+version:              1.0.0+synopsis:             Language for algorithmic generation of MIDI files description:    MIDA is a minimalistic language for algorithmic generation of MIDI@@ -48,15 +47,23 @@ license-file:         LICENSE.md author:               Mark Karpov maintainer:           Mark Karpov-copyright:            Copyright © 2014, 2015 Mark Karpov+copyright:            Copyright © 2014–2016 Mark Karpov category:             Language build-type:           Simple extra-source-files:   README.md, CHANGELOG.md cabal-version:        >= 1.10 +flag dev+  description:        Turn on development settings.+  manual:             True+  default:            False+ library   hs-source-dirs:     src-  ghc-options:        -O2 -Wall+  if flag(dev)+    ghc-options:      -O2 -Wall -Werror+  else+    ghc-options:      -O2 -Wall   ghc-prof-options:   -O2 -Wall -prof -fprof-cafs -rtsopts   build-depends:      HCodecs                >= 0.5                     , base                   >= 4.8 && < 5@@ -68,13 +75,12 @@                     , random                     , text                   >= 1.2.0.4                     , tf-random              >= 0.5-                    , transformers           >= 0.2.0.0 && < 0.5+                    , transformers           >= 0.2.0.0   default-extensions: FlexibleContexts                     , FlexibleInstances                     , OverloadedStrings                     , TupleSections-  exposed-modules:    Mida.Configuration-                    , Mida.Language+  exposed-modules:    Mida.Language                     , Mida.Language.Element                     , Mida.Language.Environment                     , Mida.Language.Eval@@ -90,30 +96,36 @@   main-is:            Main.hs   hs-source-dirs:     src   other-modules:      Mida.Interaction-  ghc-options:        -O2 -Wall+  if flag(dev)+    ghc-options:      -O2 -Wall -Werror+  else+    ghc-options:      -O2 -Wall   ghc-prof-options:   -O2 -Wall -prof -fprof-cafs -rtsopts   build-depends:      HCodecs                >= 0.5+                    , aeson                  >= 0.7                     , base                   >= 4.8 && < 5                     , containers             >= 0.5.5.1-                    , directory              >= 1.2.1.0+                    , data-default           >= 0.5.3                     , exceptions             >= 0.8                     , filepath               >= 1.3.0.2                     , formatting             >= 6.2                     , haskeline              >= 0.7.1.3                     , megaparsec             >= 4.2-                    , mida                   >= 0.4.6+                    , mida                   >= 1.0.0                     , mtl                    >= 2.1.3.1                     , optparse-applicative   >= 0.11.0.2                     , path                   >= 0.5.3+                    , path-io                >= 0.3.1                     , process                >= 1.2.0.0                     , random-                    , temporary              >= 1.2                     , text                   >= 1.2.0.4                     , tf-random              >= 0.5-                    , transformers           >= 0.2.0.0 && < 0.5+                    , transformers           >= 0.2.0.0+                    , yaml                   >= 0.8.15.1   default-extensions: FlexibleContexts                     , FlexibleInstances                     , OverloadedStrings+                    , RecordWildCards                     , TupleSections   other-modules:      Mida.Configuration                     , Mida.Interaction@@ -136,21 +148,24 @@   main-is:            Main.hs   hs-source-dirs:     tests   type:               exitcode-stdio-1.0-  ghc-options:        -O2 -Wall -rtsopts+  if flag(dev)+    ghc-options:      -O2 -Wall -Werror+  else+    ghc-options:      -O2 -Wall   default-language:   Haskell2010   build-depends:      HCodecs                    >= 0.5                     , QuickCheck                 >= 2.4 && < 3                     , base                       >= 4.8 && < 5                     , containers                 >= 0.5.5.1                     , megaparsec                 >= 4.2-                    , mida                       >= 0.4.6+                    , mida                       >= 1.0.0                     , mtl                        >= 2.1.3.1                     , random                     , test-framework             >= 0.4 && < 1                     , test-framework-quickcheck2 >= 0.3 && < 0.4                     , text                       >= 1.2.0.4                     , tf-random                  >= 0.5-                    , transformers               >= 0.2.0.0 && < 0.5+                    , transformers               >= 0.2.0.0  source-repository head   type:               git
src/Main.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- -- -- Main module of MIDA describes logic of the program on top level. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software@@ -20,6 +19,7 @@ module Main (main) where  import Control.Monad+import Control.Monad.IO.Class import Data.Text.Lazy (Text) import Data.Version (showVersion) import Formatting@@ -27,10 +27,8 @@ import Mida.Interaction import Numeric.Natural import Options.Applicative-import Path+import Path.IO import Paths_mida (version)-import System.Directory (getHomeDirectory, doesFileExist, getCurrentDirectory)-import qualified Data.Map as M import qualified Data.Text.Lazy.IO as T  -- | MIDA application command line options.@@ -67,7 +65,7 @@  notice :: Text notice =-  "MIDA Copyright © 2014, 2015 Mark Karpov\n\n\+  "MIDA Copyright © 2014–2016 Mark Karpov\n\n\   \This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n\   \and you are welcome to redistribute it under certain conditions; see\n\   \GNU General Public License for details.\n"@@ -77,7 +75,7 @@ license :: Text license =   "MIDA — realization of MIDA, language for generation of MIDI files.\n\-  \Copyright © 2014, 2015 Mark Karpov\n\+  \Copyright © 2014–2016 Mark Karpov\n\   \\n\   \MIDA is free software: you can redistribute it and/or modify it under the\n\   \terms of the GNU General Public License as published by the Free Software\n\@@ -94,38 +92,27 @@  -- | Read configuration file if present and run MIDA monad. -runMida' :: Mida () -> IO ()+runMida' :: Mida a -> IO () runMida' e = do-  params <- loadConfig-  wdir   <- getCurrentDirectory >>= parseAbsDir-  dfname <- parseRelFile "foo.da"-  let dfltSrcFile = fromAbsFile (wdir </> dfname)-  srcFile <- parseAbsFile (lookupCfg params "src" dfltSrcFile)+  mconfig <- forgivingAbsence (resolveFile' ".mida.yaml")+  c <- case mconfig of+    Nothing -> return def+    Just file -> do+      econfig <- parseMidaConfig file+      case econfig of+        Left msg -> liftIO (putStrLn msg) >> return def+        Right val -> return val+  srcFile <- makeAbsolute (configSrcFile c)   void $ runMida e-    MidaSt { stPrevLen = lookupCfg params "prvlen" 18-           , stSrcFile = srcFile-           , stProg    = lookupCfg params "prog"   0-           , stTempo   = lookupCfg params "tempo"  120 }-    MidaCfg { cfgPrompt  = lookupCfg params "prompt"  "> "-            , cfgVerbose = lookupCfg params "verbose" True-            , cfgPrvCmd  = lookupCfg params "prvcmd"  "timidity"-            , cfgProgOp  = lookupCfg params "progop"  "--force-program"-            , cfgTempoOp = lookupCfg params "tempop"  "--adjust-tempo" }---- | Read configuration file.--loadConfig :: IO Params-loadConfig = do-  home  <- getHomeDirectory >>= parseAbsDir-  cfn   <- parseRelFile ".mida"-  let file = fromAbsFile (home </> cfn)-  exist <- doesFileExist file-  if exist-  then do params <- parseConfig file <$> T.readFile file-          case params of-            Right x -> return x-            Left  _ -> return M.empty-  else return M.empty+    MidaSt  { stPrevLen  = configPrevLen c+            , stSrcFile  = srcFile+            , stProg     = configProg    c+            , stTempo    = configTempo   c }+    MidaCfg { cfgPrompt  = configPrompt  c+            , cfgVerbose = configVerbose c+            , cfgPrvCmd  = configPrvCmd  c+            , cfgProgOp  = configProgOp  c+            , cfgTempoOp = configTempoOp c }  -- | Some information about the program. 
src/Mida/Configuration.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- ----- This module describes how to parse Unix-style configuration files.+-- Parse YAML configuration. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software@@ -17,82 +16,74 @@ -- You should have received a copy of the GNU General Public License along -- with this program. If not, see <http://www.gnu.org/licenses/>. -{-# LANGUAGE FlexibleInstances    #-}-{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE TemplateHaskell #-}  module Mida.Configuration-  ( Params-  , parseConfig-  , lookupCfg )+  ( MidaConfig (..)+  , parseMidaConfig+  , def ) where -import Control.Applicative-import Control.Monad-import Data.Maybe (fromMaybe, listToMaybe)-import Data.Text.Lazy (Text)-import Data.Map (Map)+import Control.Monad.IO.Class+import Data.Aeson (withObject)+import Data.Default+import Data.Yaml import Numeric.Natural-import Text.Megaparsec-import Text.Megaparsec.Text.Lazy-import qualified Data.Map as M-import qualified Text.Megaparsec.Lexer as L---- | Collection of configuration parameters. They are kept as 'String's and--- then converted on request.--type Params = Map String String--class Parsable a where-  parseValue :: String -> Maybe a--instance Parsable String where-  parseValue = Just--instance Parsable Natural where-  parseValue = fmap fst . listToMaybe . reads--instance Parsable Bool where-  parseValue "true"  = Just True-  parseValue "false" = Just False-  parseValue _       = Nothing---- | Lookup a value from configuration parameters. Type of result determines--- how value will be interpreted.--lookupCfg :: Parsable a-  => Params            -- ^ Collection of configuration parameters-  -> String            -- ^ Name of parameter to lookup-  -> a                 -- ^ Fallback value-  -> a                 -- ^ Result-lookupCfg cfg v d = fromMaybe d $ M.lookup v cfg >>= parseValue---- | Parse configuration file.--parseConfig :: String -> Text -> Either String Params-parseConfig file = either (Left . show) Right . parse pConfig file--pConfig :: Parser Params-pConfig = M.fromList <$> (sc *> many pItem <* eof)--pItem :: Parser (String, String)-pItem = (,) <$> pIdentifier <* pOperator "=" <*> (pString <|> pThing)--pIdentifier :: Parser String-pIdentifier = lexeme $ (:) <$> first <*> many other-  where first = letterChar   <|> char '_'-        other = alphaNumChar <|> char '_'+import Path -pOperator :: String -> Parser String-pOperator = lexeme . string+-- | MIDA configuration. -pString :: Parser String-pString = lexeme $ char '"' >> manyTill L.charLiteral (char '"')+data MidaConfig = MidaConfig+  { configPrevLen :: Natural       -- ^ Length of preview principles+  , configSrcFile :: Path Rel File -- ^ Name of current source file+  , configProg    :: Natural       -- ^ Program to use for preview+  , configTempo   :: Natural       -- ^ Tempo to use for preview+  , configPrompt  :: String        -- ^ REPL prompt+  , configVerbose :: Bool          -- ^ Verbose mode?+  , configPrvCmd  :: String        -- ^ Command to use for preview+  , configProgOp  :: String        -- ^ Option to set program for preview+  , configTempoOp :: String        -- ^ Option to set tempo for preview+  } deriving (Eq, Show) -pThing :: Parser String-pThing = lexeme (some alphaNumChar)+instance Default MidaConfig where+  def = MidaConfig+    { configPrevLen = 18+    , configSrcFile = $(mkRelFile "foo.da")+    , configProg    = 0+    , configTempo   = 120+    , configPrompt  = "> "+    , configVerbose = True+    , configPrvCmd  = "timidity"+    , configProgOp  = "--force-program"+    , configTempoOp = "--adjust-tempo"+    } -lexeme :: Parser a -> Parser a-lexeme = L.lexeme sc+instance FromJSON MidaConfig where+  parseJSON = withObject "MIDA Configuration" $ \o -> do+    let ω f g n = do+          mval <- o .:? n+          case mval of+            Nothing -> return (f def)+            Just val -> g val+        ξ x = case parseRelFile x of+                Nothing -> fail $ "cannot parse relative path: " ++ show x+                Just path -> return path+        τ :: Int -> Parser Natural+        τ x = if x >= 0+                then return (fromIntegral x)+                else fail $ "the value must be positive: " ++ show x+    configPrevLen <- ω configPrevLen τ "prevlen"+    configSrcFile <- ω configSrcFile ξ "src"+    configProg    <- ω configProg    τ "prog"+    configTempo   <- ω configTempo   τ "tempo"+    configPrompt  <- ω configPrompt  return "prompt"+    configVerbose <- ω configVerbose return "verbose"+    configPrvCmd  <- ω configPrvCmd  return "prvcmd"+    configProgOp  <- ω configProgOp  return "progop"+    configTempoOp <- ω configTempoOp return "tempop"+    return MidaConfig {..} -sc :: Parser ()-sc = L.space (void spaceChar) (L.skipLineComment "#") empty+parseMidaConfig :: MonadIO m => Path b File -> m (Either String MidaConfig)+parseMidaConfig path = liftIO $+  either (Left . prettyPrintParseException) Right+    <$> decodeFileEither (toFilePath path)
src/Mida/Interaction.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- This module describes how MIDA processes commands in interactive -- mode. These commands are also used in batch mode. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Interaction/Base.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- This module describes monad for interactive REPL and some basic -- functions. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software@@ -92,7 +91,8 @@ processDef n t = do   recursive <- checkRecur n t   if recursive-  then liftIO $-    fprint ("Rejected recursive definition for «" % string % "».\n") n-  else do addDef n t-          liftIO $ fprint ("• «" % string % "»\n") n+    then liftIO $+      fprint ("Rejected recursive definition for ‘" % string % "’\n") n+    else do+      addDef n t+      liftIO $ fprint ("• ‘" % string % "’\n") n
src/Mida/Interaction/Commands.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- This module describes all supported MIDA commands. It also provides all -- the functionality to load source files and generate / save MIDI files. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software@@ -28,8 +27,7 @@   , cmdPrefix ) where -import Control.Exception (SomeException)-import Control.Monad.Catch (try, MonadThrow, MonadMask, fromException, throwM)+import Control.Monad.Catch import Control.Monad.IO.Class import Control.Monad.Reader import Control.Monad.State.Class@@ -45,15 +43,8 @@ import Mida.Representation import Numeric.Natural import Path-import System.Directory-  ( doesDirectoryExist-  , doesFileExist-  , getCurrentDirectory-  , getHomeDirectory-  , makeAbsolute-  , setCurrentDirectory )+import Path.IO import System.Exit (exitSuccess, ExitCode)-import System.IO.Temp (withSystemTempDirectory) import System.Process   ( shell   , createProcess@@ -118,7 +109,7 @@             Nothing -> spitExc e         Right _ -> return ()     Nothing -> liftIO $-      fprint ("Unknown command, try " % string % "help.\n") cmdPrefix+      fprint ("Unknown command, try " % string % "help\n") cmdPrefix   where g Cmd { cmdName = c } = c == dropCmdPrefix (T.unpack cmd)         (cmd, args)           = T.break isSpace (T.strip txt) @@ -154,22 +145,21 @@  -- | Change working directory. -cmdCd :: MonadIO m => String -> m ()-cmdCd next' = liftIO $ do-  next    <- fixPath next' >>= parseAbsDir-  let npath = fromAbsDir next-  present <- doesDirectoryExist npath-  if present-  then do setCurrentDirectory npath-          fprint ("Changed to \"" % string % "\".\n") npath-  else fprint ("Cannot cd to \"" % string % "\".\n") npath+cmdCd :: (MonadIO m, MonadCatch m) => String -> m ()+cmdCd next' = do+  mnext <- forgivingAbsence (resolveDir' next')+  case mnext of+    Nothing -> liftIO $ fprint ("Cannot cd to \"" % string % "\"\n") next'+    Just next -> do+      setCurrentDir next+      liftIO $ fprint ("Changed to \"" % string % "\"\n") (fromAbsDir next)  -- | Restore default state of environment.  cmdClear :: (HasEnv m, MonadIO m) => String -> m () cmdClear _ = do   clearDefs-  liftIO (T.putStrLn "Environment cleared.")+  liftIO (T.putStrLn "Environment cleared")  -- | Print definition of given symbol. @@ -207,20 +197,21 @@ loadOne given = do   file <- output given ""   let fpath = fromAbsFile file-  b    <- liftIO $ doesFileExist fpath+  b    <- doesFileExist file   if b-  then do contents <- liftIO $ T.readFile fpath-          case parseMida fpath contents of-            Right x -> do-              mapM_ f x-              setFileName file-              liftIO $ fprint-                ("\"" % string % "\" loaded successfully.\n")-                fpath-            Left  x -> liftIO $ fprint (string % "\n") x-  else liftIO $ fprint ("Could not find \"" % string % "\".\n") fpath-    where f (Definition n t) = processDef n t-          f (Exposition   _) = return ()+    then do+      contents <- liftIO (T.readFile fpath)+      case parseMida fpath contents of+        Right x -> do+          mapM_ f x+          setFileName file+          liftIO $ fprint+            ("\"" % string % "\" loaded successfully\n")+            fpath+        Left  x -> liftIO $ fprint (string % "\n") x+    else liftIO $ fprint ("Could not find \"" % string % "\"\n") fpath+      where f (Definition n t) = processDef n t+            f (Exposition   _) = return ()  -- | Version of 'cmdMake' used by REPL. @@ -242,11 +233,11 @@   -> FilePath          -- ^ Where to save MIDI file   -> m () cmdMake s q b f = do-  file   <- output f "mid"+  file <- output f "mid"   let fpath = fromAbsFile file-  midi   <- genMidi s q b+  midi <- genMidi s q b   liftIO $ Midi.exportFile fpath midi-  liftIO $ fprint ("MIDI file saved as \"" % string % "\".\n") fpath+  liftIO $ fprint ("MIDI file saved as \"" % string % "\"\n") fpath  -- | Set program for preview. @@ -261,7 +252,6 @@           , MonadIO m           , MonadReader MidaCfg m           , MonadState MidaSt m-          , MonadThrow m           , MonadMask m )   => String -> m () cmdPrv arg = do@@ -270,11 +260,10 @@   prog    <- show <$> gets stProg   tempoOp <- asks cfgTempoOp   tempo   <- show <$> gets stTempo-  withSystemTempDirectory "mida" $ \tdir -> do-    tpath <- parseAbsDir tdir+  withSystemTempDir "mida" $ \tdir -> do     f     <- filename <$> output "" "mid"     let (s:q:b:_) = words arg ++ repeat ""-        file      = fromAbsFile (tpath </> f)+        file      = fromAbsFile (tdir </> f)         cmd       = unwords [prvcmd, progOp, prog, tempoOp, tempo, file]     cmdMake (parseNum s defaultSeed)             (parseNum q defaultQuarter)@@ -295,12 +284,12 @@ cmdPurge :: (HasEnv m, MonadIO m) => String -> m () cmdPurge _ = do   purgeEnv topDefs-  liftIO $ T.putStrLn "Environment purged."+  liftIO $ T.putStrLn "Environment purged"  -- | Print working directory.  cmdPwd :: MonadIO m => String -> m ()-cmdPwd _ = liftIO (getCurrentDirectory >>= putStrLn)+cmdPwd _ = liftIO (getCurrentDir >>= putStrLn . fromAbsDir)  -- | Quit the interactive environment. @@ -317,7 +306,7 @@   src    <- fullSrc   liftIO $ T.writeFile fpath src   setFileName file-  liftIO $ fprint ("Environment saved as \"" % string % "\".\n") fpath+  liftIO $ fprint ("Environment saved as \"" % string % "\"\n") fpath  -- | Set tempo for preview. @@ -332,7 +321,7 @@ cmdUdef arg = mapM_ f (words arg)   where f name = do           remDef name-          liftIO $ fprint ("Definition for «" % string % "» removed.\n") name+          liftIO $ fprint ("Definition for ‘" % string % "’ removed\n") name  -- | Parse a number defaulting to given value. @@ -349,19 +338,11 @@   -> String              -- ^ Extension   -> m (Path Abs File)   -- ^ Absolute path to output file output given' ext = do-  given  <- liftIO (fixPath given')+  given  <- resolveFile' given'   actual <- fromAbsFile <$> gets stSrcFile-  let a = if null ext then actual else FP.replaceExtension actual ext-  parseAbsFile (if null given' then a else given)---- | Make path absolute resolving tilde (that's actually shell-functionality,--- but we do it for convenience).--fixPath :: FilePath -> IO FilePath-fixPath path = do-  home <- getHomeDirectory-  let f x = if x == "~" then home else x-  makeAbsolute . FP.joinPath . fmap f . FP.splitDirectories $ path+  a      <- parseAbsFile $+    if null ext then actual else FP.replaceExtension actual ext+  return (if null given' then a else given)  -- | Change current file name. @@ -383,7 +364,7 @@ -- | Print out an exception.  spitExc :: MonadIO m => SomeException -> m ()-spitExc = liftIO . fprint ("× " % string % ".\n") . show+spitExc = liftIO . fprint ("× " % string % "\n") . show  -- | Stupid trimming for strings. 
src/Mida/Language.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- -- -- This is entry point of Mida.Lang library. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Language/Element.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- This module describes internal representation of principle as list of -- elements. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Language/Environment.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- Environment is formed via evaluation of definitions. This module -- describes minimal MIDA environment in form of monad transformer. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Language/Eval.hs view
@@ -1,10 +1,9 @@--- -*- Mode: Haskell; -*- -- -- This module describes process of evaluation of definitions and arbitrary -- principles. Result of evaluation is infinite list of natural numbers or -- empty list. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Language/SyntaxTree.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- -- -- This module defines abstract syntax tree of MIDA language. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Midi.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- -- -- This module describes how to create MIDI file from MIDA environment. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Representation.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- This module binds together syntax tree and textual representation of MIDA -- language. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Representation/Base.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- -- -- Textual representation of basic elements in MIDA language. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Representation/Parser.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- This module describes how to build syntax tree from textual -- representation of MIDA statements. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
src/Mida/Representation/Show.hs view
@@ -1,9 +1,8 @@--- -*- Mode: Haskell; -*- -- -- Here we describe how to build textual representation of syntax trees and -- principles. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software
tests/Main.hs view
@@ -1,8 +1,7 @@--- -*- Mode: Haskell; -*- -- -- QuickCheck tests for MIDA. ----- Copyright © 2014, 2015 Mark Karpov+-- Copyright © 2014–2016 Mark Karpov -- -- MIDA is free software: you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software