はじめに
TidalCyclesで3度上、5度下などの音を重ねたいと思ったときにいいやり方がわからなかったので、degreesUp
関数を作ってみました。
degreesUp関数の実装
以下のコードをBootTidal.hsに追記して、TidalCyclesを再起動すればdegreesUp
関数が使えるようになるかと思います
BootTidal.hs
:{
majorC :: Num a => [a]
majorC = [0,2,4,5,7,9,11]
majorKey :: (Eq a1, Data.String.IsString a1, Num a2) => a1 -> [a2]
majorKey key
| elem key ["c"] = majorC
| elem key ["cs","df"] = map (+1) majorC
| elem key ["d"] = map (+2) majorC
| elem key ["ds", "ef"] = map (+3) majorC
| elem key ["e"] = map (+4) majorC
| elem key ["f"] = map (+5) majorC
| elem key ["fs", "gf"] = map (+6) majorC
| elem key ["g"] = map (+7) majorC
| elem key ["gs", "af"] = map (+8) majorC
| elem key ["gs", "af"] = map (+9) majorC
| elem key ["a"] = map (+10) majorC
| elem key ["as", "bf"] = map (+11) majorC
| elem key ["b"] = map (+12) majorC
| otherwise = error "invalid key name!"
degreesUp :: (Num a, Eq a1, Data.String.IsString a1) => a1 -> Int -> Int -> a
degreesUp key degree n =
noteInScale (majorScale) (degree+elemScaleIndex n)
where majorScale = majorKey key
octave s x = x `div` length s
noteInScale s x = (s !! (mod x (length s))) + fromIntegral (12 * octave s x)
elemScaleIndex n
| isJust(elemIndex (mod n 12) majorScale) = fromJust(elemIndex (mod n 12) majorScale) + (length majorScale)*(n `div` 12)
| otherwise = elemScaleIndex (n+1)
degreesUp' :: (Num a, Eq a1, Data.String.IsString a1) => a1 -> Int -> Int -> a
degreesUp' key degree n
| degree==0 = degreesUp key 0 n
| degree>0 = degreesUp key (degree-1) n
| degree<0 = degreesUp key (degree+1) n
:}
degreesUp関数の使い方
例えば、キーがCで3度上の音を重ねたい場合は以下のようにすると実現できます。
live.tidal
do
let
nPat = "[c4|d6|e5|f5|g4|a5|b4]*8"
degree = 3
d1
$ stack[
s "superpiano*8"
# n nPat
,
s "superpiano*8"
# n (degreesUp' "c" degree <$> nPat)
]
いろいろな度数で試してみるとこんな感じになります。