Planeshift

basemusicscore.h

Go to the documentation of this file.
00001 /*
00002  * basemusicscore.h, Author: Andrea Rizzi <[email protected]>
00003  *
00004  * Copyright (C) 2001-2013 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 BASE_MUSIC_SCORE_H
00021 #define BASE_MUSIC_SCORE_H
00022 
00023 
00024 //====================================================================================
00025 // Crystal Space Includes
00026 //====================================================================================
00027 
00028 //====================================================================================
00029 // Project Includes
00030 //====================================================================================
00031 
00032 //====================================================================================
00033 // Local Includes
00034 //====================================================================================
00035 #include "scoreelements.h"
00036 
00037 //------------------------------------------------------------------------------------
00038 // Forward Declarations
00039 //------------------------------------------------------------------------------------
00040 
00058 template<template<typename> class MeasureType = Measure, typename MeasureElementType = MeasureElement>
00059 class BaseMusicalScore
00060 {
00061 
00062 public:
00063     class Cursor;
00064 
00068     BaseMusicalScore();
00069 
00073     ~BaseMusicalScore();
00074 
00078     bool AdvanceCursor(bool ignoreEndOfMeasure);
00079 
00085     Cursor* GetEditCursor();
00086 
00093     const MeasureType<MeasureElementType>* GetMeasure(size_t n) const;
00094 
00100     size_t GetNMeasures() const { return measures.GetSize(); }
00101 
00107     const Cursor* GetPlayCursor() const;
00108 
00115     Cursor* SetEditMode();
00116 
00123     const Cursor* SetPlayMode();
00124 
00125 private:
00126     enum ScoreMode
00127     {
00128         EDIT,
00129         PLAY
00130     };
00131 
00132     Cursor* cursor; 
00133     ScoreMode mode; 
00134 
00139     csArray<MeasureType<MeasureElementType>> measures;
00140 };
00141 
00142 //------------------------------------------------------------------------------------
00143 
00163 template<template<typename> class MeasureType, typename MeasureElementType>
00164 class BaseMusicalScore<MeasureType, MeasureElementType>::Cursor
00165 {
00166 public:
00170     ~Cursor();
00171 
00183     bool Advance(bool ignoreEndOfMeasure);
00184 
00191     MeasureElementType* GetCurrentElement();
00192 
00196     const MeasureElementType* GetCurrentElement() const;
00197 
00204     MeasureType<MeasureElementType>* GetCurrentMeasure();
00205 
00209     const MeasureType<MeasureElementType>* GetCurrentMeasure() const;
00210 
00221     bool HasNext(bool ignoreEndOfMeasure) const;
00222 
00232     void InsertElementAfter(const MeasureElementType &element);
00233 
00242     void InsertElementBefore(const MeasureElementType &element);
00243 
00252     void InsertMeasureAfter(const MeasureType<MeasureElementType> &measure);
00253 
00261     void InsertMeasureBefore(const MeasureType<MeasureElementType> &measure);
00262 
00268     bool IsEndOfMeasure() const;
00269 
00277     bool IsEndOfScore() const;
00278 
00285     bool IsValid() const;
00286 
00296     bool RemoveCurrentElement();
00297 
00308     bool RemoveCurrentMeasure();
00309 
00315     void Validate();
00316 
00317 private:
00318     // In this way only BaseMusicalScore can access the private constructor
00319     friend BaseMusicalScore<MeasureType, MeasureElementType>::BaseMusicalScore();
00320     friend Cursor* BaseMusicalScore<MeasureType, MeasureElementType>::SetEditMode();
00321     friend const Cursor* BaseMusicalScore<MeasureType, MeasureElementType>::SetPlayMode();
00322 
00323     size_t currElementIdx; 
00324     size_t currMeasureIdx; 
00325 
00330     ScoreContext* context;
00331     BaseMusicalScore<MeasureType, MeasureElementType>* score; 
00332 
00340     Cursor(BaseMusicalScore<MeasureType, MeasureElementType>* score,
00341            typename BaseMusicalScore<MeasureType, MeasureElementType>::ScoreMode mode);
00342 
00349     bool CheckRepeat() const;
00350 
00360     bool HasNextWritten(bool ignoreEndOfMeasure) const;
00361 
00365     void Reset();
00366 };
00367 
00368 #include "basemusicscore.hpp"
00369 
00370 #endif // BASE_MUSIC_SCORE_H