Skip to content

Commit

Permalink
Merge branch 'master' into feature/clipboardRefactor
Browse files Browse the repository at this point in the history
	Resolves the conflict on src/tracks/Pattern.cpp caused by LMMS#5619. On this PR the only change to the file was removing an unnecessary include of the header "StringPairDrag.h", which the PR LMMS#5619 also did. So the file was kept the same way as in the master branch.
  • Loading branch information
IanCaio committed Sep 13, 2020
2 parents 4e05470 + 9eb787c commit 408b470
Show file tree
Hide file tree
Showing 47 changed files with 2,838 additions and 1,841 deletions.
63 changes: 63 additions & 0 deletions include/DeprecationHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* DeprecationHelper.h - This file contains the declarations of helper functions
* which helps centralize the #ifdefs preprocessors regarding deprecation based on Qt versions.
* The functions are defined differently based on the callers' Qt versions.
*
* Copyright (c) 2020 Tien Dat Nguyen <ntd.bk.k56/at/gmail.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.
*
*/

#ifndef DEPRECATIONHELPER_H
#define DEPRECATIONHELPER_H

#include <QFontMetrics>
#include <QWheelEvent>

/**
* @brief horizontalAdvance is a backwards-compatible adapter for
* QFontMetrics::horizontalAdvance and width functions.
* @param metrics
* @param text
* @return text's horizontal advance based on metrics.
*/
inline int horizontalAdvance(const QFontMetrics& metrics, const QString& text)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
return metrics.horizontalAdvance(text);
#else
return metrics.width(text);
#endif
}

/**
* @brief position is a backwards-compatible adapter for
* QWheelEvent::position and pos functions.
* @param wheelEvent
* @return the position of wheelEvent
*/
inline QPoint position(QWheelEvent *wheelEvent)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return wheelEvent->position().toPoint();
#else
return wheelEvent->pos();
#endif
}
#endif // DEPRECATIONHELPER_H
8 changes: 4 additions & 4 deletions include/FadeButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#ifndef FADE_BUTTON_H
#define FADE_BUTTON_H

#include <QtCore/QTime>
#include <QAbstractButton>
#include <QColor>
#include <QElapsedTimer>


class FadeButton : public QAbstractButton
Expand All @@ -55,8 +55,8 @@ public slots:


private:
QTime m_stateTimer;
QTime m_releaseTimer;
QElapsedTimer m_stateTimer;
QElapsedTimer m_releaseTimer;

// the default color of the widget
QColor m_normalColor;
Expand All @@ -66,7 +66,7 @@ public slots:
QColor m_holdColor;
int activeNotes;

QColor fadeToColor(QColor, QColor, QTime, float);
QColor fadeToColor(QColor, QColor, QElapsedTimer, float);

} ;

Expand Down
11 changes: 6 additions & 5 deletions include/Fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
#ifndef FADER_H
#define FADER_H

#include <QtCore/QTime>
#include <QWidget>
#include <QElapsedTimer>
#include <QPixmap>
#include <QWidget>


#include "AutomatableModelView.h"

Expand Down Expand Up @@ -130,7 +131,7 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
return height() - ( ( height() - m_knob->height() ) * ( realVal / fRange ) );
}

void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QTime &lastPeakTime );
void setPeak( float fPeak, float &targetPeak, float &persistentPeak, QElapsedTimer &lastPeakTimer );
int calculateDisplayPeak( float fPeak );

void updateTextFloat();
Expand All @@ -144,8 +145,8 @@ class LMMS_EXPORT Fader : public QWidget, public FloatModelView
float m_fMinPeak;
float m_fMaxPeak;

QTime m_lastPeakTime_L;
QTime m_lastPeakTime_R;
QElapsedTimer m_lastPeakTimer_L;
QElapsedTimer m_lastPeakTimer_R;

