module Music.Theory.Time.KeyKit.Basic where
import Data.List
import qualified Music.Theory.List as List
import Music.Theory.Time.KeyKit
phrase_arpeggio :: Phrase t -> Phrase t
phrase_arpeggio :: forall t. Phrase t -> Phrase t
phrase_arpeggio (Phrase [Note t]
n Length
l) =
case [Note t]
n of
[] -> forall t. [Note t] -> Length -> Phrase t
Phrase [Note t]
n Length
l
Note t
n1 : [Note t]
_ ->
let t_seq :: [Length]
t_seq = forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl forall a. Num a => a -> a -> a
(+) (forall t. Note t -> Length
note_start_time Note t
n1) (forall a b. (a -> b) -> [a] -> [b]
map forall t. Note t -> Length
note_duration [Note t]
n)
n' :: [Note t]
n' = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Length
t (Note Length
_ Length
d t
e) -> forall t. Length -> Length -> t -> Note t
Note Length
t Length
d t
e) [Length]
t_seq [Note t]
n
l' :: Length
l' = forall t. Note t -> Length
note_end_time (forall a. [a] -> a
last [Note t]
n)
in forall t. [Note t] -> Length -> Phrase t
Phrase [Note t]
n' Length
l'
phrase_echo :: Ord t => Phrase t -> Int -> Time -> Phrase t
phrase_echo :: forall t. Ord t => Phrase t -> Int -> Length -> Phrase t
phrase_echo Phrase t
p Int
n Length
t = forall t. Ord t => [Phrase t] -> Phrase t
phrase_merge_list (forall a b. (a -> b) -> [a] -> [b]
map (\Int
i -> forall t. Phrase t -> Length -> Phrase t
phrase_shift Phrase t
p (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i forall a. Num a => a -> a -> a
* Length
t)) [Int
0 .. Int
n forall a. Num a => a -> a -> a
- Int
1])
phrase_step :: Phrase t -> Duration -> Phrase t
phrase_step :: forall t. Phrase t -> Length -> Phrase t
phrase_step (Phrase [Note t]
n Length
_) Length
d =
let g :: [[Note t]]
g = forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (\Note t
i Note t
j -> forall t. Note t -> Length
note_start_time Note t
i forall a. Eq a => a -> a -> Bool
== forall t. Note t -> Length
note_start_time Note t
j) [Note t]
n
f :: [Note t] -> Length -> [Note t]
f [Note t]
l Length
t = forall a b. (a -> b) -> [a] -> [b]
map (\(Note Length
_ Length
_ t
e) -> forall t. Length -> Length -> t -> Note t
Note Length
t Length
d t
e) [Note t]
l
n' :: [Note t]
n' = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {t}. [Note t] -> Length -> [Note t]
f [[Note t]]
g [Length
0, Length
d ..])
in forall t. [Note t] -> Length -> Phrase t
Phrase [Note t]
n' (forall t. Note t -> Length
note_end_time (forall a. [a] -> a
last [Note t]
n'))
phrase_shuffle :: Phrase t -> Phrase t
phrase_shuffle :: forall t. Phrase t -> Phrase t
phrase_shuffle (Phrase [Note t]
n Length
l) =
let ([t]
lhs, [t]
rhs) = forall t. [t] -> ([t], [t])
List.split_into_halves (forall a b. (a -> b) -> [a] -> [b]
map forall t. Note t -> t
note_value [Note t]
n)
f :: Note t -> t -> Note t
f (Note Length
t Length
d t
_) t
e = forall t. Length -> Length -> t -> Note t
Note Length
t Length
d t
e
n' :: [Note t]
n' = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall {t} {t}. Note t -> t -> Note t
f [Note t]
n (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a. [[a]] -> [[a]]
transpose [[t]
lhs, [t]
rhs]))
in forall t. [Note t] -> Length -> Phrase t
Phrase [Note t]
n' Length
l