35 class FileMIDIDevice:
public MIDIDevice
38 std::string mFilename;
42 bool mHavePendingEvent;
49 FileMIDIDevice(
const std::string& name,
const std::string& device);
52 void ConcreteStart(
void) throw(Err);
53 void ConcreteStop(
void) throw(Err);
55 void Read(
void) throw(Err);
56 void Write(
unsigned char* msg,
int size) throw(Err);
60 FileMIDIDevice::FileMIDIDevice(const std::
string& name,const std::
string& fname):
64 mHavePendingEvent =
false;
69 void FileMIDIDevice::ConcreteStart(
void) throw(Err)
79 std::string str(
"Could not open FileMIDIDevice with file ");
81 throw Err(str.c_str());
90 mSongPlayer.Init(&mSong);
96 void FileMIDIDevice::ConcreteStop(
void) throw(Err)
105 void FileMIDIDevice::Write(
unsigned char* msg,
int size)
throw(Err)
107 throw Err(
"FileMIDIDevice::Write not implemented yet");
110 void FileMIDIDevice::Read(
void) throw(Err)
113 static int nbytesPerChnMsg[7] =
118 if (!mHavePendingEvent)
121 mSongPlayer.GetEvent(mPendingEvent,mPendingTrackId);
122 if (mHavePendingEvent)
124 mPendingTime = mTempo.TicksToTime(mPendingEvent.GetTicks());
129 if (mHavePendingEvent) {
130 if (mCurTime >= mPendingTime)
133 mPendingEvent[0] != 0xF0 &&
134 mPendingEvent[0] != 0xF7 &&
135 mPendingEvent[0] != 0xFF)
138 int nbytes = nbytesPerChnMsg[((mPendingEvent[0]&0xF0)>>4)-8];
139 if ((mPendingEvent[0]&0xF0)==0x80)
145 for (
int i = 0; i < nbytes; i++)
150 mHavePendingEvent =
false;
157 FileMIDIDevice::~FileMIDIDevice()
161 class FileMIDIDeviceList:
public MIDIDeviceList
163 static FileMIDIDeviceList sDevices;
166 :MIDIDeviceList(std::string(
"file"))
169 mAvailableDevices.push_back(
"*.mid");
173 std::string DefaultDevice(
void)
175 return "file:unknown.mid";
179 const std::string& name,
const std::string& device)
181 return new FileMIDIDevice(name,device);
185 FileMIDIDeviceList FileMIDIDeviceList::sDevices;