281 lines
7.1 KiB
C++
281 lines
7.1 KiB
C++
#include <midiseq/mididata.hpp>
|
|
#include <sgi_stl/list>
|
|
|
|
void testNotes(void);
|
|
void testFile(void);
|
|
void testEvent(void);
|
|
|
|
void testSort();
|
|
|
|
int PASCAL WinMain(HINSTANCE /*hInstance*/,HINSTANCE /*hPrevInstance*/,LPSTR /*lpszCmdLine*/,int /*nCmdShow*/)
|
|
{
|
|
// testEvent();
|
|
// testSort();
|
|
testFile();
|
|
// testNotes();
|
|
return 0;
|
|
}
|
|
|
|
void testFile(void)
|
|
{
|
|
// String musicFileName("E:\\WORK\\SCENE\\MEDIA\\BMP\\E1M2.MID");
|
|
// String musicFileName("E:\\WORK\\GUITAR\\MIDI\\DIANA.MID"); // OK
|
|
// String musicFileName("E:\\WORK\\GUITAR\\MIDI\\JESU_1.MID"); // OK
|
|
// String musicFileName("E:\\WORK\\GUITAR\\MIDI\\paco.MID"); // OK
|
|
|
|
|
|
String musicFileName("E:\\WORK\\GUITAR\\MIDI\\zapatead.mid");
|
|
// String musicFileName("C:\\WINNT\\MEDIA\\PASSPORT.MID");
|
|
// String musicFileName("E:\\WORK\\GUITAR\\MIDI\\BUMBLEBEE.MID"); // OK
|
|
// String musicFileName("C:\\WINNT\\MEDIA\\CANYON.MID");
|
|
|
|
|
|
|
|
MidiData midiData(musicFileName);
|
|
midiData.play();
|
|
while(midiData.isInPlay());
|
|
midiData.stop();
|
|
::MessageBox(::GetFocus(),(LPSTR)musicFileName,(LPSTR)"End Play",MB_OK);
|
|
return;
|
|
}
|
|
|
|
void testEvent(void)
|
|
{
|
|
String musicFileName("D:\\WORK\\SCENE\\MEDIA\\BMP\\E1M2.MID");
|
|
int requiredChannel=0;
|
|
|
|
|
|
MidiData midiData(musicFileName);
|
|
midiData.makeRealTime();
|
|
::OutputDebugString(String("MIDI events=")+String().fromInt(midiData.getEventCount()));
|
|
for(int index=0;index<midiData.getEventCount();index++)
|
|
{
|
|
PureEvent &pureEvent=midiData.getEventAt(index);
|
|
if(144==pureEvent.eventType()&&requiredChannel==pureEvent.channel())
|
|
{
|
|
::OutputDebugString(pureEvent.toString()+String("\n"));
|
|
}
|
|
// ::OutputDebugString(pureEvent.toString()+String("\n"));
|
|
|
|
// eventType:144 [ MIDINoteOn] deltaTime: 31 playTime: 2323643 channel: 0 byteOne: 74 byteTwo: 62 midiTime: 0
|
|
// midiChannelMessage(PureEvent(mEventType,mDeltaTime,channel,mNoteOn.pitch(),mNoteOn.velocity()));
|
|
// PureEvent(BYTE eventType,DWORD deltaTime,BYTE channel,BYTE firstData,BYTE secondData);
|
|
// pureEvent.playTime();
|
|
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
#include <common/qsort.hpp>
|
|
|
|
void testSort()
|
|
{
|
|
|
|
|
|
/*
|
|
list<PureEvent> lst;
|
|
PureEvent p1;
|
|
PureEvent p2;
|
|
PureEvent p3;
|
|
PureEvent p4;
|
|
PureEvent p5;
|
|
PureEvent p6;
|
|
PureEvent p7;
|
|
PureEvent p8;
|
|
PureEvent p9;
|
|
|
|
p1.eventType(128);
|
|
p2.eventType(128);
|
|
p3.eventType(128);
|
|
p4.eventType(144);
|
|
p5.eventType(128);
|
|
p6.eventType(128);
|
|
p7.eventType(128);
|
|
p8.eventType(128);
|
|
p9.eventType(144);
|
|
|
|
lst.push_back(p1);
|
|
lst.push_back(p2);
|
|
lst.push_back(p3);
|
|
lst.push_back(p4);
|
|
lst.push_back(p5);
|
|
lst.push_back(p6);
|
|
lst.push_back(p7);
|
|
lst.push_back(p8);
|
|
lst.push_back(p9);
|
|
lst.sort();
|
|
|
|
list<PureEvent>::iterator p=lst.begin();
|
|
while(p!=lst.end())
|
|
{
|
|
::OutputDebugString((*p).toString()+String("\n"));
|
|
p++;
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
Array<PureEvent> pureEvents;
|
|
QuickSort<PureEvent> eventSorter;
|
|
PureEvent pureEvent;
|
|
|
|
pureEvents.size(9);
|
|
pureEvent.eventType(128);
|
|
pureEvents[0]=pureEvent;
|
|
pureEvent.eventType(128);
|
|
pureEvents[1]=pureEvent;
|
|
pureEvent.eventType(128);
|
|
pureEvents[2]=pureEvent;
|
|
pureEvent.eventType(144);
|
|
pureEvents[3]=pureEvent;
|
|
pureEvent.eventType(128);
|
|
pureEvents[4]=pureEvent;
|
|
pureEvent.eventType(128);
|
|
pureEvents[5]=pureEvent;
|
|
pureEvent.eventType(128);
|
|
pureEvents[6]=pureEvent;
|
|
pureEvent.eventType(128);
|
|
pureEvents[7]=pureEvent;
|
|
pureEvent.eventType(144);
|
|
pureEvents[8]=pureEvent;
|
|
|
|
eventSorter.sortItems(pureEvents);
|
|
::OutputDebugString("\n");
|
|
for(int index=0;index<pureEvents.size();index++)
|
|
{
|
|
::OutputDebugString(pureEvents[index].toString()+String("\n"));
|
|
}
|
|
|
|
|
|
/*eventType:128 [ MIDINoteOff] deltaTime: 1 playTime:147650742.00 channel: 0 byteOne: 56 byteTwo: 0 midiTime: 0
|
|
eventType:128 [ MIDINoteOff] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 59 byteTwo: 0 midiTime: 0
|
|
eventType:128 [ MIDINoteOff] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 64 byteTwo: 0 midiTime: 0
|
|
eventType:144 [ MIDINoteOn] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 64 byteTwo: 64 midiTime: 0
|
|
eventType:128 [ MIDINoteOff] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 53 byteTwo: 0 midiTime: 0
|
|
eventType:128 [ MIDINoteOff] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 57 byteTwo: 0 midiTime: 0
|
|
eventType:128 [ MIDINoteOff] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 60 byteTwo: 0 midiTime: 0
|
|
eventType:128 [ MIDINoteOff] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 64 byteTwo: 0 midiTime: 0
|
|
eventType:144 [ MIDINoteOn] deltaTime: 0 playTime:147650742.00 channel: 0 byteOne: 59 byteTwo: 64 midiTime: 0 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* for(DWORD index=0;index<MIDIBlock::MaxChannels;index++)maxEvents+=midiEventBlocks[(WORD)index].size();
|
|
sortedEvents.size(maxEvents);
|
|
for(index=0;index<MIDIBlock::MaxChannels;index++)
|
|
{
|
|
eventCount=midiEventBlocks[(WORD)index].size();
|
|
if(!eventCount)continue;
|
|
for(DWORD eventIndex=0;eventIndex<eventCount;eventIndex++)
|
|
sortedEvents[runningCount++]=(midiEventBlocks[(WORD)index])[eventIndex];
|
|
}
|
|
if(!sortedEvents.size())return;
|
|
eventSorter.sortItems(sortedEvents); */
|
|
|
|
|
|
}
|
|
|
|
class PitchBend
|
|
{
|
|
public:
|
|
enum {MinPitch=0x0000,MaxPitch=0x3FFF,CenterPitch=0x2000};
|
|
PitchBend(void);
|
|
PureEvent getEvent(void)const;
|
|
void setPitch(WORD pitch);
|
|
WORD getPitch(void)const;
|
|
void centerWheel(void);
|
|
private:
|
|
BYTE getLo(void)const;
|
|
BYTE getHi(void)const;
|
|
|
|
WORD mPitch;
|
|
};
|
|
|
|
inline
|
|
PitchBend::PitchBend()
|
|
: mPitch(CenterPitch)
|
|
{
|
|
}
|
|
|
|
inline
|
|
void PitchBend::setPitch(WORD pitch)
|
|
{
|
|
if(pitch>MaxPitch)pitch=MaxPitch;
|
|
mPitch=pitch;
|
|
}
|
|
|
|
inline
|
|
WORD PitchBend::getPitch(void)const
|
|
{
|
|
return mPitch;
|
|
}
|
|
|
|
inline
|
|
void PitchBend::centerWheel(void)
|
|
{
|
|
mPitch=CenterPitch;
|
|
}
|
|
|
|
inline
|
|
BYTE PitchBend::getLo(void)const
|
|
{
|
|
return mPitch&0xFF;
|
|
}
|
|
|
|
inline
|
|
BYTE PitchBend::getHi(void)const
|
|
{
|
|
return mPitch>>8;
|
|
}
|
|
|
|
inline
|
|
PureEvent PitchBend::getEvent(void)const
|
|
{
|
|
String strPitch;
|
|
::sprintf(strPitch.str(),"lo:0x%04lx hi:0x%04lx\n",getLo(),getHi());
|
|
::OutputDebugString(strPitch.str());
|
|
PureEvent pureEvent(MIDIPitchBend,0,0,getHi(),getLo());
|
|
return pureEvent;
|
|
}
|
|
|
|
void testNotes(void)
|
|
{
|
|
MIDIOutputDevice midiOut;
|
|
|
|
NoteOn noteOn(PureNote(70,60));
|
|
PitchBend pitchBend;
|
|
pitchBend.setPitch(0x0);
|
|
pitchBend.setPitch(0x2000+128);
|
|
|
|
// pitchBend.setPitch(0x3FFF);
|
|
NoteOff noteOff(PureNote(70,60));
|
|
|
|
if(!midiOut.openDevice())return;
|
|
|
|
midiOut.midiEvent(noteOn.getEvent());
|
|
midiOut.midiEvent(pitchBend.getEvent());
|
|
pitchBend.setPitch(0x2000);
|
|
midiOut.midiEvent(pitchBend.getEvent());
|
|
|
|
midiOut.midiEvent(noteOn.getEvent());
|
|
|
|
midiOut.midiEvent(noteOff.getEvent());
|
|
|
|
midiOut.closeDevice();
|
|
return;
|
|
}
|
|
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\WALTHIUS\\DEMON21T.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\CYBRBEAT.MID");
|
|
// String musicFileName("C:\\WINDOWS\\CANYON.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\MID\\D_STALKS.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\MID\\E1M9.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\EXORCIST.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\YYZ.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\K330-1.MID");
|
|
// String musicFileName("C:\\WORK\\SCENE\\MEDIA\\K330-2.MID");
|