Skip to content

Commit

Permalink
MIDI range MKII (extracted from microtonal PR) (#5868)
Browse files Browse the repository at this point in the history
* Update MIDI range to match MIDI specification

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>
Co-authored-by: Kevin Zander <veratil@gmail.com>
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: Spekular <Spekular@users.noreply.github.com>
  • Loading branch information
5 people authored Apr 21, 2021
1 parent fbea789 commit f288137
Show file tree
Hide file tree
Showing 30 changed files with 480 additions and 240 deletions.
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 @@ -165,9 +165,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 @@ -197,9 +197,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 @@ -120,6 +120,7 @@ class LMMS_EXPORT DataFile : public QDomDocument
void upgrade_1_3_0();
void upgrade_noHiddenClipNames();
void upgrade_automationNodes();
void upgrade_extendedNoteRange();

// List of all upgrade methods
static const std::vector<UpgradeMethod> UPGRADE_METHODS;
Expand Down
19 changes: 16 additions & 3 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,19 @@ 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()
{
Expand Down Expand Up @@ -265,11 +277,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,7 +296,6 @@ protected slots:
IntModel m_effectChannelModel;
BoolModel m_useMasterPitchModel;


Instrument * m_instrument;
InstrumentSoundShaping m_soundShaping;
InstrumentFunctionArpeggio m_arpeggio;
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;

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 @@ -86,10 +86,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 @@ -398,7 +400,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 @@ -475,10 +476,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
4 changes: 2 additions & 2 deletions plugins/Xpressive/Xpressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,8 @@ QString XpressiveHelpView::s_helpText=
"<h4>Available variables:</h4><br>"
"<b>t</b> - Time in seconds.<br>"
"<b>f</b> - Note's pitched frequency. Available only in the output expressions.<br>"
"<b>key</b> - Note's keyboard key. 0 denotes C0, 48 denotes C4, 96 denotes C8. Available only in the output expressions.<br>"
"<b>bnote</b> - Base note. By default it is 57 which means A5, unless you change it.<br>"
"<b>key</b> - Note's keyboard key. 0 denotes C-1, 60 denotes C4, 127 denotes G9. Available only in the output expressions.<br>"
"<b>bnote</b> - Base note. By default it is 69 which means A4, unless you change it.<br>"
"<b>srate</b> - Sample rate. In wave expression it returns the wave's number of samples.<br>"
"<b>tempo</b> - Song's Tempo. Available only in the output expressions.<br>"
"<b>v</b> - Note's volume. Note that the output is already multiplied by the volume. Available only in the output expressions.<br>"
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 @@ -34,7 +34,6 @@

#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 @@ -31,7 +31,6 @@
#include "AutomationTrack.h"
#include "BBTrackContainer.h"
#include "LocaleHelper.h"
#include "Note.h"
#include "ProjectJournal.h"
#include "Song.h"

Expand Down
Loading

0 comments on commit f288137

Please sign in to comment.