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

Adds support for MIDI CC events inside LMMS #5581

Merged
merged 51 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
374abf2
First commit
IanCaio Jul 10, 2020
f1603ea
Updates the MIDI CC Rack GUI
IanCaio Jul 11, 2020
53fe0d0
Keeps working on the MIDI CC Rack GUI
IanCaio Jul 11, 2020
755cf12
Add class members
IanCaio Jul 11, 2020
7599fec
Starts implementing the track ComboBox syncing
IanCaio Jul 11, 2020
fb71375
Updates tracks ComboBox when tracks are moved
IanCaio Jul 12, 2020
c58fbbe
Merge branch 'master' into feature/midiCCSupport
IanCaio Jul 12, 2020
a309207
Merge branch 'master' into feature/midiCCSupport
IanCaio Jul 12, 2020
cfead27
Starts implementing the CC controllers models
IanCaio Jul 13, 2020
f73d42f
Implements the CC event handling itself
IanCaio Jul 14, 2020
72addfe
Adds the enable/disable functionality for MIDI CC
IanCaio Jul 14, 2020
65a2bc0
Changes shortcuts and titles
IanCaio Jul 14, 2020
7546e22
Merge branch 'master' into feature/midiCCSupport
IanCaio Jul 14, 2020
f2d5302
Removes unused comment
IanCaio Jul 14, 2020
15141a9
Fix SEGFAULT bug and hide MIDI CC rack at start up
IanCaio Jul 14, 2020
6dc7018
Save/Load MIDI controllers models on project file
IanCaio Jul 15, 2020
cedcf6b
Uses lambda functions instead of QSignalMapper
IanCaio Jul 15, 2020
0ff2835
Corrects tooltip of MIDI CC rack
IanCaio Jul 15, 2020
64c83ff
Removes unused header
IanCaio Jul 15, 2020
36a6de3
Includes the MIDI CC Rack in the View Menu
IanCaio Jul 18, 2020
73216f4
Merge branch 'master' into feature/midiCCSupport
IanCaio Aug 2, 2020
c40fc49
Replaces constant with existent one from Midi.h
IanCaio Aug 3, 2020
e0a3939
Processes MIDI CC rack events as hardware ones
IanCaio Aug 3, 2020
d18b25b
Merge branch 'master' into feature/midiCCSupport
IanCaio Sep 9, 2020
6abd130
Fixes a Segmentation Fault bug
IanCaio Sep 9, 2020
279832a
Merge branch 'master' into feature/midiCCSupport
IanCaio Sep 13, 2020
56363bf
Fixes mistake on processInEvent logic
IanCaio Sep 13, 2020
91d9d06
Fixes memory leak and "used ID" bug
IanCaio Sep 14, 2020
df544ee
Merge branch 'master' into feature/midiCCSupport
IanCaio Sep 20, 2020
39c21b6
Changes MIDI CC Rack GUI
IanCaio Sep 21, 2020
b3e2479
Fixes bug where CC events are ignored on export
IanCaio Sep 21, 2020
527a959
Removes argument from MidiEvent copy constructor
IanCaio Sep 22, 2020
b8081a4
Changes variable fromHardware to ignoreOnExport
IanCaio Nov 16, 2020
19018c3
Remove unused signals
IanCaio Nov 16, 2020
23911d2
Randomizes MIDI CC rack position
IanCaio Nov 16, 2020
b104f99
Merge branch 'master' into feature/midiCCSupport
IanCaio Nov 16, 2020
c0a5c66
Merge branch 'master' into feature/midiCCSupport
IanCaio Nov 24, 2020
aba42c2
Fixes some code style issues
IanCaio Nov 24, 2020
babeb8e
Merge branch 'master' into feature/midiCCSupport
IanCaio Nov 29, 2020
d791b7e
Moves MidiCCRackView.cpp to src/gui
IanCaio Nov 29, 2020
df71382
Removes track label and increases knobs per row
IanCaio Nov 29, 2020
7d78af8
Adds tr and remove unnecessary QString conversions
IanCaio Nov 29, 2020
c928f97
Uses std::unique_ptr for the MIDI CC models
IanCaio Nov 29, 2020
aa6345b
Implements the MidiCCRackView destructor
IanCaio Nov 29, 2020
2e2b7c0
Uses lazy creation on the MidiCCRackView
IanCaio Nov 29, 2020
f4e5662
Merge branch 'master' into feature/midiCCSupport
IanCaio Nov 30, 2020
9d1aab6
Changes access specifiers and destructor
IanCaio Nov 30, 2020
6bc6d8b
Changes MIDI CC Rack icon
IanCaio Nov 30, 2020
2c6a55f
Uses the MIDI CC icon on the menu action too
IanCaio Nov 30, 2020
4a4cead
Reorganizes included headers
IanCaio Nov 30, 2020
291ebc4
Changes code to use std::make_unique
IanCaio Nov 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/themes/classic/midi_cc_rack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/default/midi_cc_rack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions include/AutomatableModelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LMMS_EXPORT AutomatableModelView : public ModelView
}

