Bool perform (const InvocationInfo& info) Never called

Hi, sorry for this post, I found a lot of topic like this, but it’s making me mad!

I created a class that inherits ApplicationCommandTarget and in my main component I have an ApplicationCommandManager and I register all commands for the target, but nothing happens if I press my keys (if not that hateful alert sound!):

In MyComponent.h:

**class** MyComponent : **public** Component, **public** ApplicationCommandTarget

{

**public** :

MyComponent(tracktion_engine::TempoSequence& TempoSequence);

~MyComponent();

**void** paint (Graphics&) **override** ;

**void** resized() **override** ;

**enum** KeyPressCommandIDs { rightScroll = 1, leftScroll = 2, zoomIn = 3, zoomOut = 4 };

**void** mouseDown( **const** MouseEvent& event) **override** ;

**void** mouseDrag( **const** MouseEvent& event) **override** ;

**void** mouseUp( **const** MouseEvent& event) **override** ;

**void** mouseWheelMove( **const** MouseEvent& event, **const** MouseWheelDetails& wheel) **override** ;

**void** mouseMagnify( **const** MouseEvent& event, **float** scaleFactor) **override** ;

**void** performZoom( **float** zoomFactor);

**void** performScroll( **float** scrollFactor);

    struct CommandModel
    {
        CommandModel() = default;
        virtual ~CommandModel() {}

        virtual ModifierKeys getScrollModifierKeysCommand() { return ModifierKeys::noModifiers; }
        virtual ModifierKeys getZoomModifierKeysCommand()   { return ModifierKeys::noModifiers; }
        virtual ModifierKeys getScrollModifierKeysAction()  { return ModifierKeys::altModifier;  }
        virtual ModifierKeys getZoomModifierKeysAction()    { return ModifierKeys::altModifier; }
        
        virtual KeyPress getRightScrollKeys()               { return KeyPress(KeyPress::rightKey); }
        virtual KeyPress getLeftScrollKeys()                { return KeyPress(KeyPress::leftKey); }
        virtual KeyPress getZoomInKeys()                    { return KeyPress('h'); }
        virtual KeyPress getZoomOutKeys()                   { return KeyPress('g'); }
    };
    
    void changeCommandModel(CommandModel* model)
    {
        commandModel.release();
        commandModel.reset(model);
    }
    
    CommandModel* removeCommandModel()  { return commandModel.release(); }
    
    
    ApplicationCommandTarget* getNextCommandTarget() override { return nullptr; }
    void getAllCommands (Array<CommandID>& commands) override;
    void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result) override;
    bool perform (const InvocationInfo& info) override;
**private** :

tracktion_engine::TempoSequence& sequence;
    
    float zoom = 1.0;
    float xScroll = 0.0, dragFactor = 0.0;
    
    std::unique_ptr<DesignerModel> designerModel{new DesignerModel()};
    std::unique_ptr<CommandModel> commandModel{new CommandModel()};
};

In MyComponent.cpp:

MyComponent::MyComponent(tracktion_engine::TempoSequence& TempoSequence) : sequence(TempoSequence)
{
   //... 
}

MyComponent::~MyComponent() {}

void MyComponent::paint (Graphics& g) {}

void MyComponent::resized() {}

void MyComponent::mouseDown(const MouseEvent& event)
{
    grabKeyboardFocus();
}

void MyComponent::mouseDrag(const MouseEvent& event)
{
    //...
}

void MyComponent::mouseUp(const MouseEvent& event)
{
    //...
}

void MyComponent::mouseWheelMove(const MouseEvent& event, const MouseWheelDetails& wheel)
{
    //...
}

void MyComponent::mouseMagnify(const MouseEvent& event, float scaleFactor)
{
    //...
}

void MyComponent::performZoom(float zoomFactor)
{
    //...
}

void MyComponent::performScroll(float scrollFactor)
{
    //...
}

void MyComponent::getAllCommands (Array<CommandID>& commands)
{
    Array<CommandID> ids { KeyPressCommandIDs::rightScroll, KeyPressCommandIDs::leftScroll, KeyPressCommandIDs::zoomIn, KeyPressCommandIDs::zoomOut };

    commands.addArray(ids);
}

void MyComponent::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
{

    switch (commandID)
        {
            case KeyPressCommandIDs::rightScroll:
                result.setInfo ("Scroll Forward", "Scroll timeline Foreward", "Scroll", 0);
                result.addDefaultKeypress (commandModel->getRightScrollKeys().getKeyCode(), commandModel->getScrollModifierKeysCommand().getRawFlags());
                break;
            case KeyPressCommandIDs::leftScroll:
                result.setInfo ("Scroll Backward", "Scroll timeline Backward", "Scroll", 0);
                result.addDefaultKeypress (commandModel->getLeftScrollKeys().getKeyCode(), commandModel->getScrollModifierKeysCommand().getRawFlags());
                break;
            case KeyPressCommandIDs::zoomIn:
                result.setInfo ("Zoom In", "Zoom timeline In", "Zoom", 0);
                result.addDefaultKeypress (commandModel->getLeftScrollKeys().getKeyCode(), commandModel->getZoomModifierKeysCommand().getRawFlags());
                break;
            case KeyPressCommandIDs::zoomOut:
                result.setInfo ("Zoom Out", "Zoom timeline Out", "Zoom", 0);
                result.addDefaultKeypress (commandModel->getLeftScrollKeys().getKeyCode(), commandModel->getZoomModifierKeysCommand().getRawFlags());
                break;
            default:
                break;
        }
}

bool MyComponent::perform (const InvocationInfo& info)
{
    float factor = getNumPixelsForMovement();
    
    switch (info.commandID)
    {
        case KeyPressCommandIDs::rightScroll:
            performScroll(factor);
            break;
        case KeyPressCommandIDs::leftScroll:
            performScroll(-factor);
            break;
        case KeyPressCommandIDs::zoomIn:
            performZoom(factor);
            break;
        case KeyPressCommandIDs::zoomOut:
            performZoom(-factor);
            break;
        default:
            return false;
    }

    return true;    
}

In MainComponent:

**class** MainComponent : **public** Component

{

**public** :

MainComponent();

~MainComponent();

**void** paint (Graphics&) **override** ;

**void** resized() **override** ;

**private** :

tracktion_engine::Engine engine{ProjectInfo::projectName};

std::unique_ptr<tracktion_engine::Edit> edit;

std::unique_ptr<tracktion_engine::TransportControl> transportControl;

std::unique_ptr<MyComponent> myComponent;

ApplicationCommandManager commandManager;
};

in MainComponent.cpp:

MainComponent::MainComponent()
{
    setSize (1000, 600);
    edit.reset(new tracktion_engine::Edit{engine, tracktion_engine::createEmptyEdit(), tracktion_engine::Edit::forEditing, nullptr, 0});
    
    transportControl.reset(&edit->getTransport());
    
    myComponent.reset(new MyComponent(edit->tempoSequence));
    commandManager.registerAllCommandsForTarget(myComponent.get());
    
    addAndMakeVisible(myComponent.get());
    getTopLevelComponent()->addKeyListener(commandManager.getKeyMappings());
    
   resized();
}

MainComponent::~MainComponent() {}

void MainComponent::paint (Graphics& g) {}

void MainComponent::resized()
{
    if(myComponent.get()) { myComponent->setBounds(getLocalBounds()); }
}

Sorry again!

anyone has any ideas about it? :slight_smile: