Don't copy DetuningHelper in Note copy constructor (#7888)

Reworks how note detuning copying works so as not to perform a clip duplication and allocation by default in the constructors

---------

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
This commit is contained in:
regulus79
2025-05-28 19:28:13 -04:00
committed by GitHub
parent cb84fce599
commit 7e02795f47
7 changed files with 26 additions and 119 deletions

View File

@@ -36,7 +36,7 @@ namespace lmms
Note::Note( const TimePos & length, const TimePos & pos,
int key, volume_t volume, panning_t panning,
DetuningHelper * detuning ) :
std::shared_ptr<DetuningHelper> detuning ) :
m_selected( false ),
m_oldKey(std::clamp(key, 0, NumKeys)),
m_oldPos( pos ),
@@ -46,13 +46,10 @@ Note::Note( const TimePos & length, const TimePos & pos,
m_volume(std::clamp(volume, MinVolume, MaxVolume)),
m_panning(std::clamp(panning, PanningLeft, PanningRight)),
m_length( length ),
m_pos( pos )
m_pos(pos),
m_detuning(std::move(detuning))
{
if (detuning)
{
m_detuning = std::make_unique<DetuningHelper>(*detuning);
}
else
if (!detuning)
{
createDetuning();
}
@@ -73,12 +70,9 @@ Note::Note( const Note & note ) :
m_panning( note.m_panning ),
m_length( note.m_length ),
m_pos( note.m_pos ),
m_detuning(note.m_detuning),
m_type(note.m_type)
{
if (note.m_detuning)
{
m_detuning = std::make_unique<DetuningHelper>(*note.m_detuning);
}
}
Note& Note::operator=(const Note& note)
@@ -94,16 +88,19 @@ Note& Note::operator=(const Note& note)
m_length = note.m_length;
m_pos = note.m_pos;
m_type = note.m_type;
if (note.m_detuning)
{
m_detuning = std::make_unique<DetuningHelper>(*note.m_detuning);
}
m_detuning = note.m_detuning;
return *this;
}
Note* Note::clone() const
{
Note* newNote = new Note(*this);
newNote->m_detuning = std::make_shared<DetuningHelper>(*newNote->m_detuning);
return newNote;
}
Note::~Note()
@@ -234,7 +231,7 @@ void Note::createDetuning()
{
if( m_detuning == nullptr )
{
m_detuning = std::make_unique<DetuningHelper>();
m_detuning = std::make_shared<DetuningHelper>();
(void) m_detuning->automationClip();
m_detuning->setRange( -MaxDetuning, MaxDetuning, 0.5f );
m_detuning->automationClip()->setProgressionType( AutomationClip::ProgressionType::Linear );

View File

@@ -54,7 +54,7 @@ NotePlayHandle::NotePlayHandle( InstrumentTrack* instrumentTrack,
int midiEventChannel,
Origin origin ) :
PlayHandle( PlayHandle::Type::NotePlayHandle, _offset ),
Note( n.length(), n.pos(), n.key(), n.getVolume(), n.getPanning(), n.detuning() ),
Note(n),
m_pluginData( nullptr ),
m_instrumentTrack( instrumentTrack ),
m_frames( 0 ),
@@ -84,7 +84,7 @@ NotePlayHandle::NotePlayHandle( InstrumentTrack* instrumentTrack,
lock();
if( hasParent() == false )
{
m_baseDetuning = new BaseDetuning( detuning() );
m_baseDetuning = new BaseDetuning(detuning().get());
m_instrumentTrack->m_processHandles.push_back( this );
}
else

View File

@@ -68,7 +68,7 @@ MidiClip::MidiClip( const MidiClip& other ) :
{
for (const auto& note : other.m_notes)
{
m_notes.push_back(new Note(*note));
m_notes.push_back(note->clone());
}
init();
@@ -197,7 +197,7 @@ TimePos MidiClip::beatClipLength() const
Note * MidiClip::addNote( const Note & _new_note, const bool _quant_pos )
{
auto new_note = new Note(_new_note);
auto new_note = _new_note.clone();
if (_quant_pos && gui::getGUI()->pianoRoll())
{
new_note->quantizePos(gui::getGUI()->pianoRoll()->quantization());