Lomse library. API documentation  0.30.0
CmdTransposeKey Class Reference

#include <lomse_command.h>

Inheritance diagram for CmdTransposeKey:
CmdTranspose DocCmdSimple DocCommand

Detailed Description

A command for transposing a selection to a different key signature.

Transposing a melody to a new key signature is a two steps process: replace the key signature symbol by the new key signature and transpose the affected notes, chromatically, by the interval between the new key and the old key signatures.

Therefore, for transposing by key no special command is needed, just CmdTransposeChromatically; and also a method to compute the interval between two key signatures. Class KeyUtilities provides three methods for this: KeyUtilities::up_interval() KeyUtilities::down_interval() KeyUtilities::closest_interval()

Take into account that a command for transposing to a different key signature can not be a general basic command because it must deal with notes and with keys, and how to deal with them is an application behaviour decision that can not be generalized. There are many scenarios to consider:

  • scores with key changes;
  • transposing instruments with a different key;
  • scope of the command: the command must affect to all the score? or only to a selection? (e.g. selected notes, a certain number of measures, other);
  • what to do when in the scope of the command there is a key signature change?:
    • apply the same transposition interval to any key signature found in the selection set,
    • stop transposing,
    • other;
  • what to do when not all notes are transposed:
    • nothing,
    • insert the old key signature after the last transposed note,
    • other.

Because all of these considerations and possible application scenarios, Lomse can not provide a generic key transposition command. Nevertheless, for convenience, the CmdTransposeKey command has been created to be used in simple cases.

See constructor for details.

Public Member Functions

 CmdTransposeKey (FIntval interval, const std::string &name="")
 
- Public Member Functions inherited from CmdTranspose
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

◆ CmdTransposeKey()

CmdTransposeKey::CmdTransposeKey ( FIntval  interval,
const std::string &  name = "" 
)

This command changes all the keys in the selection, and transposes chromatically all the notes in the selection.

Parameters
intervalThe interval by which you want the selected music transposed. If the interval is negative, the direction of the transposition will be 'down'; otherwise it will be 'up'.
nameThe displayable name for the command. If not specified or empty will be replaced by "Transpose key signature".

Remarks

  • If the selection does not contain key signatures, only the notes will be transposed.
  • If the selection only contains key signatures they will be changed but no notes will be transposed.
  • After executing the command:
    • the selection set will be unmodified.
    • the cursor will not change its position.

Example

void CommandHandler::transpose(FIntval interval)
{
if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())
{
string name = gettext("Transpose key signature");
SpInteractor->exec_command(
new CmdTransposeKey(interval) );
}
}