This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

BIN
midiwrt/CNVTDN.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
midiwrt/CNVTUP.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
midiwrt/DNARDN.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

BIN
midiwrt/DNARUP.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

74
midiwrt/INSTRMNT.CPP Normal file
View File

@@ -0,0 +1,74 @@
#include <stdlib.h>
#include <midiwrt/instrmnt.hpp>
Instruments::Instruments(WORD startOrdinal,WORD endOrdinal)
{
loadInstruments(startOrdinal,endOrdinal);
}
Instruments::~Instruments()
{
}
WORD Instruments::loadInstruments(WORD startOrdinal,WORD endOrdinal)
{
String semicolonString(";");
String nullString("\\0");
String ordinalString;
String categoryString;
String nameString;
char *lpBuffer;
BYTE lineFeed;
size((endOrdinal-startOrdinal)+1);
for(short index=startOrdinal,offset=0;index<=endOrdinal;index++,offset++)
{
String tempString(index);
lpBuffer=::strtok(tempString,semicolonString);
if(!lpBuffer)continue;
ordinalString=lpBuffer;
lpBuffer=::strtok(0,semicolonString);
if(!lpBuffer)continue;
categoryString=lpBuffer;
lpBuffer=::strtok(0,nullString);
if(!lpBuffer)continue;
nameString=lpBuffer;
operator[](offset)=PureInstrument(::atoi(ordinalString),categoryString,nameString);
}
return (WORD)size();
}
WORD Instruments::getInstruments(PureVector<PureInstrument> &vectoredInstruments)
{
vectoredInstruments.size(0);
if(!size())return FALSE;
vectoredInstruments.size(size());
for(int i=0;i<size();i++)vectoredInstruments[i]=operator[](i);
return vectoredInstruments.size();
}
WORD Instruments::locateInstrument(WORD ordinalValue,PureInstrument &somePureInstrument)
{
short itemIndex;
if(!binarySearch(ordinalValue,itemIndex))return FALSE;
somePureInstrument=operator[](itemIndex);
return TRUE;
}
WORD Instruments::binarySearch(WORD ordinal,short &itemIndex)
{
short lowerBound(0);
short upperBound((short)size()-1);
short indexItem;
do{
indexItem=(lowerBound+upperBound)/2;
if(operator[](indexItem).ordinal()<ordinal)lowerBound=indexItem+1;
else upperBound=indexItem-1;
}while(operator[](indexItem).ordinal()!=ordinal&&lowerBound<=upperBound);
itemIndex=indexItem;
return operator[](indexItem).ordinal()==ordinal;
}


21
midiwrt/INSTRMNT.HPP Normal file
View File

@@ -0,0 +1,21 @@
#ifndef _INSTRUMENT_HPP_
#define _INSTRUMENT_HPP_
#include <common/windows.hpp>
#include <common/string.hpp>
#include <common/pvector.hpp>
#include <midiwrt/pureinst.hpp>
class Instruments : public PureVector<PureInstrument>
{
public:
Instruments(WORD startOrdinal,WORD endOrdinal);
~Instruments();
WORD getInstruments(PureVector<PureInstrument> &vectoredInstruments);
WORD locateInstrument(WORD ordinalValue,PureInstrument &somePureInstrument);
private:
WORD binarySearch(WORD ordinalValue,short &itemIndex);
enum {Semicolon=';'};
WORD loadInstruments(WORD startOrdinal,WORD endOrdinal);
};
#endif


BIN
midiwrt/LED.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

52
midiwrt/LED.CPP Normal file
View File

@@ -0,0 +1,52 @@
#include <stdio.h>
#include <midiwrt/led.hpp>
void LedDisplay::paint(void)
{
HBITMAP hOldBitmap;
HDC hDisplayDC;
HDC hMemDC;
WORD firstOffset;
WORD secondOffset;
WORD thirdOffset;
WORD fourthOffset;
hDisplayDC=::GetDC(mhDisplayWindow);
hMemDC=::CreateCompatibleDC(hDisplayDC);
hOldBitmap=(HBITMAP)::SelectObject(hMemDC,mhFilm);
positions(firstOffset,secondOffset,thirdOffset,fourthOffset);
::BitBlt(hDisplayDC,mWindowPoint.x(),mWindowPoint.y(),Width,Height,
hMemDC,0,firstOffset*Height,SRCCOPY);
::BitBlt(hDisplayDC,mWindowPoint.x()+Width,mWindowPoint.y(),Width,Height,
hMemDC,0,secondOffset*Height,SRCCOPY);
::BitBlt(hDisplayDC,mWindowPoint.x()+(Width*2),mWindowPoint.y(),Width,Height,
hMemDC,0,thirdOffset*Height,SRCCOPY);
::BitBlt(hDisplayDC,mWindowPoint.x()+(Width*3),mWindowPoint.y(),Width,Height,
hMemDC,0,fourthOffset*Height,SRCCOPY);
::SelectObject(hMemDC,hOldBitmap);
::DeleteObject(hMemDC);
::ReleaseDC(mhDisplayWindow,hDisplayDC);
}
void LedDisplay::positions(WORD &firstOffset,WORD &secondOffset,WORD &thirdOffset,WORD &fourthOffset)const
{
String numberString;
if(mHasSpecialChar)
{
if(BlankChar==mCurrentSpecialChar)
firstOffset=secondOffset=thirdOffset=fourthOffset=OffsetBlankChar;
else
firstOffset=secondOffset=thirdOffset=fourthOffset=OffsetDashChar;
}
else
{
::sprintf(numberString,"%04d",mCurrentNumber);
firstOffset=charPosition(*(numberString));
secondOffset=charPosition(*((char*)numberString+1));
thirdOffset=charPosition(*((char*)numberString+2));
fourthOffset=charPosition(*((char*)numberString+3));
}
}


75
midiwrt/LED.HPP Normal file
View File

@@ -0,0 +1,75 @@
#ifndef _LEDDISPLAY_HPP_
#define _LEDDISPLAY_HPP_
#include <common/windows.hpp>
#include <common/string.hpp>
#include <common/point.hpp>
class LedDisplay
{
public:
enum SpecialChar{BlankChar,DashChar};
LedDisplay(HWND hDisplayWindow,Point windowPoint);
virtual ~LedDisplay();
void setNumber(short someNumber);
void setNumber(SpecialChar specialChar);
short getNumber(void)const;
void paint(void);
private:
enum {Width=13,Height=23,Frames=12};
enum {OffsetDashChar,OffsetBlankChar};
WORD charPosition(char someDisplayChar)const;
void positions(WORD &firstOffset,WORD &secondOffset,WORD &thirdOffset,WORD &fourthOffset)const;
HBITMAP mhFilm;
short mCurrentNumber;
SpecialChar mCurrentSpecialChar;
WORD mHasSpecialChar;
Point mWindowPoint;
HWND mhDisplayWindow;
};
inline
LedDisplay::LedDisplay(HWND hDisplayWindow,Point windowPoint)
: mWindowPoint(windowPoint), mhDisplayWindow(hDisplayWindow), mCurrentNumber(-1),
mHasSpecialChar(TRUE), mCurrentSpecialChar(DashChar),
#if defined(__FLAT__)
mhFilm(::LoadBitmap((HINSTANCE)::GetWindowWord(hDisplayWindow,GWL_HINSTANCE),"LED"))
#else
mhFilm(::LoadBitmap((HINSTANCE)::GetWindowWord(hDisplayWindow,GWW_HINSTANCE),"LED"))
#endif
{
}
inline
LedDisplay::~LedDisplay()
{
if(mhFilm){::DeleteObject(mhFilm);mhFilm=0;}
}
inline
WORD LedDisplay::charPosition(char someChar)const
{
return ((Frames-1)-((int)someChar-'0'));
}
inline
short LedDisplay::getNumber(void)const
{
return mCurrentNumber;
}
inline
void LedDisplay::setNumber(SpecialChar specialChar)
{
mHasSpecialChar=TRUE;
mCurrentSpecialChar=specialChar;
paint();
}
inline
void LedDisplay::setNumber(short someNumber)
{
mHasSpecialChar=FALSE;
mCurrentNumber=someNumber;
paint();
}
#endif

BIN
midiwrt/MIDI.DSW Normal file

Binary file not shown.

BIN
midiwrt/MIDI.IDE Normal file

Binary file not shown.

BIN
midiwrt/MIDI.OBR Normal file

Binary file not shown.

BIN
midiwrt/MIDI32.DSW Normal file

Binary file not shown.

BIN
midiwrt/MIDI32.IDE Normal file

Binary file not shown.

BIN
midiwrt/MIDI32.OBR Normal file

Binary file not shown.

66
midiwrt/MIDIDATA.HPP Normal file
View File

@@ -0,0 +1,66 @@
#ifndef _MIDIDATA_HPP_
#define _MIDIDATA_HPP_
#include <stdio.h>
#include <common/windows.hpp>
#include <common/string.hpp>
#include <midiwrt/midihdr.hpp>
#include <midiwrt/miditrck.hpp>
class MidiData
{
public:
MidiData(String midiPathFileName);
~MidiData();
operator MemFile&(void);
WORD writeHeader(MidiHeader &midiHeader);
WORD readHeader(MidiHeader &midiHeader);
WORD flush(void);
WORD isOkay(void)const;
private:
MemFile mMidiFile;
};
inline
MidiData::MidiData(String midiPathFileName)
: mMidiFile(midiPathFileName,100000L,MemFile::BigEndian)
{
}
inline
MidiData::~MidiData()
{
}
inline
WORD MidiData::writeHeader(MidiHeader &midiHeader)
{
if(!mMidiFile.isOkay())return FALSE;
return midiHeader.writeHeader(mMidiFile);
}
inline
WORD MidiData::readHeader(MidiHeader &midiHeader)
{
if(!mMidiFile.isOkay())return FALSE;
return midiHeader.readHeader(mMidiFile);
}
inline
WORD MidiData::flush(void)
{
if(!isOkay())return FALSE;
return mMidiFile.flushBuffer();
}
inline
MidiData::operator MemFile&(void)
{
return mMidiFile;
}
inline
WORD MidiData::isOkay(void)const
{
return mMidiFile.isOkay();
}
#endif

197
midiwrt/MIDIDEF.H Normal file
View File

@@ -0,0 +1,197 @@
/* defines for MUS convert window */
#define MUS_TEMPOBUTTONUP 5000
#define MUS_TEMPOBUTTONDN 5001
#define MUS_CVTBUTTON 5002
#define MUS_CONVERTFILE 5003
#define MUS_LISTBOX 5004
#define MUS_STATIC 5005
/* string defines */
#define STRING_BUTTONSTRING 5006
#define STRING_LISTBOXSTRING 5007
#define STRING_STATICSTRING 5008
#define STRING_BITMAPUPARUP 5009
#define STRING_BITMAPUPARDN 5010
#define STRING_BITMAPDNARUP 5011
#define STRING_BITMAPDNARDN 5012
#define STRING_BITMAPCNVTUP 5013
#define STRING_BITMAPCNVTDN 5014
/* defines for instrument categories and types */
#define STRING_MUSINST1 5020
#define STRING_MUSINST2 5021
#define STRING_MUSINST3 5022
#define STRING_MUSINST4 5023
#define STRING_MUSINST5 5024
#define STRING_MUSINST6 5025
#define STRING_MUSINST7 5026
#define STRING_MUSINST8 5027
#define STRING_MUSINST9 5028
#define STRING_MUSINST10 5029
#define STRING_MUSINST11 5030
#define STRING_MUSINST12 5031
#define STRING_MUSINST13 5032
#define STRING_MUSINST14 5033
#define STRING_MUSINST15 5034
#define STRING_MUSINST16 5035
#define STRING_MUSINST17 5036
#define STRING_MUSINST18 5037
#define STRING_MUSINST19 5038
#define STRING_MUSINST20 5039
#define STRING_MUSINST21 5040
#define STRING_MUSINST22 5041
#define STRING_MUSINST23 5042
#define STRING_MUSINST24 5043
#define STRING_MUSINST25 5044
#define STRING_MUSINST26 5045
#define STRING_MUSINST27 5046
#define STRING_MUSINST28 5047
#define STRING_MUSINST29 5048
#define STRING_MUSINST30 5049
#define STRING_MUSINST31 5050
#define STRING_MUSINST32 5051
#define STRING_MUSINST33 5052
#define STRING_MUSINST34 5053
#define STRING_MUSINST35 5054
#define STRING_MUSINST36 5055
#define STRING_MUSINST37 5056
#define STRING_MUSINST38 5057
#define STRING_MUSINST39 5058
#define STRING_MUSINST40 5059
#define STRING_MUSINST41 5060
#define STRING_MUSINST42 5061
#define STRING_MUSINST43 5062
#define STRING_MUSINST44 5063
#define STRING_MUSINST45 5064
#define STRING_MUSINST46 5065
#define STRING_MUSINST47 5066
#define STRING_MUSINST48 5067
#define STRING_MUSINST49 5068
#define STRING_MUSINST50 5069
#define STRING_MUSINST51 5070
#define STRING_MUSINST52 5071
#define STRING_MUSINST53 5072
#define STRING_MUSINST54 5073
#define STRING_MUSINST55 5074
#define STRING_MUSINST56 5075
#define STRING_MUSINST57 5076
#define STRING_MUSINST58 5077
#define STRING_MUSINST59 5078
#define STRING_MUSINST60 5079
#define STRING_MUSINST61 5080
#define STRING_MUSINST62 5081
#define STRING_MUSINST63 5082
#define STRING_MUSINST64 5083
#define STRING_MUSINST65 5084
#define STRING_MUSINST66 5085
#define STRING_MUSINST67 5086
#define STRING_MUSINST68 5087
#define STRING_MUSINST69 5088
#define STRING_MUSINST70 5089
#define STRING_MUSINST71 5090
#define STRING_MUSINST72 5091
#define STRING_MUSINST73 5092
#define STRING_MUSINST74 5093
#define STRING_MUSINST75 5094
#define STRING_MUSINST76 5095
#define STRING_MUSINST77 5096
#define STRING_MUSINST78 5097
#define STRING_MUSINST79 5098
#define STRING_MUSINST80 5099
#define STRING_MUSINST81 5100
#define STRING_MUSINST82 5101
#define STRING_MUSINST83 5102
#define STRING_MUSINST84 5103
#define STRING_MUSINST85 5104
#define STRING_MUSINST86 5105
#define STRING_MUSINST87 5106
#define STRING_MUSINST88 5107
#define STRING_MUSINST89 5108
#define STRING_MUSINST90 5109
#define STRING_MUSINST91 5110
#define STRING_MUSINST92 5111
#define STRING_MUSINST93 5112
#define STRING_MUSINST94 5113
#define STRING_MUSINST95 5114
#define STRING_MUSINST96 5115
#define STRING_MUSINST97 5116
#define STRING_MUSINST98 5117
#define STRING_MUSINST99 5118
#define STRING_MUSINST100 5119
#define STRING_MUSINST101 5120
#define STRING_MUSINST102 5121
#define STRING_MUSINST103 5122
#define STRING_MUSINST104 5123
#define STRING_MUSINST105 5124
#define STRING_MUSINST106 5125
#define STRING_MUSINST107 5126
#define STRING_MUSINST108 5127
#define STRING_MUSINST109 5128
#define STRING_MUSINST110 5129
#define STRING_MUSINST111 5130
#define STRING_MUSINST112 5131
#define STRING_MUSINST113 5132
#define STRING_MUSINST114 5133
#define STRING_MUSINST115 5134
#define STRING_MUSINST116 5135
#define STRING_MUSINST117 5136
#define STRING_MUSINST118 5137
#define STRING_MUSINST119 5138
#define STRING_MUSINST120 5139
#define STRING_MUSINST121 5140
#define STRING_MUSINST122 5141
#define STRING_MUSINST123 5142
#define STRING_MUSINST124 5143
#define STRING_MUSINST125 5144
#define STRING_MUSINST126 5145
#define STRING_MUSINST127 5146
#define STRING_MUSINST128 5147
#define STRING_MUSINST129 5148
#define STRING_MUSINST130 5149
#define STRING_MUSINST131 5150
#define STRING_MUSINST132 5151
#define STRING_MUSINST133 5152
#define STRING_MUSINST134 5153
#define STRING_MUSINST135 5154
#define STRING_MUSINST136 5155
#define STRING_MUSINST137 5156
#define STRING_MUSINST138 5157
#define STRING_MUSINST139 5158
#define STRING_MUSINST140 5159
#define STRING_MUSINST141 5160
#define STRING_MUSINST142 5161
#define STRING_MUSINST143 5162
#define STRING_MUSINST144 5163
#define STRING_MUSINST145 5164
#define STRING_MUSINST146 5165
#define STRING_MUSINST147 5166
#define STRING_MUSINST148 5167
#define STRING_MUSINST149 5168
#define STRING_MUSINST150 5169
#define STRING_MUSINST151 5170
#define STRING_MUSINST152 5171
#define STRING_MUSINST153 5172
#define STRING_MUSINST154 5173
#define STRING_MUSINST155 5174
#define STRING_MUSINST156 5175
#define STRING_MUSINST157 5176
#define STRING_MUSINST158 5177
#define STRING_MUSINST159 5178
#define STRING_MUSINST160 5179
#define STRING_MUSINST161 5180
#define STRING_MUSINST162 5181
#define STRING_MUSINST163 5182
#define STRING_MUSINST164 5183
#define STRING_MUSINST165 5184
#define STRING_MUSINST166 5185
#define STRING_MUSINST167 5186
#define STRING_MUSINST168 5187
#define STRING_MUSINST169 5188
#define STRING_MUSINST170 5189
#define STRING_MUSINST171 5190
#define STRING_MUSINST172 5191
#define STRING_MUSINST173 5192
#define STRING_MUSINST174 5193
#define STRING_MUSINST175 5194

4
midiwrt/MIDIDEF.HPP Normal file
View File

@@ -0,0 +1,4 @@
#ifndef _MIDIDEF_HPP_
#define _MIDIDEF_HPP_
#include <midiwrt/mididef.h>
#endif

36
midiwrt/MIDIHDR.CPP Normal file
View File

@@ -0,0 +1,36 @@
#include <iostream.h>
#include <midiwrt/midihdr.hpp>
MidiHeader &MidiHeader::operator=(const MidiHeader &someMidiHeader)
{
::memcpy(mHeader,someMidiHeader.mHeader,sizeof(mHeader));
mLengthData=someMidiHeader.mLengthData;
mSMFType=someMidiHeader.mSMFType;
mTracks=someMidiHeader.mTracks;
mDeltaTempo=someMidiHeader.mDeltaTempo;
mHeaderString=someMidiHeader.mHeaderString;
return *this;
}
WORD MidiHeader::writeHeader(MemFile &midiFile)
{
if(!midiFile.rewind())return FALSE;
if(!midiFile.write(mHeaderString,mHeaderString.length()))return FALSE;
if(!midiFile.write(mLengthData))return FALSE;
if(!midiFile.write(mSMFType))return FALSE;
if(!midiFile.write(mTracks))return FALSE;
if(!midiFile.write(mDeltaTempo))return FALSE;
return TRUE;
}
WORD MidiHeader::readHeader(MemFile &midiFile)
{
if(!midiFile.rewind())return FALSE;
if(!midiFile.read(mHeader,sizeof(mHeader)))return FALSE;
if(!midiFile.read(mLengthData))return FALSE;
if(!midiFile.read(mSMFType))return FALSE;
if(!midiFile.read(mTracks))return FALSE;
if(!midiFile.read(mDeltaTempo))return FALSE;
return TRUE;
}

93
midiwrt/MIDIHDR.HPP Normal file
View File

@@ -0,0 +1,93 @@
#ifndef _MIDIHEADER_HPP_
#define _MIDIHEADER_HPP_
#include <string.h>
#include <common/windows.hpp>
#include <common/memfile.hpp>
class MidiHeader
{
public:
MidiHeader(void);
MidiHeader(const MidiHeader &someMidiHeader);
~MidiHeader();
MidiHeader &operator=(const MidiHeader &someMidiHeader);
WORD readHeader(MemFile &midiFile);
WORD writeHeader(MemFile &midiFile);
DWORD lengthData(void)const;
void smfType(USHORT smfType);
USHORT smfType(void)const;
USHORT tracks(void)const;
void tracks(USHORT tracks);
void deltaTempo(USHORT deltaTempo);
USHORT deltaTempo(void)const;
private:
enum {MaxHeaderIDLength=4,SingleTrack=0,MultiTrack=1,Sequential=2,DefaultTempo=136};
char mHeader[MaxHeaderIDLength];
DWORD mLengthData;
USHORT mSMFType;
USHORT mTracks;
USHORT mDeltaTempo;
String mHeaderString;
};
inline
MidiHeader::MidiHeader(void)
: mLengthData(0L), mSMFType(MultiTrack), mTracks(0), mDeltaTempo(DefaultTempo),
mHeaderString("MThd")
{
mLengthData=sizeof(*this)-(sizeof(mLengthData)+sizeof(mHeader)+sizeof(mHeaderString));
}
inline
MidiHeader::~MidiHeader()
{
}
inline
DWORD MidiHeader::lengthData(void)const
{
return mLengthData;
}
inline
USHORT MidiHeader::smfType(void)const
{
return mSMFType;
}
inline
void MidiHeader::smfType(USHORT smfType)
{
mSMFType=smfType;
}
inline
USHORT MidiHeader::tracks(void)const
{
return mTracks;
}
inline
void MidiHeader::tracks(USHORT tracks)
{
mTracks=tracks;
}
inline
USHORT MidiHeader::deltaTempo(void)const
{
return mDeltaTempo;
}
inline
void MidiHeader::deltaTempo(USHORT deltaTempo)
{
mDeltaTempo=deltaTempo;
}
inline
MidiHeader::MidiHeader(const MidiHeader &someMidiHeader)
{
*this=someMidiHeader;
}
#endif

51
midiwrt/MIDIPTCH.HPP Normal file
View File

@@ -0,0 +1,51 @@
#ifndef _MIDIPITCH_HPP_
#define _MIDIPITCH_HPP_
#include <common/windows.hpp>
#include <common/fileio.hpp>
class MidiPitchBend
{
public:
enum {PitchBendDataLength=2};
MidiPitchBend(void);
MidiPitchBend(BYTE musPitchBend);
void setPitchBend(BYTE musPitchBend);
operator BYTE*(void);
private:
void operator=(const MidiPitchBend &someMidiPitchBend);
BYTE mlpMidiPitchBend[PitchBendDataLength];
};
inline
MidiPitchBend::MidiPitchBend(void)
{
setPitchBend(0);
}
inline
MidiPitchBend::MidiPitchBend(BYTE musPitchBend)
{
setPitchBend(musPitchBend);
}
inline
void MidiPitchBend::setPitchBend(BYTE musPitchBend)
{
WORD midiPitchBend(musPitchBend*64);
*(mlpMidiPitchBend)=(BYTE)(midiPitchBend&0x7F);
*(mlpMidiPitchBend+1)=(BYTE)((midiPitchBend>>7)&0x7F);
}
inline
MidiPitchBend::operator BYTE*(void)
{
return mlpMidiPitchBend;
}
inline
void MidiPitchBend::operator=(const MidiPitchBend &someMidiPitchBend)
{
return;
}
#endif

50
midiwrt/MIDITIME.HPP Normal file
View File

@@ -0,0 +1,50 @@
#ifndef _MIDITIME_HPP_
#define _MIDITIME_HPP_
#include <common/windows.hpp>
class MidiDeltaTime
{
public:
MidiDeltaTime(void);
~MidiDeltaTime();
void resetTime(void);
DWORD deltaTime(void)const;
MidiDeltaTime &operator+=(DWORD musDeltaTime);
private:
DWORD mDeltaTime;
DWORD mPrevDeltaTime;
};
inline
MidiDeltaTime::MidiDeltaTime(void)
{
resetTime();
}
inline
MidiDeltaTime::~MidiDeltaTime()
{
}
inline
DWORD MidiDeltaTime::deltaTime(void)const
{
return mDeltaTime;
}
inline
MidiDeltaTime &MidiDeltaTime::operator+=(DWORD musDeltaTime)
{
musDeltaTime/=.6;
mDeltaTime=(musDeltaTime-mPrevDeltaTime);
mPrevDeltaTime+=mDeltaTime;
return *this;
}
inline
void MidiDeltaTime::resetTime(void)
{
mDeltaTime=0L;
mPrevDeltaTime=0L;
}
#endif

100
midiwrt/MIDITRCK.CPP Normal file
View File

@@ -0,0 +1,100 @@
#include <string.h>
#include <iostream.h>
#include <iomanip.h>
#include <assert.h>
#include <midiwrt/miditrck.hpp>
WORD MidiTrack::readHeader(void)
{
if(!mMidiFile.isOkay())return FALSE;
if(!mMidiFile.seek(mHeaderPosition,MemFile::SeekBeginning))return FALSE;
if(!mMidiFile.read(mTrack,sizeof(mTrack)))return FALSE;
if(!mMidiFile.read(mLengthData))return FALSE;
return TRUE;
}
WORD MidiTrack::writeHeader(void)
{
if(!mMidiFile.isOkay())return FALSE;
if(!mMidiFile.seek(mHeaderPosition,MemFile::SeekBeginning))return FALSE;
if(!mMidiFile.write(mTrack,sizeof(mTrack)))return FALSE;
if(!mMidiFile.write(mLengthData))return FALSE;
return TRUE;
}
WORD MidiTrack::writeMetaEvent(MetaEventType metaEventType,void *lpData,BYTE lengthData)
{
BYTE eventType(MetaEvent);
if(!mMidiFile.isOkay())return FALSE;
if(!writeTimeValue(mDeltaTime))return FALSE;
if(!mMidiFile.write(eventType))return FALSE;
if(!mMidiFile.write((BYTE)metaEventType))return FALSE;
if(!mMidiFile.write(lengthData))return FALSE;
if(!mMidiFile.write((char*)lpData,lengthData))return FALSE;
mByteCount+=(3+lengthData);
if(!flushTrack())return FALSE;
return TRUE;
}
WORD MidiTrack::writeMidiChannelMessage(MidiChannelMsg midiChannelMessage,BYTE channel,void *lpData,BYTE lengthData)
{
BYTE midiMessage(midiChannelMessage|channel);
if(!mMidiFile.isOkay())return FALSE;
if(!writeTimeValue(mDeltaTime))return FALSE;
if(!mMidiFile.write(midiMessage))return FALSE;
if(!mMidiFile.write((char*)lpData,lengthData))return FALSE;
mByteCount+=(lengthData+1);
if(!flushTrack())return FALSE;
return TRUE;
}
WORD MidiTrack::writeEndTrack(void)
{
BYTE eventType(MetaEvent);
BYTE metaEventType(EndOfTrack);
BYTE nullByte(0);
if(!mMidiFile.isOkay())return FALSE;
if(!writeTimeValue(mDeltaTime))return FALSE;
if(!mMidiFile.write(eventType))return FALSE;
if(!mMidiFile.write(metaEventType))return FALSE;
if(!mMidiFile.write(nullByte))return FALSE;
mByteCount+=3;
if(!flushTrack())return FALSE;
return TRUE;
}
WORD MidiTrack::flushTrack(void)
{
DWORD currPos(mMidiFile.tell());
if(!readHeader())return FALSE;
mLengthData=mByteCount;
if(!writeHeader())return FALSE;
if(!mMidiFile.seek(currPos,MemFile::SeekBeginning))return FALSE;
return TRUE;
}
WORD MidiTrack::writeTimeValue(DWORD value)
{
DWORD tempValue;
tempValue=(value&0x7F);
while((value>>=7)>0)
{
tempValue<<=8;
tempValue|=0x80;
tempValue+=(value&0x7F);
}
while(TRUE)
{
if(!mMidiFile.write((BYTE)(tempValue&0xFF)))return FALSE;
mByteCount++;
if(!(tempValue&0x80))break;
tempValue>>=8;
}
return TRUE;
}

87
midiwrt/MIDITRCK.HPP Normal file
View File

@@ -0,0 +1,87 @@
#ifndef _MIDITRACK_HPP_
#define _MIDITRACK_HPP_
#include <stdio.h>
#include <common/windows.hpp>
#include <common/memfile.hpp>
#include <midiwrt/midihdr.hpp>
class MidiTrack
{
public:
enum EventType{MetaEvent=0xFF,SystemExclusiveOne=0xF0,SystemExclusiveTwo=0xF7,NullEvent=0x00};
enum MidiChannelMsg{MIDIProgramChange=0xC0,MIDINoteOff=0x80,MIDINoteOn=0x90,
MIDIKeyPressure=0xA0,MIDIParameter=0xB0,MIDIPitchBend=0xE0,MIDIProgram=0xC0,
MIDIChannelPressure=0xD0};
enum MetaEventType{SequenceNumberEvent=0x00,TextEvent=0x01,CopyrightNotice=0x02,
SequenceTrackName=0x03,InstrumentName=0x04,Lyric=0x05,Marker=0x06,CuePoint=0x07,
EndOfTrack=0x2F,SetTempo=0x51,SMPTEFormatSpec=0x54,TimeSignature=0x58,
KeySignature=0x59,SequencerSpecificMetaEvent=0x7F};
MidiTrack(MemFile &midiFile);
~MidiTrack();
WORD writeHeader(void);
WORD readHeader(void);
WORD rewind(void);
void setDeltaTime(DWORD eventTime);
WORD writeMetaEvent(MetaEventType metaEventType,void *lpData,BYTE lengthData);
WORD writeMidiChannelMessage(MidiChannelMsg midiChannelMessage,BYTE channel,void *lpData,BYTE lengthData);
WORD writeEndTrack(void);
DWORD length(void)const;
void setLocation(MemFile &midiFile);
private:
enum {TrackIDLen=4};
void length(DWORD lengthData);
WORD flushTrack(void);
WORD writeTimeValue(DWORD longValue);
char mTrack[TrackIDLen];
DWORD mLengthData;
DWORD mDeltaTime;
DWORD mHeaderPosition;
DWORD mByteCount;
MemFile &mMidiFile;
};
inline
MidiTrack::MidiTrack(MemFile &midiFile)
: mLengthData(0), mDeltaTime(0), mHeaderPosition(0L), mMidiFile(midiFile), mByteCount(0)
{
::memcpy(mTrack,"MTrk",sizeof(mTrack));
}
inline
MidiTrack::~MidiTrack()
{
}
inline
void MidiTrack::setDeltaTime(DWORD eventTime)
{
mDeltaTime=eventTime;
}
inline
DWORD MidiTrack::length(void)const
{
return mLengthData;
}
inline
void MidiTrack::length(DWORD lengthData)
{
mLengthData=lengthData;
}
inline
WORD MidiTrack::rewind(void)
{
if(!mMidiFile.seek(mHeaderPosition,MemFile::SeekBeginning))return FALSE;
return TRUE;
}
inline
void MidiTrack::setLocation(MemFile &midiFile)
{
mLengthData=mDeltaTime=mByteCount=0;
mHeaderPosition=midiFile.tell();
}
#endif

15
midiwrt/MIDIWRT.DEF Normal file
View File

@@ -0,0 +1,15 @@
NAME MUS
DESCRIPTION 'MUS FILE CONVERTER'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE
HEAPSIZE 8191
STACKSIZE 8191
EXPORTS CONVERTFILE


212
midiwrt/MIDIWRT.RC Normal file
View File

@@ -0,0 +1,212 @@
#include <windows.h>
#include <midiwrt/mididef.h>
UPARUP BITMAP UPARUP.BMP
UPARDN BITMAP UPARDN.BMP
DNARUP BITMAP DNARUP.BMP
DNARDN BITMAP DNARDN.BMP
CNVTUP BITMAP CNVTUP.BMP
CNVTDN BITMAP CNVTDN.BMP
OPENUP BITMAP OPENUP.BMP
OPENDN BITMAP OPENDN.BMP
SELUP BITMAP SELUP.BMP
SELDN BITMAP SELDN.BMP
WND BITMAP WND.BMP
LED BITMAP LED.BMP
STRINGTABLE
{
STRING_MUSINST1, "0;PIANO;Acoustic Grand Piano"
STRING_MUSINST2, "1;PIANO;Bright Acoustic Piano"
STRING_MUSINST3, "2;PIANO;Electric Grand Piano"
STRING_MUSINST4, "3;PIANO;Honky-tonk Piano"
STRING_MUSINST5, "4;PIANO;Rhodes Piano"
STRING_MUSINST6, "5;PIANO;Chorused Piano"
STRING_MUSINST7, "6;PIANO;Harpsichord"
STRING_MUSINST8, "7;PIANO;Clavinet"
STRING_MUSINST9, "8;CHROM PERCUSSION;Celesta"
STRING_MUSINST10, "9;CHROM PERCUSSION;Glockenspiel"
STRING_MUSINST11, "10;CHROM PERCUSSION;Music Box"
STRING_MUSINST12, "11;CHROM PERCUSSION;Vibraphone"
STRING_MUSINST13, "12;CHROM PERCUSSION;Marimba"
STRING_MUSINST14, "13;CHROM PERCUSSION;Xylophone"
STRING_MUSINST15, "14;CHROM PERCUSSION;Tubular-bell"
STRING_MUSINST16, "15;CHROM PERCUSSION;Dulcimer"
STRING_MUSINST17, "16;ORGAN;Hammond Organ"
STRING_MUSINST18, "17;ORGAN;Percussive Organ"
STRING_MUSINST19, "18;ORGAN;Rock Organ"
STRING_MUSINST20, "19;ORGAN;Church Organ"
STRING_MUSINST21, "20;ORGAN;Reed Organ"
STRING_MUSINST22, "21;ORGAN;Accordion"
STRING_MUSINST23, "22;ORGAN;Harmonica"
STRING_MUSINST24, "23;ORGAN;Tango Accordion"
STRING_MUSINST25, "24;GUITAR;Acoustic Guitar(nylon)"
STRING_MUSINST26, "25;GUITAR;Acoustic Guitar(steel)"
STRING_MUSINST27, "26;GUITAR;Electric Guitar(jazz)"
STRING_MUSINST28, "27;GUITAR;Electric Guitar(clean)"
STRING_MUSINST29, "28;GUITAR;Electric Guitar(muted)"
STRING_MUSINST30, "29;GUITAR;Overdriven Guitar"
STRING_MUSINST31, "30;GUITAR;Distortion Guitar"
STRING_MUSINST32, "31;GUITAR;Guitar Harmonics"
STRING_MUSINST33, "32;BASS;Acoustic Bass"
STRING_MUSINST34, "33;BASS;Electric Bass(finger)"
STRING_MUSINST35, "34;BASS;Electric Bass(pick)"
STRING_MUSINST36, "35;BASS;Fretless Bass"
STRING_MUSINST37, "36;BASS;Slap Bass 1"
STRING_MUSINST38, "37;BASS;Slap Bass 2"
STRING_MUSINST39, "38;BASS;Synth Bass 1"
STRING_MUSINST40, "39;BASS;Synth Bass 2"
STRING_MUSINST41, "40;STRINGS;Violin"
STRING_MUSINST42, "41;STRINGS;Viola"
STRING_MUSINST43, "42;STRINGS;Cello"
STRING_MUSINST44, "43;STRINGS;Contrabass"
STRING_MUSINST45, "44;STRINGS;Tremolo Strings"
STRING_MUSINST46, "45;STRINGS;Pizzicato Strings"
STRING_MUSINST47, "46;STRINGS;Orchestral Harp"
STRING_MUSINST48, "47;STRINGS;Timpani"
STRING_MUSINST49, "48;ENSEMBLE;String Ensemble 1"
STRING_MUSINST50, "49;ENSEMBLE;String Ensemble 2"
STRING_MUSINST51, "50;ENSEMBLE;Synth Strings 1"
STRING_MUSINST52, "51;ENSEMBLE;Synth Strings 2"
STRING_MUSINST53, "52;ENSEMBLE;Choir Aahs"
STRING_MUSINST54, "53;ENSEMBLE;Voice Oohs"
STRING_MUSINST55, "54;ENSEMBLE;Synth Voice"
STRING_MUSINST56, "55;ENSEMBLE;Orchestra Hit"
STRING_MUSINST57, "56;BRASS;Trumpet"
STRING_MUSINST58, "57;BRASS;Trombone"
STRING_MUSINST59, "58;BRASS;Tuba"
STRING_MUSINST60, "59;BRASS;Muted Trumpet"
STRING_MUSINST61, "60;BRASS;French Horn"
STRING_MUSINST62, "61;BRASS;Brass Section"
STRING_MUSINST63, "62;BRASS;Synth Brass 1"
STRING_MUSINST64, "63;BRASS;Synth Brass 2"
STRING_MUSINST65, "64;REED;Soprano Sax"
STRING_MUSINST66, "65;REED;Alto Sax"
STRING_MUSINST67, "66;REED;Tenor Sax"
STRING_MUSINST68, "67;REED;Baritone Sax"
STRING_MUSINST69, "68;REED;Oboe"
STRING_MUSINST70, "69;REED;English Horn"
STRING_MUSINST71, "70;REED;Bassoon"
STRING_MUSINST72, "71;REED;Clarinet"
STRING_MUSINST73, "72;PIPE;Piccolo"
STRING_MUSINST74, "73;PIPE;Flute"
STRING_MUSINST75, "74;PIPE;Recorder"
STRING_MUSINST76, "75;PIPE;Pan Flute"
STRING_MUSINST77, "76;PIPE;Bottle Blow"
STRING_MUSINST78, "77;PIPE;Shakuhachi"
STRING_MUSINST79, "78;PIPE;Whistle"
STRING_MUSINST80, "79;PIPE;Ocarina"
STRING_MUSINST81, "80;SYNTH LEAD;Lead 1(square)"
STRING_MUSINST82, "81;SYNTH LEAD;Lead 2(sawtooth)"
STRING_MUSINST83, "82;SYNTH LEAD;Lead 3(calliope)"
STRING_MUSINST84, "83;SYNTH LEAD;Lead 4(chiffer)"
STRING_MUSINST85, "84;SYNTH LEAD;Lead 5(charang)"
STRING_MUSINST86, "85;SYNTH LEAD;Lead 6(voice)"
STRING_MUSINST87, "86;SYNTH LEAD;Lead 7(5th sawtooth)"
STRING_MUSINST88, "87;SYNTH LEAD;Lead 8(bass&lead)"
STRING_MUSINST89, "88;SYNTH PAD;Pad 1(new age)"
STRING_MUSINST90, "89;SYNTH PAD;Pad 2(warm)"
STRING_MUSINST91, "90;SYNTH PAD;Pad 3(polysynth)"
STRING_MUSINST92, "91;SYNTH PAD;Pad 4(choir)"
STRING_MUSINST93, "92;SYNTH PAD;Pad 5(bowed glass)"
STRING_MUSINST94, "93;SYNTH PAD;Pad 6(metal)"
STRING_MUSINST95, "94;SYNTH PAD;Pad 7(halo)"
STRING_MUSINST96, "95;SYNTH PAD;Pad 8(sweep)"
STRING_MUSINST97, "96;SYNTH EFFECTS;FX 1(rain)"
STRING_MUSINST98, "97;SYNTH EFFECTS;FX 2(soundtrack)"
STRING_MUSINST99, "98;SYNTH EFFECTS;FX 3(crystal)"
STRING_MUSINST100, "99;SYNTH EFFECTS;FX 4(atmosphere)"
STRING_MUSINST101, "100;SYNTH EFFECTS;FX 5(brightness)"
STRING_MUSINST102, "101;SYNTH EFFECTS;FX 6(goblin)"
STRING_MUSINST103, "102;SYNTH EFFECTS;FX 7(echo drops)"
STRING_MUSINST104, "103;SYNTH EFFECTS;FX 8(star-theme)"
STRING_MUSINST105, "104;ETHNIC;Sitar"
STRING_MUSINST106, "105;ETHNIC;Banjo"
STRING_MUSINST107, "106;ETHNIC;Shamisen"
STRING_MUSINST108, "107;ETHNIC;Koto"
STRING_MUSINST109, "108;ETHNIC;Kalimba"
STRING_MUSINST110, "109;ETHNIC;Bag Pipe"
STRING_MUSINST111, "110;ETHNIC;Fiddle"
STRING_MUSINST112, "111;ETHNIC;Shanai"
STRING_MUSINST113, "112;PERCUSSIVE;Tinkle Bell"
STRING_MUSINST114, "113;PERCUSSIVE;Agogo"
STRING_MUSINST115, "114;PERCUSSIVE;Steel Drums"
STRING_MUSINST116, "115;PERCUSSIVE;Woodblock"
STRING_MUSINST117, "116;PERCUSSIVE;Taiko Drum"
STRING_MUSINST118, "117;PERCUSSIVE;Melodic Tom"
STRING_MUSINST119, "118;PERCUSSIVE;Synth Drum"
STRING_MUSINST120, "119;PERCUSSIVE;Reverse Cymbal"
STRING_MUSINST121, "120;SOUND EFFECTS;Guitar Fret Noise"
STRING_MUSINST122, "121;SOUND EFFECTS;Breath Noise"
STRING_MUSINST123, "122;SOUND EFFECTS;Seashore"
STRING_MUSINST124, "123;SOUND EFFECTS;Bird Tweet"
STRING_MUSINST125, "124;SOUND EFFECTS;Telephone Ring"
STRING_MUSINST126, "125;SOUND EFFECTS;Helicopter"
STRING_MUSINST127, "126;SOUND EFFECTS;Applause"
STRING_MUSINST128, "127;SOUND EFFECTS;Gun Shot"
STRING_MUSINST129, "135;MIDI PERCUSSION;Acoustic Bass Drum"
STRING_MUSINST130, "136;MIDI PERCUSSION;Bass Drum"
STRING_MUSINST131, "137;MIDI PERCUSSION;Slide Stick"
STRING_MUSINST132, "138;MIDI PERCUSSION;Acoustic Snare"
STRING_MUSINST133, "139;MIDI PERCUSSION;Hand Clap"
STRING_MUSINST134, "140;MIDI PERCUSSION;Electric Snare"
STRING_MUSINST135, "141;MIDI PERCUSSION;Low Floor Tom"
STRING_MUSINST136, "142;MIDI PERCUSSION;Closed High-Hat"
STRING_MUSINST137, "143;MIDI PERCUSSION;High Floor Tom"
STRING_MUSINST138, "144;MIDI PERCUSSION;Pedal High Hat"
STRING_MUSINST139, "145;MIDI PERCUSSION;Low Tom"
STRING_MUSINST140, "146;MIDI PERCUSSION;Open High Hat"
STRING_MUSINST141, "147;MIDI PERCUSSION;Low-Mid Tom"
STRING_MUSINST142, "148;MIDI PERCUSSION;High-Mid Tom"
STRING_MUSINST143, "149;MIDI PERCUSSION;Crash Cymbal 1"
STRING_MUSINST144, "150;MIDI PERCUSSION;High Tom"
STRING_MUSINST145, "151;MIDI PERCUSSION;Ride Cymbal 1"
STRING_MUSINST146, "152;MIDI PERCUSSION;Chinese Cymbal"
STRING_MUSINST147, "153;MIDI PERCUSSION;Ride Bell"
STRING_MUSINST148, "154;MIDI PERCUSSION;Tambourine"
STRING_MUSINST149, "155;MIDI PERCUSSION;Splash Cymbal"
STRING_MUSINST150, "156;MIDI PERCUSSION;Cowbell"
STRING_MUSINST151, "157;MIDI PERCUSSION;Crash Cymbal 2"
STRING_MUSINST152, "158;MIDI PERCUSSION;Vibraslap"
STRING_MUSINST153, "159;MIDI PERCUSSION;Ride Cymbal 2"
STRING_MUSINST154, "160;MIDI PERCUSSION;High Bongo"
STRING_MUSINST155, "161;MIDI PERCUSSION;Low Bongo"
STRING_MUSINST156, "162;MIDI PERCUSSION;Mute High Conga"
STRING_MUSINST157, "163;MIDI PERCUSSION;Open High Conga"
STRING_MUSINST158, "164;MIDI PERCUSSION;Low Conga"
STRING_MUSINST159, "165;MIDI PERCUSSION;High Timbale"
STRING_MUSINST160, "166;MIDI PERCUSSION;Low Timbale"
STRING_MUSINST161, "167;MIDI PERCUSSION;High Agogo"
STRING_MUSINST162, "168;MIDI PERCUSSION;Low Agogo"
STRING_MUSINST163, "169;MIDI PERCUSSION;Cabasa"
STRING_MUSINST164, "170;MIDI PERCUSSION;Maracas"
STRING_MUSINST165, "171;MIDI PERCUSSION;Short Whistle"
STRING_MUSINST166, "172;MIDI PERCUSSION;Long Whistle"
STRING_MUSINST167, "173;MIDI PERCUSSION;Short Guiro"
STRING_MUSINST168, "174;MIDI PERCUSSION;Long Guiro"
STRING_MUSINST169, "175;MIDI PERCUSSION;Claves"
STRING_MUSINST170, "176;MIDI PERCUSSION;High Wood Block"
STRING_MUSINST171, "177;MIDI PERCUSSION;Low Wood Block"
STRING_MUSINST172, "178;MIDI PERCUSSION;Mute Cuica"
STRING_MUSINST173, "179;MIDI PERCUSSION;Open Cuica"
STRING_MUSINST174, "180;MIDI PERCUSSION;Mute Triangle"
STRING_MUSINST175, "181;MIDI PERCUSSION;Open Triangle"
}
STRINGTABLE
{
STRING_BITMAPUPARUP, "UPARUP"
STRING_BITMAPUPARDN, "UPARDN"
STRING_BITMAPDNARUP, "DNARUP"
STRING_BITMAPDNARDN, "DNARDN"
STRING_BITMAPCNVTUP, "CNVTUP"
STRING_BITMAPCNVTDN, "CNVTDN"
}
STRINGTABLE
{
STRING_BUTTONSTRING, "BUTTON"
STRING_LISTBOXSTRING, "LISTBOX"
STRING_STATICSTRING, "STATIC"
}

BIN
midiwrt/MUS.DSW Normal file

Binary file not shown.

205
midiwrt/MUSCNV.CPP Normal file
View File

