From fd871e46c950931d45050d4c812d9212d1750664 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Fri, 9 Mar 2018 23:03:19 -0800 Subject: [PATCH 1/7] refactor: Use unique_ptr for memory management --- include/AudioPort.h | 5 +- include/ComboBoxModel.h | 18 ++--- include/stdshims.h | 12 +++ plugins/DualFilter/DualFilterControls.cpp | 93 ++++++++++++----------- plugins/monstro/Monstro.h | 53 ++++++------- src/core/ComboBoxModel.cpp | 10 +-- src/core/InstrumentFunctions.cpp | 18 ++--- src/core/InstrumentSoundShaping.cpp | 45 +++++------ src/core/audio/AudioPort.cpp | 1 - src/gui/editors/PianoRoll.cpp | 13 ++-- 10 files changed, 141 insertions(+), 127 deletions(-) create mode 100644 include/stdshims.h diff --git a/include/AudioPort.h b/include/AudioPort.h index 6a62d8809..2842c6a17 100644 --- a/include/AudioPort.h +++ b/include/AudioPort.h @@ -25,6 +25,7 @@ #ifndef AUDIO_PORT_H #define AUDIO_PORT_H +#include #include #include #include @@ -79,7 +80,7 @@ public: inline EffectChain * effects() { - return m_effects; + return m_effects.get(); } void setNextFxChannel( const fx_ch_t _chnl ) @@ -119,7 +120,7 @@ private: QString m_name; - EffectChain * m_effects; + std::unique_ptr m_effects; PlayHandleList m_playHandles; QMutex m_playHandleLock; diff --git a/include/ComboBoxModel.h b/include/ComboBoxModel.h index e1fcf65af..ed2465cfb 100644 --- a/include/ComboBoxModel.h +++ b/include/ComboBoxModel.h @@ -25,12 +25,12 @@ #ifndef COMBOBOX_MODEL_H #define COMBOBOX_MODEL_H -#include -#include +#include +#include +#include #include "AutomatableModel.h" - -class PixmapLoader; +#include "embed.h" class EXPORT ComboBoxModel : public IntModel @@ -49,7 +49,7 @@ public: clear(); } - void addItem( const QString& item, PixmapLoader* loader = NULL ); + void addItem( const QString& item, std::unique_ptr loader = nullptr ); void clear(); @@ -62,7 +62,7 @@ public: const PixmapLoader* currentData() const { - return m_items[value()].second; + return m_items[value()].second.get(); } const QString & itemText( int i ) const @@ -72,7 +72,7 @@ public: const PixmapLoader* itemPixmap( int i ) const { - return m_items[qBound( minValue(), i, maxValue() )].second; + return m_items[qBound( minValue(), i, maxValue() )].second.get(); } int size() const @@ -82,9 +82,9 @@ public: private: - typedef QPair Item; + typedef std::pair > Item; - QVector m_items; + std::vector m_items; } ; diff --git a/include/stdshims.h b/include/stdshims.h new file mode 100644 index 000000000..1551d0a0f --- /dev/null +++ b/include/stdshims.h @@ -0,0 +1,12 @@ +//! Shims for std:: functions that aren't available in the current C++ versions +//! we target. + +#pragma once + +/// Shim for http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique +template +std::unique_ptr make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + diff --git a/plugins/DualFilter/DualFilterControls.cpp b/plugins/DualFilter/DualFilterControls.cpp index 63f7887f1..13749e8b9 100644 --- a/plugins/DualFilter/DualFilterControls.cpp +++ b/plugins/DualFilter/DualFilterControls.cpp @@ -26,12 +26,13 @@ #include +#include "BasicFilters.h" #include "DualFilterControls.h" #include "DualFilter.h" +#include "embed.h" #include "Engine.h" #include "Song.h" -#include "BasicFilters.h" -#include "embed.h" +#include "stdshims.h" DualFilterControls::DualFilterControls( DualFilterEffect* effect ) : EffectControls( effect ), @@ -51,51 +52,51 @@ DualFilterControls::DualFilterControls( DualFilterEffect* effect ) : m_res2Model( 0.5, BasicFilters<>::minQ(), 10.0, 0.01, this, tr( "Q/Resonance 2" ) ), m_gain2Model( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Gain 2" ) ) { - m_filter1Model.addItem( tr( "LowPass" ), new PixmapLoader( "filter_lp" ) ); - m_filter1Model.addItem( tr( "HiPass" ), new PixmapLoader( "filter_hp" ) ); - m_filter1Model.addItem( tr( "BandPass csg" ), new PixmapLoader( "filter_bp" ) ); - m_filter1Model.addItem( tr( "BandPass czpg" ), new PixmapLoader( "filter_bp" ) ); - m_filter1Model.addItem( tr( "Notch" ), new PixmapLoader( "filter_notch" ) ); - m_filter1Model.addItem( tr( "Allpass" ), new PixmapLoader( "filter_ap" ) ); - m_filter1Model.addItem( tr( "Moog" ), new PixmapLoader( "filter_lp" ) ); - m_filter1Model.addItem( tr( "2x LowPass" ), new PixmapLoader( "filter_2lp" ) ); - m_filter1Model.addItem( tr( "RC LowPass 12dB" ), new PixmapLoader( "filter_lp" ) ); - m_filter1Model.addItem( tr( "RC BandPass 12dB" ), new PixmapLoader( "filter_bp" ) ); - m_filter1Model.addItem( tr( "RC HighPass 12dB" ), new PixmapLoader( "filter_hp" ) ); - m_filter1Model.addItem( tr( "RC LowPass 24dB" ), new PixmapLoader( "filter_lp" ) ); - m_filter1Model.addItem( tr( "RC BandPass 24dB" ), new PixmapLoader( "filter_bp" ) ); - m_filter1Model.addItem( tr( "RC HighPass 24dB" ), new PixmapLoader( "filter_hp" ) ); - m_filter1Model.addItem( tr( "Vocal Formant Filter" ), new PixmapLoader( "filter_hp" ) ); - m_filter1Model.addItem( tr( "2x Moog" ), new PixmapLoader( "filter_2lp" ) ); - m_filter1Model.addItem( tr( "SV LowPass" ), new PixmapLoader( "filter_lp" ) ); - m_filter1Model.addItem( tr( "SV BandPass" ), new PixmapLoader( "filter_bp" ) ); - m_filter1Model.addItem( tr( "SV HighPass" ), new PixmapLoader( "filter_hp" ) ); - m_filter1Model.addItem( tr( "SV Notch" ), new PixmapLoader( "filter_notch" ) ); - m_filter1Model.addItem( tr( "Fast Formant" ), new PixmapLoader( "filter_hp" ) ); - m_filter1Model.addItem( tr( "Tripole" ), new PixmapLoader( "filter_lp" ) ); + m_filter1Model.addItem( tr( "LowPass" ), make_unique( "filter_lp" ) ); + m_filter1Model.addItem( tr( "HiPass" ), make_unique( "filter_hp" ) ); + m_filter1Model.addItem( tr( "BandPass csg" ), make_unique( "filter_bp" ) ); + m_filter1Model.addItem( tr( "BandPass czpg" ), make_unique( "filter_bp" ) ); + m_filter1Model.addItem( tr( "Notch" ), make_unique( "filter_notch" ) ); + m_filter1Model.addItem( tr( "Allpass" ), make_unique( "filter_ap" ) ); + m_filter1Model.addItem( tr( "Moog" ), make_unique( "filter_lp" ) ); + m_filter1Model.addItem( tr( "2x LowPass" ), make_unique( "filter_2lp" ) ); + m_filter1Model.addItem( tr( "RC LowPass 12dB" ), make_unique( "filter_lp" ) ); + m_filter1Model.addItem( tr( "RC BandPass 12dB" ), make_unique( "filter_bp" ) ); + m_filter1Model.addItem( tr( "RC HighPass 12dB" ), make_unique( "filter_hp" ) ); + m_filter1Model.addItem( tr( "RC LowPass 24dB" ), make_unique( "filter_lp" ) ); + m_filter1Model.addItem( tr( "RC BandPass 24dB" ), make_unique( "filter_bp" ) ); + m_filter1Model.addItem( tr( "RC HighPass 24dB" ), make_unique( "filter_hp" ) ); + m_filter1Model.addItem( tr( "Vocal Formant Filter" ), make_unique( "filter_hp" ) ); + m_filter1Model.addItem( tr( "2x Moog" ), make_unique( "filter_2lp" ) ); + m_filter1Model.addItem( tr( "SV LowPass" ), make_unique( "filter_lp" ) ); + m_filter1Model.addItem( tr( "SV BandPass" ), make_unique( "filter_bp" ) ); + m_filter1Model.addItem( tr( "SV HighPass" ), make_unique( "filter_hp" ) ); + m_filter1Model.addItem( tr( "SV Notch" ), make_unique( "filter_notch" ) ); + m_filter1Model.addItem( tr( "Fast Formant" ), make_unique( "filter_hp" ) ); + m_filter1Model.addItem( tr( "Tripole" ), make_unique( "filter_lp" ) ); - m_filter2Model.addItem( tr( "LowPass" ), new PixmapLoader( "filter_lp" ) ); - m_filter2Model.addItem( tr( "HiPass" ), new PixmapLoader( "filter_hp" ) ); - m_filter2Model.addItem( tr( "BandPass csg" ), new PixmapLoader( "filter_bp" ) ); - m_filter2Model.addItem( tr( "BandPass czpg" ), new PixmapLoader( "filter_bp" ) ); - m_filter2Model.addItem( tr( "Notch" ), new PixmapLoader( "filter_notch" ) ); - m_filter2Model.addItem( tr( "Allpass" ), new PixmapLoader( "filter_ap" ) ); - m_filter2Model.addItem( tr( "Moog" ), new PixmapLoader( "filter_lp" ) ); - m_filter2Model.addItem( tr( "2x LowPass" ), new PixmapLoader( "filter_2lp" ) ); - m_filter2Model.addItem( tr( "RC LowPass 12dB" ), new PixmapLoader( "filter_lp" ) ); - m_filter2Model.addItem( tr( "RC BandPass 12dB" ), new PixmapLoader( "filter_bp" ) ); - m_filter2Model.addItem( tr( "RC HighPass 12dB" ), new PixmapLoader( "filter_hp" ) ); - m_filter2Model.addItem( tr( "RC LowPass 24dB" ), new PixmapLoader( "filter_lp" ) ); - m_filter2Model.addItem( tr( "RC BandPass 24dB" ), new PixmapLoader( "filter_bp" ) ); - m_filter2Model.addItem( tr( "RC HighPass 24dB" ), new PixmapLoader( "filter_hp" ) ); - m_filter2Model.addItem( tr( "Vocal Formant Filter" ), new PixmapLoader( "filter_hp" ) ); - m_filter2Model.addItem( tr( "2x Moog" ), new PixmapLoader( "filter_2lp" ) ); - m_filter2Model.addItem( tr( "SV LowPass" ), new PixmapLoader( "filter_lp" ) ); - m_filter2Model.addItem( tr( "SV BandPass" ), new PixmapLoader( "filter_bp" ) ); - m_filter2Model.addItem( tr( "SV HighPass" ), new PixmapLoader( "filter_hp" ) ); - m_filter2Model.addItem( tr( "SV Notch" ), new PixmapLoader( "filter_notch" ) ); - m_filter2Model.addItem( tr( "Fast Formant" ), new PixmapLoader( "filter_hp" ) ); - m_filter2Model.addItem( tr( "Tripole" ), new PixmapLoader( "filter_lp" ) ); + m_filter2Model.addItem( tr( "LowPass" ), make_unique( "filter_lp" ) ); + m_filter2Model.addItem( tr( "HiPass" ), make_unique( "filter_hp" ) ); + m_filter2Model.addItem( tr( "BandPass csg" ), make_unique( "filter_bp" ) ); + m_filter2Model.addItem( tr( "BandPass czpg" ), make_unique( "filter_bp" ) ); + m_filter2Model.addItem( tr( "Notch" ), make_unique( "filter_notch" ) ); + m_filter2Model.addItem( tr( "Allpass" ), make_unique( "filter_ap" ) ); + m_filter2Model.addItem( tr( "Moog" ), make_unique( "filter_lp" ) ); + m_filter2Model.addItem( tr( "2x LowPass" ), make_unique( "filter_2lp" ) ); + m_filter2Model.addItem( tr( "RC LowPass 12dB" ), make_unique( "filter_lp" ) ); + m_filter2Model.addItem( tr( "RC BandPass 12dB" ), make_unique( "filter_bp" ) ); + m_filter2Model.addItem( tr( "RC HighPass 12dB" ), make_unique( "filter_hp" ) ); + m_filter2Model.addItem( tr( "RC LowPass 24dB" ), make_unique( "filter_lp" ) ); + m_filter2Model.addItem( tr( "RC BandPass 24dB" ), make_unique( "filter_bp" ) ); + m_filter2Model.addItem( tr( "RC HighPass 24dB" ), make_unique( "filter_hp" ) ); + m_filter2Model.addItem( tr( "Vocal Formant Filter" ), make_unique( "filter_hp" ) ); + m_filter2Model.addItem( tr( "2x Moog" ), make_unique( "filter_2lp" ) ); + m_filter2Model.addItem( tr( "SV LowPass" ), make_unique( "filter_lp" ) ); + m_filter2Model.addItem( tr( "SV BandPass" ), make_unique( "filter_bp" ) ); + m_filter2Model.addItem( tr( "SV HighPass" ), make_unique( "filter_hp" ) ); + m_filter2Model.addItem( tr( "SV Notch" ), make_unique( "filter_notch" ) ); + m_filter2Model.addItem( tr( "Fast Formant" ), make_unique( "filter_hp" ) ); + m_filter2Model.addItem( tr( "Tripole" ), make_unique( "filter_lp" ) ); connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( updateFilters() ) ); } diff --git a/plugins/monstro/Monstro.h b/plugins/monstro/Monstro.h index 831782846..2cf05f300 100644 --- a/plugins/monstro/Monstro.h +++ b/plugins/monstro/Monstro.h @@ -38,6 +38,7 @@ #include "Oscillator.h" #include "lmms_math.h" #include "BandLimitedWave.h" +#include "stdshims.h" // // UI Macros @@ -305,35 +306,35 @@ class MonstroInstrument : public Instrument Q_OBJECT #define setwavemodel( name ) \ - name .addItem( tr( "Sine wave" ), static_cast( new PluginPixmapLoader( "sin" ) ) ); \ - name .addItem( tr( "Bandlimited Triangle wave" ), static_cast( new PluginPixmapLoader( "tri" ) ) ); \ - name .addItem( tr( "Bandlimited Saw wave" ), static_cast( new PluginPixmapLoader( "saw" ) ) ); \ - name .addItem( tr( "Bandlimited Ramp wave" ), static_cast( new PluginPixmapLoader( "ramp" ) ) ); \ - name .addItem( tr( "Bandlimited Square wave" ), static_cast( new PluginPixmapLoader( "sqr" ) ) ); \ - name .addItem( tr( "Bandlimited Moog saw wave" ), static_cast( new PluginPixmapLoader( "moog" ) ) ); \ - name .addItem( tr( "Soft square wave" ), static_cast( new PluginPixmapLoader( "sqrsoft" ) ) ); \ - name .addItem( tr( "Absolute sine wave" ), static_cast( new PluginPixmapLoader( "sinabs" ) ) ); \ - name .addItem( tr( "Exponential wave" ), static_cast( new PluginPixmapLoader( "exp" ) ) ); \ - name .addItem( tr( "White noise" ), static_cast( new PluginPixmapLoader( "noise" ) ) ); \ - name .addItem( tr( "Digital Triangle wave" ), static_cast( new PluginPixmapLoader( "tri" ) ) ); \ - name .addItem( tr( "Digital Saw wave" ), static_cast( new PluginPixmapLoader( "saw" ) ) ); \ - name .addItem( tr( "Digital Ramp wave" ), static_cast( new PluginPixmapLoader( "ramp" ) ) ); \ - name .addItem( tr( "Digital Square wave" ), static_cast( new PluginPixmapLoader( "sqr" ) ) ); \ - name .addItem( tr( "Digital Moog saw wave" ), static_cast( new PluginPixmapLoader( "moog" ) ) ); + name .addItem( tr( "Sine wave" ), make_unique( "sin" ) ); \ + name .addItem( tr( "Bandlimited Triangle wave" ), make_unique( "tri" ) ); \ + name .addItem( tr( "Bandlimited Saw wave" ), make_unique( "saw" ) ); \ + name .addItem( tr( "Bandlimited Ramp wave" ), make_unique( "ramp" ) ); \ + name .addItem( tr( "Bandlimited Square wave" ), make_unique( "sqr" ) ); \ + name .addItem( tr( "Bandlimited Moog saw wave" ), make_unique( "moog" ) ); \ + name .addItem( tr( "Soft square wave" ), make_unique( "sqrsoft" ) ); \ + name .addItem( tr( "Absolute sine wave" ), make_unique( "sinabs" ) ); \ + name .addItem( tr( "Exponential wave" ), make_unique( "exp" ) ); \ + name .addItem( tr( "White noise" ), make_unique( "noise" ) ); \ + name .addItem( tr( "Digital Triangle wave" ), make_unique( "tri" ) ); \ + name .addItem( tr( "Digital Saw wave" ), make_unique( "saw" ) ); \ + name .addItem( tr( "Digital Ramp wave" ), make_unique( "ramp" ) ); \ + name .addItem( tr( "Digital Square wave" ), make_unique( "sqr" ) ); \ + name .addItem( tr( "Digital Moog saw wave" ), make_unique( "moog" ) ); #define setlfowavemodel( name ) \ - name .addItem( tr( "Sine wave" ), static_cast( new PluginPixmapLoader( "sin" ) ) ); \ - name .addItem( tr( "Triangle wave" ), static_cast( new PluginPixmapLoader( "tri" ) ) ); \ - name .addItem( tr( "Saw wave" ), static_cast( new PluginPixmapLoader( "saw" ) ) ); \ - name .addItem( tr( "Ramp wave" ), static_cast( new PluginPixmapLoader( "ramp" ) ) ); \ - name .addItem( tr( "Square wave" ), static_cast( new PluginPixmapLoader( "sqr" ) ) ); \ - name .addItem( tr( "Moog saw wave" ), static_cast( new PluginPixmapLoader( "moog" ) ) ); \ - name .addItem( tr( "Soft square wave" ), static_cast( new PluginPixmapLoader( "sqrsoft" ) ) ); \ - name .addItem( tr( "Abs. sine wave" ), static_cast( new PluginPixmapLoader( "sinabs" ) ) ); \ - name .addItem( tr( "Exponential wave" ), static_cast( new PluginPixmapLoader( "exp" ) ) ); \ - name .addItem( tr( "Random" ), static_cast( new PluginPixmapLoader( "rand" ) ) ); \ - name .addItem( tr( "Random smooth" ), static_cast( new PluginPixmapLoader( "rand" ) ) ); + name .addItem( tr( "Sine wave" ), make_unique( "sin" ) ); \ + name .addItem( tr( "Triangle wave" ), make_unique( "tri" ) ); \ + name .addItem( tr( "Saw wave" ), make_unique( "saw" ) ); \ + name .addItem( tr( "Ramp wave" ), make_unique( "ramp" ) ); \ + name .addItem( tr( "Square wave" ), make_unique( "sqr" ) ); \ + name .addItem( tr( "Moog saw wave" ), make_unique( "moog" ) ); \ + name .addItem( tr( "Soft square wave" ), make_unique( "sqrsoft" ) ); \ + name .addItem( tr( "Abs. sine wave" ), make_unique( "sinabs" ) ); \ + name .addItem( tr( "Exponential wave" ), make_unique( "exp" ) ); \ + name .addItem( tr( "Random" ), make_unique( "rand" ) ); \ + name .addItem( tr( "Random smooth" ), make_unique( "rand" ) ); public: MonstroInstrument( InstrumentTrack * _instrument_track ); diff --git a/src/core/ComboBoxModel.cpp b/src/core/ComboBoxModel.cpp index 9cbc1021b..1c7e2d9c5 100644 --- a/src/core/ComboBoxModel.cpp +++ b/src/core/ComboBoxModel.cpp @@ -27,9 +27,9 @@ -void ComboBoxModel::addItem( const QString& item, PixmapLoader* loader ) +void ComboBoxModel::addItem( const QString& item, std::unique_ptr loader ) { - m_items.push_back( qMakePair( item, loader ) ); + m_items.push_back( std::make_pair( item, std::move(loader) ) ); setRange( 0, m_items.size() - 1 ); } @@ -39,10 +39,6 @@ void ComboBoxModel::addItem( const QString& item, PixmapLoader* loader ) void ComboBoxModel::clear() { setRange( 0, 0 ); - for( const Item& i : m_items ) - { - delete i.second; - } m_items.clear(); @@ -54,7 +50,7 @@ void ComboBoxModel::clear() int ComboBoxModel::findText( const QString& txt ) const { - for( QVector::ConstIterator it = m_items.begin(); it != m_items.end(); ++it ) + for( auto it = m_items.begin(); it != m_items.end(); ++it ) { if( ( *it ).first == txt ) { diff --git a/src/core/InstrumentFunctions.cpp b/src/core/InstrumentFunctions.cpp index 2860045b8..97f5e2957 100644 --- a/src/core/InstrumentFunctions.cpp +++ b/src/core/InstrumentFunctions.cpp @@ -30,7 +30,7 @@ #include "InstrumentTrack.h" #include "Mixer.h" #include "PresetPreviewPlayHandle.h" - +#include "stdshims.h" InstrumentFunctionNoteStacking::ChordTable::Init InstrumentFunctionNoteStacking::ChordTable::s_initTable[] = @@ -316,16 +316,16 @@ InstrumentFunctionArpeggio::InstrumentFunctionArpeggio( Model * _parent ) : m_arpModel.addItem( chord_table[i].getName() ); } - m_arpDirectionModel.addItem( tr( "Up" ), new PixmapLoader( "arp_up" ) ); - m_arpDirectionModel.addItem( tr( "Down" ), new PixmapLoader( "arp_down" ) ); - m_arpDirectionModel.addItem( tr( "Up and down" ), new PixmapLoader( "arp_up_and_down" ) ); - m_arpDirectionModel.addItem( tr( "Down and up" ), new PixmapLoader( "arp_up_and_down" ) ); - m_arpDirectionModel.addItem( tr( "Random" ), new PixmapLoader( "arp_random" ) ); + m_arpDirectionModel.addItem( tr( "Up" ), make_unique( "arp_up" ) ); + m_arpDirectionModel.addItem( tr( "Down" ), make_unique( "arp_down" ) ); + m_arpDirectionModel.addItem( tr( "Up and down" ), make_unique( "arp_up_and_down" ) ); + m_arpDirectionModel.addItem( tr( "Down and up" ), make_unique( "arp_up_and_down" ) ); + m_arpDirectionModel.addItem( tr( "Random" ), make_unique( "arp_random" ) ); m_arpDirectionModel.setInitValue( ArpDirUp ); - m_arpModeModel.addItem( tr( "Free" ), new PixmapLoader( "arp_free" ) ); - m_arpModeModel.addItem( tr( "Sort" ), new PixmapLoader( "arp_sort" ) ); - m_arpModeModel.addItem( tr( "Sync" ), new PixmapLoader( "arp_sync" ) ); + m_arpModeModel.addItem( tr( "Free" ), make_unique( "arp_free" ) ); + m_arpModeModel.addItem( tr( "Sort" ), make_unique( "arp_sort" ) ); + m_arpModeModel.addItem( tr( "Sync" ), make_unique( "arp_sync" ) ); } diff --git a/src/core/InstrumentSoundShaping.cpp b/src/core/InstrumentSoundShaping.cpp index 8d13754da..e25a0d744 100644 --- a/src/core/InstrumentSoundShaping.cpp +++ b/src/core/InstrumentSoundShaping.cpp @@ -33,6 +33,7 @@ #include "Instrument.h" #include "InstrumentTrack.h" #include "Mixer.h" +#include "stdshims.h" const float CUT_FREQ_MULTIPLIER = 6000.0f; @@ -79,28 +80,28 @@ InstrumentSoundShaping::InstrumentSoundShaping( tr( targetNames[i][2].toUtf8().constData() ) ); } - m_filterModel.addItem( tr( "LowPass" ), new PixmapLoader( "filter_lp" ) ); - m_filterModel.addItem( tr( "HiPass" ), new PixmapLoader( "filter_hp" ) ); - m_filterModel.addItem( tr( "BandPass csg" ), new PixmapLoader( "filter_bp" ) ); - m_filterModel.addItem( tr( "BandPass czpg" ), new PixmapLoader( "filter_bp" ) ); - m_filterModel.addItem( tr( "Notch" ), new PixmapLoader( "filter_notch" ) ); - m_filterModel.addItem( tr( "Allpass" ), new PixmapLoader( "filter_ap" ) ); - m_filterModel.addItem( tr( "Moog" ), new PixmapLoader( "filter_lp" ) ); - m_filterModel.addItem( tr( "2x LowPass" ), new PixmapLoader( "filter_2lp" ) ); - m_filterModel.addItem( tr( "RC LowPass 12dB" ), new PixmapLoader( "filter_lp" ) ); - m_filterModel.addItem( tr( "RC BandPass 12dB" ), new PixmapLoader( "filter_bp" ) ); - m_filterModel.addItem( tr( "RC HighPass 12dB" ), new PixmapLoader( "filter_hp" ) ); - m_filterModel.addItem( tr( "RC LowPass 24dB" ), new PixmapLoader( "filter_lp" ) ); - m_filterModel.addItem( tr( "RC BandPass 24dB" ), new PixmapLoader( "filter_bp" ) ); - m_filterModel.addItem( tr( "RC HighPass 24dB" ), new PixmapLoader( "filter_hp" ) ); - m_filterModel.addItem( tr( "Vocal Formant Filter" ), new PixmapLoader( "filter_hp" ) ); - m_filterModel.addItem( tr( "2x Moog" ), new PixmapLoader( "filter_2lp" ) ); - m_filterModel.addItem( tr( "SV LowPass" ), new PixmapLoader( "filter_lp" ) ); - m_filterModel.addItem( tr( "SV BandPass" ), new PixmapLoader( "filter_bp" ) ); - m_filterModel.addItem( tr( "SV HighPass" ), new PixmapLoader( "filter_hp" ) ); - m_filterModel.addItem( tr( "SV Notch" ), new PixmapLoader( "filter_notch" ) ); - m_filterModel.addItem( tr( "Fast Formant" ), new PixmapLoader( "filter_hp" ) ); - m_filterModel.addItem( tr( "Tripole" ), new PixmapLoader( "filter_lp" ) ); + m_filterModel.addItem( tr( "LowPass" ), make_unique( "filter_lp" ) ); + m_filterModel.addItem( tr( "HiPass" ), make_unique( "filter_hp" ) ); + m_filterModel.addItem( tr( "BandPass csg" ), make_unique( "filter_bp" ) ); + m_filterModel.addItem( tr( "BandPass czpg" ), make_unique( "filter_bp" ) ); + m_filterModel.addItem( tr( "Notch" ), make_unique( "filter_notch" ) ); + m_filterModel.addItem( tr( "Allpass" ), make_unique( "filter_ap" ) ); + m_filterModel.addItem( tr( "Moog" ), make_unique( "filter_lp" ) ); + m_filterModel.addItem( tr( "2x LowPass" ), make_unique( "filter_2lp" ) ); + m_filterModel.addItem( tr( "RC LowPass 12dB" ), make_unique( "filter_lp" ) ); + m_filterModel.addItem( tr( "RC BandPass 12dB" ), make_unique( "filter_bp" ) ); + m_filterModel.addItem( tr( "RC HighPass 12dB" ), make_unique( "filter_hp" ) ); + m_filterModel.addItem( tr( "RC LowPass 24dB" ), make_unique( "filter_lp" ) ); + m_filterModel.addItem( tr( "RC BandPass 24dB" ), make_unique( "filter_bp" ) ); + m_filterModel.addItem( tr( "RC HighPass 24dB" ), make_unique( "filter_hp" ) ); + m_filterModel.addItem( tr( "Vocal Formant Filter" ), make_unique( "filter_hp" ) ); + m_filterModel.addItem( tr( "2x Moog" ), make_unique( "filter_2lp" ) ); + m_filterModel.addItem( tr( "SV LowPass" ), make_unique( "filter_lp" ) ); + m_filterModel.addItem( tr( "SV BandPass" ), make_unique( "filter_bp" ) ); + m_filterModel.addItem( tr( "SV HighPass" ), make_unique( "filter_hp" ) ); + m_filterModel.addItem( tr( "SV Notch" ), make_unique( "filter_notch" ) ); + m_filterModel.addItem( tr( "Fast Formant" ), make_unique( "filter_hp" ) ); + m_filterModel.addItem( tr( "Tripole" ), make_unique( "filter_lp" ) ); } diff --git a/src/core/audio/AudioPort.cpp b/src/core/audio/AudioPort.cpp index 868f9f64f..e9beb3c0e 100644 --- a/src/core/audio/AudioPort.cpp +++ b/src/core/audio/AudioPort.cpp @@ -56,7 +56,6 @@ AudioPort::~AudioPort() { setExtOutputEnabled( false ); Engine::mixer()->removeAudioPort( this ); - delete m_effects; BufferManager::release( m_portBuffer ); } diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 691a0af88..7813e1926 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -40,6 +40,7 @@ #endif #include +#include #include "AutomationEditor.h" #include "ActionGroup.h" @@ -57,6 +58,7 @@ #include "MainWindow.h" #include "Pattern.h" #include "SongEditor.h" +#include "stdshims.h" #include "TextFloat.h" #include "TimeLineWidget.h" @@ -65,6 +67,7 @@ #define MiddleButton MidButton #endif +using namespace std; typedef AutomationPattern::timeMap timeMap; @@ -370,7 +373,7 @@ PianoRoll::PianoRoll() : // Set up note length model m_noteLenModel.addItem( tr( "Last note" ), - new PixmapLoader( "edit_draw" ) ); + make_unique( "edit_draw" ) ); const QString pixmaps[] = { "whole", "half", "quarter", "eighth", "sixteenth", "thirtysecond", "triplethalf", "tripletquarter", "tripleteighth", @@ -378,13 +381,13 @@ PianoRoll::PianoRoll() : for( int i = 0; i < NUM_EVEN_LENGTHS; ++i ) { - PixmapLoader *loader = new PixmapLoader( "note_" + pixmaps[i] ); - m_noteLenModel.addItem( "1/" + QString::number( 1 << i ), loader ); + auto loader = make_unique( "note_" + pixmaps[i] ); + m_noteLenModel.addItem( "1/" + QString::number( 1 << i ), ::move(loader) ); } for( int i = 0; i < NUM_TRIPLET_LENGTHS; ++i ) { - PixmapLoader *loader = new PixmapLoader( "note_" + pixmaps[i+NUM_EVEN_LENGTHS] ); - m_noteLenModel.addItem( "1/" + QString::number( (1 << i) * 3 ), loader ); + auto loader = make_unique( "note_" + pixmaps[i+NUM_EVEN_LENGTHS] ); + m_noteLenModel.addItem( "1/" + QString::number( (1 << i) * 3 ), ::move(loader) ); } m_noteLenModel.setValue( 0 ); From 0f993895d40afec8d3a7fd9e7c69e04d88f8580f Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Fri, 9 Mar 2018 23:48:07 -0800 Subject: [PATCH 2/7] Fix missing includes --- include/stdshims.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/stdshims.h b/include/stdshims.h index 1551d0a0f..a17902d7e 100644 --- a/include/stdshims.h +++ b/include/stdshims.h @@ -3,6 +3,9 @@ #pragma once +#include +#include + /// Shim for http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique template std::unique_ptr make_unique(Args&&... args) From 876615e3a3addea608ce85114dc3f4bd22e9caa2 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sat, 10 Mar 2018 00:28:58 -0800 Subject: [PATCH 3/7] Warn when compiling with C++14 or greater. --- include/stdshims.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/stdshims.h b/include/stdshims.h index a17902d7e..14958e1fc 100644 --- a/include/stdshims.h +++ b/include/stdshims.h @@ -6,6 +6,10 @@ #include #include +#if (__cplusplus >= 201402L) +#warning "This file should now be removed! The functions it provides are part of the C++14 standard." +#endif + /// Shim for http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique template std::unique_ptr make_unique(Args&&... args) From a9d097cad957582f3c524825493ea4e4bdc16d0c Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sat, 10 Mar 2018 16:08:21 -0800 Subject: [PATCH 4/7] Prefer emplace_back; take argument by value. We copy the QString, so it makes sense to accept it by value and _move_ it into the collection instead. This causes the caller to move any rvalue QString into the function, and then the QString is never actually copied at all. --- include/ComboBoxModel.h | 2 +- src/core/ComboBoxModel.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ComboBoxModel.h b/include/ComboBoxModel.h index ed2465cfb..e4088679f 100644 --- a/include/ComboBoxModel.h +++ b/include/ComboBoxModel.h @@ -49,7 +49,7 @@ public: clear(); } - void addItem( const QString& item, std::unique_ptr loader = nullptr ); + void addItem( QString item, std::unique_ptr loader = nullptr ); void clear(); diff --git a/src/core/ComboBoxModel.cpp b/src/core/ComboBoxModel.cpp index 1c7e2d9c5..c91b4483d 100644 --- a/src/core/ComboBoxModel.cpp +++ b/src/core/ComboBoxModel.cpp @@ -27,9 +27,9 @@ -void ComboBoxModel::addItem( const QString& item, std::unique_ptr loader ) +void ComboBoxModel::addItem( QString item, std::unique_ptr loader ) { - m_items.push_back( std::make_pair( item, std::move(loader) ) ); + m_items.emplace_back( std::move(item), std::move(loader) ); setRange( 0, m_items.size() - 1 ); } From ba278becbd123498e11535dac4671d8bd128bbfe Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sat, 10 Mar 2018 23:29:22 -0800 Subject: [PATCH 5/7] Don't use #pragma; don't redefine make_unique if using C++14 --- include/stdshims.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/stdshims.h b/include/stdshims.h index 14958e1fc..86e355d04 100644 --- a/include/stdshims.h +++ b/include/stdshims.h @@ -1,14 +1,17 @@ //! Shims for std:: functions that aren't available in the current C++ versions //! we target. -#pragma once +#ifndef STDSHIMS_H +#define STDSHIMS_H #include #include #if (__cplusplus >= 201402L) #warning "This file should now be removed! The functions it provides are part of the C++14 standard." -#endif +using std::unique_ptr; + +#else /// Shim for http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique template @@ -16,4 +19,7 @@ std::unique_ptr make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } +#endif + +#endif // include guard From c8d9cc02d560108fe3406236dd27029761942d2c Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sat, 10 Mar 2018 23:30:30 -0800 Subject: [PATCH 6/7] Use namespace std instead of prefixing {move,unique_ptr} with std::. --- src/core/ComboBoxModel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ComboBoxModel.cpp b/src/core/ComboBoxModel.cpp index c91b4483d..62c673aad 100644 --- a/src/core/ComboBoxModel.cpp +++ b/src/core/ComboBoxModel.cpp @@ -25,11 +25,11 @@ #include "ComboBoxModel.h" #include "embed.h" +using namespace std; - -void ComboBoxModel::addItem( QString item, std::unique_ptr loader ) +void ComboBoxModel::addItem( QString item, unique_ptr loader ) { - m_items.emplace_back( std::move(item), std::move(loader) ); + m_items.emplace_back( move(item), move(loader) ); setRange( 0, m_items.size() - 1 ); } From ec3c9cdf100a41e0f9738a49b75944d4115ab944 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sun, 11 Mar 2018 09:07:00 -0700 Subject: [PATCH 7/7] Only `use` specific `std::` items we need. Also, fix `using std::unique_ptr` to `using std::make_unique` in stdshims.h --- include/stdshims.h | 2 +- src/core/ComboBoxModel.cpp | 3 ++- src/gui/editors/PianoRoll.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/stdshims.h b/include/stdshims.h index 86e355d04..456d31607 100644 --- a/include/stdshims.h +++ b/include/stdshims.h @@ -9,7 +9,7 @@ #if (__cplusplus >= 201402L) #warning "This file should now be removed! The functions it provides are part of the C++14 standard." -using std::unique_ptr; +using std::make_unique; #else diff --git a/src/core/ComboBoxModel.cpp b/src/core/ComboBoxModel.cpp index 62c673aad..7fa905abe 100644 --- a/src/core/ComboBoxModel.cpp +++ b/src/core/ComboBoxModel.cpp @@ -25,7 +25,8 @@ #include "ComboBoxModel.h" #include "embed.h" -using namespace std; +using std::unique_ptr; +using std::move; void ComboBoxModel::addItem( QString item, unique_ptr loader ) { diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 7813e1926..4a044891e 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -67,7 +67,7 @@ #define MiddleButton MidButton #endif -using namespace std; +using std::move; typedef AutomationPattern::timeMap timeMap;