module Harmonic.Interface.Tidal.Devices.RC10R
(
rcTrk1, rcTrk1Stop, rcTrk2, rcTrk2Stop, rcStop
, rcBreak, rcRhythmBreak
, rcRhythm, rcRhythmStop, rcFill, rcPattern, rcKit
, rcLoopLevel, rcRhythmLevel, rcLevel
, rcGate
, x3rc10
) where
import qualified Data.Map.Strict as Map
import Sound.Tidal.Context
import Harmonic.Interface.Tidal.Instruments (ch)
import Harmonic.Interface.Tidal.Form (Kinetics(..), IK, beatsPerBar)
rcLane :: Pattern ValueMap
rcLane :: Pattern ValueMap
rcLane = Int -> Pattern ValueMap
ch Int
10
ccRaw :: Pattern Double -> Pattern Double -> ControlPattern
ccRaw :: Pattern Double -> Pattern Double -> Pattern ValueMap
ccRaw Pattern Double
num Pattern Double
v = Pattern Double -> Pattern ValueMap
control Pattern Double
v Pattern ValueMap -> Pattern ValueMap -> Pattern ValueMap
forall b. Unionable b => Pattern b -> Pattern b -> Pattern b
# Pattern String -> Pattern ValueMap
midicmd Pattern String
"control" Pattern ValueMap -> Pattern ValueMap -> Pattern ValueMap
forall b. Unionable b => Pattern b -> Pattern b -> Pattern b
# Pattern Double -> Pattern ValueMap
ctlNum Pattern Double
num Pattern ValueMap -> Pattern ValueMap -> Pattern ValueMap
forall b. Unionable b => Pattern b -> Pattern b -> Pattern b
# Pattern ValueMap
rcLane
pressCC :: Pattern Double -> Pattern Bool -> ControlPattern
pressCC :: Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
num Pattern Bool
g = [Pattern ValueMap] -> Pattern ValueMap
forall a. [Pattern a] -> Pattern a
stack
[ Pattern Bool -> Pattern ValueMap -> Pattern ValueMap
forall a. Pattern Bool -> Pattern a -> Pattern a
struct Pattern Bool
g (Pattern Double -> Pattern Double -> Pattern ValueMap
ccRaw Pattern Double
num Pattern Double
127)
, (Pattern Time
1Pattern Time -> Pattern Time -> Pattern Time
forall a. Fractional a => a -> a -> a
/Pattern Time
16) Pattern Time -> Pattern ValueMap -> Pattern ValueMap
forall a. Pattern Time -> Pattern a -> Pattern a
~> Pattern Bool -> Pattern ValueMap -> Pattern ValueMap
forall a. Pattern Bool -> Pattern a -> Pattern a
struct Pattern Bool
g (Pattern Double -> Pattern Double -> Pattern ValueMap
ccRaw Pattern Double
num Pattern Double
0)
]
rcTrk1, rcTrk1Stop, rcTrk2, rcTrk2Stop :: Pattern Bool -> ControlPattern
rcTrk1 :: Pattern Bool -> Pattern ValueMap
rcTrk1 = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
70
rcTrk1Stop :: Pattern Bool -> Pattern ValueMap
rcTrk1Stop = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
71
rcTrk2 :: Pattern Bool -> Pattern ValueMap
rcTrk2 = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
72
rcTrk2Stop :: Pattern Bool -> Pattern ValueMap
rcTrk2Stop = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
73
rcStop :: Pattern Bool -> ControlPattern
rcStop :: Pattern Bool -> Pattern ValueMap
rcStop = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
74
rcBreak :: Pattern Bool -> ControlPattern
rcBreak :: Pattern Bool -> Pattern ValueMap
rcBreak = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
75
rcRhythmBreak :: Pattern Bool -> ControlPattern
rcRhythmBreak :: Pattern Bool -> Pattern ValueMap
rcRhythmBreak = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
76
rcRhythm, rcRhythmStop, rcFill, rcPattern :: Pattern Bool -> ControlPattern
rcRhythm :: Pattern Bool -> Pattern ValueMap
rcRhythm = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
77
rcRhythmStop :: Pattern Bool -> Pattern ValueMap
rcRhythmStop = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
78
rcFill :: Pattern Bool -> Pattern ValueMap
rcFill = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
79
rcPattern :: Pattern Bool -> Pattern ValueMap
rcPattern = Pattern Double -> Pattern Bool -> Pattern ValueMap
pressCC Pattern Double
80
rcKit :: Pattern Double -> ControlPattern
rcKit :: Pattern Double -> Pattern ValueMap
rcKit = Pattern Double -> Pattern Double -> Pattern ValueMap
ccRaw Pattern Double
84
rcLoopLevel, rcRhythmLevel, rcLevel :: Pattern Double -> ControlPattern
rcLoopLevel :: Pattern Double -> Pattern ValueMap
rcLoopLevel = Pattern Double -> Pattern Double -> Pattern ValueMap
levelCC Pattern Double
81
rcRhythmLevel :: Pattern Double -> Pattern ValueMap
rcRhythmLevel = Pattern Double -> Pattern Double -> Pattern ValueMap
levelCC Pattern Double
82
rcLevel :: Pattern Double -> Pattern ValueMap
rcLevel = Pattern Double -> Pattern Double -> Pattern ValueMap
levelCC Pattern Double
83
levelCC :: Pattern Double -> Pattern Double -> ControlPattern
levelCC :: Pattern Double -> Pattern Double -> Pattern ValueMap
levelCC Pattern Double
num Pattern Double
v = Pattern Double -> Pattern Double -> Pattern ValueMap
ccRaw Pattern Double
num ((Double -> Double) -> Pattern Double -> Pattern Double
forall a b. (a -> b) -> Pattern a -> Pattern b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Double
x -> Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Double -> Int
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Double -> Double
forall a. Ord a => a -> a -> a
max Double
0 (Double -> Double -> Double
forall a. Ord a => a -> a -> a
min Double
1 Double
x) Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
127) :: Int)) (Pattern Time -> Pattern Double -> Pattern Double
forall a. Pattern Time -> Pattern a -> Pattern a
segment Pattern Time
4 Pattern Double
v))
rcGate :: (Double, Double) -> IK -> Int -> ControlPattern
rcGate :: (Double, Double) -> IK -> Int -> Pattern ValueMap
rcGate (Double
lo, Double
hi) IK
k Int
trk =
let bar :: Time
bar = Double -> Time
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
beatsPerBar :: Time
inBand :: Pattern Bool
inBand = (Double -> Bool) -> Pattern Double -> Pattern Bool
forall a b. (a -> b) -> Pattern a -> Pattern b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Double
x -> Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>= Double
lo Bool -> Bool -> Bool
&& Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
hi) (Kinetics -> Pattern Double
kSignal (IK -> Kinetics
forall a b. (a, b) -> a
fst IK
k))
now :: Pattern Bool
now = Pattern Time -> Pattern Bool -> Pattern Bool
forall a. Pattern Time -> Pattern a -> Pattern a
slow (Time -> Pattern Time
forall a. a -> Pattern a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Time
bar) (Pattern Time -> Pattern Bool -> Pattern Bool
forall a. Pattern Time -> Pattern a -> Pattern a
segment Pattern Time
1 (Pattern Time -> Pattern Bool -> Pattern Bool
forall a. Pattern Time -> Pattern a -> Pattern a
fast (Time -> Pattern Time
forall a. a -> Pattern a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Time
bar) Pattern Bool
inBand))
before :: Pattern Bool
before = Time
bar Time -> Pattern Bool -> Pattern Bool
forall a. Time -> Pattern a -> Pattern a
`rotR` Pattern Bool
now
edge :: (Bool -> Bool -> Bool) -> Pattern Bool
edge Bool -> Bool -> Bool
f = (Bool -> Bool) -> Pattern Bool -> Pattern Bool
forall a. (a -> Bool) -> Pattern a -> Pattern a
filterValues Bool -> Bool
forall a. a -> a
id (Bool -> Bool -> Bool
f (Bool -> Bool -> Bool) -> Pattern Bool -> Pattern (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Pattern Bool
now Pattern (Bool -> Bool) -> Pattern Bool -> Pattern Bool
forall a b. Pattern (a -> b) -> Pattern a -> Pattern b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Pattern Bool
before)
entering :: Pattern Bool
entering = (Bool -> Bool -> Bool) -> Pattern Bool
edge (\Bool
a Bool
b -> Bool
a Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
b)
leaving :: Pattern Bool
leaving = (Bool -> Bool -> Bool) -> Pattern Bool
edge (\Bool
a Bool
b -> Bool -> Bool
not Bool
a Bool -> Bool -> Bool
&& Bool
b)
(Pattern Bool -> Pattern ValueMap
onTrk, Pattern Bool -> Pattern ValueMap
offTrk) = if Int
trk Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2 then (Pattern Bool -> Pattern ValueMap
rcTrk2, Pattern Bool -> Pattern ValueMap
rcTrk2Stop) else (Pattern Bool -> Pattern ValueMap
rcTrk1, Pattern Bool -> Pattern ValueMap
rcTrk1Stop)
in [Pattern ValueMap] -> Pattern ValueMap
forall a. [Pattern a] -> Pattern a
stack [Pattern Bool -> Pattern ValueMap
onTrk Pattern Bool
entering, Pattern Bool -> Pattern ValueMap
offTrk Pattern Bool
leaving]
x3rc10 :: ControlPattern -> ControlPattern
x3rc10 :: Pattern ValueMap -> Pattern ValueMap
x3rc10 = Pattern (Maybe ValueMap) -> Pattern ValueMap
forall a. Pattern (Maybe a) -> Pattern a
filterJust (Pattern (Maybe ValueMap) -> Pattern ValueMap)
-> (Pattern ValueMap -> Pattern (Maybe ValueMap))
-> Pattern ValueMap
-> Pattern ValueMap
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValueMap -> Maybe ValueMap)
-> Pattern ValueMap -> Pattern (Maybe ValueMap)
forall a b. (a -> b) -> Pattern a -> Pattern b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValueMap -> Maybe ValueMap
forall {k}.
(Ord k, IsString k) =>
Map k Value -> Maybe (Map k Value)
toLane
where
toLane :: Map k Value -> Maybe (Map k Value)
toLane Map k Value
vm = do
nt <- k -> Map k Value -> Maybe Value
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
"note" Map k Value
vm Maybe Value -> (Value -> Maybe Note) -> Maybe Note
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Maybe Note
getN
let a = Double -> (Double -> Double) -> Maybe Double -> Double
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Double
0.4 Double -> Double
forall a. a -> a
id (k -> Map k Value -> Maybe Value
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
"amp" Map k Value
vm Maybe Value -> (Value -> Maybe Double) -> Maybe Double
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Maybe Double
getF)
pad = Double -> Int
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Note -> Double
unNote Note
nt) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
60 :: Int
v = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
127 (Double -> Int
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Double
a Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
127)) :: Int
if pad < 0 || pad > 15 || v < 1 then Nothing else
Just $ Map.union
(Map.fromList [ ("s", VS "thru"), ("midichan", VF 9), ("midicmd", VS "control")
, ("ctlNum", VF (fromIntegral (33 + pad))), ("control", VF (fromIntegral v)) ])
(foldr Map.delete vm ["note", "amp", "sustain"])