{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

{-
    Simple.hs - Things for making Tidal extra-simple to use, originally made for 8 year olds.
    Copyright (C) 2020, Alex McLean and contributors

    This library 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 Foundation, either version 3 of the License, or
    (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this library.  If not, see <http://www.gnu.org/licenses/>.
-}

module Sound.Tidal.Simple where

import Sound.Tidal.Control (chop, hurry)
import Sound.Tidal.Core ((#), (|*), (<~))
import Sound.Tidal.Params (crush, gain, pan, speed, s)
import Sound.Tidal.ParseBP (parseBP_E)
import Sound.Tidal.Pattern (ControlPattern, silence, rev)
import GHC.Exts ( IsString(..) )

instance {-# OVERLAPPING #-} IsString ControlPattern where
  fromString :: String -> ControlPattern
fromString = Pattern String -> ControlPattern
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (Enumerable a, Parseable a) => String -> Pattern a
parseBP_E

crunch :: ControlPattern -> ControlPattern
crunch :: ControlPattern -> ControlPattern
crunch = (forall b. Unionable b => Pattern b -> Pattern b -> Pattern b
# Pattern Double -> ControlPattern
crush Pattern Double
3)

scratch :: ControlPattern -> ControlPattern
scratch :: ControlPattern -> ControlPattern
scratch = forall a. Pattern a -> Pattern a
rev forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pattern Int -> ControlPattern -> ControlPattern
chop Pattern Int
32

louder :: ControlPattern -> ControlPattern
louder :: ControlPattern -> ControlPattern
louder = (forall a. Num a => Pattern a -> Pattern a -> Pattern a
|* Pattern Double -> ControlPattern
gain Pattern Double
1.2)

quieter :: ControlPattern -> ControlPattern
quieter :: ControlPattern -> ControlPattern
quieter = (forall a. Num a => Pattern a -> Pattern a -> Pattern a
|* Pattern Double -> ControlPattern
gain Pattern Double
0.8)

silent :: ControlPattern -> ControlPattern
silent :: ControlPattern -> ControlPattern
silent = forall a b. a -> b -> a
const forall a. Pattern a
silence

skip :: ControlPattern -> ControlPattern
skip :: ControlPattern -> ControlPattern
skip = (Pattern Rational
0.25 forall a. Pattern Rational -> Pattern a -> Pattern a
<~)

left :: ControlPattern -> ControlPattern
left :: ControlPattern -> ControlPattern
left = (forall b. Unionable b => Pattern b -> Pattern b -> Pattern b
# Pattern Double -> ControlPattern
pan Pattern Double
0)

right :: ControlPattern -> ControlPattern
right :: ControlPattern -> ControlPattern
right = (forall b. Unionable b => Pattern b -> Pattern b -> Pattern b
# Pattern Double -> ControlPattern
pan Pattern Double
1)

higher :: ControlPattern -> ControlPattern
higher :: ControlPattern -> ControlPattern
higher = (forall a. Num a => Pattern a -> Pattern a -> Pattern a
|* Pattern Double -> ControlPattern
speed Pattern Double
1.5)

lower :: ControlPattern -> ControlPattern
lower :: ControlPattern -> ControlPattern
lower = (forall a. Num a => Pattern a -> Pattern a -> Pattern a
|* Pattern Double -> ControlPattern
speed Pattern Double
0.75)

faster :: ControlPattern -> ControlPattern
faster :: ControlPattern -> ControlPattern
faster = Pattern Rational -> ControlPattern -> ControlPattern
hurry Pattern Rational
2

slower :: ControlPattern -> ControlPattern
slower :: ControlPattern -> ControlPattern
slower = Pattern Rational -> ControlPattern -> ControlPattern
hurry Pattern Rational
0.5