\section{Convenient Functions for Getting Started With Haskore}
\label{test-functions}
{\small
\begin{verbatim}
> module Haskore.Test where
> import Haskore.Basics
> import Haskore.Performance
> import Haskore.ToMidi
>
> import Haskore.GeneralMidi
> import Haskore.OutputMidi
>
>
>
>
>
> mToMF :: PMap -> Context -> UserPatchMap -> String -> Music -> IO ()
> mToMF pmap c upm fn m =
> let pf = perform pmap c m
> mf = performToMidi pf upm
> in outputMidiFile fn mf
>
>
>
>
>
>
> defUpm :: UserPatchMap
> defUpm = [("piano","Acoustic Grand Piano",1),
> ("vibes","Vibraphone",2),
> ("bass","Acoustic Bass",3),
> ("flute","Flute",4),
> ("sax","Tenor Sax",5),
> ("guitar","Acoustic Guitar (steel)",6),
> ("violin","Viola",7),
> ("violins","String Ensemble 1",8),
> ("drums","Acoustic Grand Piano",9)]
>
>
>
> defPMap :: String -> Player
> defPMap pname =
> MkPlayer pname nf pf sf
> where MkPlayer _ nf pf sf = fancyPlayer
>
>
> defCon :: Context
> defCon = Context { cTime = 0,
> cPlayer = fancyPlayer,
> cInst = "piano",
> cDur = metro 120 qn,
> cKey = 0,
> cVol = 127 }
>
>
>
> testPerf :: Music -> Performance
> testPerf m = perform defPMap defCon m
> testPerfDur :: Music -> (Performance, DurT)
> testPerfDur m = perf defPMap defCon m
>
>
> testMidi :: Music -> MidiFile
> testMidi m = performToMidi (testPerf m) defUpm
>
>
> test :: Music -> IO ()
> test m = outputMidiFile "test.mid" (testMidi m)
>
>
Alternatively, just run "test m" manually, and then invoke the midi
player on your system using "play", defined below for NT:
>
A more general function in the tradition of testMidi, makeMidi also
takes a Context and a UserPatchMap.
> makeMidi :: (Music, Context, UserPatchMap) -> MidiFile
> makeMidi (m,c,upm) = performToMidi (perform defPMap c m) upm
>
>
>
>
>
>
>
> gmUpm :: UserPatchMap
> gmUpm = map (\(gmn,n) -> (gmn, gmn, mod n 16 + 1)) genMidiMap
>
>
>
> gmTest :: Int -> IO()
> gmTest i = let gMM = take 8 (drop (i*8) genMidiMap)
> mu = line (map simple gMM)
> simple (inm,_) = Instr inm cMajArp
> in mToMF defPMap defCon gmUpm "test.mid" mu
\end{verbatim} }