temporal-music-notation-demo 0.2 → 0.2.1
raw patch · 5 files changed
+513/−7 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- examples/break.hs +43/−0
- examples/choral.hs +258/−0
- examples/readme.hs +12/−0
- gen/genGM.hs +186/−0
- temporal-music-notation-demo.cabal +14/−7
+ examples/break.hs view
@@ -0,0 +1,43 @@+-- break beat++import System.Cmd(system)++import Temporal.Music.Western.P12+import Temporal.Music.Demo.GeneralMidi++tom11 = line [qd 0, qd 0, qnr, qd 0, hd 0.5, dhnr]+tom12 = line [qd 0, qd 0, qnr, qd 0, hd 0.5, qnr, qd 0]++scoTom = ff' $ line [tom11, tom12]+scoSnare = mp' $ line [hnr, hd 0, hnr, hd 0]++scoMaracas = mp' $ line [dhnr, tri $ line [ed 0.5, ed 0, ed 0]]++drums = loop 8 $ chord [+ bassDrum1 scoTom,+ loop 2 $ acousticSnare scoSnare,+ loop 3 $ maracas scoMaracas+ ]+++scoAccomp = envelopeRel [0, 1, 0.5, 1.5, 0.5, 1, 0] $ + loop 2 $ + mf' $ high $ sustain 0.5 $ chord [+ p' $ loop 2 $ qn $ line [f, c, e, f, c, e, f, c],+ accent 1 $ low $ line [dwn a, dwn gs, hnr],+ accent 1.5 $ line [bnr, hnr, tri $ line [dhn gs, dhn e, dhn d]]+ ]++accomp = loop 4 $ glockenspiel scoAccomp ++-- fade out after 0.7*totalDur+res = envelopeSeg [0, 0.7, 0, 0.3, -5] $ chord [+ drums,+ accomp+ ]++main = do+ exportMidi "break.mid" res+ system "timidity break.mid"++
+ examples/choral.hs view
@@ -0,0 +1,258 @@+-- J.S. Bach - Choral prelude F-moll 'Ich ruf zu dir Herr Jesu Christ'++import System.Cmd(system)++import Temporal.Music.Western.P12+import Temporal.Music.Demo.GeneralMidi+++pedal = sustainT+trill n a b = loop n $ line [a, b]++-- alto dynamics++type Score12 = Score (Note ())++up :: Double -> [Score12] -> Score12+up x = envelopeRel [x, x + accDiap] . line . map sn ++down :: Double -> [Score12] -> Score12+down x = envelopeRel [x + accDiap, x] . line . map sn ++upDown :: Double -> [Score12] -> Score12+upDown x = envelopeRel [x, x + accDiap, x] . line . map sn ++downUp :: Double -> [Score12] -> Score12+downUp x = envelopeRel [x, x-accDiap, x] . line . map sn ++flat :: Double -> [Score12] -> Score12+flat x = accent x . line . map sn++accDiap = 0.5++--------------------------------------------------+-- solo++-- Part I++solo0 = qn $ high c++solo1 = line [+-- 1 bar+ qn af, qn bf, den af, sn g, den f, sn g,+-- 2 bar+ envelopeRel [0, 0.4, 0] $ line [line $ map sn [af, bf, af, bf],+ dim 1.5 $ hn $ trill 6 (accent 0.2 $ tn $ high c) (tn bf), tn af, tn bf], + high $ line [accent 0.2 $ qn $ c, den c, sn df, +-- 3 bar+ qn ef, tn df, stretch (1/4 - 3/32) $ wn c, + sn $ low bf, qn $ low af, en $ low bf, en c] + ]++solo11 = high $ line [+ stretch (1/4 + 1/16) $ wn df, + line $ map tn [ef, f, ef, df], sn c, qn c, qn c]+++solo12 = high $ line [+ qn df, sn df,+ line $ map tn [ef, f, ef, df],sn c, qn c, qn ef]++ +soloI = line [solo0, reprise solo1 solo11 solo12]+++-- Part II++solo21 = high $ line [+-- 1 bar+ qn f, en ef, tn df, tn c, sn df,+ low $ line $ map en [high c, bf, af, bf],+-- 2 bar+ qn c, qn c, qn $ low bf, qn $ low af,+-- 3 bar+ low $ line [hn g, hn f, +-- 4 bar + qn af, qn g, hn f]+ ]++solo22 = line [+-- 5 bar+ dhn ef, qn ef,+-- 6 bar+ qn af, qn af, qn bf, qn bf,+-- 7 bar + high $ line [dhn c, qn df],+-- 8 bar+ high $ qn c, qn bf, qn af, den f, sn g,+-- 9 bar+ qn af, qn g, qn f+ ]++soloII = solo21 +:+ solo22++solo = pedal (1/64) $ soloI +:+ soloII++---------------------------------------------------+-- alto++-- Part I++alto0 = high $ up 0 [low af, c, f, e] ++alto1 = line [+-- 1 bar+ high $ down 0.5 [f, c, low af, low f], + upDown 0 [g, bf, high df, high c],+ upDown 0 [f, af, high c, bf],+ downUp 0 [af, f, af, high c],++-- 2 bar+ high $ downUp 0.2 [f, e, f, af],+ high $ down 0 [g, f, e, f],+ high $ downUp 0 [e, c, low g, low bf, low af, c, f, af],++-- 3 bar+ high $ flat 0 [g, ef, af, g],+ high $ up 0 [af, ef, f, gf, f, df, f, af, g, df, c, gf]+ ] ++alto11 = high $ line [+ upDown 0 [f, low bf, df, f, bf, af, g, af, g, c, e, low bf],+ upDown 0 [low f, c, f, e]+ ]++alto12 = high $ line [+ upDown 0 [f, low bf, df, f, bf, af, g, af],+ down 0 [g, low bf, low af, f, low g, df, low af, c]+ ]++ +altoI = line [alto0, reprise alto1 alto11 alto12]++-- Part II++alto21 = high $ line [+-- 1 bar+ upDown 0 [+ low af, c, low bf, df, low bf, df, af, g, + af, ef, df, g, c, f, af, g],+-- 2 bar+ down (-accDiap) [+ af, ef, low af, gf, f, low af, low g, df, + c, low af, c, ef, g, c, low bf, g,+-- 3 bar + df, f, g, f],+ up (-accDiap) [+ e, low bf, df, c,+ low af, c, f, e, f, c, low af, low f],+-- 4 bar+ flat 0 [+ low bf, f, g, f, low bf, ef, f, ef,+ c, ef, f, ef, d, low g, low b, d+ ]+ ]++alto22 = high $ line [+-- 5 bar+ down (-accDiap) $ [+ low g, c, ef, df, low g, low bf, df, c] +++ map low [ef, af, high c, bf, high df, bf, c, high df,+-- 6 bar+ f, af, high df, high c, f, af, high c, bf, + f, af, bf, af, g, bf, high df, high c],++-- 7 bar+ up (-accDiap) [+ low af, c, ef, af, ef, bf, high c, bf,+ a, ef, gf, low a, low bf, g, low af, f+ ],++-- 8 bar+ down (-accDiap) [+ low af, ef, d, ef, low f, df, ef, df, + low ef, c, df, c, low bf, f, g, f,+-- 9 bar+ d, f, g, f, e, df, low bf, low g, + low a, c]++ ]++alto23 = en $ high f++altoII = line [alto21, alto22, alto23]++alto = pedal (1/128) $ lower 3 $ line [altoI, altoII]+++----------------------------------------------------------+-- bass ++-- Part I++bass0 = lower 1 $ line [en f, en f]++bass1 = (line $ map en [+-- 1 bar+ f, f, f, e, f, f, f, ef,+-- 2 bar+ df, df, df, df, c, c, f, f]) +:++-- 3 bar+ (high $ line $ map en [c, c, c, c, c, c, low bf, low a])++bass11 = line $ map en [bf, af, g, f, e, c, low f, low f]++bass12 = line $ map en [bf, af, g, f, e, f, c, c]++bassI = line [bass0, reprise bass1 bass11 bass12]+++-- Part II++bass21 = line $ map en [+-- 1 bar+ df, df, ef, ef, af, ef, f, df,+-- 2 bar+ low f, low f, f, f, d, e, f, df,+-- 3 bar+ low bf, low g, c, c, df, df, df , df,+-- 4 bar+ d, d, d, d, low a, low a, low b, low b+ ] + +bass22 = low $ line $ map en [+-- 5 bar+ high c, high c, bf, bf, af, af, g, g,+-- 6 bar+ f, f, ef, ef, d, d, ef, ef, +-- 7 bar+ af, af, gf, gf, f, f, bf, bf,+-- 8 bar+ bf, af, af, g, g, f, high df, high df,+-- 9 bar+ b, b, high c, high c+ ]++bass23 = qn $ low f++ +bassII = line [bass21, bass22, bass23]++bass = lower 3 $ line [bassI, bassII]++sco = delay (-4) $ bpm (lento $ -0.2) $ chord [+ solo, + mp' $ higher 2 alto, + accent 0.2 $ p' $ higher 2 $ bass,+ rest 0+ ]++file = "out.csd"+flags = "-d"++out = acousticGrandPiano sco++main = do+ exportMidi "choral.mid" $ out+ system "timidity choral.mid"+
+ examples/readme.hs view
@@ -0,0 +1,12 @@+{-+Readme+'temporal-music-notation-demo' examples.+++Examples rely on one external package 'temporal-music-notation-western'.+This package contains names specific to western music tradition.+So to run them do first.++>>cabal update+>>cabal install temporal-music-notation-western+-}
+ gen/genGM.hs view
@@ -0,0 +1,186 @@+-- | Generates module 'GeneralMidi'++import Data.Char+import Data.List.Split++import Language.Haskell.Exts.Syntax+import Language.Haskell.Exts.Pretty+import Language.Haskell.Exts.Build'++import qualified Text.PrettyPrint as P++toFunName :: String -> String+toFunName x = map toLower pref ++ suff+ where pref = takeWhile isUpper x+ suff = dropWhile isUpper x ++-- module+++moduleGM name instrs drums = P.vcat $ P.punctuate wspace [+ P.text "-- | General MIDI names",+ moduleHead name instrs drums,+ imports,+ division "Instruments",+ pp $ instrSig instrs,+ P.vcat $ map pp $ instrFuns instrs,+ division "Percussion",+ pp $ drumSig drums,+ P.vcat $ map pp $ drumFuns drums]+ where pp = P.text . prettyPrint+ wspace = P.text "\n\n"+ division x = (P.text $ replicate 20 '-') + P.$$ (P.text $ "--" ++ x)+++moduleHead name instrs drums = P.vcat [+ P.text $ "module " ++ name ++ "(",+ P.nest 4 $ exports instrs drums P.<> P.rparen,+ P.text "where"]++exports instrs drums =+ P.vcat [+ P.text (toSec1 "Instruments"),+ + P.vcat $ map ( P.<> P.comma) $+ map (uncurry expFunNames) $ + expInstrFunNames (map toSec2 familyNames) instrs, + P.text "\n\n",+ expFunNames (toSec1 "Percussion") drums]++toSec1 = ("-- * " ++ )+toSec2 = ("-- ** " ++)++expInstrFunNames fams names = zip fams $ splitEvery 8 names ++expFunNames :: String -> [String] -> P.Doc+expFunNames sec names = (P.text sec P.$$ ) $ P.vcat $ + P.punctuate P.comma $ map P.text names++imports :: P.Doc+imports = P.vcat [+ P.text "import Temporal.Music.Notation(Score, Seg)",+ P.text "import Temporal.Music.Notation.Note(Note, Drum)",+ P.text "import Temporal.Music.Notation.Demo"]++-- instruments++zSrcLoc = SrcLoc "" 0 0 ++instrSig :: [String] -> Decl+instrSig xs = typeSig zSrcLoc xs $ + [var "Seg" "nVol", var "Seg" "nPch"] + =>> var "Score" <$> var "Note" `apps` [var "nVol", var "nPch", var "a"] + ->> var "Score" <$> var "MidiEvent"++instrFuns = toFuns 0 "instr"++-- drums++drumSig :: [String] -> Decl+drumSig xs = typeSig zSrcLoc xs $ + [var "Seg" "nVol"] + =>> var "Score" <$> var "Drum" `apps` [var "nVol", var "a"] + ->> var "Score" <$> var "MidiEvent"++drumFuns = toFuns 35 "drumInstr"++-- funs++toFuns :: Integer -> String -> [String] -> [Decl]+toFuns i0 constr = map (uncurry $ toFun constr) . zip [i0 .. ]++toFun :: String -> Integer -> String -> Decl+toFun constr id name = fun zSrcLoc name [] <=> (var constr <$> int id)++out :: Pretty a => a -> IO ()+out = putStrLn . prettyPrint+++main = do+ let i = map (toFunName . show) $ [(minBound :: InstrumentName) .. maxBound]+ d = map (toFunName . show) $ [(minBound :: PercussionName) .. maxBound] ++ writeFile "GeneralMidi.hs" $ show $ + moduleGM "Temporal.Music.Notation.Demo.GeneralMidi" i d ++ +familyNames :: [String]+familyNames = map (splitAtUpper . show) + [(minBound :: InstrumentFamily) .. maxBound] + where splitAtUpper = unwords . split (keepDelimsL $ whenElt isUpper) +++data InstrumentFamily = + Piano | ChromaticPercussion | Organ | Guitar+ | Bass | Strings | Ensemble | Brass + | Reed | Pipe | SynthLead | SynthPad + | SynthEffects | Ethnic | Percussive | SoundEffects+ deriving (Show, Enum, Bounded)+++data InstrumentName = + AcousticGrandPiano | BrightAcousticPiano | ElectricGrandPiano+ | HonkyTonkPiano | RhodesPiano | ChorusedPiano+ | Harpsichord | Clavinet | Celesta + | Glockenspiel | MusicBox | Vibraphone + | Marimba | Xylophone | TubularBells+ | Dulcimer | HammondOrgan | PercussiveOrgan + | RockOrgan | ChurchOrgan | ReedOrgan+ | Accordion | Harmonica | TangoAccordion+ | AcousticGuitarNylon | AcousticGuitarSteel | ElectricGuitarJazz+ | ElectricGuitarClean | ElectricGuitarMuted | OverdrivenGuitar+ | DistortionGuitar | GuitarHarmonics | AcousticBass+ | ElectricBassFingered | ElectricBassPicked | FretlessBass+ | SlapBass1 | SlapBass2 | SynthBass1 + | SynthBass2 | Violin | Viola + | Cello | Contrabass | TremoloStrings+ | PizzicatoStrings | OrchestralHarp | Timpani+ | StringEnsemble1 | StringEnsemble2 | SynthStrings1+ | SynthStrings2 | ChoirAahs | VoiceOohs+ | SynthVoice | OrchestraHit | Trumpet+ | Trombone | Tuba | MutedTrumpet+ | FrenchHorn | BrassSection | SynthBrass1+ | SynthBrass2 | SopranoSax | AltoSax + | TenorSax | BaritoneSax | Oboe + | Bassoon | EnglishHorn | Clarinet+ | Piccolo | Flute | Recorder+ | PanFlute | BlownBottle | Shakuhachi+ | Whistle | Ocarina | Lead1Square+ | Lead2Sawtooth | Lead3Calliope | Lead4Chiff+ | Lead5Charang | Lead6Voice | Lead7Fifths+ | Lead8BassLead | Pad1NewAge | Pad2Warm+ | Pad3Polysynth | Pad4Choir | Pad5Bowed+ | Pad6Metallic | Pad7Halo | Pad8Sweep+ | FX1Train | FX2Soundtrack | FX3Crystal+ | FX4Atmosphere | FX5Brightness | FX6Goblins+ | FX7Echoes | FX8SciFi | Sitar+ | Banjo | Shamisen | Koto+ | Kalimba | Bagpipe | Fiddle + | Shanai | TinkleBell | Agogo + | SteelDrums | Woodblock | TaikoDrum+ | MelodicDrum | SynthDrum | ReverseCymbal+ | GuitarFretNoise | BreathNoise | Seashore+ | BirdTweet | TelephoneRing | Helicopter+ | Applause | Gunshot + deriving (Show, Enum, Bounded)++data PercussionName = + AcousticBassDrum | BassDrum1 | SideStick + | AcousticSnare | HandClap | ElectricSnare + | LowFloorTom | ClosedHiHat | HighFloorTom + | PedalHiHat | LowTom | OpenHiHat + | LowMidTom | HiMidTom | CrashCymbal1 + | HighTom | RideCymbal1 | ChineseCymbal + | RideBell | Tambourine | SplashCymbal + | Cowbell | CrashCymbal2 | Vibraslap + | RideCymbal2 | HiBongo | LowBongo + | MuteHiConga | OpenHiConga | LowConga + | HighTimbale | LowTimbale | HighAgogo + | LowAgogo | Cabasa | Maracas + | ShortWhistle | LongWhistle | ShortGuiro + | LongGuiro | Claves | HiWoodBlock + | LowWoodBlock | MuteCuica | OpenCuica + | MuteTriangle | OpenTriangle+ deriving (Show, Enum, Bounded)+
temporal-music-notation-demo.cabal view
@@ -1,6 +1,6 @@ Name: temporal-music-notation-demo-Version: 0.2-Cabal-Version: >= 1.2+Version: 0.2.1+Cabal-Version: >= 1.6 License: BSD3 License-file: LICENSE Author: Anton Kholomiov@@ -19,11 +19,18 @@ Tested-With: GHC==6.12.3 Build-Type: Simple --- Extra-Source-Files : --- gen/genGM.hs--- examples/choral.hs--- examples/break.hs--- examples/readme.hs+Extra-Source-Files : + gen/genGM.hs+ examples/choral.hs+ examples/break.hs+ examples/readme.hs+++ +Source-repository head+ Type: git+ Location: https://github.com/anton-k/temporal-music-notation-demo+ Library Build-Depends: