Skip to content

Commit

Permalink
[Ref] CommandSet: Small cleanup.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22310 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 25, 2024
1 parent cc4f997 commit 7d730ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 42 deletions.
8 changes: 4 additions & 4 deletions mptrack/CommandSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ CCommandSet::CCommandSet()

// Setup

KeyCommand::KeyCommand(uint32 uid, const TCHAR *message, std::vector<KeyCombination> keys)
KeyCommand::KeyCommand(uint32 uid, const TCHAR *commandName, std::vector<KeyCombination> keys)
: kcList{std::move(keys)}
, Message{message}
, name{commandName}
, UID{uid}
{
}
Expand Down Expand Up @@ -964,11 +964,11 @@ void CCommandSet::SetupCommands()

for(int i = kcVPStartNotes; i <= kcVPEndNotes; i++)
{
m_commands[i - kcVPStartNotes + contextStartNotes] = {KeyCommand::Hidden, m_commands[i].Message};
m_commands[i - kcVPStartNotes + contextStartNotes] = {KeyCommand::Hidden, m_commands[i].name};
}
for(int i = kcVPStartNoteStops; i <= kcVPEndNoteStops; i++)
{
m_commands[i - kcVPStartNoteStops + contextStopNotes] = {KeyCommand::Hidden, m_commands[i].Message};
m_commands[i - kcVPStartNoteStops + contextStopNotes] = {KeyCommand::Hidden, m_commands[i].name};
}
}

Expand Down
69 changes: 32 additions & 37 deletions mptrack/CommandSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "openmpt/base/FlagSet.hpp"
#include <bitset>
#include <map>
#include <string>

OPENMPT_NAMESPACE_BEGIN

Expand Down Expand Up @@ -1197,23 +1196,21 @@ struct KeyCombination
using KeyMap = std::multimap<KeyCombination, CommandID>;
using KeyMapRange = std::pair<KeyMap::const_iterator, KeyMap::const_iterator>;

//KeyMap

struct KeyCommand
{
static constexpr uint32 Dummy = 1u << 31;
static constexpr uint32 Hidden = 1u << 30;
static constexpr uint32 UIDMask = Hidden - 1u;

std::vector<KeyCombination> kcList;
CString Message;
CString name;

protected:
uint32 UID = 0;

public:
KeyCommand() = default;
KeyCommand(uint32 uid, const TCHAR *message = _T(""), std::vector<KeyCombination> keys = {});
KeyCommand(uint32 uid, const TCHAR *commandName = _T(""), std::vector<KeyCombination> keys = {});

// Unique ID for on-disk keymap format.
// Note that hidden commands do not have a unique ID, because they are never written to keymap files.
Expand All @@ -1234,40 +1231,10 @@ enum class KeyboardPreset
};


enum RuleID
{
krPreventDuplicate,
krDeleteOldOnConflict,

krAllowNavigationWithSelection,
krAllowSelectionWithNavigation,
krAutoSelectOff,
krAllowSelectCopySelectCombos,
krLockNotesToChords,
krNoteOffOnKeyRelease,
krPropagateNotes,
krReassignDigitsToOctaves,
krAutoSpacing,
krCheckModifiers,
krPropagateSampleManipulation,
kNumRules
};

struct CModSpecifications;

class CCommandSet
{
protected:
//util
void SetupCommands();
void SetupContextHierarchy();
void EnforceAll(KeyCombination kc, CommandID cmd, bool adding);

CommandID FindCmd(uint32 uid) const;
bool KeyCombinationConflict(KeyCombination kc1, KeyCombination kc2, bool checkEventConflict = true) const;

void ApplyDefaultKeybindings(KeyboardPreset preset, const Version onlyCommandsAfterVersion = {});

public:
CCommandSet();

Expand All @@ -1290,7 +1257,7 @@ class CCommandSet
mpt::span<const KeyCombination> GetKeyChoices(CommandID cmd) const { return mpt::as_span(m_commands[cmd].kcList); }
bool IsHidden(UINT c) const { return m_commands[c].IsHidden(); }
int GetKeyListSize(CommandID cmd) const { return (cmd != kcNull) ? static_cast<int>(m_commands[cmd].kcList.size()) : 0; }
CString GetCommandText(CommandID cmd) const { return m_commands[cmd].Message; }
CString GetCommandText(CommandID cmd) const { return m_commands[cmd].name; }
CString GetKeyTextFromCommand(CommandID c, UINT key = uint32_max) const;
CString FormatConflict(KeyCombination kc, CommandID conflictCommand, KeyCombination conflictCombination) const;

Expand All @@ -1305,8 +1272,36 @@ class CCommandSet
static bool MustBeModifierKey(CommandID id);

protected:
void SetupCommands();
void SetupContextHierarchy();
void EnforceAll(KeyCombination kc, CommandID cmd, bool adding);

CommandID FindCmd(uint32 uid) const;
bool KeyCombinationConflict(KeyCombination kc1, KeyCombination kc2, bool checkEventConflict = true) const;

void ApplyDefaultKeybindings(KeyboardPreset preset, const Version onlyCommandsAfterVersion = {});

enum RuleID
{
krPreventDuplicate,
krDeleteOldOnConflict,

krAllowNavigationWithSelection,
krAllowSelectionWithNavigation,
krAutoSelectOff,
krAllowSelectCopySelectCombos,
krLockNotesToChords,
krNoteOffOnKeyRelease,
krPropagateNotes,
krReassignDigitsToOctaves,
krAutoSpacing,
krCheckModifiers,
krPropagateSampleManipulation,
kNumRules
};

const CModSpecifications *m_currentModSpecs = nullptr;
KeyCommand m_commands[kcNumCommands];
std::array<KeyCommand, kcNumCommands> m_commands;
std::bitset<kCtxMaxInputContexts> m_isParentContext[kCtxMaxInputContexts];
std::bitset<kNumRules> m_enforceRule;
};
Expand Down
2 changes: 1 addition & 1 deletion mptrack/DefaultKeyBindings.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DefaultKeyBindings.h
* --------------------
* Purpose: The default key binding definitions, including IT and FT2 flavours
* Purpose: The default key binding definitions, including IT and FT2 flavours.
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
Expand Down

0 comments on commit 7d730ff

Please sign in to comment.