Lomse library. API documentation  0.30.0
CmdAddNoteRest Class Reference

#include <lomse_command.h>

Inheritance diagram for CmdAddNoteRest:
DocCmdSimple DocCommand

Detailed Description

A command for inserting a note or a rest.

See constructor for details.

Public Member Functions

 CmdAddNoteRest (const std::string &source, int editMode, 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 ()
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ CmdAddNoteRest()

CmdAddNoteRest::CmdAddNoteRest ( const std::string &  source,
int  editMode,
const std::string &  name = "" 
)

This command adds a new note or rest at current cursor position.

Parameters
sourceLDP source code for the note or rest to insert.
editModeEdition mode for executing the command. It must be a value from EEditMode, either k_edit_mode_replace or k_edit_mode_ripple. See Supported edition modes. Attention: Currently this parameter is ignored and the command always work in replace mode.
nameThe displayable name for the command. If not specified or empty will default to "Add note" or "Add rest" depending on object to insert.

Remarks

  • In ripple mode, the new note or rest will be inserted before the object currently pointed by the cursor. In replace mode, the new note or rest will replace the object currently pointed by the cursor.
  • After executing the command:
    • the selection will be cleared and the added note or rest will be selected. That is, the selection will contain only the new added note or rest.
    • In ripple mode, the cursor will not change its position. The inserted note/rest will be just behind the cursor. In replace mode the cursor will be pointing after the inserted note/rest.

Example

void CommandHandler::insert_note(string stepLetter, int octave, EAccidentals acc,
ENoteType noteType, int dots,
int voice, int staff)
{
//insert a note at current cursor position
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
stringstream src;
src << "(n ";
if (acc != k_no_accidentals)
src << LdpExporter::accidentals_to_string(acc);
src << stepLetter << octave
<< " " << LdpExporter::notetype_to_string(noteType, dots)
<< " v" << voice
<< " p" << staff+1
<< ")";
string name = gettext("Insert note") + " (" + stepLetter + octave + ")";
int editMode = k_edit_mode_replace;
SpInteractor->exec_command( new CmdAddNoteRest(src.str(), editMode, name) );
}
}

Member Function Documentation

◆ get_cursor_update_policy()

int CmdAddNoteRest::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 CmdAddNoteRest::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 CmdAddNoteRest::get_undo_policy ( )
inlineoverridevirtual

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

Implements DocCommand.