GIS_Head.h
gehe zur Dokumentation dieser Datei
00001 //     -*- C++ -*-
00028 // #################################################################
00029 // header file for read header for GIS (GMN Intern Structur)
00030 // ##################################################################
00031 
00032 #ifndef GIS_HEAD_H
00033 #define GIS_HEAD_H
00034 
00035 #include "GIS.h"
00036 #include "stdint.h"
00037 
00038 // arcticulation modes
00039 enum ARType { ARNormal, ARSlur, ARTenuto, ARPortato, ARStaccatto };
00040 
00041 // GisReadHead ------------------------------------------------------
00042 
00043 class GisReadHead
00044 {
00045 
00046 public:
00047         GisReadHead *Next, **PrevPtr, *Prev; // double chained, first Prev points to its own adress
00048         GisReadHead *Boss;
00049         int nSub;
00050         GisToken *Cursor;
00051         frac Time;
00052         mutString Id;
00053         char Turn;
00054         bool SingleToken; // proceed only one token (in accords)
00055 
00056         GisReadHead(GisReadHead *boss, GisToken *cursor, const mutString &id, bool singleToken = false)
00057         {
00058                 PrevPtr = &Prev;
00059                 DEBUGLOG(other,_T("boss = %p"),boss);
00060                 Next = Prev = NULL;
00061                 Cursor = cursor;
00062                 mutCopyString(Id,id);
00063                 InsertInfrontOf(boss);
00064                 Boss = boss;
00065                 nSub = -1;
00066                 Time = frac(0, 1);
00067                 SingleToken = singleToken;
00068         }
00069 
00070         virtual ~GisReadHead()
00071 
00072         {
00073                 mutFreeString(Id);
00074 
00075                 if ( Next ) delete Next; // only the following will be deleted
00076         }
00077 
00078         virtual GisReadHead *Build(GisReadHead *boss, GisToken *cursor, const mutString &id, bool singleToken = false)
00079         {
00080                 return new GisReadHead(boss, cursor, id, singleToken);
00081         }
00082 
00083         GisReadHead *InsertInfrontOf(GisReadHead *position);
00084 
00085         GisReadHead *CutOut();
00086         GisToken *CursorNext() // move Cursor, care for single token mode
00087         {
00088                 Turn = 0;
00089 
00090                 if ( !Cursor )
00091                         return 0;
00092 
00093                 if ( SingleToken && Cursor->Type() == GTComma)
00094                         Cursor = 0;
00095                 else
00096                         Cursor = Cursor->Next;
00097 
00098                 return Cursor;
00099         }
00100         void CreateSegmentSubs();
00101         void CreateSequenzSubs();
00102         void Read();
00103 #ifdef WX
00104         operator wxString()
00105         {
00106                 if (Next)
00107                         return ToString() + (wxString) (*Next) ;
00108                 else
00109                         return ToString();
00110         }
00111 
00112         virtual wxString ToString();
00113 #endif
00114 
00115 };
00116 
00117 typedef void GisReadProceed(GisReadHead*, char) ;
00118 
00119 extern GisReadProceed GisReadDummy;
00120 
00121 frac GisReadHeadOn(GisReadHead **Head, frac dTime = frac(0, 1), GisReadProceed *proceed = GisReadDummy);
00122 
00123 // TagList ----------------------------------------------------------
00124 
00125 typedef struct TagListData
00126 {
00127 
00128         struct TagListData *Next;
00129         GisTag *Tag;
00130         union data
00131         {
00132                 char ch;
00133                 int i;
00134         } Data;
00135 }
00136 
00137 TagList;
00138 
00139 TagList *Copy(TagList *tag);
00140 void Erase(TagList *tag);
00141 
00142 // GisReadArtHead -----------------------------------------------------
00143 
00144 class GisReadArtHead : public GisReadHead
00145 {
00146 
00147 public:
00148         frac Time2;
00149         long Delta; // in 2ms-Ticks
00150         int Box;
00151 
00152 private:
00153         TagList *Intensity;
00154         TagList *Articulation;
00155         TagList *Octave;
00156         TagList *Alter;
00157         TagList *Instr;
00158         TagList *Tempo;
00159 
00160 public:
00161 
00162         GisReadArtHead(GisReadArtHead *boss, GisToken *cursor, const mutString id, bool singleToken = false)
00163                         : GisReadHead(boss, cursor, id, singleToken)
00164         {
00165                 DEBUGLOG(other,_T("boss = %p"), boss);
00166                 DEBUGLOG(other,_T("cursor = %p"), cursor);
00167 
00168                 if ( boss ) {
00169                         Intensity = Copy(boss->Intensity);
00170                         Articulation = Copy(boss->Articulation);
00171                         Octave = Copy(boss->Octave);
00172                         Alter = Copy(boss->Alter);
00173                         Instr = Copy(boss->Instr);
00174                         Tempo = Copy(boss->Tempo);
00175                         Box = boss->Box;
00176                 } else {
00177                         Intensity = NULL;
00178                         Articulation = NULL;
00179                         Octave = NULL;
00180                         Alter = NULL;
00181                         Instr = NULL;
00182                         Tempo = NULL;
00183                         Box = 0;
00184                 }
00185 
00186                 Time2 = 0;
00187 
00188                 Delta = 0;
00189                 Turn = 0;
00190         }
00191 
00192         ~GisReadArtHead()
00193 
00194         {
00195                 Erase(Intensity);
00196                 Erase(Articulation);
00197                 Erase(Octave);
00198                 Erase(Alter);
00199                 Erase(Instr);
00200                 Erase(Tempo);
00201         }
00202 
00203         virtual GisReadHead *Build(GisReadHead *boss, GisToken *cursor, const mutString & id, bool singleToken = false)
00204         {
00205                 return new GisReadArtHead((GisReadArtHead*)boss, cursor, id, singleToken);
00206         }
00207 
00208         void Read();
00209 
00210         ARType GetArticulation()
00211         {
00212                 if ( Articulation )
00213                         return (ARType) Articulation->Data.ch;
00214                 else
00215                         return ARNormal;
00216         }
00217 
00218         char GetIntensity(char noteOff = 0)
00219         {
00220                 if ( !noteOff ) {
00221                         if ( Intensity )
00222                                 return Intensity->Data.ch;
00223                         else
00224                                 return 80;
00225                 } else {
00226                         if ( GetArticulation() >= ARPortato )
00227                                 return 127;
00228                         else
00229                                 return 60;
00230                 }
00231         }
00232 
00233         int GetOctave()
00234         {
00235                 if ( Octave )
00236                         return Octave->Data.i;
00237                 else
00238                         return 0;
00239         }
00240 
00241         int GetAlter()
00242         {
00243                 if ( Alter )
00244                         return Alter->Data.i;
00245                 else
00246                         return 0;
00247         }
00248 
00249         int GetInstr()
00250         {
00251                 if ( Instr )
00252                         return Instr->Data.ch;
00253                 else
00254                         return -1;
00255         }
00256 
00257         int GetSpeedFactor()
00258         {
00259                 DEBUGLOG(other,_T("Tempo: %p"));
00260 
00261                 if (Tempo)
00262                         DEBUGLOG(other,_T("Tempo->Data.i: %d"),Tempo);
00263 
00264                 if ( Tempo )
00265                         return Tempo->Data.i;
00266                 else
00267                         return 2000;
00268         }
00269 
00270 #ifdef WX
00271         operator wxString()
00272         {
00273                 if (Next)
00274                         return ToString() + (wxString) (*Next) ;
00275                 else
00276                         return ToString();
00277         }
00278 
00279         virtual wxString ToString();
00280 #endif
00281 };
00282 
00283 typedef void GisReadArtProceed(GisReadArtHead* token, char turn) ;
00284 
00285 extern GisReadArtProceed GisReadArtDummy;
00286 
00287 frac GisReadArtHeadOn(GisReadArtHead **Head, frac dTime = frac(0, 1), GisReadArtProceed *proceed = GisReadArtDummy);
00288 
00289 // GisWriteHead -----------------------------------------------------
00290 
00291 class ChordNote;
00292 
00293 class GisWriteHead
00294 {
00295 
00296 public:
00297         GisWriteHead *Next, *Prev; // double chained, first Prev points to its on adress
00298         GisWriteHead *Boss;
00299         int nSub;
00300         GisToken *Data, **Cursor;
00301         frac TotalTime, CurrentTime;
00302         mutString Id;
00303         char SingleToken; // proceed only one token (in accords)
00304         GisToken **ChordPos;
00305         ChordNote *ChordNotes;
00306         char NoteOn;
00307         char CommaAtEnd;
00308         TagList *Octave;
00309         TagList *Key;
00310 
00311         GisWriteHead(GisWriteHead *boss, const mutString id)
00312         {
00313                 Prev = 0;
00314                 Next = 0;
00315                 Data = 0;
00316                 Cursor = &Data;
00317                 CHECKDUP(Id, id);
00318                 Boss = boss;
00319 
00320                 if ( boss ) {
00321                         if ( boss->nSub == -1 )
00322                                 boss->nSub = 1;
00323                         else
00324                                 boss->nSub++;
00325                 }
00326 
00327                 nSub = -1;
00328 
00329                 TotalTime = frac(0, 1);
00330                 CurrentTime = frac(0, 1);
00331                 SingleToken = (boss && boss->State() == GTSegment);
00332                 ChordNotes = 0;
00333                 NoteOn = 0;
00334                 CommaAtEnd = 0;
00335                 Octave = 0;
00336                 Key = 0;
00337         }
00338 
00339         ~GisWriteHead()
00340 
00341         {
00342                 mutFreeString(Id);
00343                 Erase(Octave);
00344                 Erase(Key);
00345 
00346                 if ( Next ) delete Next; // only the following will be deleted
00347         }
00348 
00349         GisWriteHead *InsertAfter(GisWriteHead *position);
00350         GisWriteHead *CutOut();
00351         GisType State()
00352         {
00353                 if ( *Cursor )
00354                         return (*Cursor)->Type();
00355                 else
00356                         return GTNull;
00357         }
00358 
00359         ChordNote *GetFreeNote();
00360         ChordNote *GetNote(int instrId, int taste);
00361         int ReadyForBoss();
00362         void RemoveComma();
00363         int CloseSubs(GisToken **cont = 0);
00364         int CloseCurrentToken(char insertRest = 1);
00365         int ProceedGis(GisToken *token, char turn = 0);  // returns error code, 0 means OK
00366         void WriteChord();
00367         void AddTime(frac dTime);
00368         int GetOctave()
00369         {
00370                 if ( Octave )
00371                         return Octave->Data.i;
00372                 else
00373                         return 0;
00374         }
00375 
00376         int GetKey()
00377         {
00378                 if ( Key )
00379                         return Key->Data.i;
00380                 else
00381                         return 0;
00382         }
00383 };
00384 
00385 
00386 int GisWriteHeadGis(GisWriteHead **head, mutString id, GisToken *token, char turn);
00387 
00388 /*
00389 int GisWriteAlteredNoteOn(GisWriteHead **head,  char *id, long freq, int noteId,
00390   int octave, int acc, char *Sep);
00391 int GisWriteAlteredNoteOff(GisWriteHead **head,  char *id, int noteId);
00392 */
00393 // search the header with the matching Id
00394 GisWriteHead *GetMatchingHeader(GisWriteHead **head, mutString id);
00395 
00396 void CloseAllSubs(GisWriteHead *head);
00397 
00398 /*
00399 class MisTrack;
00400 
00401 int GisWriteHeadMis(GisWriteHead **head, char *id, DWORD midi, MisTrack* track);
00402 */
00403 
00404 #define CNAlter  1  // ChordNote - status
00405 #define CNNoteOn 2
00406 
00407 // ------------------------------------------------------------------
00408 // ChordNote - buffer element for writing notes
00409 // The identity of a ChordNote depends on InstrId, Key and Pitch.
00410 
00411 class ChordNote
00412 {
00413 
00414 public:
00415         ChordNote *Next;
00416         GisToken *Data;
00417         GisToken **Cursor;
00418         GisWriteHead *Boss;
00419         frac CurrentTime;
00420         frac TotalTime;
00421         GisToken **BossPos;
00422         int InstrId;
00423         char Status;
00424         GisToken **AlterBegin;
00425         GisToken **TieBegin;
00426         int nTie;  // number of notes in tie
00427         mutString *LastSep;
00428         int Taste;     // original pressed key
00429         int Key;       // outputed key
00430         double Pitch;  // corresponding pitch
00431         ChordNote(GisWriteHead *boss) // first ChordNote of a WriteHead
00432         {
00433                 Boss = boss;
00434                 BossPos = Boss->Cursor;
00435                 Next = 0;
00436                 TotalTime = Boss->CurrentTime;
00437                 Data = 0;
00438                 Cursor = &Data;
00439 
00440                 if ( (bool) TotalTime )
00441                         AddGis(new GisNote(mutT("_"),
00442                                            mutEmptyString,
00443                                            0,
00444                                            TotalTime,
00445                                            mutT(" "), 0));
00446 
00447                 CurrentTime = 0;
00448 
00449                 Boss->ChordPos = Boss->Cursor;
00450 
00451                 Status = 0;
00452 
00453                 TieBegin = 0;
00454 
00455                 nTie = 0;
00456 
00457                 LastSep = 0;
00458 
00459                 InstrId = -1;
00460 
00461                 Taste = NO_KEY;
00462 
00463                 Key = NO_KEY;
00464 
00465                 Pitch = 0;
00466         }
00467         ChordNote(ChordNote *first); // not the first ChordNote
00468         ~ChordNote()
00469         {
00470                 if ( Data ) delete Data;
00471 
00472                 if ( Next ) delete Next;
00473         }
00474 
00475         void CountOnTime(frac dTime);
00476         void SetNoteOn(GisToken *note);
00477         int SetNoteOff(GisToken *note); // returns 1, when note was finished, else 0
00478         void AddGis(GisToken *token);
00479         void CheckCloseAlter();
00480         void CheckCloseTie();
00481         void CheckClose()
00482         {
00483                 CheckCloseAlter();
00484                 CheckCloseTie();
00485         }
00486 
00487         int MutNoteOn(int key, double pitch, int instrId, int taste, mutString sep);
00488         int MutNoteOff();
00489         char CheckId(int instrId, int taste)
00490         {
00491                 return (InstrId == instrId) && (Taste == taste);
00492         }
00493 
00494         char Cmp(int key, double pitch)
00495         {
00496                 if ( key != NO_KEY )
00497                         return Key == NO_KEY;
00498 
00499                 if ( (double)key + pitch == (double)Key + Pitch )
00500                         return 1;
00501                 else
00502                         return 0;
00503         }
00504 };
00505 
00506 
00507 #endif
00508 
00509 

Erzeugt am Sun Aug 21 2011 10:51:53 für Mutabor von doxygen 1.7.4