Lomse library. API documentation  0.30.0
CmdCursor Class Reference

#include <lomse_command.h>

Inheritance diagram for CmdCursor:
DocCmdSimple DocCommand

Detailed Description

A command for moving the cursor to a new position.

See constructors for details. Each constructor offers a different alternative for specifying the new cursor position.

Public Types

enum  ECursorAction
 
- Public Types inherited from DocCommand
enum  ECmdCursorPolicy
 
enum  ECmdUndoPolicy
 
enum  ECmdSelectionPolicy
 

Public Member Functions

 CmdCursor (ECursorAction cmd, const std::string &name="")
 
 CmdCursor (ImoId id, const std::string &name="")
 
 CmdCursor (int measure, int instr, int staff, const std::string &name="")
 
 CmdCursor (TimeUnits time, int instr, int staff, const std::string &name="")
 
 CmdCursor (DocCursorState &state, const std::string &name="")
 
int get_cursor_update_policy () override
 
int get_undo_policy () override
 
int get_selection_update_policy () override
 
- Public Member Functions inherited from DocCmdSimple
virtual ~DocCmdSimple ()
 
bool is_composite () override
 
- Public Member Functions inherited from DocCommand
virtual ~DocCommand ()
 
std::string get_name ()
 
bool is_reversible ()
 
bool is_recordable ()
 
std::string get_error ()
 

Member Enumeration Documentation

◆ ECursorAction

This enum describes the posible actions for CmdCursor commands.

Enumerator
k_move_next 

Move cursor to the next valid position.

k_move_prev 

Move cursor to the previous valid position.

k_enter 

When cursor is pointing to a top level element, this action causes the cursor to enter into this top level element and point to first sub-element.

k_exit 

When cursor is inside a top level element, this action causes the cursor to move up, out of this top level element, and to point to it.

k_point_to 

Move cursor to the specified element.

k_to_state 

Move cursor to the specified state.

k_to_measure 

When cursor is inside of a music score, this action moves the cursor to the specified measure.

k_to_time 

When cursor is inside of a music score, this action moves the cursor to the specified time position.

k_move_up 

When cursor is inside of a music score, this action moves the cursor to the previous staff or system, pointing to the nearest note or rest to current vertical position.

k_move_down 

When cursor is inside of a music score, this action moves the cursor to the next staff or system, pointing to the nearest note or rest to current vertical position.

k_cursor_dump 

This action is restricted for debugging Lomse. Your application should not use it.

Constructor & Destructor Documentation

◆ CmdCursor() [1/5]

CmdCursor::CmdCursor ( ECursorAction  cmd,
const std::string &  name = "" 
)

This command moves the cursor to a new position, as specified by parameter cmd.

Parameters
cmdThe action to be performed. It must be one of the following values from enum ECursorAction: k_move_next, k_move_prev, k_enter, k_exit, k_move_up, k_move_down or k_cursor_dump.
nameThe displayable name for the command. If not specified or empty will default to one of the following vaues, depending on the requested action: "Cursor: move next", "Cursor: move prev", "Cursor: move up", "Cursor: move down", "Cursor: enter element" or "Cursor: exit element".

Remarks

  • After executing the command:
    • the selection will not be changed.
    • the cursor will point to a new position.
  • CmdCursor is a transient command, meaning that it is not saved in the undo/redo history and, therefore, undo and redo operations are not available for this command.

Example

bool CommandHandler::process_cursor_key_command(int keyCmd)
{
//A key has been pressed in the keyboard. The command implied by the
//pressed key is passed to this method. If it is a cursor command
//it will be processed here and TRUE is returned.
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
//cursor is only valid if document edition is enabled
if (!spInteractor->is_edition_enabled())
return false;
switch (keyCmd)
{
//cursor keys
case k_cmd_cursor_move_prev:
SpInteractor->exec_command( new CmdCursor(CmdCursor::k_move_prev) );
return true;
case k_cmd_cursor_move_next:
SpInteractor->exec_command( new CmdCursor(CmdCursor::k_move_next) );
return true;
case k_cmd_cursor_exit:
SpInteractor->exec_command( new CmdCursor(CmdCursor::k_exit) );
return true;
case k_cmd_cursor_enter:
{
if (!m_cursor->is_inside_terminal_node())
{
ImoObj* pImo = m_cursor->get_pointee();
if (pImo && pImo->is_score())
{
SpInteractor->exec_command( new CmdCursor(CmdCursor::k_enter) );
return true;
}
}
return false;
}
case k_cmd_cursor_to_next_measure:
case k_cmd_cursor_to_prev_measure:
case k_cmd_cursor_to_first_measure:
case k_cmd_cursor_to_last_measure:
{
ImoObj* pImo = m_cursor->get_parent_object();
if (pImo && pImo->is_score())
{
ScoreCursor* pSC =
static_cast<ScoreCursor*>(m_cursor->get_inner_cursor());
int measure = pSC->measure();
if (keyCmd == k_cmd_cursor_to_next_measure)
++measure;
else if (keyCmd == k_cmd_cursor_to_prev_measure)
{
if (measure > 0) --measure;
}
else if (keyCmd == k_cmd_cursor_to_first_measure)
measure = 0;
else if (keyCmd == k_cmd_cursor_to_last_measure)
measure = 9999999;
else;
SpInteractor->exec_command( new CmdCursor(measure, -1, -1) );
return true;
}
return false;
}
case k_cmd_cursor_move_up:
case k_cmd_cursor_move_down:
{
ImoObj* pImo = m_cursor->get_parent_object();
if (pImo && pImo->is_score())
{
if (keyCmd == k_cmd_cursor_move_up)
SpInteractor->exec_command( new CmdCursor(CmdCursor::k_move_up) );
else
SpInteractor->exec_command( new CmdCursor(CmdCursor::k_move_down) );
return true;
}
return false;
}
default:
return false;
}
}
return false;
}

