Planeshift
BaseMusicalScore< MeasureType, MeasureElementType >::Cursor Class Reference

This is part of the BaseMusicalScore API. More...

#include <basemusicscore.h>

Public Member Functions

bool Advance (bool ignoreEndOfMeasure)
 Move the cursor to the next element. More...
 
MeasureElementType * GetCurrentElement ()
 Get the element currently pointed by the cursor. More...
 
const MeasureElementType * GetCurrentElement () const
 Get the element currently pointed by the cursor. More...
 
MeasureType< MeasureElementType > * GetCurrentMeasure ()
 Get the measure currently pointed by the cursor. More...
 
const MeasureType< MeasureElementType > * GetCurrentMeasure () const
 Get the measure currently pointed by the cursor. More...
 
bool HasNext (bool ignoreEndOfMeasure) const
 Check if the element after the current one is the end-of-score element. More...
 
void InsertElementAfter (const MeasureElementType &element)
 Insert a copy of the given element before the current one. More...
 
void InsertElementBefore (const MeasureElementType &element)
 Insert a copy of the given element before the current one. More...
 
void InsertMeasureAfter (const MeasureType< MeasureElementType > &measure)
 Insert a copy of the given measure after the current one. More...
 
void InsertMeasureBefore (const MeasureType< MeasureElementType > &measure)
 Insert a copy of the given measure before the current one. More...
 
bool IsEndOfMeasure () const
 Check that the cursor is on an end-of-measure element. More...
 
bool IsEndOfScore () const
 Check that the cursor is on the end-of-score element. More...
 
bool IsValid () const
 Check that the cursor is in a valid position which means that it is not on a special element. More...
 
bool RemoveCurrentElement ()
 Remove the current element. More...
 
bool RemoveCurrentMeasure ()
 Remove the current measure. More...
 
void Validate ()
 If the cursor is pointing to a non-existent element, this moves it to the end-of-measure character in the same measure. More...
 
 ~Cursor ()
 Destructor. More...
 

Friends

CursorBaseMusicalScore ()
 
const CursorBaseMusicalScore ()
 

Detailed Description

template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
class BaseMusicalScore< MeasureType, MeasureElementType >::Cursor

This is part of the BaseMusicalScore API.

Only a BaseMusicalScore object can create an instance of this object.

In order to grasp how the cursor works, it is useful to understand that, similarly to the end-of-file character in files, musical scores use a couple of special measure elements. The end of a measure is marked by an end-of-measure element. Each measure in the score contains at least that one. Moreover, the last element of the score is a special end-of-score element. This is positioned after the last measure and it does not belong to any of them. An empty measure has only the end-of-measure element. Similarly, an empty score contains only the end-of-score element.

Though the user is free to add and remove elements to an existing measure by using the methods provided by the MeasureType class, it must be noticed that by doing so the cursor is not updated in any way. This may cause undesired effects (e.g. the cursor may point to a non-existent measure). For this reason it is safer to use the methods of this class which clearly state their effect on the cursor. If you still want to use the methods in MeasureType, be sure to call Cursor::Validate() after.

Definition at line 164 of file basemusicscore.h.

Constructor & Destructor Documentation

template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::~Cursor ( )

Destructor.

Member Function Documentation

template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::Advance ( bool  ignoreEndOfMeasure)

Move the cursor to the next element.

This takes into account repeat sections only if the score is in play mode. If the current element is the last one of the score, false is returned and the cursor is moved to the end-of-score element. Any subsequent call will not affect the cursor and return false.

Parameters
ignoreEndOfMeasureSkip end-of-measure elements if true.
Returns
False if the score is in edit mode and there is no element written after the current one or if the score is in play mode and there is no element to play after the current one, true otherwise.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
MeasureElementType* BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::GetCurrentElement ( )

Get the element currently pointed by the cursor.

Returns
The current measure element or a null pointer in case the cursor is on a end-of-measure or the end-of-score element.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
const MeasureElementType* BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::GetCurrentElement ( ) const

Get the element currently pointed by the cursor.

Returns
The current measure element or a null pointer in case the cursor is on a end-of-measure or the end-of-score element.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
MeasureType<MeasureElementType>* BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::GetCurrentMeasure ( )

Get the measure currently pointed by the cursor.

Returns
The current measure or a null pointer if the cursor is on a end-of-measure or the end-of-score element.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
const MeasureType<MeasureElementType>* BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::GetCurrentMeasure ( ) const

Get the measure currently pointed by the cursor.

Returns
The current measure or a null pointer if the cursor is on a end-of-measure or the end-of-score element.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::HasNext ( bool  ignoreEndOfMeasure) const

Check if the element after the current one is the end-of-score element.

This takes into account repeat sections only if the score is in play mode.

Parameters
ignoreEndOfMeasureIf this is false, end-of-measure elements are considered valid next elements, otherwise they are ignored.
Returns
True if the score is in edit mode and there is another note written on the score after the current one or if the score is in play mode and there is another note that must be played after the current one, false otherwise.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
void BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::InsertElementAfter ( const MeasureElementType &  element)

Insert a copy of the given element before the current one.

The cursor does not change position. If the cursor points to the end-of-score element, a new measure is pushed at the end of the score and the cursor is moved to the element just inserted. If the cursor points to an end-of-measure element, the element is inserted before it and the cursor is moved to the element just inserted.

Parameters
elementThe element to insert.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
void BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::InsertElementBefore ( const MeasureElementType &  element)

Insert a copy of the given element before the current one.

The cursor does not change position. If the cursor point to the end-of-score element, a new measure is pushed at the end of the score and the cursor is moved to the end-of-measure element of the new measure.

Parameters
elementThe element to insert.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
void BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::InsertMeasureAfter ( const MeasureType< MeasureElementType > &  measure)

Insert a copy of the given measure after the current one.

The cursor does not change position. If the cursor is on the end-of-score element, the measure is pushed at the end of the score and the cursor is moved to the first element of the new measure (which is end-of-measure if the given measure is empty).

Parameters
measureThe measure to insert.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
void BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::InsertMeasureBefore ( const MeasureType< MeasureElementType > &  measure)

Insert a copy of the given measure before the current one.

The cursor does not change position. If the cursor is on the end-of-score element, the measure is pushed at the end of the score and the cursor is kept on end-of-score.

Parameters
measureThe measure to insert.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::IsEndOfMeasure ( ) const

Check that the cursor is on an end-of-measure element.

Returns
True if the cursor is on an end-of-measure element, false otherwise.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::IsEndOfScore ( ) const

Check that the cursor is on the end-of-score element.

Notice that this is different than checking if the current element is the last one of the score. You can use Cursor::HasNext()for that.

Returns
True if the cursor is on an end-of-score element, false otherwise.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::IsValid ( ) const

Check that the cursor is in a valid position which means that it is not on a special element.

Returns
True if the cursor is valid, false otherwise.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::RemoveCurrentElement ( )

Remove the current element.

The cursor is moved to the previous element within the same measure. If the removed element is the first one of the measure, the cursor is moved to the next element. If the cursor is on a end-of-measure or the end-of-score element, nothing happens and false is returned.

Returns
True if the element was removed, false if the cursor is on a end-of-measure or the end-of-score element.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
bool BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::RemoveCurrentMeasure ( )

Remove the current measure.

The cursor is moved to the first element of the previous measure. If the removed measure is the first one of the score, the cursor is moved to the first element of the next measure or to the end-of-score element in case the removed measure was the only one in the score. If the cursor is already on the end-of-score element, nothing happens and false is returned.

Returns
True if the measure was removed, false if the cursor is on the end-of-score element.
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
void BaseMusicalScore< MeasureType, MeasureElementType >::Cursor::Validate ( )

If the cursor is pointing to a non-existent element, this moves it to the end-of-measure character in the same measure.

You have no reason to use this method unless you modify add/remove elements in a MeasureType by using its methods.

Friends And Related Function Documentation

template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
Cursor* BaseMusicalScore ( )
friend
template<template< typename > class MeasureType = Measure, typename MeasureElementType = MeasureElement>
const Cursor* BaseMusicalScore ( )
friend

The documentation for this class was generated from the following file: