-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiFile.lhs
117 lines (100 loc) · 3.23 KB
/
MidiFile.lhs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
\subsection{Midi-File Datatypes}
\begin{verbatim}
> module MidiFile(
> MidiFile(..), Division(..), Track, MFType, MEvent(..), ElapsedTime,
> MPitch, Velocity, ControlNum, PBRange, ProgNum, Pressure,
> MidiChannel, ControlVal,
> MidiEvent(..),
> MTempo, SMPTEHours, SMPTEMins, SMPTESecs, SMPTEFrames, SMPTEBits,
> MetaEvent(..),
> KeyName(..), Mode(..),
> defST, defDurT
> ) where
> import Ix
\end{verbatim}
\begin{verbatim}
The datatypes for Midi Files and Midi Events
------------------------------------------------------------------------
> data MidiFile = MidiFile MFType Division [Track] deriving (Show, Eq)
>
> data Division = Ticks Int | SMPTE Int Int
> deriving (Show,Eq)
>
> type Track = [MEvent]
> type MFType = Int
>
> data MEvent = MidiEvent ElapsedTime MidiEvent
> | MetaEvent ElapsedTime MetaEvent
> | NoEvent
> deriving (Show,Eq)
>
> type ElapsedTime = Int
>
> -- Midi Events
>
> type MPitch = Int
> type Velocity = Int
> type ControlNum = Int
> type PBRange = Int
> type ProgNum = Int
> type Pressure = Int
> type MidiChannel = Int
> type ControlVal = Int
>
> data MidiEvent = NoteOff MidiChannel MPitch Velocity
> | NoteOn MidiChannel MPitch Velocity
> | PolyAfter MidiChannel MPitch Pressure
> | ProgChange MidiChannel ProgNum
> | Control MidiChannel ControlNum ControlVal
> | PitchBend MidiChannel PBRange
> | MonoAfter MidiChannel Pressure
> deriving (Show, Eq)
>
> -- Meta Events
>
> type MTempo = Int
> type SMPTEHours = Int
> type SMPTEMins = Int
> type SMPTESecs = Int
> type SMPTEFrames = Int
> type SMPTEBits = Int
>
> data MetaEvent = SequenceNum Int
> | TextEvent String
> | Copyright String
> | TrackName String
> | InstrName String
> | Lyric String
> | Marker String
> | CuePoint String
> | MIDIPrefix MidiChannel
> | EndOfTrack
> | SetTempo MTempo
> | SMPTEOffset SMPTEHours SMPTEMins SMPTESecs SMPTEFrames SMPTEBits
> | TimeSig Int Int Int Int
> | KeySig KeyName Mode
> | SequencerSpecific [Int]
> | Unknown String
> deriving (Show, Eq)
>
\end{verbatim}
The following enumerated type lists all the keys in order of their key
signatures from flats to sharps. (Cf = 7 flats, Gf = 6 flats ... F =
1 flat, C = 0 flats/sharps, G = 1 sharp, ... Cs = 7 sharps.) Useful
for transposition. \begin{verbatim}
> data KeyName = KeyCf | KeyGf | KeyDf | KeyAf | KeyEf | KeyBf | KeyF
> | KeyC | KeyG | KeyD | KeyA | KeyE | KeyB | KeyFs | KeyCs
> deriving (Eq, Ord, Ix, Enum, Show)
\end{verbatim}
The Key Signature specifies a mode, either major or minor.
\begin{verbatim}
> data Mode = Major | Minor
> deriving (Show, Eq)
\end{verbatim}
Default duration of a whole note, in seconds; and the default SetTempo
value, in microseconds per quarter note. Both express the default of
120 beats per minute.
\begin{verbatim}
> defDurT = 2 :: Float
> defST = truncate (1000000 / defDurT) :: Int
\end{verbatim}