resonance 1.0.1
Loading...
Searching...
No Matches
reader.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "mid/tick.h"
6
7class HxIListChunk;
8class HxStream;
9
11namespace Mid {
12
13class Receiver;
14
36class Reader {
37public:
39 static constexpr short kTargetDivision = 480;
40
44 struct Midi {
45 unsigned char mStatus;
46 unsigned char mData1;
47 unsigned char mData2;
48 };
49
51 typedef bool (*EventCompare)(const Midi &left, const Midi &right);
52
61 Reader(HxIListChunk *pReader, Receiver *pReceiver);
62
70
81 bool ReadChunk();
82
90
98 void ReadHeader(HxStream &stream);
99
108
116 void ReadTrack(HxStream &stream);
117
128 void ReadEvent(HxStream &stream);
129
138
149 void ReadMeta(unsigned char nType, HxStream &stream);
150
164 unsigned char nStatus,
165 unsigned char nData1,
166 unsigned char nData2);
167
180 void
181 QueueEvent(Sch::Tick tick, unsigned char nStatus, unsigned char nData1, unsigned char nData2);
182
189 void Flush();
190
191 short mFormat;
193 short mDivision;
195 int mTrack;
197 int mTick;
198 unsigned char mRunningStatus;
201 std::vector<Midi> mPending;
204};
205
206} // namespace Mid
Cursor over the chunks inside one RIFF list or Standard MIDI File.
Definition hxilistchunk.h:19
Seekable data source interface, unrelated to IBStream and OBStream.
Definition hxstream.h:35
static constexpr short kTargetDivision
Ticks per quarter note of every position delivered to the receiver.
Definition reader.h:39
void ReadTrackChunk(HxStream &stream)
Read one MTrk chunk when the file format has one track per chunk.
void Flush()
Sort mPending with mCompare, deliver every event at mPendingTick, and empty it.
void QueueEvent(Sch::Tick tick, unsigned char nStatus, unsigned char nData1, unsigned char nData2)
Deliver a channel event, or collect it in mPending when mCompare is set.
short mTrackCount
Definition reader.h:192
void ReadMeta(unsigned char nType, HxStream &stream)
Read one meta event and deliver end of track, tempo, and the seven text types.
int mTrackDone
Definition reader.h:199
EventCompare mCompare
Definition reader.h:203
void ReadHeader(HxStream &stream)
Read the format, track count, and division of an MThd chunk.
void SendChannelMsg(Sch::Tick tick, unsigned char nStatus, unsigned char nData1, unsigned char nData2)
Deliver one channel event to the receiver slot its status selects.
int mTrack
Definition reader.h:195
void AllTracksRead()
Report the end of the file to the receiver's AllDone().
void ReadSystemEvent(HxStream &stream)
Skip a system-exclusive event or read a meta event, depending on mRunningStatus.
short mFormat
Definition reader.h:191
bool ReadChunk()
Read the next chunk.
void ReadAllTracks()
Read every chunk of the file.
Reader(HxIListChunk *pReader, Receiver *pReceiver)
Build a reader over the chunks of a file.
short mDivision
Definition reader.h:193
short mTargetDivision
Definition reader.h:194
bool(* EventCompare)(const Midi &left, const Midi &right)
Ordering mPending is sorted by.
Definition reader.h:51
std::vector< Midi > mPending
Definition reader.h:201
void ReadEvent(HxStream &stream)
Read one delta time and event.
HxIListChunk * mReader
Definition reader.h:200
unsigned char mRunningStatus
Definition reader.h:198
int mTick
Definition reader.h:197
Sch::Tick mPendingTick
Definition reader.h:202
Receiver * mReceiver
Definition reader.h:196
void ReadTrack(HxStream &stream)
Begin a track at the receiver and read its events until the end-of-track meta event.
Sink a Standard MIDI File reader delivers one event at a time to.
Definition receiver.h:27
Song position in MIDI ticks, printed as measure, beat, and tick.
Definition tick.h:70
Reading of Standard MIDI Files and the receivers their events go to.
Definition reader.h:11
One channel event waiting in mPending.
Definition reader.h:44
unsigned char mData1
Definition reader.h:46
unsigned char mStatus
Definition reader.h:45
unsigned char mData2
Definition reader.h:47