-
Notifications
You must be signed in to change notification settings - Fork 2
/
CsoundExp.hs
44 lines (32 loc) · 1.69 KB
/
CsoundExp.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-# LANGUAGE EmptyDataDecls,
MultiParamTypeClasses,
GADTs,
RankNTypes,
FlexibleInstances #-}
module CsoundExp (noteToTrack, phraseToTrack, musicToTrack, playCsound, writeCsound) where
import Music (mapPhraseSingle, apPitch, apDur, apTran, apInt,
explodeVoices, splitVoices, mapMusic, Metronome(..),
AbstractNote(..), Music(..), mapPhrase, noteToSound, Tuning(..),
revVoices, Note3, AbstractDur3(..), AbstractPitch3(..), AbstractPhrase(..))
import qualified Csound.Base as C
-- import Csound.Catalog
import Csound.Patch
noteToTrack :: Note3 -> C.Track C.D (C.D, C.D)
noteToTrack (AbstractPitch p d) = C.str (durToSeconds d) $ C.temp (1, getFreq p)
noteToTrack (Rest d) = C.rest (durToSeconds d)
durToSeconds (AbstractDur3 l) = (C.double l)/1000
getFreq (AbstractPitch3 f) = C.double f
phraseToTrack :: AbstractPhrase Note3 -> C.Track C.D (C.D, C.D)
phraseToTrack (AbstractPhrase notes) = C.mel $ phraseToTrack' notes
where phraseToTrack' [] = []
phraseToTrack' (n@(AbstractPitch _ _):ns) = (noteToTrack n) : (phraseToTrack' ns)
phraseToTrack' (n@(Rest _):ns) = (noteToTrack n) : (phraseToTrack' ns)
phraseToTrack' (n:ns) = phraseToTrack' ns
musicToTrack :: Music Note3 -> C.Track C.D (C.D, C.D)
musicToTrack (Start phrase) = musicToTrack $ explodeVoices (Start phrase)
musicToTrack (Voices phrases) = C.har $ map phraseToTrack phrases
-- playCsoundsDemo q = C.dac $ C.mix $ C.sco h q
-- where h x = return $ harpsichord x
playCsoundsInstr i q = C.mix $ C.atSco i q
playCsound i m = C.dac $ playCsoundsInstr i $ musicToTrack m
writeCsound f i m = C.writeSnd f $ playCsoundsInstr i $ musicToTrack m