Files
lmms/include/Note.h
saker 9a0add49fb Core Refactor: Replace `QVector with std::vector` (#6477)
* Replace QVector with std::vector in AudioEngine

* Replace QVector with std::vector in AudioEngineWorkerThread

* Replace QVector with std::vector in AudioJack

* Replace QVector with std::vector in AutomatableModel

* Replace QVector with std::vector in AutomationClip

* Replace QVector with std::vector in AutomationEditor

* Replace QVector with std::vector in ConfigManager

* Replace QVector with std::vector in Controller

* Replace QVector with std::vector in ControllerConnection

* Replace QVector with std::vector in EffectChain

* Replace QVector with std::vector in EnvelopeAndLfoParameters

* Replace QVector with std::vector in InstrumentFunctions

* Replace QVector with std::vector in MidiClient

* Replace QVector with std::vector in Mixer

* Replace QVector with std::vector in Note

* Replace QVector with std::vector in PeakController

* Replace QVector with std::vector in PianoRoll

* Replace QVector with std::vector in PluginFactory

* Replace QVector with std::vector in RenderManager

* Replace QVector with std::vector in StepRecorder

* Replace QVector with std::vector in Track

* Replace QVector with std::vector in TrackContainer

* Replace QVector with std::vector in Song

* Adapt QVector to std::vector changes in ControllerConnectionDialog

* Phase 2: Use std::abs in panning.h
Without this, the QVector changes will make the code not compile.

* Phase 2: Replace QVector with std::vector in PeakControllerEffect

* Phase 2: Replace QVector with std::vector in AutomatableModel

* Phase 2: Replace QVector with std::vector in AutomationClip

* Phase 2: Replace QVector with std::vector in ControllerConnection

* Phase 2: Replace QVector with std::vector in EffectChain

* Phase 2: Replace QVector with std::vector in Mixer

* Phase 2: Replace QVector with std::vector in PeakController

* Phase 2: Replace QVector with std::vector in RenderManager

* Phase 2: Replace QVector with std::vector in Song

* Phase 2: Replace QVector with std::vector in StepRecorder

* Phase 2: Replace QVector with std::vector in Track

* Phase 2: Replace QVector with std::vector in TrackContainer

* Phase 2: Adapt QVector changes in EffectRackView

* Phase 2: Adapt QVector changes in AutomationClipView

* Phase 2: Adapt QVector changes in ClipView

* Phase 2: Adapt QVector changes in AutomationEditor

* Phase 2: Adapt QVector changes in PianoRoll

* Phase 2: Adapt QVector changes in TrackContainerView

* Phase 2: Adapt QVector changes in TrackContentWidget

* Phase 2: Adapt QVector changes in InstrumentTrack

* Phase 2: Adapt QVector changes in MidiClip

* Phase 2: Adapt QVector changes in SampleTrack

* Fix segmentation fault in ConfigManager::value

* Fix unintended faulty std::vector insert in AutomationClip::resolveAllIDs

* Resolve trailing whitespace in src/core/StepRecorder.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Use std::next and std::prev in EffectChain::moveUp/moveDown

* Introduce static "combineAllTracks" function in AutomationClip

* Adjust variable name in Song::automatedValuesAt

* Adjust removal of long step notes in StepRecorder::removeNotesReleasedForTooLong

* Iterate over m_chords by const reference in src/core/InstrumentFunctions.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Fix StepRecorder::removeNotesReleasedForTooLong again

* Combine the ConfigManager::value overloads using std::optional

* Revise StepRecorder::removeNotesReleasedForTooLong

* Remove redundant std::optional in ConfigManager::value

* Remove trailing whitespace in ConfigManager::value

* Fix: Prevent incorrect use of std::distance when element not found

* Chore: Remove trailing whitespace in edited files

* Only set the id attribute if the controller was found

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Remove extra indents from 84b8fe8a559855ed263b74cc582eab3655250c5f

* Fix compilation issues

* Add LMMS_ prefix for header guard in Track.h

* Undo changes made to MixerView::deleteUnusedChannels

* Simplify code to handle failure of finding tracks
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Split ternary operator into separate if statement
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Undo changes to indentation in MixerRoute

* Do general clean-up
Some of the changes made:
+ Use auto where benefical
+ Fix bug in AutomatableModel::globalAutomationValueAt (for loop should be looping over clips variable, not clipsInRange)
+ Undo out of focus whitespace changes

* Always assign to m_steps regardless if clip is found or not
Even when the clip is not found (i.e., currentClip is -1), m_steps still
gets assigned to.

* Insert at the end of tracks vector in src/core/Mixer.cpp

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Insert at the end of tracks vector in src/core/Mixer.cpp (2)

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Remove redundant template parameter

* Use std::array for zoomLevels

---------

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: Dominic Clark <mrdomclark@gmail.com>
2023-08-22 12:08:56 +09:00

269 lines
5.3 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 LMMS_NOTE_H
#define LMMS_NOTE_H
#include <optional>
#include <vector>
#include "volume.h"
#include "panning.h"
#include "SerializingObject.h"
#include "TimePos.h"
namespace lmms
{
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 );
~Note() override;
// 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;
};
using NoteVector = std::vector<Note*>;
struct NoteBounds
{
TimePos start;
TimePos end;
int lowest;
int highest;
};
std::optional<NoteBounds> boundsForNotes(const NoteVector& notes);
} // namespace lmms
#endif // LMMS_NOTE_H