@@ -0,0 +1,205 @@
#include <iostream.h>
#include <midiwrt/muscnv.hpp>
#include <midiwrt/midiptch.hpp>
MUSConverter::MUSConverter(String midiPathFileName,String musPathFileName)
: MUSFile(musPathFileName), mMidiData(midiPathFileName),
mNumTracks(0), mMidiTrack((MemFile&)mMidiData)
{
}
MUSConverter::~MUSConverter()
{
}
WORD MUSConverter::convertFile(void)
{
if(!isOkay())return FALSE;
if(!writeInfoTrack())return FALSE;
if(!readMUSFile())return FALSE;
if(!updateTrackInfo())return FALSE;
return TRUE;
}
WORD MUSConverter::updateTrackInfo(void)
{
if(!mNumTracks)return FALSE;
mMidiHeader.tracks(mNumTracks);
if(!mMidiData.writeHeader(mMidiHeader))return FALSE;
if(!mMidiData.flush())return FALSE;
return TRUE;
}
WORD MUSConverter::writeInfoTrack(void)
{
String copyRightNotice("(c) Copyright 1995 Sean M. Kessler.");
String textEventOne("WINMUS v1.00 Beta.");
char timeSignature[]={0x04,0x02,0x60,0x08};
char setTempo[]={0x09,0xA3,0x1A};
if(!mMidiData.isOkay()||!MUSFile::isOkay())return FALSE;
if(!mMidiData.writeHeader(mMidiHeader))return FALSE;
mMidiTrack.setLocation((MemFile&)mMidiData);
if(!mMidiTrack.writeHeader())return FALSE;
if(!mMidiTrack.writeMetaEvent(MidiTrack::TimeSignature,(void*)timeSignature,sizeof(timeSignature)))return FALSE;
mMidiTrack.setDeltaTime(0);
if(!mMidiTrack.writeMetaEvent(MidiTrack::SetTempo,(void*)setTempo,sizeof(setTempo)))return FALSE;
mMidiTrack.setDeltaTime(0);
if(!mMidiTrack.writeMetaEvent(MidiTrack::CopyrightNotice,(void*)(LPSTR)copyRightNotice,copyRightNotice.length()))return FALSE;
mMidiTrack.setDeltaTime(0);
if(!mMidiTrack.writeMetaEvent(MidiTrack::TextEvent,(void*)(LPSTR)textEventOne,textEventOne.length()))return FALSE;
mMidiTrack.setDeltaTime(0);
if(!mMidiTrack.writeEndTrack())return FALSE;
mNumTracks++;
return TRUE;
}
WORD MUSConverter::handleScoreStart(void)
{
mMidiTrack.setLocation((MemFile&)mMidiData);
if(!mMidiTrack.writeHeader())return FALSE;
mDeltaTime.resetTime();
return TRUE;
}
WORD MUSConverter::handleReleaseNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &releaseNote,BYTE trackNumber)
{
fixChannel(pureEvent,trackNumber);
mDeltaTime+=pureDelay.deltaTicks();
mMidiTrack.setDeltaTime(mDeltaTime.deltaTime());
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDINoteOff,pureEvent.channel(),(void*)&releaseNote,PureNote::DataLength);
return FALSE;
}
WORD MUSConverter::handlePlayNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &playNote,BYTE trackNumber)
{
fixChannel(pureEvent,trackNumber);
mDeltaTime+=pureDelay.deltaTicks();
mMidiTrack.setDeltaTime(mDeltaTime.deltaTime());
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDINoteOn,pureEvent.channel(),(void*)&playNote,PureNote::DataLength);
return FALSE;
}
WORD MUSConverter::handlePitchBend(PureEvent &pureEvent,PureDelay &pureDelay,BYTE pitchBenderValue,BYTE trackNumber)
{
fixChannel(pureEvent,trackNumber);
MidiPitchBend midiPitchBend(pitchBenderValue);
mDeltaTime+=pureDelay.deltaTicks();
mMidiTrack.setDeltaTime(mDeltaTime.deltaTime());
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIPitchBend,pureEvent.channel(),(BYTE*)midiPitchBend,MidiPitchBend::PitchBendDataLength);
return FALSE;
}
WORD MUSConverter::handleReset(PureEvent &pureEvent,PureDelay &pureDelay,BYTE tempoValue,BYTE trackNumber)
{
BYTE resetData[2];
fixChannel(pureEvent,trackNumber);
mDeltaTime+=pureDelay.deltaTicks();
mMidiTrack.setDeltaTime(mDeltaTime.deltaTime());
resetData[1]=0;
switch(tempoValue)
{
case 0x0A :
resetData[0]=0x78;
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIParameter,pureEvent.channel(),resetData,sizeof(resetData));
break;
case 0x0B :
resetData[0]=0x7B;
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIParameter,pureEvent.channel(),resetData,sizeof(resetData));
break;
case 0x0C :
resetData[0]=0x7E;
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIParameter,pureEvent.channel(),resetData,sizeof(resetData));
break;
case 0x0D :
resetData[0]=0x7F;
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIParameter,pureEvent.channel(),resetData,sizeof(resetData));
break;
case 0x0E :
resetData[0]=0x79;
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIParameter,pureEvent.channel(),resetData,sizeof(resetData));
break;
default :
resetData[0]=0;
mMidiTrack.writeMidiChannelMessage(MidiTrack::MIDIParameter,pureEvent.channel(),resetData,1);
break;
}
return TRUE;
}
WORD MUSConverter::handleController(PureEvent &pureEvent,PureDelay &pureDelay,PureController &pureController,BYTE trackNumber)
{
MidiTrack::MidiChannelMsg midiChannelMessage;
BYTE midiData[2];
fixChannel(pureEvent,trackNumber);
mDeltaTime+=pureDelay.deltaTicks();
mMidiTrack.setDeltaTime(mDeltaTime.deltaTime());
if(0==pureController.controllerNumber())midiChannelMessage=MidiTrack::MIDIProgram;
else midiChannelMessage=MidiTrack::MIDIParameter;
switch(pureController.controllerNumber())
{
case 0x00 :
midiData[0]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,1);
break;
case 0x01 :
midiData[0]=0x00;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x02 :
midiData[0]=0x01;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x03 :
midiData[0]=0x07;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x04 :
midiData[0]=0x0A;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x05 :
midiData[0]=0x0B;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x06 :
midiData[0]=0x5B;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x07 :
midiData[0]=0x5D;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x08 :
midiData[0]=0x40;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
case 0x09 :
midiData[0]=0x43;
midiData[1]=pureController.controllerValue();
mMidiTrack.writeMidiChannelMessage(midiChannelMessage,pureEvent.channel(),midiData,sizeof(midiData));
break;
}
return TRUE;
}
WORD MUSConverter::handleScoreEnd(PureDelay &pureDelay)
{
if(!mMidiTrack.length()){mMidiTrack.rewind();return TRUE;}
mDeltaTime+=pureDelay.deltaTicks();
mMidiTrack.setDeltaTime(mDeltaTime.deltaTime());
mMidiTrack.writeEndTrack();
mNumTracks++;
return TRUE;
}

62
midiwrt/MUSCNV.HPP Normal file
View File

@@ -0,0 +1,62 @@
#ifndef _MUSCONVERTER_HPP_
#define _MUSCONVERTER_HPP_
#include <midiwrt/mididata.hpp>
#include <midiwrt/musfile.hpp>
#include <midiwrt/puredly.hpp>
#include <midiwrt/purenote.hpp>
#include <midiwrt/purecntl.hpp>
#include <midiwrt/miditime.hpp>
class MUSConverter : private MUSFile
{
public:
MUSConverter(String midiPathFileName,String musPathFileName);
~MUSConverter();
WORD convertFile(void);
void setTempo(USHORT midiTempo);
USHORT getTempo(void)const;
WORD isOkay(void)const;
WORD updateTrackInfo(void);
protected:
WORD virtual handleScoreStart(void);
WORD virtual handleReleaseNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &releaseNote,BYTE trackNumber);
WORD virtual handlePlayNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &playNote,BYTE trackNumber);
WORD virtual handlePitchBend(PureEvent &pureEvent,PureDelay &pureDelay,BYTE pitchBenderValue,BYTE trackNumber);
WORD virtual handleReset(PureEvent &pureEvent,PureDelay &pureDelay,BYTE tempoValue,BYTE trackNumber);
WORD virtual handleController(PureEvent &pureEvent,PureDelay &pureDelay,PureController &pureController,BYTE trackNumber);
WORD virtual handleScoreEnd(PureDelay &pureDelay);
private:
void fixChannel(PureEvent &pureEvent,BYTE trackNumber);
WORD writeInfoTrack(void);
MidiData mMidiData;
MidiTrack mMidiTrack;
MidiHeader mMidiHeader;
MidiDeltaTime mDeltaTime;
WORD mNumTracks;
};
inline
WORD MUSConverter::isOkay(void)const
{
return (mMidiData.isOkay()&&MUSFile::isOkay());
}
inline
void MUSConverter::setTempo(WORD midiTempo)
{
mMidiHeader.deltaTempo(midiTempo);
}
inline
USHORT MUSConverter::getTempo(void)const
{
return mMidiHeader.deltaTempo();
}
inline
void MUSConverter::fixChannel(PureEvent &pureEvent,BYTE trackNumber)
{
if(15==trackNumber)pureEvent.channel(9);
if(9==trackNumber)pureEvent.channel(15);
}
#endif

322
midiwrt/MUSDLG.CPP Normal file
View File

@@ -0,0 +1,322 @@
#include <common/purehdc.hpp>
#include <midiwrt/musdlg.hpp>
#include <midiwrt/mididef.hpp>
#include <midiwrt/instrmnt.hpp>
char MUSDlg::szClassName[]={"MUSConverter"};
char MUSDlg::szMenuName[]={""};
MUSDlg::MUSDlg(Window &parentWindow,String midiPathFileName,String musPathFileName)
: MUSConverter(midiPathFileName,musPathFileName),
mCommandHandler(this,&MUSDlg::commandHandler),
mCreateHandler(this,&MUSDlg::createHandler),
mDrawItemHandler(this,&MUSDlg::drawItemHandler),
mPaintHandler(this,&MUSDlg::paintHandler),
mDestroyHandler(this,&MUSDlg::destroyHandler),
mCloseHandler(this,&MUSDlg::closeHandler),
mControlColorHandler(this,&MUSDlg::controlColorHandler),
mlpLedTrackDisplay(0), mlpLedTempoDisplay(0),
mOwnerDraw(OwnerDraw::UseInstance), mhButtonCvtWnd(0), mhButtonUpWnd(0),
mhGrayBrush(::CreateSolidBrush(RGB(btnRed,btnGreen,btnBlue))),
mhButtonDnWnd(0), mhListBoxWnd(0), mhStaticWnd(0),
mLinkedBitmap(0,String("WND"),parentWindow.processInstance()),
mOutputPathFileName(midiPathFileName), mhInstance(parentWindow.processInstance()),
mhParentWnd(parentWindow)
{
registerClass();
insertHandlers();
}
MUSDlg::MUSDlg(DWindow &parentWindow,String midiPathFileName,String musPathFileName)
: MUSConverter(midiPathFileName,musPathFileName),
mCommandHandler(this,&MUSDlg::commandHandler),
mCreateHandler(this,&MUSDlg::createHandler),
mDrawItemHandler(this,&MUSDlg::drawItemHandler),
mPaintHandler(this,&MUSDlg::paintHandler),
mDestroyHandler(this,&MUSDlg::destroyHandler),
mCloseHandler(this,&MUSDlg::closeHandler),
mControlColorHandler(this,&MUSDlg::controlColorHandler),
mlpLedTrackDisplay(0), mlpLedTempoDisplay(0),
mOwnerDraw(OwnerDraw::UseInstance), mhButtonCvtWnd(0), mhButtonUpWnd(0),
mhGrayBrush(::CreateSolidBrush(RGB(btnRed,btnGreen,btnBlue))),
mhButtonDnWnd(0), mhListBoxWnd(0), mhStaticWnd(0),
mLinkedBitmap(0,String("WND"),parentWindow.processInstance()),
mOutputPathFileName(midiPathFileName), mhInstance(parentWindow.processInstance()),
mhParentWnd(parentWindow)
{
registerClass();
insertHandlers();
}
MUSDlg::~MUSDlg()
{
if(mlpLedTrackDisplay){delete mlpLedTrackDisplay;mlpLedTrackDisplay=0;}
if(mlpLedTempoDisplay){delete mlpLedTempoDisplay;mlpLedTempoDisplay=0;}
if(::IsWindow(mhButtonUpWnd))::DestroyWindow(mhButtonUpWnd);
if(::IsWindow(mhButtonDnWnd))::DestroyWindow(mhButtonDnWnd);
if(::IsWindow(mhButtonCvtWnd))::DestroyWindow(mhButtonCvtWnd);
if(::IsWindow(mhListBoxWnd))::DestroyWindow(mhListBoxWnd);
if(::IsWindow(mhStaticWnd))::DestroyWindow(mhStaticWnd);
if(mhGrayBrush)::DeleteObject(mhGrayBrush);
if((HWND)*this)destroy();
removeHandlers();
}
void MUSDlg::registerClass(void)const
{
WNDCLASS wndClass;
if(::GetClassInfo(mhInstance,szClassName,(WNDCLASS FAR*)&wndClass))return;
wndClass.style =CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
wndClass.lpfnWndProc =(WNDPROC)Window::WindowWndProc;
wndClass.cbClsExtra =0;
wndClass.cbWndExtra =sizeof(MUSDlg*);
wndClass.hInstance =mhInstance;
wndClass.hIcon =::LoadIcon(NULL,IDI_APPLICATION);
wndClass.hCursor =::LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground =(HBRUSH)::GetStockObject(LTGRAY_BRUSH);
wndClass.lpszMenuName =szMenuName;
wndClass.lpszClassName =szClassName;
::RegisterClass(&wndClass);
assert(0!=::GetClassInfo(mhInstance,szClassName,(WNDCLASS FAR*)&wndClass));
}
WORD MUSDlg::performDialog(void)
{
createDialogControls();
loadInstruments();
while(::IsWindow((HWND)*this))yieldTask();
return FALSE;
}
void MUSDlg::loadInstruments(void)
{
Instruments midiInstruments(StartOrdinal,EndOrdinal);
PureVector<PureInstrument> vectoredInstruments;
String itemString;
midiInstruments.getInstruments(vectoredInstruments);
::SendMessage(mhListBoxWnd,WM_SETREDRAW,FALSE,0L);
for(int index=0;index<vectoredInstruments.size();index++)
{
itemString=vectoredInstruments[index].category();
itemString+="-";
itemString+=vectoredInstruments[index].name();
::SendMessage(::GetDlgItem(*this,MUS_LISTBOX),LB_ADDSTRING,0,(LPARAM)(LPSTR)itemString);
}
::SendMessage(mhListBoxWnd,WM_SETREDRAW,TRUE,0L);
}
void MUSDlg::insertHandlers(void)
{
insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
insertHandler(VectorHandler::DrawItemHandler,&mDrawItemHandler);
insertHandler(VectorHandler::PaintHandler,&mPaintHandler);
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
insertHandler(VectorHandler::CloseHandler,&mCloseHandler);
insertHandler(VectorHandler::ControlColorHandler,&mControlColorHandler);
}
void MUSDlg::removeHandlers(void)
{
removeHandler(VectorHandler::CommandHandler,&mCommandHandler);
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
removeHandler(VectorHandler::DrawItemHandler,&mDrawItemHandler);
removeHandler(VectorHandler::PaintHandler,&mPaintHandler);
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
removeHandler(VectorHandler::CloseHandler,&mCloseHandler);
removeHandler(VectorHandler::ControlColorHandler,&mControlColorHandler);
}
void MUSDlg::createDialogControls(void)
{
String buttonString(STRING_BUTTONSTRING);
String listboxString(STRING_LISTBOXSTRING);
String staticString(STRING_STATICSTRING);
PureDevice pureDevice;
::CreateWindow(szClassName,szClassName,
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_CLIPCHILDREN,
CW_USEDEFAULT,CW_USEDEFAULT,
mLinkedBitmap.width(),mLinkedBitmap.height()+CaptionHeight,
mhParentWnd,NULL,mhInstance,(LPSTR)((MUSDlg*)this));
mhButtonUpWnd=::CreateWindow(buttonString,"",BS_OWNERDRAW|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,152,45,10,8,*this,(HMENU)MUS_TEMPOBUTTONUP,mhInstance,0);
mhButtonDnWnd=::CreateWindow(buttonString,"",BS_OWNERDRAW|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,152,54,10,8,*this,(HMENU)MUS_TEMPOBUTTONDN,mhInstance,0);
mhButtonCvtWnd=::CreateWindow(buttonString,"",BS_OWNERDRAW|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,167,17,15,15,*this,(HMENU)MUS_CVTBUTTON,mhInstance,0);
mhListBoxWnd=::CreateWindow(listboxString,"",LBS_NOTIFY|WS_VSCROLL|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,19,130,280,62,*this,(HMENU)MUS_LISTBOX,mhInstance,0);
mhStaticWnd=::CreateWindow(staticString,"",WS_CHILD|WS_CLIPSIBLINGS,21,210,275,18,*this,(HMENU)MUS_STATIC,mhInstance,0);
show(SW_SHOW);update();
::ShowWindow(mhStaticWnd,SW_SHOW);
}
CallbackData::ReturnType MUSDlg::commandHandler(CallbackData &someCallbackData)
{
switch(someCallbackData.wmCommandID())
{
case MUS_TEMPOBUTTONUP :
handleTempoUpEvent();
break;
case MUS_TEMPOBUTTONDN :
handleTempoDnEvent();
break;
case MUS_CVTBUTTON :
::PostMessage(*this,WM_COMMAND,MUS_CONVERTFILE,0L);
return FALSE;
case MUS_CONVERTFILE :
handleConvertFileEvent();
break;
case IDCANCEL :
destroy();
break;
}
return (CallbackData::ReturnType)FALSE;
}
void MUSDlg::handleTempoUpEvent(void)
{
setTempo(getTempo()+1);
mlpLedTempoDisplay->setNumber(getTempo());
}
void MUSDlg::handleTempoDnEvent(void)
{
setTempo(getTempo()-1);
mlpLedTempoDisplay->setNumber(getTempo());
}
void MUSDlg::handleConvertFileEvent(void)
{
String convertMessageString("writing ");
convertMessageString+=mOutputPathFileName;
setMessage(convertMessageString);
if(!convertFile())setMessage("Error converting file...");
else setMessage("Complete...");
}
CallbackData::ReturnType MUSDlg::createHandler(CallbackData &/*someCallbackData*/)
{
mOwnerDraw.associate(MUS_TEMPOBUTTONUP,String(STRING_BITMAPUPARUP),String(STRING_BITMAPUPARUP),String(STRING_BITMAPUPARDN),OwnerDraw::NOFOCUS);
mOwnerDraw.associate(MUS_TEMPOBUTTONDN,String(STRING_BITMAPDNARUP),String(STRING_BITMAPDNARUP),String(STRING_BITMAPDNARDN),OwnerDraw::NOFOCUS);
mOwnerDraw.associate(MUS_CVTBUTTON,String(STRING_BITMAPCNVTUP),String(STRING_BITMAPCNVTUP),String(STRING_BITMAPCNVTDN),OwnerDraw::NOFOCUS);
mlpLedTrackDisplay=new LedDisplay(*this,Point(xTrack,yTrack));
mlpLedTempoDisplay=new LedDisplay(*this,Point(xTempo,yTempo));
mlpLedTempoDisplay->setNumber(getTempo());
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType MUSDlg::destroyHandler(CallbackData &/*someCallbackData*/)
{
mOwnerDraw.freeBitmap(MUS_TEMPOBUTTONUP);
mOwnerDraw.freeBitmap(MUS_TEMPOBUTTONDN);
mOwnerDraw.freeBitmap(MUS_CVTBUTTON);
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType MUSDlg::closeHandler(CallbackData &/*someCallbackData*/)
{
destroy();
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType MUSDlg::controlColorHandler(CallbackData &someCallbackData)
{
::SetBkColor((HDC)someCallbackData.wParam(),RGB(btnRed,btnGreen,btnBlue));
return (CallbackData::ReturnType)mhGrayBrush;
}
CallbackData::ReturnType MUSDlg::drawItemHandler(CallbackData &someCallbackData)
{
if(MUS_TEMPOBUTTONUP==((LPDRAWITEMSTRUCT)someCallbackData.lParam())->CtlID)
mOwnerDraw.handleOwnerButton(MUS_TEMPOBUTTONUP,someCallbackData.lParam());
else if(MUS_TEMPOBUTTONDN==((LPDRAWITEMSTRUCT)someCallbackData.lParam())->CtlID)
mOwnerDraw.handleOwnerButton(MUS_TEMPOBUTTONDN,someCallbackData.lParam());
else if(MUS_CVTBUTTON==((LPDRAWITEMSTRUCT)someCallbackData.lParam())->CtlID)
mOwnerDraw.handleOwnerButton(MUS_CVTBUTTON,someCallbackData.lParam());
return (CallbackData::ReturnType)FALSE;
}
CallbackData::ReturnType MUSDlg::paintHandler(CallbackData &someCallbackData)
{
RECT windowRect;
PaintInformation *lpPaintInformation((PaintInformation*)someCallbackData.lParam());
::SetRect(&windowRect,0,0,mLinkedBitmap.width(),mLinkedBitmap.height()+CaptionHeight);
mLinkedBitmap.drawBitmap((PureDevice)(*lpPaintInformation),windowRect);
if(mlpLedTrackDisplay)mlpLedTrackDisplay->paint();
if(mlpLedTempoDisplay)mlpLedTempoDisplay->paint();
return (CallbackData::ReturnType)0;
}
void MUSDlg::yieldTask(void)const
{
MSG msg;
while(::IsWindow((HWND)*this)&&::PeekMessage(&msg,0,0,0,PM_REMOVE))
{
if(WM_PAINT==msg.message||isComponentWnd(msg.hwnd))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
}
WORD MUSDlg::isComponentWnd(HWND hWnd)const
{
if(!::IsWindow(hWnd)||!::IsWindow((HWND)*this))return FALSE;
if(hWnd==(HWND)*this)return TRUE;
if(mhButtonUpWnd==hWnd)return TRUE;
if(mhButtonDnWnd==hWnd)return TRUE;
if(mhButtonCvtWnd==hWnd)return TRUE;
if(mhListBoxWnd==hWnd)return TRUE;
if(mhStaticWnd==hWnd)return TRUE;
return FALSE;
}
WORD MUSDlg::handleScoreStart(void)
{
return MUSConverter::handleScoreStart();
}
WORD MUSDlg::handleReleaseNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &releaseNote,BYTE trackNumber)
{
if(trackNumber!=mlpLedTrackDisplay->getNumber())
mlpLedTrackDisplay->setNumber(trackNumber);
return MUSConverter::handleReleaseNote(pureEvent,pureDelay,releaseNote,trackNumber);
}
WORD MUSDlg::handlePlayNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &playNote,BYTE trackNumber)
{
if(trackNumber!=mlpLedTrackDisplay->getNumber())
mlpLedTrackDisplay->setNumber(trackNumber);
return MUSConverter::handlePlayNote(pureEvent,pureDelay,playNote,trackNumber);
}
WORD MUSDlg::handlePitchBend(PureEvent &pureEvent,PureDelay &pureDelay,BYTE pitchBenderValue,BYTE trackNumber)
{
if(trackNumber!=mlpLedTrackDisplay->getNumber())
mlpLedTrackDisplay->setNumber(trackNumber);
return MUSConverter::handlePitchBend(pureEvent,pureDelay,pitchBenderValue,trackNumber);
}
WORD MUSDlg::handleReset(PureEvent &pureEvent,PureDelay &pureDelay,BYTE tempoValue,BYTE trackNumber)
{
if(trackNumber!=mlpLedTrackDisplay->getNumber())
mlpLedTrackDisplay->setNumber(trackNumber);
return MUSConverter::handleReset(pureEvent,pureDelay,tempoValue,trackNumber);
}
WORD MUSDlg::handleController(PureEvent &pureEvent,PureDelay &pureDelay,PureController &pureController,BYTE trackNumber)
{
if(trackNumber!=mlpLedTrackDisplay->getNumber())
mlpLedTrackDisplay->setNumber(trackNumber);
return MUSConverter::handleController(pureEvent,pureDelay,pureController,trackNumber);
}
WORD MUSDlg::handleScoreEnd(PureDelay &pureDelay)
{
return MUSConverter::handleScoreEnd(pureDelay);
}

79
midiwrt/MUSDLG.HPP Normal file
View File

@@ -0,0 +1,79 @@
#ifndef _MUSDIALOG_HPP_
#define _MUSDIALOG_HPP_
#include <common/window.hpp>
#include <common/dwindow.hpp>
#include <common/string.hpp>
#include <common/owner.hpp>
#include <common/bitmap.hpp>
#include <midiwrt/muscnv.hpp>
#include <midiwrt/led.hpp>
class MUSDlg : public Window, private MUSConverter
{
public:
MUSDlg(Window &parentWindow,String midiPathFileName,String musPathFileName);
MUSDlg(DWindow &parentWindow,String midiPathFileName,String musPathFileName);
~MUSDlg();
WORD performDialog(void);
protected:
WORD virtual handleScoreStart(void);
WORD virtual handleReleaseNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &releaseNote,BYTE trackNumber);
WORD virtual handlePlayNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &playNote,BYTE trackNumber);
WORD virtual handlePitchBend(PureEvent &pureEvent,PureDelay &pureDelay,BYTE pitchBenderValue,BYTE trackNumber);
WORD virtual handleReset(PureEvent &pureEvent,PureDelay &pureDelay,BYTE tempoValue,BYTE trackNumber);
WORD virtual handleController(PureEvent &pureEvent,PureDelay &pureDelay,PureController &pureController,BYTE trackNumber);
WORD virtual handleScoreEnd(PureDelay &pureDelay);
private:
enum{xTrack=35,yTrack=40,xTempo=98,yTempo=40};
enum{btnRed=192,btnGreen=192,btnBlue=192};
enum{CaptionHeight=20,StartOrdinal=5020,EndOrdinal=5194};
CallbackData::ReturnType commandHandler(CallbackData &someCallbackData);
CallbackData::ReturnType createHandler(CallbackData &someCallbackData);
CallbackData::ReturnType drawItemHandler(CallbackData &someCallbackData);
CallbackData::ReturnType paintHandler(CallbackData &someCallbackData);
CallbackData::ReturnType destroyHandler(CallbackData &someCallbackData);
CallbackData::ReturnType closeHandler(CallbackData &someCallbackData);
CallbackData::ReturnType controlColorHandler(CallbackData &someCallbackData);
void registerClass(void)const;
void insertHandlers(void);
void removeHandlers(void);
void createDialogControls(void);
void handleTempoDnEvent(void);
void handleTempoUpEvent(void);
void handleConvertFileEvent(void);
void loadInstruments(void);
void setMessage(String messageString)const;
void yieldTask(void)const;
WORD isComponentWnd(HWND hWnd)const;
Callback<MUSDlg> mCommandHandler;
Callback<MUSDlg> mCreateHandler;
Callback<MUSDlg> mDrawItemHandler;
Callback<MUSDlg> mPaintHandler;
Callback<MUSDlg> mDestroyHandler;
Callback<MUSDlg> mCloseHandler;
Callback<MUSDlg> mControlColorHandler;
OwnerDraw mOwnerDraw;
LedDisplay *mlpLedTrackDisplay;
LedDisplay *mlpLedTempoDisplay;
LinkedBitmap mLinkedBitmap;
HWND mhButtonUpWnd;
HWND mhButtonDnWnd;
HWND mhButtonCvtWnd;
HWND mhListBoxWnd;
HWND mhStaticWnd;
HWND mhParentWnd;
HBRUSH mhGrayBrush;
String mOutputPathFileName;
HINSTANCE mhInstance;
static char szClassName[];
static char szMenuName[];
};
inline
void MUSDlg::setMessage(String messageString)const
{
::SendMessage(mhStaticWnd,WM_SETTEXT,0,(LPARAM)(LPSTR)messageString);
}
#endif

131
midiwrt/MUSFILE.CPP Normal file
View File

@@ -0,0 +1,131 @@
#include <iostream.h>
#include <iomanip.h>
#include <stdio.h>
#include <midiwrt/musfile.hpp>
MUSFile::MUSFile(String musPathFileName)
: mMusFile(musPathFileName), mlpMUSInstruments(0), mhGlobalMUSInstruments(0),
mIsOkay(FALSE), mPitchBenderValue(0), mTempoValue(0)
{
String musIDString("MUS");
if(!mMusFile.isOkay())return;
if(!readHeader(mMusFile))return;
if(!(musIDString==headerID()))return;
if(!instruments())return;
mhGlobalMUSInstruments=::GlobalAlloc(GMEM_FIXED,instruments()*sizeof(WORD));
mlpMUSInstruments=(WORD FAR *)::GlobalLock(mhGlobalMUSInstruments);
for(int index=0;index<instruments();index++)mMusFile.read(*(mlpMUSInstruments+index));
mIsOkay=TRUE;
}
MUSFile::~MUSFile()
{
if(mlpMUSInstruments)
{
while(::GlobalUnlock(mhGlobalMUSInstruments));
::GlobalFree(mhGlobalMUSInstruments);
mlpMUSInstruments=0;
mhGlobalMUSInstruments=0;
}
}
WORD MUSFile::readMUSFile(void)
{
BYTE eventDescriptor;
BYTE trackNumber;
WORD isRunning(TRUE);
WORD returnCode(FALSE);
PureEvent pureEvent;
PureDelay pureDelay;
if(!isOkay())return FALSE;
mChannelNotes.size(MaxChannel);
for(trackNumber=0;trackNumber<=MaxTracks;trackNumber++)
{
isRunning=TRUE;
pureDelay.resetDelay();
if(!handleScoreStart())return FALSE;
if(!mMusFile.seek(scoreStart(),FileIO::SeekBeginning))return FALSE;
while(isRunning)
{
if(!mMusFile.read(eventDescriptor)){isRunning=FALSE;break;}
pureEvent.setEvent(eventDescriptor);
switch(pureEvent.eventType())
{
case PureEvent::ReleaseNote :
mChannelNotes[pureEvent.channel()].readNote(mMusFile);
if(pureEvent.channel()==trackNumber)
handleReleaseNote(pureEvent,pureDelay,mChannelNotes[pureEvent.channel()],trackNumber);
break;
case PureEvent::PlayNote :
mChannelNotes[pureEvent.channel()].readNote(mMusFile);
if(pureEvent.channel()==trackNumber)
handlePlayNote(pureEvent,pureDelay,mChannelNotes[pureEvent.channel()],trackNumber);
break;
case PureEvent::PitchWheel :
mMusFile.read(mPitchBenderValue);
if(pureEvent.channel()==trackNumber)
handlePitchBend(pureEvent,pureDelay,mPitchBenderValue,trackNumber);
break;
case PureEvent::Tempo :
mMusFile.read(mTempoValue);
if(pureEvent.channel()==trackNumber)
handleReset(pureEvent,pureDelay,mTempoValue,trackNumber);
break;
case PureEvent::ChangeController :
mPureController.readController(mMusFile);
if(pureEvent.channel()==trackNumber)
handleController(pureEvent,pureDelay,mPureController,trackNumber);
break;
case PureEvent::UnknownOne :
break;
case PureEvent::ScoreEnd :
isRunning=FALSE;
returnCode=TRUE;
handleScoreEnd(pureDelay);
break;
case PureEvent::UnknownTwo :
break;
}
if(pureEvent.hasTimeInfo())pureDelay.readDelay(mMusFile);
}
}
return returnCode;
}
WORD MUSFile::handleScoreStart(void)
{
return FALSE;
}
WORD MUSFile::handleReleaseNote(PureEvent &/*pureEvent*/,PureDelay &/*pureDelay*/,PureNote &/*releaseNote*/,BYTE /*trackNumber*/)
{
return FALSE;
}
WORD MUSFile::handlePlayNote(PureEvent &/*pureEvent*/,PureDelay &/*pureDelay*/,PureNote &/*playNote*/,BYTE /*trackNumber*/)
{
return FALSE;
}
WORD MUSFile::handlePitchBend(PureEvent &/*pureEvent*/,PureDelay &/*pureDelay*/,BYTE /*pitchBenderValue*/,BYTE /*trackNumber*/)
{
return FALSE;
}
WORD MUSFile::handleReset(PureEvent &/*pureEvent*/,PureDelay &/*pureDelay*/,BYTE /*tempoValue*/,BYTE /*trackNumber*/)
{
return FALSE;
}
WORD MUSFile::handleController(PureEvent &/*pureEvent*/,PureDelay &/*pureDelay*/,PureController &/*pureController*/,BYTE /*trackNumber*/)
{
return FALSE;
}
WORD MUSFile::handleScoreEnd(PureDelay &/*pureDelay*/)
{
return FALSE;
}

46
midiwrt/MUSFILE.HPP Normal file
View File

@@ -0,0 +1,46 @@
#ifndef _MUSFILE_HPP_
#define _MUSFILE_HPP_
#include <stdio.h>
#include <common/string.hpp>
#include <common/block.hpp>
#include <common/pvector.hpp>
#include <common/fileio.hpp>
#include <midiwrt/mushdr.hpp>
#include <midiwrt/purecntl.hpp>
#include <midiwrt/purenote.hpp>
#include <midiwrt/puredly.hpp>
#include <midiwrt/pureevnt.hpp>
class MUSFile : public MUSHeader
{
public:
MUSFile(String musPathFileName);
~MUSFile();
WORD readMUSFile(void);
WORD isOkay(void)const;
protected:
virtual WORD handleScoreStart(void);
virtual WORD handleReleaseNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &releaseNote,BYTE trackNumber);
virtual WORD handlePlayNote(PureEvent &pureEvent,PureDelay &pureDelay,PureNote &playNote,BYTE trackNumber);
virtual WORD handlePitchBend(PureEvent &pureEvent,PureDelay &pureDelay,BYTE pitchBenderValue,BYTE trackNumber);
virtual WORD handleReset(PureEvent &pureEvent,PureDelay &pureDelay,BYTE tempoValue,BYTE trackNumber);
virtual WORD handleController(PureEvent &pureEvent,PureDelay &pureDelay,PureController &pureController,BYTE trackNumber);
virtual WORD handleScoreEnd(PureDelay &pureDelay);
private:
enum{MaxTracks=15,MaxChannel=16};
WORD FAR *mlpMUSInstruments;
HGLOBAL mhGlobalMUSInstruments;
WORD mIsOkay;
PureVector<PureNote> mChannelNotes;
PureController mPureController;
BYTE mPitchBenderValue;
BYTE mTempoValue;
FileIO mMusFile;
};
inline
WORD MUSFile::isOkay(void)const
{
return mIsOkay;
}
#endif

12
midiwrt/MUSHDR.CPP Normal file
View File

@@ -0,0 +1,12 @@
#include <midiwrt/mushdr.hpp>
String MUSHeader::headerID(void)const
{
String headerIDString;
headerIDString.reserve(sizeof(mID));
::memset(headerIDString,0,sizeof(mID));
::memcpy(headerIDString,mID,sizeof(mID)-1);
return headerIDString;
}

72
midiwrt/MUSHDR.HPP Normal file
View File

@@ -0,0 +1,72 @@
#ifndef _MUSHEADER_HPP_
#define _MUSHEADER_HPP_
#include <string.h>
#include <common/windows.hpp>
#include <common/fileio.hpp>
#include <common/string.hpp>
class MUSHeader
{
public:
MUSHeader(void);
~MUSHeader();
WORD readHeader(FileIO &musFileIO);
String headerID(void)const;
WORD scoreLength(void)const;
WORD scoreStart(void)const;
WORD channels(void)const;
WORD instruments(void)const;
private:
enum {MaxIDLength=4};
char mID[MaxIDLength];
WORD mScoreLength;
WORD mScoreStart;
WORD mChannels;
WORD mDummyOne;
WORD mInstruments;
WORD mDummyTwo;
};
inline
MUSHeader::MUSHeader(void)
{
::memset(this,0,sizeof(*this));
}
inline
MUSHeader::~MUSHeader()
{
}
inline
WORD MUSHeader::readHeader(FileIO &musFileIO)
{
if(!musFileIO.read((char*)this,sizeof(*this)))return FALSE;
return TRUE;
}
inline
WORD MUSHeader::scoreLength(void)const
{
return mScoreLength;
}
inline
WORD MUSHeader::scoreStart(void)const
{
return mScoreStart;
}
inline
WORD MUSHeader::channels(void)const
{
return mChannels;
}
inline
WORD MUSHeader::instruments(void)const
{
return mInstruments;
}
#endif

BIN
midiwrt/OPENDN.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

BIN
midiwrt/OPENUP.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

57
midiwrt/PURECNTL.HPP Normal file
View File

@@ -0,0 +1,57 @@
#ifndef _PURECONTROLLER_HPP_
#define _PURECONTROLLER_HPP_
#include <common/windows.hpp>
#include <common/fileio.hpp>
class PureController
{
public:
PureController(void);
~PureController();
WORD readController(FileIO &musFile);
BYTE controllerNumber(void)const;
BYTE controllerValue(void)const;
private:
void operator=(const PureController &somePureController);
BYTE mControllerNumber;
BYTE mControllerValue;
};
inline
PureController::PureController(void)
: mControllerNumber(0), mControllerValue(0)
{
}
inline
PureController::~PureController()
{
}
inline
BYTE PureController::controllerNumber(void)const
{
return mControllerNumber;
}
inline
BYTE PureController::controllerValue(void)const
{
return mControllerValue;
}
inline
WORD PureController::readController(FileIO &musFile)
{
if(!musFile.isOkay())return FALSE;
if(!musFile.read(mControllerNumber))return FALSE;
if(!musFile.read(mControllerValue))return FALSE;
return TRUE;
}
inline
void PureController::operator=(const PureController &/*somePureController*/)
{
return;
}
#endif

18
midiwrt/PUREDLY.CPP Normal file
View File

@@ -0,0 +1,18 @@
#include <midiwrt/puredly.hpp>
DWORD PureDelay::readDelay(FileIO &musFile)
{
BYTE valueByte;
mCurrentTimeDelay=0L;
while(TRUE)
{
if(!musFile.read(valueByte))return 0L;
mCurrentTimeDelay=(mCurrentTimeDelay*128)+(valueByte&127);
if(!(valueByte&128))break;
}
mDeltaTicks+=mCurrentTimeDelay;
return mCurrentTimeDelay;
}

49
midiwrt/PUREDLY.HPP Normal file
View File

@@ -0,0 +1,49 @@
#ifndef _PUREDELAY_HPP_
#define _PUREDELAY_HPP_
#include <common/windows.hpp>
#include <common/fileio.hpp>
class PureDelay
{
public:
PureDelay(void);
~PureDelay();
DWORD readDelay(FileIO &musFile);
DWORD currentTimeDelay(void)const;
DWORD deltaTicks(void)const;
void resetDelay(void);
private:
DWORD mCurrentTimeDelay;
DWORD mDeltaTicks;
};
inline
PureDelay::PureDelay(void)
: mCurrentTimeDelay(0L), mDeltaTicks(0L)
{
}
inline
PureDelay::~PureDelay()
{
}
inline
DWORD PureDelay::currentTimeDelay(void)const
{
return mCurrentTimeDelay;
}
inline
DWORD PureDelay::deltaTicks(void)const
{
return mDeltaTicks;
}
inline
void PureDelay::resetDelay(void)
{
mCurrentTimeDelay=0;
mDeltaTicks=0;
}
#endif

72
midiwrt/PUREEVNT.HPP Normal file
View File

@@ -0,0 +1,72 @@
#ifndef _PUREVENT_HPP_
#define _PUREVENT_HPP_
#include <common/windows.hpp>
class PureEvent
{
public:
enum EventType{ReleaseNote=0x00,PlayNote=0x01,PitchWheel=0x02,Tempo=0x03,
ChangeController=0x04,UnknownOne=0x05,ScoreEnd=0x06,UnknownTwo=0x07};
PureEvent(void);
PureEvent(BYTE eventByte);
~PureEvent();
void setEvent(BYTE eventByte);
EventType eventType(void)const;
BYTE hasTimeInfo(void)const;
WORD channel(void)const;
void channel(WORD channel);
private:
EventType mEventType;
BYTE mHasTimeInfo;
WORD mChannel;
};
inline
PureEvent::PureEvent(void)
{
setEvent(0);
}
inline
PureEvent::PureEvent(BYTE eventByte)
{
setEvent(eventByte);
}
inline
PureEvent::~PureEvent()
{
}
inline
void PureEvent::setEvent(BYTE eventByte)
{
mHasTimeInfo=(eventByte>>7);
mEventType=(EventType)((eventByte>>4)&0x07);
mChannel=eventByte&0x0F;
}
inline
PureEvent::EventType PureEvent::eventType(void)const
{
return mEventType;
}
inline
BYTE PureEvent::hasTimeInfo(void)const
{
return mHasTimeInfo;
}
inline
WORD PureEvent::channel(void)const
{
return mChannel;
}
inline
void PureEvent::channel(WORD channel)
{
mChannel=channel;
}
#endif

104
midiwrt/PUREINST.HPP Normal file
View File

@@ -0,0 +1,104 @@
#ifndef _PUREINSTRUMENT_HPP_
#define _PUREINSTRUMENT_HPP_
#include <common/windows.hpp>
#include <common/string.hpp>
class PureInstrument
{
public:
PureInstrument(void);
PureInstrument(const PureInstrument &somePureInstrument);
PureInstrument(WORD ordinal,String category,String name);
~PureInstrument();
WORD operator==(const PureInstrument &somePureInstrument)const;
PureInstrument &operator=(const PureInstrument &somePureInstrument);
WORD ordinal(void)const;
String category(void)const;
String name(void)const;
void ordinal(WORD ordinal);
void category(String category);
void name(String name);
private:
enum {Semicolon=';'};
WORD mOrdinal;
String mCategory;
String mName;
};
inline
PureInstrument::PureInstrument(void)
: mOrdinal(0)
{
}
inline
PureInstrument::PureInstrument(const PureInstrument &somePureInstrument)
: mOrdinal(somePureInstrument.mOrdinal), mCategory(somePureInstrument.mCategory),
mName(somePureInstrument.mName)
{
}
inline
PureInstrument::PureInstrument(WORD ordinal,String category,String name)
: mOrdinal(ordinal), mCategory(category), mName(name)
{
}
inline
PureInstrument::~PureInstrument()
{
}
inline
WORD PureInstrument::ordinal(void)const
{
return mOrdinal;
}
inline
String PureInstrument::category(void)const
{
return mCategory;
}
inline
String PureInstrument::name(void)const
{
return mName;
}
inline
void PureInstrument::ordinal(WORD ordinal)
{
mOrdinal=ordinal;
}
inline
void PureInstrument::category(String category)
{
mCategory=category;
}
inline
void PureInstrument::name(String name)
{
mName=name;
}
inline
WORD PureInstrument::operator==(const PureInstrument &somePureInstrument)const
{
return (mOrdinal==somePureInstrument.mOrdinal&&
mCategory==somePureInstrument.mCategory&&
mName==somePureInstrument.mName);
}
inline
PureInstrument &PureInstrument::operator=(const PureInstrument &somePureInstrument)
{
mOrdinal=somePureInstrument.mOrdinal;
mCategory=somePureInstrument.mCategory;
mName=somePureInstrument.mName;
return *this;
}
#endif

14
midiwrt/PURENOTE.CPP Normal file
View File

@@ -0,0 +1,14 @@
#include <midiwrt/purenote.hpp>
WORD PureNote::readNote(FileIO &musFile)
{
BYTE byteValue;
if(!musFile.read(byteValue))return FALSE;
mNoteNumber=(byteValue&0x7F);
if(!(mHasVolume=(byteValue&0x80)))return TRUE;;
if(!musFile.read(byteValue))return FALSE;
mNoteVolume=(byteValue&0x7F);
return TRUE;
}

77
midiwrt/PURENOTE.HPP Normal file
View File

@@ -0,0 +1,77 @@
#ifndef _PURENOTE_HPP_
#define _PURENOTE_HPP_
#include <common/windows.hpp>
#include <common/fileio.hpp>
class PureNote
{
public:
enum{DataLength=2};
PureNote(void);
PureNote(const PureNote &somePureNote);
~PureNote();
PureNote &operator=(const PureNote &somePureNote);
WORD operator==(const PureNote &somePureNote);
WORD readNote(FileIO &musFile);
BYTE noteNumber(void)const;
BYTE noteVolume(void)const;
BYTE hasVolume(void)const;
private:
BYTE mNoteNumber;
BYTE mNoteVolume;
BYTE mHasVolume;
};
inline
PureNote::PureNote(const PureNote &somePureNote)
: mNoteNumber(somePureNote.mNoteNumber), mNoteVolume(somePureNote.mNoteVolume),
mHasVolume(somePureNote.mHasVolume)
{
}
inline
PureNote &PureNote::operator=(const PureNote &somePureNote)
{
mNoteNumber=somePureNote.mNoteNumber;
mNoteVolume=somePureNote.mNoteVolume;
mHasVolume=somePureNote.mHasVolume;
return *this;
}
inline
PureNote::PureNote(void)
: mNoteNumber(0), mNoteVolume(0), mHasVolume(0)
{
}
inline
PureNote::~PureNote()
{
}
inline
BYTE PureNote::noteNumber(void)const
{
return mNoteNumber;
}
inline
BYTE PureNote::noteVolume(void)const
{
return mNoteVolume;
}
inline
BYTE PureNote::hasVolume(void)const
{
return mHasVolume;
}
inline
WORD PureNote::operator==(const PureNote &somePureNote)
{
return (mNoteNumber==somePureNote.mNoteNumber&&
mNoteVolume==somePureNote.mNoteVolume&&
mHasVolume==somePureNote.mHasVolume);
}
#endif

BIN
midiwrt/SELDN.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

BIN
midiwrt/SELUP.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

20
midiwrt/STDTMPL.CPP Normal file
View File

@@ -0,0 +1,20 @@
#define _EXPAND_BLOCK_TEMPLATES_
#define _EXPAND_VECTOR_TEMPLATES_
#include <common/block.hpp>
#include <common/block.tpp>
#include <common/callback.hpp>
#include <common/callback.tpp>
#include <common/pvector.hpp>
#include <common/pvector.tpp>
#include <common/bmplnk.hpp>
#include <midiwrt/purenote.hpp>
#include <midiwrt/musdlg.hpp>
#include <midiwrt/pureinst.hpp>
typedef Callback<MUSDlg> a;
typedef Block<CallbackPointer> b;
typedef Block<LinkedBitmap> c;
typedef Block<LinkedBitmap> d;
typedef PureVector<PureInstrument> e;
typedef PureVector<PureNote> f;

BIN
midiwrt/TDW.TRW Normal file

Binary file not shown.

BIN
midiwrt/UPARDN.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

BIN
midiwrt/UPARUP.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

BIN
midiwrt/WND.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB