{-# LANGUAGE NamedFieldPuns, OverloadedStrings #-}

module MusicPad.Utils where

import Rika.Scene
import Rika.Engine
import Prelude ()
import Rika.Env hiding (encode)
import Rika.Component.Script.Helper
import qualified Prelude as P
import Rika.Data.Tensor
import MusicPad.Type
import Text.JSON.Generic
import Control.Monad
import Rika.Component.Script.Shell

import Rika.Engine.Loader
import MusicPad.Type.Music
import MPS.Extra

safe_ls :: String -> IO [String]
safe_ls x = ls x ^ reject (starts_with ".")

read_pitch_class :: String -> PitchClass
read_pitch_class = camel_case > P.read


read_pitch :: String -> Pitch
read_pitch x = 
  let octave = x.select (belongs_to ['0'..'9']) .P.read
      pitch_class = x.reject (belongs_to ['0'..'9']) .read_pitch_class
  in
  (pitch_class, octave)