From d42a6850079961e1945cd535375061a5d50c61ca Mon Sep 17 00:00:00 2001 From: Lukas W Date: Wed, 25 Apr 2018 18:49:39 +0200 Subject: [PATCH] Refactoring: Remove duplicate code (#4310) --- include/BandLimitedWave.h | 43 +-- include/DspEffectLibrary.h | 66 ++-- include/LadspaManager.h | 5 + include/RenderManager.h | 2 + include/SampleBuffer.h | 6 +- include/SamplePlayHandle.h | 2 +- include/Track.h | 1 + include/VstSyncController.h | 19 -- src/core/EffectChain.cpp | 30 +- src/core/LadspaManager.cpp | 553 ++++++++-------------------------- src/core/RenderManager.cpp | 37 +-- src/core/SampleBuffer.cpp | 78 ++--- src/core/SamplePlayHandle.cpp | 40 +-- src/core/Track.cpp | 28 +- src/core/main.cpp | 92 ++---- src/gui/MainWindow.cpp | 53 ++-- 16 files changed, 286 insertions(+), 769 deletions(-) diff --git a/include/BandLimitedWave.h b/include/BandLimitedWave.h index edcb595fe..55f6e482c 100644 --- a/include/BandLimitedWave.h +++ b/include/BandLimitedWave.h @@ -125,48 +125,9 @@ public: */ static inline sample_t oscillate( float _ph, float _wavelen, Waveforms _wave ) { - // high wavelen/ low freq - if( _wavelen > TLENS[ MAXTBL ] ) - { - const int t = MAXTBL; - const int tlen = TLENS[t]; - const float ph = fraction( _ph ); - const float lookupf = ph * static_cast( tlen ); - const int lookup = static_cast( lookupf ); - const float ip = fraction( lookupf ); - - const sample_t s1 = s_waveforms[ _wave ].sampleAt( t, lookup ); - const sample_t s2 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 1 ) % tlen ); - const int lm = lookup == 0 ? tlen - 1 : lookup - 1; - const sample_t s0 = s_waveforms[ _wave ].sampleAt( t, lm ); - const sample_t s3 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 2 ) % tlen ); - const sample_t sr = optimal4pInterpolate( s0, s1, s2, s3, ip ); - - return sr; - } - // low wavelen/ high freq - if( _wavelen < 3.0f ) - { - const int t = 0; - const int tlen = TLENS[t]; - const float ph = fraction( _ph ); - const float lookupf = ph * static_cast( tlen ); - const int lookup = static_cast( lookupf ); - const float ip = fraction( lookupf ); - - const sample_t s1 = s_waveforms[ _wave ].sampleAt( t, lookup ); - const sample_t s2 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 1 ) % tlen ); - const int lm = lookup == 0 ? tlen - 1 : lookup - 1; - const sample_t s0 = s_waveforms[ _wave ].sampleAt( t, lm ); - const sample_t s3 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 2 ) % tlen ); - const sample_t sr = optimal4pInterpolate( s0, s1, s2, s3, ip ); - - return sr; - } - // get the next higher tlen - int t = MAXTBL - 1; - while( _wavelen < TLENS[t] ) { t--; } + int t = 0; + while( t < MAXTBL && _wavelen >= TLENS[t+1] ) { t++; } int tlen = TLENS[t]; const float ph = fraction( _ph ); diff --git a/include/DspEffectLibrary.h b/include/DspEffectLibrary.h index e440f013b..76296da0b 100644 --- a/include/DspEffectLibrary.h +++ b/include/DspEffectLibrary.h @@ -245,15 +245,37 @@ namespace DspEffectLibrary } ; - class FoldbackDistortion : public MonoBase + template + class DistortionBase : public MonoBase { public: - FoldbackDistortion( float threshold, float gain ) : + DistortionBase( float threshold, float gain ) : m_threshold( threshold ), m_gain( gain ) { } + void setThreshold( float threshold ) + { + m_threshold = threshold; + } + + void setGain( float gain ) + { + m_gain = gain; + } + + protected: + float m_threshold; + float m_gain; + }; + + + class FoldbackDistortion : public DistortionBase + { + public: + using DistortionBase::DistortionBase; + sample_t nextSample( sample_t in ) { if( in >= m_threshold || in < -m_threshold ) @@ -262,54 +284,18 @@ namespace DspEffectLibrary } return in * m_gain; } - - void setThreshold( float threshold ) - { - m_threshold = threshold; - } - - void setGain( float gain ) - { - m_gain = gain; - } - - - private: - float m_threshold; - float m_gain; - } ; - class Distortion : public MonoBase + class Distortion : public DistortionBase { public: - Distortion( float threshold, float gain ) : - m_threshold( threshold ), - m_gain( gain ) - { - } + using DistortionBase::DistortionBase; sample_t nextSample( sample_t in ) { return m_gain * ( in * ( fabsf( in )+m_threshold ) / ( in*in +( m_threshold-1 )* fabsf( in ) + 1 ) ); } - - void setThreshold( float threshold ) - { - m_threshold = threshold; - } - - void setGain( float gain ) - { - m_gain = gain; - } - - - private: - float m_threshold; - float m_gain; - } ; diff --git a/include/LadspaManager.h b/include/LadspaManager.h index 1d055c1d8..2338fbd4b 100644 --- a/include/LadspaManager.h +++ b/include/LadspaManager.h @@ -334,6 +334,11 @@ private: uint16_t getPluginInputs( const LADSPA_Descriptor * _descriptor ); uint16_t getPluginOutputs( const LADSPA_Descriptor * _descriptor ); + const LADSPA_PortDescriptor* getPortDescriptor( const ladspa_key_t& _plugin, + uint32_t _port ); + const LADSPA_PortRangeHint* getPortRangeHint( const ladspa_key_t& _plugin, + uint32_t _port ); + typedef QMap ladspaManagerMapType; ladspaManagerMapType m_ladspaManagerMap; diff --git a/include/RenderManager.h b/include/RenderManager.h index 75f308b7d..01236d747 100644 --- a/include/RenderManager.h +++ b/include/RenderManager.h @@ -64,6 +64,8 @@ private: QString pathForTrack( const Track *track, int num ); void restoreMutedState(); + void render( QString outputPath ); + const Mixer::qualitySettings m_qualitySettings; const Mixer::qualitySettings m_oldQualitySettings; const OutputSettings m_outputSettings; diff --git a/include/SampleBuffer.h b/include/SampleBuffer.h index 66f4ec873..01c685fda 100644 --- a/include/SampleBuffer.h +++ b/include/SampleBuffer.h @@ -103,12 +103,12 @@ public: } ; + SampleBuffer(); // constructor which either loads sample _audio_file or decodes // base64-data out of string - SampleBuffer( const QString & _audio_file = QString(), - bool _is_base64_data = false ); + SampleBuffer( const QString & _audio_file, bool _is_base64_data = false ); SampleBuffer( const sampleFrame * _data, const f_cnt_t _frames ); - SampleBuffer( const f_cnt_t _frames ); + explicit SampleBuffer( const f_cnt_t _frames ); virtual ~SampleBuffer(); diff --git a/include/SamplePlayHandle.h b/include/SamplePlayHandle.h index 201241885..9a051ec7b 100644 --- a/include/SamplePlayHandle.h +++ b/include/SamplePlayHandle.h @@ -38,8 +38,8 @@ class AudioPort; class SamplePlayHandle : public PlayHandle { public: - SamplePlayHandle( const QString& sampleFile ); SamplePlayHandle( SampleBuffer* sampleBuffer ); + SamplePlayHandle( const QString& sampleFile ); SamplePlayHandle( SampleTCO* tco ); virtual ~SamplePlayHandle(); diff --git a/include/Track.h b/include/Track.h index 575ed5f3d..8b1bf5e90 100644 --- a/include/Track.h +++ b/include/Track.h @@ -438,6 +438,7 @@ private slots: void cloneTrack(); void removeTrack(); void updateMenu(); + void toggleRecording(bool on); void recordingOn(); void recordingOff(); void clearTrack(); diff --git a/include/VstSyncController.h b/include/VstSyncController.h index b969ebbbe..c9190a9d8 100644 --- a/include/VstSyncController.h +++ b/include/VstSyncController.h @@ -69,25 +69,6 @@ private slots: private: - struct VstSyncData - { - bool isPlaying; - float ppqPos; - int timeSigNumer; - int timeSigDenom; - bool isCycle; - bool hasSHM; - float cycleStart; - float cycleEnd; - int m_bufferSize; - int m_sampleRate; - int m_bpm; - -#ifdef VST_SNC_LATENCY - float m_latency; -#endif - } ; - VstSyncData* m_syncData; int m_shmID; diff --git a/src/core/EffectChain.cpp b/src/core/EffectChain.cpp index b47267e8f..4d0c5e8ae 100644 --- a/src/core/EffectChain.cpp +++ b/src/core/EffectChain.cpp @@ -162,19 +162,8 @@ void EffectChain::moveDown( Effect * _effect ) { if( _effect != m_effects.last() ) { - int i = 0; - for( EffectList::Iterator it = m_effects.begin(); - it != m_effects.end(); it++, i++ ) - { - if( *it == _effect ) - { - break; - } - } - - Effect * temp = m_effects[i + 1]; - m_effects[i + 1] = _effect; - m_effects[i] = temp; + int i = m_effects.indexOf(_effect); + std::swap(m_effects[i + 1], m_effects[i]); } } @@ -185,19 +174,8 @@ void EffectChain::moveUp( Effect * _effect ) { if( _effect != m_effects.first() ) { - int i = 0; - for( EffectList::Iterator it = m_effects.begin(); - it != m_effects.end(); it++, i++ ) - { - if( *it == _effect ) - { - break; - } - } - - Effect * temp = m_effects[i - 1]; - m_effects[i - 1] = _effect; - m_effects[i] = temp; + int i = m_effects.indexOf(_effect); + std::swap(m_effects[i - 1], m_effects[i]); } } diff --git a/src/core/LadspaManager.cpp b/src/core/LadspaManager.cpp index fc06dfda9..176fde18b 100644 --- a/src/core/LadspaManager.cpp +++ b/src/core/LadspaManager.cpp @@ -235,6 +235,26 @@ uint16_t LadspaManager::getPluginOutputs( return outputs; } +const LADSPA_PortDescriptor* LadspaManager::getPortDescriptor(const ladspa_key_t &_plugin, uint32_t _port) +{ + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && _port < getPortCount( _plugin ) ) + { + return( & descriptor->PortDescriptors[_port] ); + } + return( NULL ); +} + +const LADSPA_PortRangeHint *LadspaManager::getPortRangeHint(const ladspa_key_t &_plugin, uint32_t _port) +{ + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && _port < getPortCount( _plugin ) ) + { + return( & descriptor->PortRangeHints[_port] ); + } + return( NULL ); +} + @@ -248,19 +268,8 @@ l_sortable_plugin_t LadspaManager::getSortedPlugins() QString LadspaManager::getLabel( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( QString( descriptor->Label ) ); - } - else - { - return( QString( "" ) ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->Label : "" ); } @@ -269,19 +278,9 @@ QString LadspaManager::getLabel( const ladspa_key_t & _plugin ) bool LadspaManager::hasRealTimeDependency( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( LADSPA_IS_REALTIME( descriptor->Properties ) ); - } - else - { - return( false ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? LADSPA_IS_REALTIME( descriptor->Properties ) + : false ); } @@ -289,19 +288,9 @@ bool LadspaManager::hasRealTimeDependency( bool LadspaManager::isInplaceBroken( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( LADSPA_IS_INPLACE_BROKEN( descriptor->Properties ) ); - } - else - { - return( false ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? LADSPA_IS_INPLACE_BROKEN( descriptor->Properties ) + : false ); } @@ -310,19 +299,9 @@ bool LadspaManager::isInplaceBroken( const ladspa_key_t & _plugin ) bool LadspaManager::isRealTimeCapable( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( LADSPA_IS_HARD_RT_CAPABLE( descriptor->Properties ) ); - } - else - { - return( false ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? LADSPA_IS_HARD_RT_CAPABLE( descriptor->Properties ) + : false ); } @@ -330,19 +309,8 @@ bool LadspaManager::isRealTimeCapable( QString LadspaManager::getName( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( QString( descriptor->Name ) ); - } - else - { - return( QString( "" ) ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->Name : "" ); } @@ -350,19 +318,8 @@ QString LadspaManager::getName( const ladspa_key_t & _plugin ) QString LadspaManager::getMaker( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( QString( descriptor->Maker ) ); - } - else - { - return( QString( "" ) ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->Maker : "" ); } @@ -370,19 +327,8 @@ QString LadspaManager::getMaker( const ladspa_key_t & _plugin ) QString LadspaManager::getCopyright( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( QString( descriptor->Copyright ) ); - } - else - { - return( QString( "" ) ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->Copyright : "" ); } @@ -390,19 +336,8 @@ QString LadspaManager::getCopyright( const ladspa_key_t & _plugin ) uint32_t LadspaManager::getPortCount( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( descriptor->PortCount ); - } - else - { - return( 0 ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->PortCount : 0 ); } @@ -411,22 +346,8 @@ uint32_t LadspaManager::getPortCount( const ladspa_key_t & _plugin ) bool LadspaManager::isPortInput( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - - return( LADSPA_IS_PORT_INPUT - ( descriptor->PortDescriptors[_port] ) ); - } - else - { - return( false ); - } + const auto * descriptor = getPortDescriptor( _plugin, _port ); + return( descriptor && LADSPA_IS_PORT_INPUT( * descriptor ) ); } @@ -435,22 +356,8 @@ bool LadspaManager::isPortInput( const ladspa_key_t & _plugin, bool LadspaManager::isPortOutput( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - - return( LADSPA_IS_PORT_OUTPUT - ( descriptor->PortDescriptors[_port] ) ); - } - else - { - return( false ); - } + const auto * descriptor = getPortDescriptor( _plugin, _port ); + return( descriptor && LADSPA_IS_PORT_OUTPUT( * descriptor ) ); } @@ -459,22 +366,8 @@ bool LadspaManager::isPortOutput( const ladspa_key_t & _plugin, bool LadspaManager::isPortAudio( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - - return( LADSPA_IS_PORT_AUDIO - ( descriptor->PortDescriptors[_port] ) ); - } - else - { - return( false ); - } + const auto * descriptor = getPortDescriptor( _plugin, _port ); + return( descriptor && LADSPA_IS_PORT_AUDIO( * descriptor ) ); } @@ -483,22 +376,8 @@ bool LadspaManager::isPortAudio( const ladspa_key_t & _plugin, bool LadspaManager::isPortControl( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - - return( LADSPA_IS_PORT_CONTROL - ( descriptor->PortDescriptors[_port] ) ); - } - else - { - return( false ); - } + const auto * descriptor = getPortDescriptor( _plugin, _port ); + return( descriptor && LADSPA_IS_PORT_CONTROL( * descriptor ) ); } @@ -508,22 +387,8 @@ bool LadspaManager::areHintsSampleRateDependent( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - return( LADSPA_IS_HINT_SAMPLE_RATE ( hintDescriptor ) ); - } - else - { - return( false ); - } + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + return portRangeHint && LADSPA_IS_HINT_SAMPLE_RATE( portRangeHint->HintDescriptor ); } @@ -532,59 +397,26 @@ bool LadspaManager::areHintsSampleRateDependent( float LadspaManager::getLowerBound( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + if( portRangeHint && LADSPA_IS_HINT_BOUNDED_BELOW( portRangeHint->HintDescriptor ) ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - if( LADSPA_IS_HINT_BOUNDED_BELOW( hintDescriptor ) ) - { - return( descriptor->PortRangeHints[_port].LowerBound ); - } - else - { - return( NOHINT ); - } - } - else - { - return( NOHINT ); + return( portRangeHint->LowerBound ); } + return( NOHINT ); } -float LadspaManager::getUpperBound( const ladspa_key_t & _plugin, uint32_t _port ) +float LadspaManager::getUpperBound( const ladspa_key_t & _plugin, + uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + if( portRangeHint && LADSPA_IS_HINT_BOUNDED_ABOVE( portRangeHint->HintDescriptor ) ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - if( LADSPA_IS_HINT_BOUNDED_ABOVE( hintDescriptor ) ) - { - return( descriptor->PortRangeHints[_port].UpperBound ); - } - else - { - return( NOHINT ); - } - } - else - { - return( NOHINT ); + return( portRangeHint->UpperBound ); } + return( NOHINT ); } @@ -593,22 +425,8 @@ float LadspaManager::getUpperBound( const ladspa_key_t & _plugin, uint32 bool LadspaManager::isPortToggled( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - return( LADSPA_IS_HINT_TOGGLED( hintDescriptor ) ); - } - else - { - return( false ); - } + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + return( portRangeHint && LADSPA_IS_HINT_TOGGLED( portRangeHint->HintDescriptor ) ); } @@ -617,69 +435,54 @@ bool LadspaManager::isPortToggled( const ladspa_key_t & _plugin, float LadspaManager::getDefaultSetting( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + if( portRangeHint ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; + LADSPA_PortRangeHintDescriptor hintDescriptor = portRangeHint->HintDescriptor; switch( hintDescriptor & LADSPA_HINT_DEFAULT_MASK ) { case LADSPA_HINT_DEFAULT_NONE: return( NOHINT ); case LADSPA_HINT_DEFAULT_MINIMUM: - return( descriptor->PortRangeHints[_port]. - LowerBound ); + return( portRangeHint->LowerBound ); case LADSPA_HINT_DEFAULT_LOW: if( LADSPA_IS_HINT_LOGARITHMIC ( hintDescriptor ) ) { - return( exp( log( descriptor->PortRangeHints[_port].LowerBound ) - * 0.75 - + log( descriptor->PortRangeHints[_port].UpperBound ) - * 0.25 ) ); + return( exp( log( portRangeHint->LowerBound ) * 0.75 + + log( portRangeHint->UpperBound ) * 0.25 ) ); } else { - return( descriptor->PortRangeHints[_port].LowerBound - * 0.75 - + descriptor->PortRangeHints[_port].UpperBound - * 0.25 ); + return( portRangeHint->LowerBound * 0.75 + + portRangeHint->UpperBound * 0.25 ); } case LADSPA_HINT_DEFAULT_MIDDLE: if( LADSPA_IS_HINT_LOGARITHMIC ( hintDescriptor ) ) { - return( sqrt( descriptor->PortRangeHints[_port].LowerBound - * descriptor->PortRangeHints[_port].UpperBound ) ); + return( sqrt( portRangeHint->LowerBound + * portRangeHint->UpperBound ) ); } else { - return( 0.5 * ( descriptor->PortRangeHints[_port].LowerBound - + descriptor->PortRangeHints[_port].UpperBound ) ); + return( 0.5 * ( portRangeHint->LowerBound + + portRangeHint->UpperBound ) ); } case LADSPA_HINT_DEFAULT_HIGH: if( LADSPA_IS_HINT_LOGARITHMIC ( hintDescriptor ) ) { - return( exp( log( descriptor->PortRangeHints[_port].LowerBound ) - * 0.25 - + log( descriptor->PortRangeHints[_port].UpperBound ) - * 0.75 ) ); + return( exp( log( portRangeHint->LowerBound ) * 0.25 + + log( portRangeHint->UpperBound ) * 0.75 ) ); } else { - return( descriptor->PortRangeHints[_port].LowerBound - * 0.25 - + descriptor->PortRangeHints[_port].UpperBound - * 0.75 ); + return( portRangeHint->LowerBound * 0.25 + + portRangeHint->UpperBound * 0.75 ); } case LADSPA_HINT_DEFAULT_MAXIMUM: - return( descriptor->PortRangeHints[_port].UpperBound ); + return( portRangeHint->UpperBound ); case LADSPA_HINT_DEFAULT_0: return( 0.0 ); case LADSPA_HINT_DEFAULT_1: @@ -704,22 +507,8 @@ float LadspaManager::getDefaultSetting( const ladspa_key_t & _plugin, bool LadspaManager::isLogarithmic( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - return( LADSPA_IS_HINT_LOGARITHMIC( hintDescriptor ) ); - } - else - { - return( false ); - } + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + return( portRangeHint && LADSPA_IS_HINT_LOGARITHMIC( portRangeHint->HintDescriptor ) ); } @@ -728,22 +517,8 @@ bool LadspaManager::isLogarithmic( const ladspa_key_t & _plugin, bool LadspaManager::isInteger( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - LADSPA_PortRangeHintDescriptor hintDescriptor = - descriptor->PortRangeHints[_port].HintDescriptor; - return( LADSPA_IS_HINT_INTEGER( hintDescriptor ) ); - } - else - { - return( false ); - } + const auto* portRangeHint = getPortRangeHint( _plugin, _port ); + return( portRangeHint && LADSPA_IS_HINT_INTEGER( portRangeHint->HintDescriptor ) ); } @@ -777,21 +552,8 @@ bool LadspaManager::isEnum( const ladspa_key_t & _plugin, uint32_t _port ) QString LadspaManager::getPortName( const ladspa_key_t & _plugin, uint32_t _port ) { - if( m_ladspaManagerMap.contains( _plugin ) && - _port < getPortCount( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - - return( QString( descriptor->PortNames[_port] ) ); - } - else - { - return( QString( "" ) ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->PortNames[_port] : QString( "" ) ); } @@ -800,19 +562,8 @@ QString LadspaManager::getPortName( const ladspa_key_t & _plugin, const void * LadspaManager::getImplementationData( const ladspa_key_t & _plugin ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( descriptor->ImplementationData ); - } - else - { - return( NULL ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? descriptor->ImplementationData : NULL ); } @@ -843,20 +594,10 @@ LADSPA_Handle LadspaManager::instantiate( const ladspa_key_t & _plugin, uint32_t _sample_rate ) { - if( m_ladspaManagerMap.contains( _plugin ) ) - { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - return( ( descriptor->instantiate ) - ( descriptor, _sample_rate ) ); - } - else - { - return( NULL ); - } + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + return( descriptor ? + ( descriptor->instantiate )( descriptor, _sample_rate ) : + NULL ); } @@ -867,20 +608,13 @@ bool LadspaManager::connectPort( const ladspa_key_t & _plugin, uint32_t _port, LADSPA_Data * _data_location ) { - if( m_ladspaManagerMap.contains( _plugin ) - && _port < getPortCount( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->connect_port != NULL && + _port < getPortCount( _plugin ) ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->connect_port != NULL ) - { - ( descriptor->connect_port ) - ( _instance, _port, _data_location ); - return( true ); - } + ( descriptor->connect_port ) + ( _instance, _port, _data_location ); + return( true ); } return( false ); } @@ -891,18 +625,11 @@ bool LadspaManager::connectPort( const ladspa_key_t & _plugin, bool LadspaManager::activate( const ladspa_key_t & _plugin, LADSPA_Handle _instance ) { - if( m_ladspaManagerMap.contains( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->activate != NULL ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->activate != NULL ) - { - ( descriptor->activate ) ( _instance ); - return( true ); - } + ( descriptor->activate ) ( _instance ); + return( true ); } return( false ); } @@ -914,18 +641,11 @@ bool LadspaManager::run( const ladspa_key_t & _plugin, LADSPA_Handle _instance, uint32_t _sample_count ) { - if( m_ladspaManagerMap.contains( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->run!= NULL ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->run != NULL ) - { - ( descriptor->run ) ( _instance, _sample_count ); - return( true ); - } + ( descriptor->run ) ( _instance, _sample_count ); + return( true ); } return( false ); } @@ -937,19 +657,12 @@ bool LadspaManager::runAdding( const ladspa_key_t & _plugin, LADSPA_Handle _instance, uint32_t _sample_count ) { - if( m_ladspaManagerMap.contains( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->run_adding!= NULL + && descriptor->set_run_adding_gain != NULL ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->run_adding != NULL && - descriptor->set_run_adding_gain != NULL ) - { - ( descriptor->run_adding ) ( _instance, _sample_count ); - return( true ); - } + ( descriptor->run_adding ) ( _instance, _sample_count ); + return( true ); } return( false ); } @@ -961,20 +674,12 @@ bool LadspaManager::setRunAddingGain( const ladspa_key_t & _plugin, LADSPA_Handle _instance, LADSPA_Data _gain ) { - if( m_ladspaManagerMap.contains( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->run_adding!= NULL + && descriptor->set_run_adding_gain != NULL ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->run_adding != NULL && - descriptor->set_run_adding_gain != NULL ) - { - ( descriptor->set_run_adding_gain ) - ( _instance, _gain ); - return( true ); - } + ( descriptor->set_run_adding_gain ) ( _instance, _gain ); + return( true ); } return( false ); } @@ -985,18 +690,11 @@ bool LadspaManager::setRunAddingGain( const ladspa_key_t & _plugin, bool LadspaManager::deactivate( const ladspa_key_t & _plugin, LADSPA_Handle _instance ) { - if( m_ladspaManagerMap.contains( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->deactivate!= NULL ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->deactivate != NULL ) - { - ( descriptor->deactivate ) ( _instance ); - return( true ); - } + ( descriptor->deactivate ) ( _instance ); + return( true ); } return( false ); } @@ -1007,18 +705,11 @@ bool LadspaManager::deactivate( const ladspa_key_t & _plugin, bool LadspaManager::cleanup( const ladspa_key_t & _plugin, LADSPA_Handle _instance ) { - if( m_ladspaManagerMap.contains( _plugin ) ) + const LADSPA_Descriptor * descriptor = getDescriptor( _plugin ); + if( descriptor && descriptor->cleanup!= NULL ) { - LADSPA_Descriptor_Function descriptorFunction = - m_ladspaManagerMap[_plugin]->descriptorFunction; - const LADSPA_Descriptor * descriptor = - descriptorFunction( - m_ladspaManagerMap[_plugin]->index ); - if( descriptor->cleanup != NULL ) - { - ( descriptor->cleanup ) ( _instance ); - return( true ); - } + ( descriptor->cleanup ) ( _instance ); + return( true ); } return( false ); } diff --git a/src/core/RenderManager.cpp b/src/core/RenderManager.cpp index e01e19bcd..9cad4dd1e 100644 --- a/src/core/RenderManager.cpp +++ b/src/core/RenderManager.cpp @@ -88,30 +88,7 @@ void RenderManager::renderNextTrack() // for multi-render, prefix each output file with a different number int trackNum = m_tracksToRender.size() + 1; - // create a renderer for this track - m_activeRenderer = make_unique( - m_qualitySettings, - m_outputSettings, - m_format, - pathForTrack(renderTrack, trackNum)); - - if ( m_activeRenderer->isReady() ) - { - // pass progress signals through - connect( m_activeRenderer.get(), SIGNAL( progressChanged( int ) ), - this, SIGNAL( progressChanged( int ) ) ); - - // when it is finished, render the next track - connect( m_activeRenderer.get(), SIGNAL( finished() ), - this, SLOT( renderNextTrack() ) ); - - m_activeRenderer->startProcessing(); - } - else - { - qDebug( "Renderer failed to acquire a file device!" ); - renderNextTrack(); - } + render( pathForTrack(renderTrack, trackNum) ); } } @@ -153,12 +130,17 @@ void RenderManager::renderTracks() // Render the song into a single track void RenderManager::renderProject() +{ + render( m_outputPath ); +} + +void RenderManager::render(QString outputPath) { m_activeRenderer = make_unique( m_qualitySettings, m_outputSettings, m_format, - m_outputPath); + outputPath); if( m_activeRenderer->isReady() ) { @@ -166,7 +148,8 @@ void RenderManager::renderProject() connect( m_activeRenderer.get(), SIGNAL( progressChanged( int ) ), this, SIGNAL( progressChanged( int ) ) ); - // as we have not queued any tracks, renderNextTrack will just clean up + // when it is finished, render the next track. + // if we have not queued any tracks, renderNextTrack will just clean up connect( m_activeRenderer.get(), SIGNAL( finished() ), this, SLOT( renderNextTrack() ) ); @@ -175,7 +158,7 @@ void RenderManager::renderProject() else { qDebug( "Renderer failed to acquire a file device!" ); - emit finished(); + renderNextTrack(); } } diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index 141085dd2..2a470f4fe 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -59,34 +59,8 @@ #include "FileDialog.h" -SampleBuffer::SampleBuffer( const QString & _audio_file, - bool _is_base64_data ) : - m_audioFile( ( _is_base64_data == true ) ? "" : _audio_file ), - m_origData( NULL ), - m_origFrames( 0 ), - m_data( NULL ), - m_frames( 0 ), - m_startFrame( 0 ), - m_endFrame( 0 ), - m_loopStartFrame( 0 ), - m_loopEndFrame( 0 ), - m_amplification( 1.0f ), - m_reversed( false ), - m_frequency( BaseFreq ), - m_sampleRate( Engine::mixer()->baseSampleRate() ) -{ - if( _is_base64_data == true ) - { - loadFromBase64( _audio_file ); - } - connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( sampleRateChanged() ) ); - update(); -} - - - -SampleBuffer::SampleBuffer( const sampleFrame * _data, const f_cnt_t _frames ) : +SampleBuffer::SampleBuffer() : m_audioFile( "" ), m_origData( NULL ), m_origFrames( 0 ), @@ -101,42 +75,56 @@ SampleBuffer::SampleBuffer( const sampleFrame * _data, const f_cnt_t _frames ) : m_frequency( BaseFreq ), m_sampleRate( Engine::mixer()->baseSampleRate() ) { + + connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( sampleRateChanged() ) ); + update(); +} + + + +SampleBuffer::SampleBuffer( const QString & _audio_file, + bool _is_base64_data ) + : SampleBuffer() +{ + if( _is_base64_data ) + { + loadFromBase64( _audio_file ); + } + else + { + m_audioFile = _audio_file; + update(); + } +} + + + + +SampleBuffer::SampleBuffer( const sampleFrame * _data, const f_cnt_t _frames ) + : SampleBuffer() +{ if( _frames > 0 ) { m_origData = MM_ALLOC( sampleFrame, _frames ); memcpy( m_origData, _data, _frames * BYTES_PER_FRAME ); m_origFrames = _frames; + update(); } - connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( sampleRateChanged() ) ); - update(); } -SampleBuffer::SampleBuffer( const f_cnt_t _frames ) : - m_audioFile( "" ), - m_origData( NULL ), - m_origFrames( 0 ), - m_data( NULL ), - m_frames( 0 ), - m_startFrame( 0 ), - m_endFrame( 0 ), - m_loopStartFrame( 0 ), - m_loopEndFrame( 0 ), - m_amplification( 1.0f ), - m_reversed( false ), - m_frequency( BaseFreq ), - m_sampleRate( Engine::mixer()->baseSampleRate() ) +SampleBuffer::SampleBuffer( const f_cnt_t _frames ) + : SampleBuffer() { if( _frames > 0 ) { m_origData = MM_ALLOC( sampleFrame, _frames ); memset( m_origData, 0, _frames * BYTES_PER_FRAME ); m_origFrames = _frames; + update(); } - connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( sampleRateChanged() ) ); - update(); } diff --git a/src/core/SamplePlayHandle.cpp b/src/core/SamplePlayHandle.cpp index 7f383c68e..549a6c3a5 100644 --- a/src/core/SamplePlayHandle.cpp +++ b/src/core/SamplePlayHandle.cpp @@ -32,23 +32,6 @@ -SamplePlayHandle::SamplePlayHandle( const QString& sampleFile ) : - PlayHandle( TypeSamplePlayHandle ), - m_sampleBuffer( new SampleBuffer( sampleFile ) ), - m_doneMayReturnTrue( true ), - m_frame( 0 ), - m_ownAudioPort( true ), - m_defaultVolumeModel( DefaultVolume, MinVolume, MaxVolume, 1 ), - m_volumeModel( &m_defaultVolumeModel ), - m_track( NULL ), - m_bbTrack( NULL ) -{ - setAudioPort( new AudioPort( "SamplePlayHandle", false ) ); -} - - - - SamplePlayHandle::SamplePlayHandle( SampleBuffer* sampleBuffer ) : PlayHandle( TypeSamplePlayHandle ), m_sampleBuffer( sharedObject::ref( sampleBuffer ) ), @@ -66,17 +49,20 @@ SamplePlayHandle::SamplePlayHandle( SampleBuffer* sampleBuffer ) : -SamplePlayHandle::SamplePlayHandle( SampleTCO* tco ) : - PlayHandle( TypeSamplePlayHandle ), - m_sampleBuffer( sharedObject::ref( tco->sampleBuffer() ) ), - m_doneMayReturnTrue( true ), - m_frame( 0 ), - m_ownAudioPort( false ), - m_defaultVolumeModel( DefaultVolume, MinVolume, MaxVolume, 1 ), - m_volumeModel( &m_defaultVolumeModel ), - m_track( tco->getTrack() ), - m_bbTrack( NULL ) +SamplePlayHandle::SamplePlayHandle( const QString& sampleFile ) : + SamplePlayHandle( new SampleBuffer( sampleFile ) ) { + sharedObject::unref( m_sampleBuffer ); + setAudioPort( new AudioPort( "SamplePlayHandle", false ) ); +} + + + + +SamplePlayHandle::SamplePlayHandle( SampleTCO* tco ) : + SamplePlayHandle( tco->sampleBuffer() ) +{ + m_track = tco->getTrack(); setAudioPort( ( (SampleTrack *)tco->getTrack() )->audioPort() ); } diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 209be3a49..e4bd41fc9 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -1936,35 +1936,31 @@ void TrackOperationsWidget::updateMenu() } -void TrackOperationsWidget::recordingOn() +void TrackOperationsWidget::toggleRecording( bool on ) { AutomationTrackView * atv = dynamic_cast( m_trackView ); if( atv ) { - const Track::tcoVector & tcov = atv->getTrack()->getTCOs(); - for( Track::tcoVector::const_iterator it = tcov.begin(); it != tcov.end(); ++it ) + for( TrackContentObject * tco : atv->getTrack()->getTCOs() ) { - AutomationPattern * ap = dynamic_cast( *it ); - if( ap ) { ap->setRecording( true ); } + AutomationPattern * ap = dynamic_cast( tco ); + if( ap ) { ap->setRecording( on ); } } atv->update(); } } + +void TrackOperationsWidget::recordingOn() +{ + toggleRecording( true ); +} + + void TrackOperationsWidget::recordingOff() { - AutomationTrackView * atv = dynamic_cast( m_trackView ); - if( atv ) - { - const Track::tcoVector & tcov = atv->getTrack()->getTCOs(); - for( Track::tcoVector::const_iterator it = tcov.begin(); it != tcov.end(); ++it ) - { - AutomationPattern * ap = dynamic_cast( *it ); - if( ap ) { ap->setRecording( false ); } - } - atv->update(); - } + toggleRecording( false ); } diff --git a/src/core/main.cpp b/src/core/main.cpp index 6ce096815..078e9f26d 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -29,6 +29,7 @@ #include "denormals.h" +#include #include #include #include @@ -223,7 +224,17 @@ void fileCheck( QString &file ) } } +int usageError(const QString& message) +{ + qCritical().noquote() << QString("\n%1.\n\nTry \"%2 --help\" for more information.\n\n") + .arg( message ).arg( qApp->arguments()[0] ); + return EXIT_FAILURE; +} +int noInputFileError() +{ + return usageError( "No input file specified" ); +} int main( int argc, char * * argv ) @@ -328,9 +339,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo input file specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return noInputFileError(); } @@ -366,9 +375,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo input file specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return noInputFileError(); } @@ -385,9 +392,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo input file specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return noInputFileError(); } @@ -404,9 +409,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo output file specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No output file specified" ); } @@ -418,9 +421,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo output format specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No output format specified" ); } @@ -448,9 +449,7 @@ int main( int argc, char * * argv ) } else { - printf( "\nInvalid output format %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid output format %1" ).arg( argv[i] ) ); } } else if( arg == "--samplerate" || arg == "-s" ) @@ -459,9 +458,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo samplerate specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No samplerate specified" ); } @@ -472,9 +469,7 @@ int main( int argc, char * * argv ) } else { - printf( "\nInvalid samplerate %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid samplerate %1" ).arg( argv[i] ) ); } } else if( arg == "--bitrate" || arg == "-b" ) @@ -483,9 +478,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo bitrate specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No bitrate specified" ); } @@ -499,9 +492,7 @@ int main( int argc, char * * argv ) } else { - printf( "\nInvalid bitrate %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid bitrate %1" ).arg( argv[i] ) ); } } else if( arg == "--mode" || arg == "-m" ) @@ -510,9 +501,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo stereo mode specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No stereo mode specified" ); } QString const mode( argv[i] ); @@ -531,9 +520,7 @@ int main( int argc, char * * argv ) } else { - printf( "\nInvalid stereo mode %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid stereo mode %1" ).arg( argv[i] ) ); } } else if( arg =="--float" || arg == "-a" ) @@ -546,9 +533,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo interpolation method specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No interpolation method specified" ); } @@ -572,9 +557,7 @@ int main( int argc, char * * argv ) } else { - printf( "\nInvalid interpolation method %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid interpolation method %1" ).arg( argv[i] ) ); } } else if( arg == "--oversampling" || arg == "-x" ) @@ -583,9 +566,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo oversampling specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No oversampling specified" ); } @@ -606,9 +587,7 @@ int main( int argc, char * * argv ) qs.oversampling = Mixer::qualitySettings::Oversampling_8x; break; default: - printf( "\nInvalid oversampling %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid oversampling %1" ).arg( argv[i] ) ); } } else if( arg == "--import" ) @@ -617,12 +596,9 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo file specified for importing.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No file specified for importing" ); } - fileToImport = QString::fromLocal8Bit( argv[i] ); // exit after import? (only for debugging) @@ -638,9 +614,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo profile specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No profile specified" ); } @@ -652,9 +626,7 @@ int main( int argc, char * * argv ) if( i == argc ) { - printf( "\nNo configuration file specified.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[0] ); - return EXIT_FAILURE; + return usageError( "No configuration file specified" ); } configFile = QString::fromLocal8Bit( argv[i] ); @@ -663,9 +635,7 @@ int main( int argc, char * * argv ) { if( argv[i][0] == '-' ) { - printf( "\nInvalid option %s.\n\n" - "Try \"%s --help\" for more information.\n\n", argv[i], argv[0] ); - return EXIT_FAILURE; + return usageError( QString( "Invalid option %1" ).arg( argv[i] ) ); } fileToLoad = QString::fromLocal8Bit( argv[i] ); } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 5153b1951..10f2442ec 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1497,43 +1497,32 @@ void MainWindow::fillTemplatesMenu() { m_templatesMenu->clear(); - QDir user_d( ConfigManager::inst()->userTemplateDir() ); - QStringList templates = user_d.entryList( QStringList( "*.mpt" ), - QDir::Files | QDir::Readable ); + auto addTemplatesFromDir = [this]( QDir dir ) { + QStringList templates = dir.entryList( QStringList( "*.mpt" ), + QDir::Files | QDir::Readable ); - m_custom_templates_count = templates.count(); - for( QStringList::iterator it = templates.begin(); - it != templates.end(); ++it ) - { - m_templatesMenu->addAction( - embed::getIconPixmap( "project_file" ), - ( *it ).left( ( *it ).length() - 4 ) ); + if ( templates.size() && ! m_templatesMenu->actions().isEmpty() ) + { + m_templatesMenu->addSeparator(); + } + + for( QStringList::iterator it = templates.begin(); + it != templates.end(); ++it ) + { + m_templatesMenu->addAction( + embed::getIconPixmap( "project_file" ), + ( *it ).left( ( *it ).length() - 4 ).replace("&", "&&") ); #ifdef LMMS_BUILD_APPLE - m_templatesMenu->actions().last()->setIconVisibleInMenu(false); // QTBUG-44565 workaround - m_templatesMenu->actions().last()->setIconVisibleInMenu(true); + m_templatesMenu->actions().last()->setIconVisibleInMenu(false); // QTBUG-44565 workaround + m_templatesMenu->actions().last()->setIconVisibleInMenu(true); #endif - } + } - QDir d( ConfigManager::inst()->factoryProjectsDir() + "templates" ); - templates = d.entryList( QStringList( "*.mpt" ), - QDir::Files | QDir::Readable ); + return templates.size(); + }; - - if( m_custom_templates_count > 0 && !templates.isEmpty() ) - { - m_templatesMenu->addSeparator(); - } - for( QStringList::iterator it = templates.begin(); - it != templates.end(); ++it ) - { - m_templatesMenu->addAction( - embed::getIconPixmap( "project_file" ), - ( *it ).left( ( *it ).length() - 4 ).replace("&", "&&") ); -#ifdef LMMS_BUILD_APPLE - m_templatesMenu->actions().last()->setIconVisibleInMenu(false); // QTBUG-44565 workaround - m_templatesMenu->actions().last()->setIconVisibleInMenu(true); -#endif - } + m_custom_templates_count = addTemplatesFromDir( ConfigManager::inst()->userTemplateDir() ); + addTemplatesFromDir( ConfigManager::inst()->factoryProjectsDir() + "templates" ); }