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

MIDI range MKII (extracted from microtonal PR) #5868

Merged
merged 26 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
78a587b
Initial batch, mostly non-conflicting files
he29-net Dec 31, 2020
911b137
Batch 2
he29-net Dec 31, 2020
4443733
Batch 3 + selectively comment out Microtuner occurences
he29-net Dec 31, 2020
0b9a902
Fix issues in InstrumentTrack.cpp
he29-net Jan 1, 2021
8834884
Revert lmms_constants.h (changes not needed here)
he29-net Jan 1, 2021
0602882
Fixes in preset and Piano* classes
he29-net Jan 1, 2021
33bad8a
Implement temporary out-of-range keys drawing in PianoView
he29-net Jan 1, 2021
2d0c787
Implement out-of-range key drawing for PianoRoll
he29-net Jan 1, 2021
6771dda
Fix double application of the upgrade routine on the first instrument…
he29-net Jan 2, 2021
a8292fe
Fix and clean the default project template
he29-net Jan 4, 2021
0394a6d
Avoid playing out-of-range notes; add missing range saving / loading;…
he29-net Jan 23, 2021
49fa1d8
Update src/gui/PianoView.cpp
he29-net Jan 23, 2021
4cb8f7f
Fix the out-of-range avoidance condition
he29-net Jan 23, 2021
46c1b46
Add upgrade routine for VeSTige, LV2 and Carla presets
he29-net Jan 24, 2021
59317da
The Great Purge (and a modified preset upgrade routine)
he29-net Jan 25, 2021
5d5de8c
Update src/core/DataFile.cpp
he29-net Jan 27, 2021
d9d3f44
Update src/gui/editors/PianoRoll.cpp
he29-net Jan 28, 2021
f6687f9
Unified check if an instrument is affected by MIDI range change
he29-net Feb 16, 2021
ba0903f
Update src/core/DataFile.cpp
he29-net Feb 17, 2021
0df3f42
Merge branch 'master' into midi_range_2
he29-net Mar 11, 2021
3ca536c
Update src/gui/PianoView.cpp (fix typo)
he29-net Mar 11, 2021
f83e272
Add a comment explaining the computation of maximum PianoView width.
he29-net Mar 11, 2021
48ba16a
Merge branch 'master' into midi_range_2
he29-net Apr 6, 2021
1ebf7a3
Fix note descriptions in Xpressive
he29-net Nov 13, 2020
a5e4dc0
Simplify out-of-range note release
he29-net Apr 18, 2021
b303d9f
Purge most of the microtuner-related commented-out code
he29-net Apr 19, 2021
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/black_key_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ PianoRoll {
qproperty-whiteKeyInactiveTextColor: rgb( 128, 128, 128);
qproperty-whiteKeyInactiveTextShadow: rgb( 240, 240, 240 );
qproperty-whiteKeyInactiveBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #eeeeee, stop:1 #ffffff);
qproperty-whiteKeyDisabledBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #a0a0a0, stop:1 #b0b0b0);
qproperty-blackKeyWidth: 48;
qproperty-blackKeyActiveBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #43e97b, stop:1 #3bcd6c);
qproperty-blackKeyInactiveBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #333, stop:1 #000);
qproperty-blackKeyDisabledBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #606060, stop:1 #505050);
/* Grid colors */
qproperty-lineColor: rgba( 128, 128, 128, 80 );
qproperty-beatLineColor: rgba( 128, 128, 128, 160 );
Expand Down
Binary file added data/themes/classic/white_key_disabled.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/black_key_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ PianoRoll {
qproperty-whiteKeyInactiveTextColor: #000;
qproperty-whiteKeyInactiveTextShadow: #fff;
qproperty-whiteKeyInactiveBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #eeeeee, stop:1 #ffffff);
qproperty-whiteKeyDisabledBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #a0a0a0, stop:1 #b0b0b0);
qproperty-blackKeyWidth: 48;
qproperty-blackKeyActiveBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #43e97b, stop:1 #3bcd6c);
qproperty-blackKeyInactiveBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #333, stop:1 #000);
qproperty-blackKeyDisabledBackground: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #606060, stop:1 #505050);
/* Grid colors */
qproperty-lineColor: #292929;
qproperty-beatLineColor: #2d6b45;
Expand Down
Binary file added data/themes/default/white_key_disabled.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/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class LMMS_EXPORT DataFile : public QDomDocument
void upgrade_1_2_0_rc3();
void upgrade_1_3_0();
void upgrade_noHiddenClipNames();
void upgrade_extendedNoteRange();

// List of all upgrade methods
static const std::vector<UpgradeMethod> UPGRADE_METHODS;
Expand Down
27 changes: 24 additions & 3 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "GroupBox.h"
#include "InstrumentFunctions.h"
#include "InstrumentSoundShaping.h"
//#include "Microtuner.h"
#include "Midi.h"
#include "MidiCCRackView.h"
#include "MidiEventProcessor.h"
Expand Down Expand Up @@ -174,13 +175,30 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
return &m_baseNoteModel;
}

IntModel *firstKeyModel()
{
return &m_firstKeyModel;
}

IntModel *lastKeyModel()
{
return &m_lastKeyModel;
}

int baseNote() const;
int firstKey() const;
int lastKey() const;

Piano *pianoModel()
{
return &m_piano;
}

/* Microtuner *microtuner()
{
return &m_microtuner;
}*/

bool isArpeggioEnabled() const
{
return m_arpeggio.m_arpEnabledModel.value();
Expand Down Expand Up @@ -265,11 +283,13 @@ protected slots:

bool m_previewMode;

IntModel m_baseNoteModel; //!< The "A4" or "440 Hz" key (default 69)
IntModel m_firstKeyModel; //!< First key the instrument reacts to
IntModel m_lastKeyModel; //!< Last key the instrument reacts to

bool m_hasAutoMidiDev;
static InstrumentTrack *s_autoAssignedTrack;

IntModel m_baseNoteModel;

NotePlayHandleList m_processHandles;

FloatModel m_volumeModel;
Expand All @@ -282,14 +302,15 @@ protected slots:
IntModel m_effectChannelModel;
BoolModel m_useMasterPitchModel;


Instrument * m_instrument;
InstrumentSoundShaping m_soundShaping;
InstrumentFunctionArpeggio m_arpeggio;
InstrumentFunctionNoteStacking m_noteStacking;

Piano m_piano;

// Microtuner m_microtuner;

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

Expand Down
17 changes: 11 additions & 6 deletions include/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ enum Keys

enum Octaves
{
Octave_m1, // MIDI standard starts at C-1
Octave_0,
Octave_1,
Octave_2,
Expand All @@ -64,15 +65,19 @@ enum Octaves
Octave_6,
Octave_7,
Octave_8,
Octave_9, // incomplete octave, MIDI only goes up to G9
NumOctaves
} ;
};

const int FirstOctave = -1;
const int KeysPerOctave = 12;
const int DefaultKey = DefaultOctave * KeysPerOctave + Key_A;
//! Number of physical keys, limited to MIDI range (valid for both MIDI 1.0 and 2.0)
const int NumKeys = 128;

const int WhiteKeysPerOctave = 7;
const int BlackKeysPerOctave = 5;
const int KeysPerOctave = WhiteKeysPerOctave + BlackKeysPerOctave;
const int NumKeys = NumOctaves * KeysPerOctave;
const int DefaultKey = DefaultOctave*KeysPerOctave + Key_A;
const int DefaultMiddleKey = Octave_4 * KeysPerOctave + Key_C;
const int DefaultBaseKey = Octave_4 * KeysPerOctave + Key_A;
const float DefaultBaseFreq = 440.f;

const float MaxDetuning = 4 * 12.0f;

Expand Down
2 changes: 1 addition & 1 deletion include/NotePlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class LMMS_EXPORT NotePlayHandle : public PlayHandle, public Note
/*! Returns whether the play handle plays on a certain track */
bool isFromTrack( const Track* _track ) const override;

/*! Releases the note (and plays release frames */
/*! Releases the note (and plays release frames) */
void noteOff( const f_cnt_t offset = 0 );

/*! Returns number of frames to be played until the note is going to be released */
Expand Down
4 changes: 4 additions & 0 deletions include/Piano.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class Piano final : public Model
static bool isWhiteKey(int key);
static bool isBlackKey(int key);

static const unsigned int WhiteKeysPerOctave = 7;
static const unsigned int BlackKeysPerOctave = 5;
static const unsigned int NumWhiteKeys = 75;
static const unsigned int NumBlackKeys = 53;
Comment on lines +68 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to gain this through math and our constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they could be derived "mathematically"; the first two are arbitrary constants that describe how many notes from one 12-EDO octave are deemed "special" when making a piano keyboard, the other two count how many of these special keys are available in total. And since the black-white order is also arbitrary, there is no easy mathematical formula that says how many special keys are in the last, incomplete octave.

It could be determined by an algorithm though, by simply checking Piano::KeyTypes KEY_ORDER[] (defined in Piano.cpp for some reason, not the header file), i.e. running isBlackKey() and isWhiteKey() for all keys and, well, counting them. Or, more efficiently, count all complete octaves using a simple formula, and finishing the count by looping through the last, incomplete octave.

Either way seems pretty convoluted and probably would have to run in the constructor (can you initialize a constant in the constructor? Actually, can you initialize static anything in a constructor, since there is only one "instance"?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good then. Just wanted to check. 👍


private:
static bool isValidKey( int key )
Expand Down
5 changes: 4 additions & 1 deletion include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ class PianoRoll : public QWidget
Q_PROPERTY(QColor whiteKeyActiveTextColor MEMBER m_whiteKeyActiveTextColor)
Q_PROPERTY(QColor whiteKeyActiveTextShadow MEMBER m_whiteKeyActiveTextShadow)
Q_PROPERTY(QBrush whiteKeyActiveBackground MEMBER m_whiteKeyActiveBackground)
Q_PROPERTY(QBrush whiteKeyDisabledBackground MEMBER m_whiteKeyDisabledBackground)
/* black key properties */
Q_PROPERTY(int blackKeyWidth MEMBER m_blackKeyWidth)
Q_PROPERTY(QBrush blackKeyInactiveBackground MEMBER m_blackKeyInactiveBackground)
Q_PROPERTY(QBrush blackKeyActiveBackground MEMBER m_blackKeyActiveBackground)
Q_PROPERTY(QBrush blackKeyDisabledBackground MEMBER m_blackKeyDisabledBackground)
public:
enum EditModes
{
Expand Down Expand Up @@ -370,7 +372,6 @@ protected slots:
int m_pianoKeysVisible;

int m_keyLineHeight;
int m_octaveHeight;
int m_whiteKeySmallHeight;
int m_whiteKeyBigHeight;
int m_blackKeyHeight;
Expand Down Expand Up @@ -441,10 +442,12 @@ protected slots:
QColor m_whiteKeyInactiveTextColor;
QColor m_whiteKeyInactiveTextShadow;
QBrush m_whiteKeyInactiveBackground;
QBrush m_whiteKeyDisabledBackground;
/* black key properties */
int m_blackKeyWidth;
QBrush m_blackKeyActiveBackground;
QBrush m_blackKeyInactiveBackground;
QBrush m_blackKeyDisabledBackground;

signals:
void positionChanged( const TimePos & );
Expand Down
13 changes: 10 additions & 3 deletions include/PianoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QPixmap>
#include <QScrollBar>

#include "AutomatableModel.h"
#include "ModelView.h"

class Piano;
Expand Down Expand Up @@ -63,17 +64,24 @@ class PianoView : public QWidget, public ModelView
private:
int getKeyFromMouse( const QPoint & _p ) const;
int getKeyX( int _key_num ) const;
int getKeyWidth(int key_num) const;
int getKeyHeight(int key_num) const;
IntModel *getNearestMarker(int key, QString* title = nullptr);

static QPixmap * s_whiteKeyPm;
static QPixmap * s_blackKeyPm;
static QPixmap * s_whiteKeyPressedPm;
static QPixmap * s_blackKeyPressedPm;
static QPixmap * s_whiteKeyDisabledPm;
static QPixmap * s_blackKeyDisabledPm;

Piano * m_piano;

QScrollBar * m_pianoScroll;
int m_startKey; // first key when drawing
int m_lastKey;
int m_startKey; //!< first key when drawing
int m_lastKey; //!< previously pressed key
IntModel *m_movedNoteModel; //!< note marker which is being moved



private slots:
Expand All @@ -87,4 +95,3 @@ private slots:


#endif

4 changes: 3 additions & 1 deletion plugins/HydrogenImport/HydrogenImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class NoteKey
else if ( sKey == "B" ) {
m_key = NoteKey::B;
}
return m_key + (nOctave*12)+57;

// Hydrogen records MIDI notes from C-1 to B5, and exports them as a number ranging from -3 to 3
return m_key + ((nOctave + 3) * 12);
}

};
Expand Down
6 changes: 2 additions & 4 deletions plugins/MidiExport/MidiExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks,
if (n.nodeName() == "instrumenttrack")
{
QDomElement it = n.toElement();
// transpose +12 semitones, workaround for #1857
base_pitch = (69 - it.attribute("basenote", "57").toInt());
base_pitch = (69 - it.attribute("basenote", "69").toInt());
if (it.attribute("usemasterpitch", "1").toInt())
{
base_pitch += masterPitch;
Expand Down Expand Up @@ -201,8 +200,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks,
if (n.nodeName() == "instrumenttrack")
{
QDomElement it = n.toElement();
// transpose +12 semitones, workaround for #1857
base_pitch = (69 - it.attribute("basenote", "57").toInt());
base_pitch = (69 - it.attribute("basenote", "69").toInt());
if (it.attribute("usemasterpitch", "1").toInt())
{
base_pitch += masterPitch;
Expand Down
2 changes: 1 addition & 1 deletion plugins/MidiImport/MidiImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool MidiImport::readSMF( TrackContainer* tc )
int ticks = noteEvt->get_duration() * ticksPerBeat;
Note n( (ticks < 1 ? 1 : ticks ),
noteEvt->get_start_time() * ticksPerBeat,
noteEvt->get_identifier() - 12,
noteEvt->get_identifier(),
noteEvt->get_loud() * (200.f / 127.f)); // Map from MIDI velocity to LMMS volume
ch->addNote( n );

Expand Down
7 changes: 3 additions & 4 deletions plugins/OpulenZ/OpulenZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ bool OpulenzInstrument::handleMidiEvent( const MidiEvent& event, const TimePos&

switch(event.type()) {
case MidiNoteOn:
// to get us in line with MIDI(?)
key = event.key() +12;
key = event.key();
vel = event.velocity();

voice = popVoice();
Expand All @@ -316,7 +315,7 @@ bool OpulenzInstrument::handleMidiEvent( const MidiEvent& event, const TimePos&
}
break;
case MidiNoteOff:
key = event.key() +12;
key = event.key();
for(voice=0; voice<OPL2_VOICES; ++voice) {
if( voiceNote[voice] == key ) {
theEmulator->write(0xA0+voice, fnums[key] & 0xff);
Expand All @@ -328,7 +327,7 @@ bool OpulenzInstrument::handleMidiEvent( const MidiEvent& event, const TimePos&
velocities[key] = 0;
break;
case MidiKeyPressure:
key = event.key() +12;
key = event.key();
vel = event.velocity();
if( velocities[key] != 0) {
velocities[key] = vel;
Expand Down
1 change: 0 additions & 1 deletion plugins/vestige/vestige.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include "Instrument.h"
#include "InstrumentView.h"
#include "Note.h"
#include "CustomTextKnob.h"
#include "SubWindow.h"
#include "AutomatableModel.h"
Expand Down
1 change: 0 additions & 1 deletion plugins/zynaddsubfx/RemoteZynAddSubFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <queue>

#define BUILD_REMOTE_PLUGIN_CLIENT
#include "Note.h"
#include "RemotePlugin.h"
#include "RemoteZynAddSubFx.h"
#include "LocalZynAddSubFx.h"
Expand Down
1 change: 0 additions & 1 deletion src/core/AutomationPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "AutomationPatternView.h"
#include "AutomationTrack.h"
#include "LocaleHelper.h"
#include "Note.h"
#include "ProjectJournal.h"
#include "BBTrackContainer.h"
#include "Song.h"
Expand Down
Loading