void setModel( Model* model, bool isOldModelValid = true ) override;
void unsetModel() override;

template<typename T>
inline T value() const
Expand Down
11 changes: 10 additions & 1 deletion include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "GroupBox.h"
#include "InstrumentFunctions.h"
#include "InstrumentSoundShaping.h"
#include "Midi.h"
#include "MidiCCRackView.h"
#include "MidiEventProcessor.h"
#include "MidiPort.h"
#include "NotePlayHandle.h"
Expand Down Expand Up @@ -229,7 +231,6 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
void newNote();
void endNote();


protected:
QString nodeName() const override
{
Expand All @@ -248,6 +249,8 @@ protected slots:


private:
void processCCEvent(int controller);

MidiPort m_midiPort;

NotePlayHandle* m_notes[NumKeys];
Expand Down Expand Up @@ -287,11 +290,14 @@ protected slots:

Piano m_piano;

std::unique_ptr<BoolModel> m_midiCCEnable;
std::unique_ptr<FloatModel> m_midiCCModel[MidiControllerCount];

friend class InstrumentTrackView;
friend class InstrumentTrackWindow;
friend class NotePlayHandle;
friend class InstrumentMiscView;
friend class MidiCCRackView;

} ;

Expand Down Expand Up @@ -339,6 +345,7 @@ class InstrumentTrackView : public TrackView

private slots:
void toggleInstrumentWindow( bool _on );
void toggleMidiCCRack();
void activityIndicatorPressed();
void activityIndicatorReleased();

Expand Down Expand Up @@ -366,6 +373,8 @@ private slots:
QAction * m_midiInputAction;
QAction * m_midiOutputAction;

std::unique_ptr<MidiCCRackView> m_midiCCRackView;

QPoint m_lastPos;

FadeButton * getActivityIndicator() override
Expand Down
40 changes: 40 additions & 0 deletions include/MidiCCRackView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef MIDI_CC_RACK_VIEW_H
#define MIDI_CC_RACK_VIEW_H

#include <QWidget>

#include "GroupBox.h"
#include "Knob.h"
#include "Midi.h"
#include "SerializingObject.h"

class InstrumentTrack;

class MidiCCRackView : public QWidget, public SerializingObject
{
Q_OBJECT
public:
MidiCCRackView(InstrumentTrack * track);
~MidiCCRackView() override;

void saveSettings(QDomDocument & doc, QDomElement & parent) override;
void loadSettings(const QDomElement &) override;

inline QString nodeName() const override
{
return "MidiCCRackView";
}

private slots:
void renameWindow();
IanCaio marked this conversation as resolved.
Show resolved Hide resolved

private:
InstrumentTrack *m_track;

GroupBox *m_midiCCGroupBox; // MIDI CC GroupBox (used to enable disable MIDI CC)

Knob *m_controllerKnob[MidiControllerCount]; // Holds the knob widgets for each controller

};

