Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to connect last changed model to AutomationClip #7622

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
10 changes: 9 additions & 1 deletion include/AutomatableModelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LMMS_EXPORT AutomatableModelView : public ModelView
{
public:
AutomatableModelView( Model* model, QWidget* _this );
~AutomatableModelView() override = default;
~AutomatableModelView() override;

// some basic functions for convenience
AutomatableModel* modelUntyped()
Expand Down Expand Up @@ -76,13 +76,21 @@ class LMMS_EXPORT AutomatableModelView : public ModelView
void setConversionFactor( float factor );
float getConversionFactor();

static AutomatableModel* lastChangedModel()
{
return s_lastChangedModel;
}


protected:
virtual void mousePressEvent( QMouseEvent* event );

QString m_description;
QString m_unit;
float m_conversionFactor; // Factor to be applied when the m_model->value is displayed

private:
inline static AutomatableModel* s_lastChangedModel = nullptr;
} ;


Expand Down
1 change: 1 addition & 0 deletions include/AutomationClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected slots:
void toggleRecording();
void flipY();
void flipX();
void connectLastChangedModel();

protected:
void constructContextMenu( QMenu * ) override;
Expand Down
1 change: 1 addition & 0 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "LocaleHelper.h"
#include "ProjectJournal.h"
#include "Song.h"
#include <QDebug>

namespace lmms
{
Expand Down
13 changes: 13 additions & 0 deletions src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ AutomatableModelView::AutomatableModelView( Model* model, QWidget* _this ) :
{
widget()->setAcceptDrops( true );
widget()->setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) );
if (modelUntyped() != nullptr)
{
QObject::connect(modelUntyped(), &AutomatableModel::dataChanged, [this](){ s_lastChangedModel = modelUntyped(); });
}
}

AutomatableModelView::~AutomatableModelView()
{
if (s_lastChangedModel != nullptr && s_lastChangedModel == modelUntyped()) { s_lastChangedModel = nullptr; }
}

void AutomatableModelView::addDefaultActions( QMenu* menu )
Expand Down Expand Up @@ -138,6 +147,10 @@ void AutomatableModelView::addDefaultActions( QMenu* menu )

void AutomatableModelView::setModel( Model* model, bool isOldModelValid )
{
if (model != nullptr && model != modelUntyped())
{
QObject::connect(model, &AutomatableModel::dataChanged, [this](){ s_lastChangedModel = modelUntyped(); });
}
ModelView::setModel( model, isOldModelValid );
}

Expand Down
29 changes: 29 additions & 0 deletions src/gui/clips/AutomationClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QMenu>

#include "AutomationEditor.h"
#include "AutomatableModelView.h"
#include "embed.h"
#include "GuiApplication.h"
#include "ProjectJournal.h"
Expand Down Expand Up @@ -100,6 +101,26 @@ void AutomationClipView::changeName()



void AutomationClipView::connectLastChangedModel()
{
if (AutomatableModelView::lastChangedModel() != nullptr)
{
bool added = m_clip->addObject(AutomatableModelView::lastChangedModel());
if (added)
{
update();
}
else
{
TextFloat::displayMessage(AutomatableModelView::lastChangedModel()->displayName(),
tr("Model is already connected to this clip."),
embed::getIconPixmap("automation"),
2000);
}
}
}



void AutomationClipView::disconnectObject( QAction * _a )
{
Expand Down Expand Up @@ -185,6 +206,14 @@ void AutomationClipView::constructContextMenu( QMenu * _cm )
_cm->addAction( embed::getIconPixmap( "flip_x" ),
tr( "Flip Horizontally (Visible)" ),
this, SLOT(flipX()));
if (AutomatableModelView::lastChangedModel() != nullptr)
{
_cm->addAction(tr("Connect last changed model (%1)").arg(
!AutomatableModelView::lastChangedModel()->displayName().isEmpty()
? AutomatableModelView::lastChangedModel()->fullDisplayName()
: "Unknown Model Name"),
this, &AutomationClipView::connectLastChangedModel);
}
if (!m_clip->m_objects.empty())
{
_cm->addSeparator();
Expand Down
Loading