module HarmTrace.IO.BasePaths ( BasePaths, setPaths , consBasePaths, basePathsExist , getVampDir, getFeatDir , getOutDir , getBeatVampPath, getChromaVampPath , getKeyVampPath) where import System.FilePath (()) import HarmTrace.IO.Common (fileExists, dirExists) import Constants ( defaultVampDir, defaultOutDir, defaultFeatDir , beatVampPath, chromaVampPath, keyVampPath) -- | A datatype for storing the base directories of the vamp plugins, feature -- csv files, and the chord and log Files. data BasePaths = BasePaths { getVampDir :: FilePath , getFeatDir :: FilePath , getOutDir :: FilePath , getBeatVampPath :: FilePath , getChromaVampPath :: FilePath , getKeyVampPath :: FilePath } -- | Similar to 'consBasePaths', but instead excepts 'Maybe FilePath's instead -- of 'FilePath's setPaths :: Maybe FilePath -> Maybe FilePath -> Maybe FilePath -> BasePaths setPaths mv mf mo = let vamp = maybe defaultVampDir id mv feat = maybe defaultFeatDir id mf out = maybe defaultOutDir id mo in consBasePaths vamp feat out -- | contructs a new 'BasePaths' based on a VAMP transform directory, -- a feature directory (to store the CSV files), and an output directory. consBasePaths :: FilePath -> FilePath -> FilePath -> BasePaths consBasePaths vamp feat out = BasePaths vamp feat out (vamp beatVampPath) (vamp chromaVampPath) (vamp keyVampPath) -- | checks (verbosely) if the paths stored in a 'BaseDir' exist. basePathsExist :: BasePaths -> IO (Bool) basePathsExist dirs = do v <- fileExists (getBeatVampPath dirs) c <- fileExists (getChromaVampPath dirs) k <- fileExists (getKeyVampPath dirs) f <- dirExists (getFeatDir dirs) o <- dirExists (getOutDir dirs) return (v && c && k && f && o)