Files
lmms/include/Note.h
Levin Oehlmann f742710758 Macro cleanup (#6095)
Summary:

* `NULL` -> `nullptr`
* `gui` -> Function `getGUI()`
* `pluginFactory` -> Function `getPluginFactory()`
* `assert` (redefinition) -> using `NDEBUG` instead, which standard `assert` respects.
* `powf` (C stdlib symbol clash) -> removed and all expansions replaced with calls to `std::pow`.
* `exp10` (nonstandard function symbol clash) -> removed and all expansions replaced with calls to `std::pow`.
* `PATH_DEV_DSP` -> File-scope QString of identical name and value.
* `VST_SNC_SHM_KEY_FILE` -> constexpr char* with identical name and value.
* `MM_ALLOC` and `MM_FREE` -> Functions with identical name and implementation.
* `INVAL`, `OUTVAL`, etc. for automation nodes -> Functions with identical names and implementations.
* BandLimitedWave.h: All integer constant macros replaced with constexpr ints of same name and value.
* `FAST_RAND_MAX` -> constexpr int of same name and value.
* `QSTR_TO_STDSTR` -> Function with identical name and equivalent implementation.
* `CCONST` -> constexpr function template with identical name and implementation.
* `F_OPEN_UTF8` -> Function with identical name and equivalent implementation.
* `LADSPA_PATH_SEPARATOR` -> constexpr char with identical name and value.
* `UI_CTRL_KEY` -> constexpr char* with identical name and value.
* `ALIGN_SIZE` -> Renamed to `LMMS_ALIGN_SIZE` and converted from a macro to a constexpr size_t.
* `JACK_MIDI_BUFFER_MAX` -> constexpr size_t with identical name and value.
* versioninfo.h: `PLATFORM`, `MACHINE` and `COMPILER_VERSION` -> prefixed with `LMMS_BUILDCONF_` and converted from macros to constexpr char* literals.
* Header guard _OSCILLOSCOPE -> renamed to OSCILLOSCOPE_H
* Header guard _TIME_DISPLAY_WIDGET -> renamed to TIME_DISPLAY_WIDGET_H
* C-style typecasts in DrumSynth.cpp have been replaced with `static_cast`.
* constexpr numerical constants are initialized with assignment notation instead of curly brace intializers.
* In portsmf, `Alg_seq::operator[]` will throw an exception instead of returning null if the operator index is out of range.

Additionally, in many places, global constants that were declared as `const T foo = bar;` were changed from const to constexpr, leaving them const and making them potentially evaluable at compile time.

Some macros that only appeared in single source files and were unused in those files have been removed entirely.
2021-09-30 18:01:27 +02:00

251 lines
5.1 KiB
C++

/*
* Note.h - declaration of class note which contains all informations about a
* note + definitions of several constants and enums
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* 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 NOTE_H
#define NOTE_H
#include <QtCore/QVector>
#include "volume.h"
#include "panning.h"
#include "SerializingObject.h"
#include "TimePos.h"
class DetuningHelper;
enum Keys
{
Key_C = 0,
Key_CIS = 1, Key_DES = 1,
Key_D = 2,
Key_DIS = 3, Key_ES = 3,
Key_E = 4, Key_FES = 4,
Key_F = 5,
Key_FIS = 6, Key_GES = 6,
Key_G = 7,
Key_GIS = 8, Key_AS = 8,
Key_A = 9,
Key_AIS = 10, Key_B = 10,
Key_H = 11
} ;
enum Octaves
{
Octave_m1, // MIDI standard starts at C-1
Octave_0,
Octave_1,
Octave_2,
Octave_3,
Octave_4, DefaultOctave = Octave_4,
Octave_5,
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 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;
class LMMS_EXPORT Note : public SerializingObject
{
public:
Note( const TimePos & length = TimePos( 0 ),
const TimePos & pos = TimePos( 0 ),
int key = DefaultKey,
volume_t volume = DefaultVolume,
panning_t panning = DefaultPanning,
DetuningHelper * detuning = nullptr );
Note( const Note & note );
virtual ~Note();
// used by GUI
inline void setSelected( const bool selected ) { m_selected = selected; }
inline void setOldKey( const int oldKey ) { m_oldKey = oldKey; }
inline void setOldPos( const TimePos & oldPos ) { m_oldPos = oldPos; }
inline void setOldLength( const TimePos & oldLength )
{
m_oldLength = oldLength;
}
inline void setIsPlaying( const bool isPlaying )
{
m_isPlaying = isPlaying;
}
void setLength( const TimePos & length );
void setPos( const TimePos & pos );
void setKey( const int key );
virtual void setVolume( volume_t volume );
virtual void setPanning( panning_t panning );
void quantizeLength( const int qGrid );
void quantizePos( const int qGrid );
static inline bool lessThan( const Note * lhs, const Note * rhs )
{
// function to compare two notes - must be called explictly when
// using qSort
if( (int)( *lhs ).pos() < (int)( *rhs ).pos() )
{
return true;
}
else if( (int)( *lhs ).pos() > (int)( *rhs ).pos() )
{
return false;
}
return ( (int)( *lhs ).key() > (int)( *rhs ).key() );
}
inline bool selected() const
{
return m_selected;
}
inline int oldKey() const
{
return m_oldKey;
}
inline TimePos oldPos() const
{
return m_oldPos;
}
inline TimePos oldLength() const
{
return m_oldLength;
}
inline bool isPlaying() const
{
return m_isPlaying;
}
inline TimePos endPos() const
{
const int l = length();
return pos() + l;
}
inline const TimePos & length() const
{
return m_length;
}
inline const TimePos & pos() const
{
return m_pos;
}
inline TimePos pos( TimePos basePos ) const
{
const int bp = basePos;
return m_pos - bp;
}
inline int key() const
{
return m_key;
}
inline volume_t getVolume() const
{
return m_volume;
}
int midiVelocity( int midiBaseVelocity ) const
{
return qMin( MidiMaxVelocity, getVolume() * midiBaseVelocity / DefaultVolume );
}
inline panning_t getPanning() const
{
return m_panning;
}
static QString classNodeName()
{
return "note";
}
inline QString nodeName() const override
{
return classNodeName();
}
static TimePos quantized( const TimePos & m, const int qGrid );
DetuningHelper * detuning() const
{
return m_detuning;
}
bool hasDetuningInfo() const;
bool withinRange(int tickStart, int tickEnd) const;
void createDetuning();
protected:
void saveSettings( QDomDocument & doc, QDomElement & parent ) override;
void loadSettings( const QDomElement & _this ) override;
private:
// for piano roll editing
bool m_selected;
int m_oldKey;
TimePos m_oldPos;
TimePos m_oldLength;
bool m_isPlaying;
int m_key;
volume_t m_volume;
panning_t m_panning;
TimePos m_length;
TimePos m_pos;
DetuningHelper * m_detuning;
};
typedef QVector<Note *> NoteVector;
#endif