Planeshift

pawssheetline.h

Go to the documentation of this file.
00001 /*
00002  * pawssheetline.h, Author: Andrea Rizzi <[email protected]>
00003  *
00004  * Copyright (C) 2001-2011 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef PAWS_SHEET_LINE_H
00021 #define PAWS_SHEET_LINE_H
00022 
00023 
00024 //====================================================================================
00025 // Project Includes
00026 //====================================================================================
00027 #include <paws/pawswidget.h>
00028 
00029 //------------------------------------------------------------------------------------
00030 // Forward Declarations
00031 //------------------------------------------------------------------------------------
00032 class Measure;
00033 class SheetLine;
00034 class pawsSheetLine;
00035 
00040 //--------------------------------------------------
00041 
00046 enum Duration
00047 {
00048     SIXTEENTH_DURATION      = 1,
00049     EIGHTH_DURATION         = 2,
00050     DOTTED_EIGHTH_DURATION  = 3,
00051     QUARTER_DURATION        = 4,
00052     DOTTED_QUARTER_DURATION = 6,
00053     HALF_DURATION           = 8,
00054     DOTTED_HALF_DURATION    = 12,
00055     WHOLE_DURATION          = 16,
00056     DOTTED_WHOLE_DURATION   = 24
00057 };
00058 
00059 //--------------------------------------------------
00060 
00061 struct Note
00062 {
00063     short int position;     
00064     short int alter;        
00065 
00072     Note(short int position, short int alter);
00073 
00079     csString ToXML();
00080 };
00081 
00082 //--------------------------------------------------
00083 
00084 class Chord
00085 {
00086 public:
00090     Chord();
00091 
00097     Chord(Chord* chord);
00098 
00102     ~Chord();
00103 
00109     Chord* Next() { return next; }
00110 
00116     Chord* Prev() { return prev; }
00117 
00123     bool IsRest() { return isRest; }
00124 
00130     bool IsEmpty() { return notes.GetSize() == 0; }
00131 
00137     int GetDuration() { return duration; }
00138 
00144     void SetDuration(int duration);
00145 
00158     void AddNote(int position, int alter, bool isRest);
00159 
00165     void AddNote(csRef<iDocumentNode> pitch);
00166 
00170     void Empty();
00171 
00177     void AttachChord(Chord* chord);
00178 
00186     void Draw(pawsSheetLine* pawsLine, Chord* selectedChord, int horizontalPos);
00187 
00192     csString ToXML();
00193 
00194 private:
00195     friend class Measure;
00196 
00197     Chord* prev;                
00198     Chord* next;                
00199 
00200     bool isRest;                
00201     csArray<Note> notes;        
00202     short int duration;         
00203 
00210     wchar_t GetNoteChar(bool isNoteDown);
00211 
00218     wchar_t GetChordNoteChar(bool isNoteDown);
00219 
00224     wchar_t GetCircleNoteChar();
00225 };
00226 
00227 //--------------------------------------------------
00228 
00229 class Measure
00230 {
00231 public:
00236     Measure(Chord* firstChord);
00237 
00243     Measure(csRef<iDocumentNode> measure, int quarterDivisions);
00244 
00248     ~Measure();
00249 
00254     Measure* Next() { return next; }
00255 
00260     Measure* Prev() { return prev; }
00261 
00266     uint GetNChords() { return nChords; }
00267 
00273     uint GetSize(uint noteLength);
00274 
00280     uint GetMimimumSize(uint noteLength);
00281 
00289     bool SetSize(uint size, uint noteLength);
00290 
00295     bool GetStartRepeat() { return startRepeat; }
00296 
00301     void SetStartRepeat(bool repeat) { startRepeat = repeat; }
00302 
00307     uint GetEndRepeat() { return endRepeat; }
00308 
00313     void SetEndRepeat(uint repeat) { endRepeat = repeat; }
00314 
00319     uint GetEnding() { return ending; }
00320 
00325     void SetEnding(bool isEnding);
00326 
00332     void AppendMeasure(Measure* measure);
00333 
00339     void AttachMeasure(Measure* measure);
00340 
00345     Chord* GetFirstChord() { return firstChord; }
00346 
00351     Chord* GetLastChord() { return lastChord; }
00352 
00357     void PushChord(Chord* chord);
00358 
00366     Chord* InsertChord(Chord* nearChord, bool before);
00367 
00372     void DeleteChord(Chord* chord);
00373 
00377     void Empty();
00378 
00385     bool Cut(uint divisions);
00386 
00393     void Fill(uint divisions);
00394 
00401     void Draw(pawsSheetLine* pawsLine, Chord* selectedChord, int startPosition);
00402 
00413     bool Hit(int x, Chord* &chord, bool &before);
00414 
00422     csString ToXML(uint number, csString attributes = "");
00423 
00424 private:
00425     friend class SheetLine;
00426 
00427     Measure* prev;          
00428     Measure* next;          
00429 
00430     bool startRepeat;       
00431     uint endRepeat;         
00432     uint ending;            
00433 
00434     uint nChords;           
00435     uint notesSpace;        
00436     Chord* firstChord;      
00437     Chord* lastChord;       
00438 
00444     void InsertChord(Chord* prevChord, Chord* chord);
00445 
00451     void DeleteOwnChord(Chord* chord);
00452 
00459     void DrawRepeatDots(pawsSheetLine* pawsLine, int x, bool start);
00460 
00468     int GetBiggerDivision(uint divisions);
00469 };
00470 
00471 //--------------------------------------------------
00472 
00473 class SheetLine
00474 {
00475 public:
00480     SheetLine(Measure* firstMeasure);
00481 
00485     ~SheetLine();
00486 
00491     SheetLine* Next() { return next; }
00492 
00497     SheetLine* Prev() { return prev; }
00498 
00503     bool HasFirstMeasure() { return (prev == 0); }
00504 
00509     bool HasLastMeasure() { return (lastMeasure->next == 0); }
00510 
00516     bool Contains(Measure* measure);
00517 
00522     Measure* GetFirstMeasure() { return firstMeasure; }
00523 
00528     Measure* GetLastMeasure() { return lastMeasure; }
00529 
00536     bool SetSize(uint size, pawsSheetLine* pawsLine);
00537 
00545     SheetLine* AttachNewLine(Measure* firstMeasure);
00546 
00552     Measure* InsertNewMeasure(Measure* measureAfter);
00553 
00558     void PushMeasure(Measure* measure);
00559 
00566     void DeleteMeasure(Measure* measure);
00567 
00572     bool Resize();
00573 
00579     void ResizeAll(bool forceAll = false);
00580 
00590     void Draw(pawsSheetLine* pawsLine, Chord* selectedChord, int startPosition, int height);
00591 
00604     bool Hit(int x, Chord* &chord, Measure* &measure, bool &before);
00605 
00614     Chord* Advance(uint divisions);
00615 
00623     void SetCallback(void* object, void (*function)(void*, SheetLine*));
00624 
00625 private:
00626     SheetLine* prev;                                  
00627     SheetLine* next;                                  
00628 
00629     uint size;                                        
00630     uint noteLength;                                  
00631     Measure* firstMeasure;                            
00632     Measure* lastMeasure;                             
00633 
00634     bool hasCallback;                                 
00635     void* callbackObject;                             
00636     void (*callbackFunction)(void*, SheetLine*);      
00637 
00641     void Callback();
00642 };
00643 
00644 //--------------------------------------------------
00645 
00651 class pawsSheetLine: public pawsWidget
00652 {
00653 public:
00657     pawsSheetLine();
00658 
00662     virtual ~pawsSheetLine();
00663 
00668     SheetLine* GetLine() { return line; }
00669 
00675     void SetLine(SheetLine* sheetLine, bool resize = true);
00676 
00681     bool GetDoubleStaff() { return isDouble; }
00682 
00687     void SetDoubleStaff(bool doubleStaff);
00688 
00696     void DrawDoubleLine(int x, int y, int height);
00697 
00698 
00699     // From pawsWidget
00700     //-----------------
00701     virtual void Draw();
00702     virtual bool OnMouseDown(int button, int modifiers, int x, int y);
00703     virtual bool PostSetup();
00704 
00705 private:
00706     friend class Chord;
00707     friend class Measure;
00708     friend class SheetLine;
00709 
00710     bool isDouble;              
00711     SheetLine* line;            
00712 
00713     // positioning parameters
00714     int staffMarginUp;          
00715     int staffMarginLateral;     
00716 
00717     int cleffCharLength;        
00718     int alterCharLength;        
00719     int metricCharLength;       
00720     int noteCharLength;         
00721     int doubleLineWidth;        
00722     int ledgerLineShift;        
00723 
00724     int noteCharHeight;         
00725     float staffRowHeight;       
00726     int centralCPos;            
00727 
00733     static wchar_t GetSymbolChar(char symbol);
00734 
00741     static wchar_t GetSmallNumber(char number);
00742 
00747     void SetDrawParameters();
00748 };
00749 
00750 CREATE_PAWS_FACTORY(pawsSheetLine);
00751 
00754 #endif // PAWS_SHEET_LINE_H