Planeshift
basemusicscore.h
Go to the documentation of this file.
1 /*
2  * basemusicscore.h, Author: Andrea Rizzi <88whacko@gmail.com>
3  *
4  * Copyright (C) 2001-2013 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 BASE_MUSIC_SCORE_H
21 #define BASE_MUSIC_SCORE_H
22 
23 
24 //====================================================================================
25 // Crystal Space Includes
26 //====================================================================================
27 
28 //====================================================================================
29 // Project Includes
30 //====================================================================================
31 
32 //====================================================================================
33 // Local Includes
34 //====================================================================================
35 #include "scoreelements.h"
36 
37 //------------------------------------------------------------------------------------
38 // Forward Declarations
39 //------------------------------------------------------------------------------------
40 
58 template<template<typename> class MeasureType = Measure, typename MeasureElementType = MeasureElement>
60 {
61 
62 public:
63  class Cursor;
64 
69 
74 
78  bool AdvanceCursor(bool ignoreEndOfMeasure);
79 
86 
93  const MeasureType<MeasureElementType>* GetMeasure(size_t n) const;
94 
100  size_t GetNMeasures() const { return measures.GetSize(); }
101 
107  const Cursor* GetPlayCursor() const;
108 
115  Cursor* SetEditMode();
116 
123  const Cursor* SetPlayMode();
124 
125 private:
126  enum ScoreMode
127  {
128  EDIT,
129  PLAY
130  };
131 
132  Cursor* cursor;
133  ScoreMode mode;
134 
139  csArray<MeasureType<MeasureElementType>> measures;
140 };
141 
142 //------------------------------------------------------------------------------------
143 
163 template<template<typename> class MeasureType, typename MeasureElementType>
164 class BaseMusicalScore<MeasureType, MeasureElementType>::Cursor
165 {
166 public:
170  ~Cursor();
171 
183  bool Advance(bool ignoreEndOfMeasure);
184 
191  MeasureElementType* GetCurrentElement();
192 
196  const MeasureElementType* GetCurrentElement() const;
197 
204  MeasureType<MeasureElementType>* GetCurrentMeasure();
205 
209  const MeasureType<MeasureElementType>* GetCurrentMeasure() const;
210 
221  bool HasNext(bool ignoreEndOfMeasure) const;
222 
232  void InsertElementAfter(const MeasureElementType &element);
233 
242  void InsertElementBefore(const MeasureElementType &element);
243 
252  void InsertMeasureAfter(const MeasureType<MeasureElementType> &measure);
253 
261  void InsertMeasureBefore(const MeasureType<MeasureElementType> &measure);
262 
268  bool IsEndOfMeasure() const;
269 
277  bool IsEndOfScore() const;
278 
285  bool IsValid() const;
286 
296  bool RemoveCurrentElement();
297 
308  bool RemoveCurrentMeasure();
309 
315  void Validate();
316 
317 private:
318  // In this way only BaseMusicalScore can access the private constructor
322 
323  size_t currElementIdx;
324  size_t currMeasureIdx;
325 
330  ScoreContext* context;
332 
341  typename BaseMusicalScore<MeasureType, MeasureElementType>::ScoreMode mode);
342 
349  bool CheckRepeat() const;
350 
360  bool HasNextWritten(bool ignoreEndOfMeasure) const;
361 
365  void Reset();
366 };
367 
368 #include "basemusicscore.hpp"
369 
370 #endif // BASE_MUSIC_SCORE_H
A measure containing measure elements.
Cursor * SetEditMode()
Set the mode to edit.
BaseMusicalScore()
Create an empty score in edit mode.
bool AdvanceCursor(bool ignoreEndOfMeasure)
Move the cursor to the next element.
This is used to keep track of everything needed to play a score and provide some utility functions fo...
Implements a musical score.
const MeasureType< MeasureElementType > * GetMeasure(size_t n) const
Return the n-th measure in the score.
const Cursor * SetPlayMode()
Set the mode to play.
This is part of the BaseMusicalScore API.
const Cursor * GetPlayCursor() const
Return the cursor if the score is in play mode.
size_t GetNMeasures() const
Return the number of measures in the score.
An element of a measure with a given duration.
Cursor * GetEditCursor()
Return the cursor if the score is in edit mode.
~BaseMusicalScore()
Destructor.