Planeshift
pawssheetline.h
Go to the documentation of this file.
1 /*
2  * pawssheetline.h, Author: Andrea Rizzi <88whacko@gmail.com>
3  *
4  * Copyright (C) 2001-2011 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef PAWS_SHEET_LINE_H
21 #define PAWS_SHEET_LINE_H
22 
23 
24 //====================================================================================
25 // Project Includes
26 //====================================================================================
27 #include <paws/pawswidget.h>
28 
29 //------------------------------------------------------------------------------------
30 // Forward Declarations
31 //------------------------------------------------------------------------------------
32 class Measure;
33 class SheetLine;
34 class pawsSheetLine;
35 
40 //--------------------------------------------------
41 
47 {
57 };
58 
59 //--------------------------------------------------
60 
61 struct Note
62 {
63  short int position;
64  short int alter;
65 
72  Note(short int position, short int alter);
73 
79  csString ToXML();
80 };
81 
82 //--------------------------------------------------
83 
84 class Chord
85 {
86 public:
90  Chord();
91 
97  Chord(Chord* chord);
98 
102  ~Chord();
103 
109  Chord* Next() { return next; }
110 
116  Chord* Prev() { return prev; }
117 
123  bool IsRest() { return isRest; }
124 
130  bool IsEmpty() { return notes.GetSize() == 0; }
131 
137  int GetDuration() { return duration; }
138 
144  void SetDuration(int duration);
145 
158  void AddNote(int position, int alter, bool isRest);
159 
165  void AddNote(csRef<iDocumentNode> pitch);
166 
170  void Empty();
171 
177  void AttachChord(Chord* chord);
178 
186  void Draw(pawsSheetLine* pawsLine, Chord* selectedChord, int horizontalPos);
187 
192  csString ToXML();
193 
194 private:
195  friend class Measure;
196 
197  Chord* prev;
198  Chord* next;
199 
200  bool isRest;
201  csArray<Note> notes;
202  short int duration;
203 
210  wchar_t GetNoteChar(bool isNoteDown);
211 
218  wchar_t GetChordNoteChar(bool isNoteDown);
219 
224  wchar_t GetCircleNoteChar();
225 };
226 
227 //--------------------------------------------------
228 
229 class Measure
230 {
231 public:
236  Measure(Chord* firstChord);
237 
243  Measure(csRef<iDocumentNode> measure, int quarterDivisions);
244 
248  ~Measure();
249 
254  Measure* Next() { return next; }
255 
260  Measure* Prev() { return prev; }
261 
266  uint GetNChords() { return nChords; }
267 
273  uint GetSize(uint noteLength);
274 
280  uint GetMimimumSize(uint noteLength);
281 
289  bool SetSize(uint size, uint noteLength);
290 
295  bool GetStartRepeat() { return startRepeat; }
296 
301  void SetStartRepeat(bool repeat) { startRepeat = repeat; }
302 
307  uint GetEndRepeat() { return endRepeat; }
308 
313  void SetEndRepeat(uint repeat) { endRepeat = repeat; }
314 
319  uint GetEnding() { return ending; }
320 
325  void SetEnding(bool isEnding);
326 
332  void AppendMeasure(Measure* measure);
333 
339  void AttachMeasure(Measure* measure);
340 
345  Chord* GetFirstChord() { return firstChord; }
346 
351  Chord* GetLastChord() { return lastChord; }
352 
357  void PushChord(Chord* chord);
358 
366  Chord* InsertChord(Chord* nearChord, bool before);
367 
372  void DeleteChord(Chord* chord);
373 
377  void Empty();
378 
385  bool Cut(uint divisions);
386 
393  void Fill(uint divisions);
394 
401  void Draw(pawsSheetLine* pawsLine, Chord* selectedChord, int startPosition);
402 
413  bool Hit(int x, Chord* &chord, bool &before);
414 
422  csString ToXML(uint number, csString attributes = "");
423 
424 private:
425  friend class SheetLine;
426 
427  Measure* prev;
428  Measure* next;
429 
430  bool startRepeat;
431  uint endRepeat;
432  uint ending;
433 
434  uint nChords;
435  uint notesSpace;
436  Chord* firstChord;
437  Chord* lastChord;
438 
444  void InsertChord(Chord* prevChord, Chord* chord);
445 
451  void DeleteOwnChord(Chord* chord);
452 
459  void DrawRepeatDots(pawsSheetLine* pawsLine, int x, bool start);
460 
468  int GetBiggerDivision(uint divisions);
469 };
470 
471 //--------------------------------------------------
472 
474 {
475 public:
480  SheetLine(Measure* firstMeasure);
481 
485  ~SheetLine();
486 
491  SheetLine* Next() { return next; }
492 
497  SheetLine* Prev() { return prev; }
498 
503  bool HasFirstMeasure() { return (prev == 0); }
504 
509  bool HasLastMeasure() { return (lastMeasure->next == 0); }
510 
516  bool Contains(Measure* measure);
517 
522  Measure* GetFirstMeasure() { return firstMeasure; }
523 
528  Measure* GetLastMeasure() { return lastMeasure; }
529 
536  bool SetSize(uint size, pawsSheetLine* pawsLine);
537 
545  SheetLine* AttachNewLine(Measure* firstMeasure);
546 
552  Measure* InsertNewMeasure(Measure* measureAfter);
553 
558  void PushMeasure(Measure* measure);
559 
566  void DeleteMeasure(Measure* measure);
567 
572  bool Resize();
573 
579  void ResizeAll(bool forceAll = false);
580 
590  void Draw(pawsSheetLine* pawsLine, Chord* selectedChord, int startPosition, int height);
591 
604  bool Hit(int x, Chord* &chord, Measure* &measure, bool &before);
605 
614  Chord* Advance(uint divisions);
615 
623  void SetCallback(void* object, void (*function)(void*, SheetLine*));
624 
625 private:
626  SheetLine* prev;
627  SheetLine* next;
628 
629  uint size;
630  uint noteLength;
631  Measure* firstMeasure;
632  Measure* lastMeasure;
633 
634  bool hasCallback;
635  void* callbackObject;
636  void (*callbackFunction)(void*, SheetLine*);
637 
641  void Callback();
642 };
643 
644 //--------------------------------------------------
645 
652 {
653 public:
657  pawsSheetLine();
658 
662  virtual ~pawsSheetLine();
663 
668  SheetLine* GetLine() { return line; }
669 
675  void SetLine(SheetLine* sheetLine, bool resize = true);
676 
681  bool GetDoubleStaff() { return isDouble; }
682 
687  void SetDoubleStaff(bool doubleStaff);
688 
696  void DrawDoubleLine(int x, int y, int height);
697 
698 
699  // From pawsWidget
700  //-----------------
701  virtual void Draw();
702  virtual bool OnMouseDown(int button, int modifiers, int x, int y);
703  virtual bool PostSetup();
704 
705 private:
706  friend class Chord;
707  friend class Measure;
708  friend class SheetLine;
709 
710  bool isDouble;
711  SheetLine* line;
712 
713  // positioning parameters
714  int staffMarginUp;
715  int staffMarginLateral;
716 
717  int cleffCharLength;
718  int alterCharLength;
719  int metricCharLength;
720  int noteCharLength;
721  int doubleLineWidth;
722  int ledgerLineShift;
723 
724  int noteCharHeight;
725  float staffRowHeight;
726  int centralCPos;
727 
733  static wchar_t GetSymbolChar(char symbol);
734 
741  static wchar_t GetSmallNumber(char number);
742 
747  void SetDrawParameters();
748 };
749 
751 
754 #endif // PAWS_SHEET_LINE_H
bool GetStartRepeat()
Gets the start repeat state.
A measure containing measure elements.
bool IsRest()
Return true if this chord is a rest, false otherwise.
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
Note()
Default constructor.
bool GetDoubleStaff()
Gets the staff status (double or single).
bool HasFirstMeasure()
Returns true if this line contains the first measure.
Measure * Next()
Returns the next Measure.
Measure * GetLastMeasure()
Returns the last measure of the line.
A single note in a musical score.
Definition: pawssheetline.h:61
void SetEndRepeat(uint repeat)
Sets the number of times this part must be repeat.
Chord * GetLastChord()
Returns the last chord of this measure.
bool IsEmpty()
Returns true if there are not notes in this chord.
uint GetNChords()
Returns the number of chords in this measure.
SheetLine * GetLine()
Gets the sheet line drawn by this widget.
Duration
The number associated to each duration is the number of sixteenths in that note.
Definition: pawssheetline.h:46
Chord * Next()
Returns the next Chord.
SheetLine * Next()
Returns the next SheetLine.
bool HasLastMeasure()
Returns true if this line contains the last measure.
Chord * Prev()
Returns the previous Chord.
csString ToXML()
Writes this note as a <pitch> XML node.
Measure * Prev()
Returns the previous Measure.
uint GetEndRepeat()
Gets the number of times this part must be repeat.
Chord * GetFirstChord()
Returns the first chord of this measure.
uint GetEnding()
Gets the number of this ending.
short int position
The note&#39;s position (0 is C4, 1 is D4 etc).
Definition: pawssheetline.h:63
void SetStartRepeat(bool repeat)
Sets the start repeat of this measure.
Measure * GetFirstMeasure()
Returns the first measure of the line.
short int alter
The note&#39;s alteration (-1 flat, 0 normal, 1 sharp).
Definition: pawssheetline.h:64
SheetLine * Prev()
Returns the previous SheetLine.
int GetDuration()
Gets the duration of this chord.
This class draws a musical staff on the widget and creates notes and chords that it can represent on ...
CREATE_PAWS_FACTORY(pawsSheetLine)