#endif
29 changes: 23 additions & 6 deletions include/MidiEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,30 @@
class MidiEvent
{
public:
MidiEvent( MidiEventTypes type = MidiActiveSensing,
MidiEvent(MidiEventTypes type = MidiActiveSensing,
int8_t channel = 0,
int16_t param1 = 0,
int16_t param2 = 0,
const void* sourcePort = NULL ) :
const void* sourcePort = nullptr,
bool ignoreOnExport = true) :
m_type( type ),
m_metaEvent( MidiMetaInvalid ),
m_channel( channel ),
m_sysExData( NULL ),
m_sourcePort( sourcePort )
m_sourcePort(sourcePort),
m_ignoreOnExport(ignoreOnExport)
{
m_data.m_param[0] = param1;
m_data.m_param[1] = param2;
}

MidiEvent( MidiEventTypes type, const char* sysExData, int dataLen ) :
MidiEvent(MidiEventTypes type, const char* sysExData, int dataLen, bool ignoreOnExport = true) :
m_type( type ),
m_metaEvent( MidiMetaInvalid ),
m_channel( 0 ),
m_sysExData( sysExData ),
m_sourcePort( NULL )
m_sourcePort(nullptr),
m_ignoreOnExport(ignoreOnExport)
{
m_data.m_sysExDataLen = dataLen;
}
Expand All @@ -64,7 +67,8 @@ class MidiEvent
m_channel( other.m_channel ),
m_data( other.m_data ),
m_sysExData( other.m_sysExData ),
m_sourcePort( other.m_sourcePort )
m_sourcePort(other.m_sourcePort),
m_ignoreOnExport(other.m_ignoreOnExport)
{
}

Expand Down Expand Up @@ -190,6 +194,16 @@ class MidiEvent
setParam( 0, pitchBend );
}

bool ignoreOnExport() const
{
return m_ignoreOnExport;
}

void setIgnoreOnExport(bool value)
{
m_ignoreOnExport = value;
}


private:
MidiEventTypes m_type; // MIDI event type
Expand All @@ -205,6 +219,9 @@ class MidiEvent
const char* m_sysExData;
const void* m_sourcePort;

// This helps us ignore MIDI events that shouldn't be processed
// during a project export, like physical controller events.
bool m_ignoreOnExport;
} ;

#endif
1 change: 1 addition & 0 deletions include/ModelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class LMMS_EXPORT ModelView
virtual ~ModelView();

virtual void setModel( Model* model, bool isOldModelValid = true );
virtual void unsetModel();

Model* model()
{
Expand Down
25 changes: 25 additions & 0 deletions src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,31 @@ void AutomatableModelView::setModel( Model* model, bool isOldModelValid )



// Unsets the current model by setting a dummy empty model. The dummy model is marked as
// "defaultConstructed", so the next call to setModel will delete it.
void AutomatableModelView::unsetModel()
{
if (dynamic_cast<FloatModelView*>(this))
{
setModel(new FloatModel(0, 0, 0, 1, nullptr, QString(), true));
}
else if (dynamic_cast<IntModelView*>(this))
{
setModel(new IntModel(0, 0, 0, nullptr, QString(), true));
}
else if (dynamic_cast<BoolModelView*>(this))
{
setModel(new BoolModel(false, nullptr, QString(), true));
}
else
{
ModelView::unsetModel();
}
}




void AutomatableModelView::mousePressEvent( QMouseEvent* event )
{
if( event->button() == Qt::LeftButton && event->modifiers() & Qt::ControlModifier )
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SET(LMMS_SRCS
gui/Lv2ViewBase.cpp
gui/MainApplication.cpp
gui/MainWindow.cpp
gui/MidiCCRackView.cpp
gui/MidiSetupWidget.cpp
gui/ModelView.cpp
gui/PeakControllerDialog.cpp
Expand Down
133 changes: 133 additions & 0 deletions src/gui/MidiCCRackView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* MidiCCRackView.cpp - implementation of the MIDI CC rack widget
*
* Copyright (c) 2020 Ian Caio <iancaio_dev/at/hotmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/


#include "MidiCCRackView.h"

#include <QGridLayout>
#include <QMdiSubWindow>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QWidget>

#include "embed.h"
#include "GroupBox.h"
#include "GuiApplication.h"
#include "InstrumentTrack.h"
#include "Knob.h"
#include "MainWindow.h"
#include "Track.h"


MidiCCRackView::MidiCCRackView(InstrumentTrack * track) :
QWidget(),
m_track(track)
{
setWindowIcon(embed::getIconPixmap("midi_cc_rack"));
setWindowTitle(tr("MIDI CC Rack - %1").arg(m_track->name()));

QMdiSubWindow * subWin = gui->mainWindow()->addWindowedWidget(this);

// Remove maximize button
Qt::WindowFlags flags = subWin->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;
subWin->setWindowFlags(flags);

// Adjust window attributes, sizing and position
subWin->setAttribute(Qt::WA_DeleteOnClose, false);
subWin->resize(350, 300);
subWin->setFixedWidth(350);
subWin->setMinimumHeight(300);
subWin->hide();

// Main window layout
QVBoxLayout *mainLayout = new QVBoxLayout(this);

// Knobs GroupBox - Here we have the MIDI CC controller knobs for the selected track
m_midiCCGroupBox = new GroupBox(tr("MIDI CC Knobs:"));

// Layout to keep scrollable area under the GroupBox header
QVBoxLayout *knobsGroupBoxLayout = new QVBoxLayout();
knobsGroupBoxLayout->setContentsMargins(5, 16, 5, 5);

m_midiCCGroupBox->setLayout(knobsGroupBoxLayout);

// Scrollable area + widget + its layout that will have all the knobs
QScrollArea *knobsScrollArea = new QScrollArea();
QWidget *knobsArea = new QWidget();
QGridLayout *knobsAreaLayout = new QGridLayout();

knobsArea->setLayout(knobsAreaLayout);
knobsScrollArea->setWidget(knobsArea);
knobsScrollArea->setWidgetResizable(true);

knobsGroupBoxLayout->addWidget(knobsScrollArea);

// Adds the controller knobs
for (int i = 0; i < MidiControllerCount; ++i)
{
m_controllerKnob[i] = new Knob(knobBright_26);
m_controllerKnob[i]->setLabel(tr("CC %1").arg(i));
knobsAreaLayout->addWidget(m_controllerKnob[i], i/4, i%4);
}

// Set all the models
// Set the LED button to enable/disable the track midi cc
m_midiCCGroupBox->setModel(m_track->m_midiCCEnable.get());

// Set the model for each Knob
for (int i = 0; i < MidiControllerCount; ++i)
{
m_controllerKnob[i]->setModel(m_track->m_midiCCModel[i].get());
}

// Connection to update the name of the track on the label
connect(m_track, SIGNAL(nameChanged()),
this, SLOT(renameWindow()));

// Adding everything to the main layout
mainLayout->addWidget(m_midiCCGroupBox);
}

MidiCCRackView::~MidiCCRackView()
{
if(parentWidget())
{
parentWidget()->hide();
parentWidget()->deleteLater();
}
}

void MidiCCRackView::renameWindow()
{
setWindowTitle(tr("MIDI CC Rack - %1").arg(m_track->name()));
}

void MidiCCRackView::saveSettings(QDomDocument & doc, QDomElement & parent)
{
}

void MidiCCRackView::loadSettings(const QDomElement &)
{
}
10 changes: 10 additions & 0 deletions src/gui/ModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ void ModelView::setModel( Model* model, bool isOldModelValid )



// Unsets the current model by setting a dummy empty model. The dummy model is marked as
// "defaultConstructed", so the next call to setModel will delete it.
void ModelView::unsetModel()
{
setModel(new Model(nullptr, QString(), true));
}




void ModelView::doConnections()
{
if( m_model != NULL )
Expand Down
Loading