◆ CmdCursor() [2/5]

CmdCursor::CmdCursor ( ImoId  id,
const std::string &  name = "" 
)

This command moves the cursor for pointing to element specified by parameter id.

Parameters
idThe ID of the object that will be pointed by the cursor.
nameThe displayable name for the command. If not specified or empty will default to "Cursor: point to".

Remarks

  • After executing the command:
    • the selection will not be changed.
    • the cursor will point to a new position.
  • CmdCursor is a transient command, meaning that it is not saved in the undo/redo history and, therefore, undo and redo operations are not available for this command.

◆ CmdCursor() [3/5]

CmdCursor::CmdCursor ( int  measure,
int  instr,
int  staff,
const std::string &  name = "" 
)

When the cursor is inside a music score, this command moves the cursor for pointing to the first element (note, rest, clef, etc.) in the measure specified by parameter measure.

Parameters
measureThe measure to move the cursor to (0..n).
instrThe instrument to move the cursor to. Value -1 means "remain in current instrumnent". For moving to another instrument use instrument number (0 ... num_instruments - 1).
staffThe staff to move the cursor to. Value -1 means "remain in current staff". For moving to another staff use staff number (0 ... num_staves - 1).
nameThe displayable name for the command. If not specified or empty will default to "Cursor: jump to new place".

Remarks

  • After executing the command:
    • the selection will not be changed.
    • the cursor will point to a new position.
  • CmdCursor is a transient command, meaning that it is not saved in the undo/redo history and, therefore, undo and redo operations are not available for this command.

Example

switch (keyCmd)
{
case k_cmd_cursor_to_next_measure:
case k_cmd_cursor_to_prev_measure:
case k_cmd_cursor_to_first_measure:
case k_cmd_cursor_to_last_measure:
{
ImoObj* pImo = m_cursor->get_parent_object();
if (pImo && pImo->is_score())
{
ScoreCursor* pSC =
static_cast<ScoreCursor*>(m_cursor->get_inner_cursor());
int measure = pSC->measure();
if (keyCmd == k_cmd_cursor_to_next_measure)
++measure;
else if (keyCmd == k_cmd_cursor_to_prev_measure)
{
if (measure > 0) --measure;
}
else if (keyCmd == k_cmd_cursor_to_first_measure)
measure = 0;
else if (keyCmd == k_cmd_cursor_to_last_measure)
measure = 9999999;
else;
SpInteractor->exec_command( new CmdCursor(measure, -1, -1) );
return true;
}
return false;
}
...
}

◆ CmdCursor() [4/5]

CmdCursor::CmdCursor ( TimeUnits  time,
int  instr,
int  staff,
const std::string &  name = "" 
)

When the cursor is inside a music score, this command moves the cursor for pointing to a time position equal than the specified by parameter time.

Parameters
timeThe new time position to move the cursor to.
instrThe instrument to move the cursor to. Value -1 means "remain in current instrument". For moving to another instrument use instrument number (0 ... num_instruments - 1).
staffThe staff to move the cursor to. Value -1 means "remain in current staff". For moving to another staff use staff number (0 ... num_staves - 1).
nameThe displayable name for the command. If not specified or empty will default to "Cursor: jump to new place".

Remarks

  • After executing the command:
    • the selection will not be changed.
    • the cursor will point to a new position.
  • CmdCursor is a transient command, meaning that it is not saved in the undo/redo history and, therefore, undo and redo operations are not available for this command.

◆ CmdCursor() [5/5]

CmdCursor::CmdCursor ( DocCursorState &  state,
const std::string &  name = "" 
)

This command moves the cursor to the state specified by parameter state.

Parameters
stateThe new state for the cursor.
nameThe displayable name for the command. If not specified or empty will default to "Cursor: jump to new place".

Remarks

  • After executing the command:
    • the selection will not be changed.
    • the cursor will point to a new position.
  • CmdCursor is a transient command, meaning that it is not saved in the undo/redo history and, therefore, undo and redo operations are not available for this command.

Member Function Documentation

◆ get_cursor_update_policy()

int CmdCursor::get_cursor_update_policy ( )
inlineoverridevirtual

Returns a value from ECmdCursorPolicy that indicates the update policy followed by this command.

Implements DocCommand.

◆ get_selection_update_policy()

int CmdCursor::get_selection_update_policy ( )
inlineoverridevirtual

Returns a value from ECmdSelectionPolicy that indicates the undo policy followed by this command.

Implements DocCommand.

◆ get_undo_policy()

int CmdCursor::get_undo_policy ( )
inlineoverridevirtual

Returns a value from ECmdUndoPolicy that indicates the undo policy followed by this command.

Implements DocCommand.