static QPixmap * s_back;
static QPixmap * s_leds;
Expand Down
3 changes: 1 addition & 2 deletions include/FileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class LMMS_EXPORT FileDialog : public QFileDialog
const QString &caption = QString(),
const QString &directory = QString(),
const QString &filter = QString(),
QString *selectedFilter = 0,
QFileDialog::Options options = 0);
QString *selectedFilter = 0);
void clearSelection();
};

Expand Down
2 changes: 1 addition & 1 deletion include/LinkedModelGroupViews.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LinkedModelGroupsView
void modelChanged(class LinkedModelGroups* ctrlBase);

private:
//! The base class must return the adressed group view,
//! The base class must return the addressed group view,
//! which has the same value as "this"
virtual LinkedModelGroupView* getGroupView() = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion include/LinkedModelGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/**
Base class for a group of linked models
See the LinkedModelGroup class for explenations
See the LinkedModelGroup class for explanations
Features:
* Models are stored by their QObject::objectName
Expand Down
2 changes: 1 addition & 1 deletion include/Lv2ControlBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PluginIssue;
This class would usually be a Model subclass. However, Qt doesn't allow
this:
* inhertiting only from Model will cause diamond inheritance for QObject,
* inheriting only from Model will cause diamond inheritance for QObject,
which will cause errors with Q_OBJECT
* making this a direct subclass of Instrument resp. EffectControls would
require CRTP, which would make this class a template class, which would
Expand Down
2 changes: 1 addition & 1 deletion include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MainWindow : public QMainWindow
void addSpacingToToolBar( int _size );

// wrap the widget with a window decoration and add it to the workspace
LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags=0);
LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags = QFlag(0));


///
Expand Down
6 changes: 3 additions & 3 deletions include/StepRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef STEP_RECORDER_H
#define STEP_RECORDER_H

#include <QTime>
#include <QElapsedTimer>
#include <QTimer>
#include <QObject>
#include <QKeyEvent>
Expand Down Expand Up @@ -130,7 +130,7 @@ class StepRecorder : public QObject

private:
bool m_pressed;
QTime releasedTimer;
QElapsedTimer releasedTimer;
} ;

QVector<StepNote*> m_curStepNotes; // contains the current recorded step notes (i.e. while user still press the notes; before they are applied to the pattern)
Expand All @@ -140,4 +140,4 @@ class StepRecorder : public QObject
bool m_isStepInProgress = false;
};

#endif //STEP_RECORDER_H
#endif //STEP_RECORDER_H
2 changes: 1 addition & 1 deletion include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow
Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor )

public:
SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = 0 );
SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = QFlag(0) );
// same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
QRect getTrueNormalGeometry() const;
QBrush activeColor() const;
Expand Down
2 changes: 1 addition & 1 deletion plugins/GigPlayer/PatchesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PatchesDialog : public QDialog, private Ui::PatchesDialog
public:

// Constructor.
PatchesDialog( QWidget * pParent = 0, Qt::WindowFlags wflags = 0 );
PatchesDialog(QWidget * pParent = 0, Qt::WindowFlags wflags = QFlag(0));

// Destructor.
virtual ~PatchesDialog();
Expand Down
49 changes: 26 additions & 23 deletions plugins/MidiImport/MidiImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QProgressDialog>

#include <sstream>
#include <unordered_map>

#include "MidiImport.h"
#include "TrackContainer.h"
Expand Down Expand Up @@ -305,7 +306,7 @@ class smfMidiChannel

bool MidiImport::readSMF( TrackContainer* tc )
{

const int MIDI_CC_COUNT = 128 + 1; // 0-127 (128) + pitch bend
const int preTrackSteps = 2;
QProgressDialog pd( TrackContainer::tr( "Importing MIDI-file..." ),
TrackContainer::tr( "Cancel" ), 0, preTrackSteps, gui->mainWindow() );
Expand All @@ -315,19 +316,20 @@ bool MidiImport::readSMF( TrackContainer* tc )

pd.setValue( 0 );

std::stringstream stream;
QByteArray arr = readAllData();
stream.str(std::string(arr.constData(), arr.size()));

std::istringstream stream(readAllData().toStdString());
Alg_seq_ptr seq = new Alg_seq(stream, true);
seq->convert_to_beats();

pd.setMaximum( seq->tracks() + preTrackSteps );
pd.setValue( 1 );

// 128 CC + Pitch Bend
smfMidiCC ccs[129];
smfMidiChannel chs[256];
smfMidiCC ccs[MIDI_CC_COUNT];

// channels can be set out of 256 range
// using unordered_map should fix most invalid loads and crashes while loading
std::unordered_map<long, smfMidiChannel> chs;
// NOTE: unordered_map::operator[] creates a new element if none exists

MeterModel & timeSigMM = Engine::getSong()->getTimeSigModel();
AutomationTrack * nt = dynamic_cast<AutomationTrack*>(
Expand Down Expand Up @@ -407,7 +409,7 @@ bool MidiImport::readSMF( TrackContainer* tc )
Alg_track_ptr trk = seq->track( t );
pd.setValue( t + preTrackSteps );

for( int c = 0; c < 129; c++ )
for( int c = 0; c < MIDI_CC_COUNT; c++ )
{
ccs[c].clear();
}
Expand All @@ -423,7 +425,10 @@ bool MidiImport::readSMF( TrackContainer* tc )
if( evt->is_update() )
{
QString attr = evt->get_attribute();
if( attr == "tracknames" && evt->get_update_type() == 's' ) {
// seqnames is a track0 identifier (see allegro code)
if (attr == (t == 0 ? "seqnames" : "tracknames")
&& evt->get_update_type() == 's')
{
trackName = evt->get_string_value();
handled = true;
}
Expand All @@ -444,7 +449,7 @@ bool MidiImport::readSMF( TrackContainer* tc )
printf( "\n" );
}
}
else if( evt->is_note() && evt->chan < 256 )
else if (evt->is_note())
{
smfMidiChannel * ch = chs[evt->chan].create( tc, trackName );
Alg_note_ptr noteEvt = dynamic_cast<Alg_note_ptr>( evt );
Expand Down Expand Up @@ -558,28 +563,26 @@ bool MidiImport::readSMF( TrackContainer* tc )
delete seq;


for( int c=0; c < 256; ++c )
for( auto& c: chs )
{
if (chs[c].hasNotes)
if (c.second.hasNotes)
{
chs[c].splitPatterns();
c.second.splitPatterns();
}
else if (chs[c].it)
else if (c.second.it)
{
printf(" Should remove empty track\n");
// must delete trackView first - but where is it?
//tc->removeTrack( chs[c].it );
//it->deleteLater();
}
}

// Set channel 10 to drums as per General MIDI's orders
if( chs[9].hasNotes && chs[9].it_inst && chs[9].isSF2 )
{
// AFAIK, 128 should be the standard bank for drums in SF2.
// If not, this has to be made configurable.
chs[9].it_inst->childModel( "bank" )->setValue( 128 );
chs[9].it_inst->childModel( "patch" )->setValue( 0 );
// Set channel 10 to drums as per General MIDI's orders
if (c.first % 16l == 9 /* channel 10 */
&& c.second.hasNotes && c.second.it_inst && c.second.isSF2)
{
c.second.it_inst->childModel("bank")->setValue(128);
c.second.it_inst->childModel("patch")->setValue(0);
}
}

return true;
Expand Down
9 changes: 5 additions & 4 deletions plugins/MidiImport/portsmf/algrd_internal.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* algread_internal.h -- interface between allegro.cpp and allegrord.cpp */

Alg_error alg_read(std::istream &file, Alg_seq_ptr new_seq);

/* algread_internal.h -- interface between allegro.cpp and allegrord.cpp */

Alg_error alg_read(std::istream &file, Alg_seq_ptr new_seq,
double *offset_ptr = NULL);

Loading

0 comments on commit 408b470

Please sign in to comment.