00001
00023
00024
00025
00026
00027
00028 #ifndef DEVMIDF_H
00029 #define DEVMIDF_H
00030
00031 #include <fstream>
00032
00033 #include "Device.h"
00034
00035 #ifdef WX
00036 #include "mhArray.h"
00037 WX_DEFINE_ARRAY_INT(BYTE, TBYTEBase1);
00038 DEF_MHARRAY(BYTE, TByteArray, TBYTEBase1);
00039 #else
00040 #include <classlib/arrays.h>
00041 typedef TArray<BYTE> TByteArray;
00042 #endif
00043
00044
00045
00046 class Track
00047 {
00048
00049 public:
00050 DWORD Time;
00051 TByteArray *Data;
00052 Track()
00053 {
00054 Time = 0;
00055 Data = new TByteArray(100, 0, 100);
00056 }
00057
00058 ~Track()
00059 {
00060 delete Data;
00061 }
00062
00063 void WriteDelta();
00064 void MidiOut3(BYTE c1, BYTE c2, BYTE c3)
00065 {
00066 WriteDelta();
00067 Data->Add(c1);
00068 Data->Add(c2);
00069 Data->Add(c3);
00070 }
00071
00072 void MidiOut2(BYTE c1, BYTE c2)
00073 {
00074 WriteDelta();
00075 Data->Add(c1);
00076 Data->Add(c2);
00077 }
00078
00079 void Save(mutOFstream &os);
00080 void Add(BYTE c)
00081 {
00082 Data->Add(c);
00083 }
00084 };
00085
00086 typedef struct TAK1
00087 {
00088 int taste;
00089 int key;
00090 int fine;
00091 DWORD id;
00092
00093 } TonAufKanal1;
00094
00095
00096
00097 class OutMidiFile : public OutDevice
00098 {
00099 int bending_range;
00100 public:
00101
00102 OutMidiFile(): OutDevice(), bending_range (2) {}
00103
00104 OutMidiFile(const wxString &name, int devId, int bendingRange = 2)
00105 : OutDevice(devId, name)
00106 {
00107 bending_range = bendingRange;
00108 }
00109
00110 virtual ~OutMidiFile()
00111 {};
00112
00114
00116 virtual void Save (tree_storage & config);
00117
00119
00124 virtual void Save (tree_storage & config, const Route * route);
00125
00126
00128
00130 virtual void Load (tree_storage & config);
00131
00133
00138 virtual void Load (tree_storage & config, Route * route);
00139
00140
00141 virtual bool Open();
00142 virtual void Close();
00143 virtual void NoteOn(int box, int taste, int velo, Route *r, int channel, ChannelData *cd);
00144 virtual void NoteOff(int box, int taste, int velo, Route *r, int channel);
00145 virtual void NotesCorrect(int box);
00146 virtual void Sustain(char on, int channel);
00147 virtual int GetChannel(int taste)
00148 {
00149 return -1;
00150 }
00151
00152 virtual void Gis(GisToken *token, char turn)
00153 {};
00154
00155 virtual void AddTime(frac time)
00156 {};
00157
00158 virtual void MidiOut(DWORD data, char n);
00159 virtual void MidiOut(BYTE *p, char n);
00160 virtual void Quite(Route *r);
00161
00162 void SetBendingRange(const int i)
00163 {
00164 bending_range = i;
00165 }
00166
00167 int GetBendingRange () const
00168 {
00169 return bending_range;
00170 }
00171
00172 virtual DevType GetType() const
00173 {
00174 return DTMidiFile;
00175 }
00176
00177
00178 virtual int GetMaxChannel() const { return 15; }
00179 virtual int GetMinChannel() const { return 0; }
00180
00181 virtual mutString GetTypeName () const {
00182 return _("MIDI output file");
00183 }
00184
00185 #ifdef WX
00186 virtual wxString TowxString() const {
00187 wxString s = OutDevice::TowxString() +
00188 wxString::Format(_T("\n Name = %s\n DevId = %d\n Bending Range = %d\n nKeyOn"),
00189 Name.c_str(), DevId, bending_range, nKeyOn);
00190 s.Printf(_T("\n KeyDir = [ %d"), KeyDir[0]);
00191 for (int i = 1; i<16; i++)
00192 s.Printf(_T(", %d"),KeyDir[i]);
00193 s.Printf(_T("]\n ton_auf_kanal = [ t=%d,k=%d,f=%d"),
00194 ton_auf_kanal[0].taste,
00195 ton_auf_kanal[0].key,
00196 ton_auf_kanal[0].fine);
00197 for (int i = 1; i<16; i++)
00198 s.Printf(_T("; t=%d,k=%d,f=%d"),
00199 ton_auf_kanal[i].taste,
00200 ton_auf_kanal[i].key,
00201 ton_auf_kanal[i].fine);
00202 s+=_T("]");
00203 return s;
00204 }
00205 #endif
00206 virtual void ReadData(wxConfigBase * config);
00207 virtual void WriteData(wxConfigBase * config);
00208
00209 protected:
00210
00211 Track Tracks;
00212 ChannelData Cd[16];
00213 char KeyDir[16];
00214 TonAufKanal1 ton_auf_kanal[16];
00215 int nKeyOn;
00216 };
00217
00218
00219
00220
00221
00222 class InMidiFile : public InDevice
00223 {
00224
00225 class MidiTimer : public wxTimer
00226 {
00227 InMidiFile * file;
00228
00229 public:
00230 MidiTimer(InMidiFile * f) : wxTimer(),file(f)
00231 {}
00232
00233 void Notify()
00234 {
00235 file->IncDelta();
00236 }
00237 };
00238
00239 MidiTimer timer;
00240 public:
00241
00242 InMidiFile(): InDevice(),timer (this),Track(NULL), TrackPos(NULL),curDelta(NULL),StatusByte(NULL) { }
00243
00244 InMidiFile(wxString name, int devId): InDevice(devId, name),timer(this),Track(NULL),TrackPos(NULL),curDelta(NULL),StatusByte(NULL) {}
00245
00246 virtual ~InMidiFile()
00247 {};
00248
00250
00252 virtual void Save (tree_storage & config);
00253
00255
00260 virtual void Save (tree_storage & config, const Route * route);
00261
00262
00264
00266 virtual void Load (tree_storage & config);
00267
00269
00274 virtual void Load (tree_storage & config, Route * route);
00275
00276
00277 virtual bool Open();
00278 virtual void Close();
00279 virtual void Stop();
00280 virtual void Play();
00281 virtual void Pause();
00282
00283
00284 virtual frac ReadOn(frac time)
00285 {
00286 return frac(0, 1);
00287 }
00288
00289 virtual DevType GetType() const
00290 {
00291 return DTMidiFile;
00292 }
00293
00294
00295 void IncDelta();
00296
00297 virtual int GetMaxChannel() const { return 15; }
00298 virtual int GetMinChannel() const { return 0; }
00299 virtual int GetMaxTrack() const { return 0xFFFF; }
00300 virtual int GetMinTrack() const { return 0; }
00301
00302 virtual mutString GetTypeName () const {
00303 return _("MIDI input file");
00304 }
00305
00306 #ifdef WX
00307 virtual wxString TowxString() const {
00308 return InDevice::TowxString() +
00309 wxString::Format(_T("\n FileType = %d\n nTrack = %d\n Speed = %d\n TrackPos = %d\n curDelta = %ld"
00310 "\n minDelta = %ld\n actDelta = %ld\n StatusByte = %x\n Busy = %d"
00311 "\n TicksPerQuater = %d\n MMSPerQuater = %ld"),
00312 FileType, nTrack, Speed, (Track?(*Track?**Track:-1):-2),
00313 (TrackPos?*TrackPos:-1), (curDelta?*curDelta:-1),
00314 minDelta, actDelta, (StatusByte?*StatusByte:-1), Busy, TicksPerQuater, MMSPerQuater);
00315 }
00316 #endif
00317 protected:
00318 BYTE FileType;
00319 size_t nTrack;
00320 int Speed;
00321 BYTE **Track;
00322 DWORD *TrackPos;
00323 long *curDelta;
00324 long minDelta;
00325 long actDelta;
00326 BYTE *StatusByte;
00327 ChannelData Cd[16];
00328
00329 BOOL Busy;
00330 DWORD TicksPerQuater;
00331 long MMSPerQuater;
00332 void Proceed(DWORD midiCode, int track);
00333 void ProceedRoute(DWORD midiCode, Route *route);
00334 long ReadMidiProceed(size_t nr, long time);
00335 };
00336
00337
00338
00339
00340 #endif
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407