diff --git a/include/AudioEngine.h b/include/AudioEngine.h index f6d8692b52d..f43b4d8a46a 100644 --- a/include/AudioEngine.h +++ b/include/AudioEngine.h @@ -237,7 +237,6 @@ class LMMS_EXPORT AudioEngine : public QObject sample_rate_t baseSampleRate() const; sample_rate_t outputSampleRate() const; - sample_rate_t inputSampleRate() const; inline float masterGain() const { diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 77453a8bad4..8a7ace10e30 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -24,18 +24,18 @@ #include "AudioEngine.h" -#include "MixHelpers.h" #include "denormals.h" - #include "lmmsconfig.h" #include "AudioEngineWorkerThread.h" #include "AudioPort.h" -#include "Mixer.h" -#include "Song.h" +#include "BufferManager.h" +#include "ConfigManager.h" #include "EnvelopeAndLfoParameters.h" +#include "Mixer.h" +#include "MixHelpers.h" #include "NotePlayHandle.h" -#include "ConfigManager.h" +#include "Song.h" #include "SamplePlayHandle.h" // platform-specific audio-interface-classes @@ -59,8 +59,6 @@ #include "MidiApple.h" #include "MidiDummy.h" -#include "BufferManager.h" - namespace lmms { @@ -71,29 +69,29 @@ static thread_local bool s_renderingThread = false; -AudioEngine::AudioEngine( bool renderOnly ) : - m_renderOnly( renderOnly ), - m_framesPerPeriod( DEFAULT_BUFFER_SIZE ), - m_inputBufferRead( 0 ), - m_inputBufferWrite( 1 ), +AudioEngine::AudioEngine(bool renderOnly) : + m_renderOnly(renderOnly), + m_framesPerPeriod(DEFAULT_BUFFER_SIZE), + m_inputBufferRead(0), + m_inputBufferWrite(1), m_outputBufferRead(nullptr), m_outputBufferWrite(nullptr), m_workers(), - m_numWorkers( QThread::idealThreadCount()-1 ), - m_newPlayHandles( PlayHandle::MaxNumber ), + m_numWorkers(QThread::idealThreadCount() - 1), + m_newPlayHandles(PlayHandle::MaxNumber), m_qualitySettings(qualitySettings::Interpolation::Linear), - m_masterGain( 1.0f ), - m_audioDev( nullptr ), - m_oldAudioDev( nullptr ), - m_audioDevStartFailed( false ), + m_masterGain(1.0f), + m_audioDev(nullptr), + m_oldAudioDev(nullptr), + m_audioDevStartFailed(false), m_profiler(), m_clearSignal(false) { - for( int i = 0; i < 2; ++i ) + for (int i = 0; i < 2; ++i) { m_inputBufferFrames[i] = 0; m_inputBufferSize[i] = DEFAULT_BUFFER_SIZE * 100; - m_inputBuffer[i] = new SampleFrame[ DEFAULT_BUFFER_SIZE * 100 ]; + m_inputBuffer[i] = new SampleFrame[DEFAULT_BUFFER_SIZE * 100]; zeroSampleFrames(m_inputBuffer[i], m_inputBufferSize[i]); } @@ -102,26 +100,25 @@ AudioEngine::AudioEngine( bool renderOnly ) : // if not only rendering (that is, using the GUI), load the buffer // size from user configuration - if( renderOnly == false ) + if (renderOnly == false) { - m_framesPerPeriod = - ( fpp_t ) ConfigManager::inst()->value( "audioengine", "framesperaudiobuffer" ).toInt(); + m_framesPerPeriod = + static_cast(ConfigManager::inst()->value("audioengine", "framesperaudiobuffer").toInt()); // if the value read from user configuration is not set or // lower than the minimum allowed, use the default value and // save it to the configuration - if( m_framesPerPeriod < MINIMUM_BUFFER_SIZE ) + if (m_framesPerPeriod < MINIMUM_BUFFER_SIZE) { - ConfigManager::inst()->setValue( "audioengine", - "framesperaudiobuffer", - QString::number( DEFAULT_BUFFER_SIZE ) ); + ConfigManager::inst()->setValue("audioengine", + "framesperaudiobuffer", QString::number(DEFAULT_BUFFER_SIZE)); m_framesPerPeriod = DEFAULT_BUFFER_SIZE; } // lmms works with chunks of size DEFAULT_BUFFER_SIZE (256) and only the final mix will use the actual // buffer size. Plugins don't see a larger buffer size than 256. If m_framesPerPeriod is larger than // DEFAULT_BUFFER_SIZE, it's set to DEFAULT_BUFFER_SIZE and the rest is handled by an increased fifoSize. - else if( m_framesPerPeriod > DEFAULT_BUFFER_SIZE ) + else if (m_framesPerPeriod > DEFAULT_BUFFER_SIZE) { fifoSize = m_framesPerPeriod / DEFAULT_BUFFER_SIZE; m_framesPerPeriod = DEFAULT_BUFFER_SIZE; @@ -129,23 +126,23 @@ AudioEngine::AudioEngine( bool renderOnly ) : } // allocte the FIFO from the determined size - m_fifo = new Fifo( fifoSize ); + m_fifo = new Fifo(fifoSize); // now that framesPerPeriod is fixed initialize global BufferManager - BufferManager::init( m_framesPerPeriod ); + BufferManager::init(m_framesPerPeriod); m_outputBufferRead = std::make_unique(m_framesPerPeriod); m_outputBufferWrite = std::make_unique(m_framesPerPeriod); - for( int i = 0; i < m_numWorkers+1; ++i ) + for (int i = 0; i < m_numWorkers+1; ++i) { auto wt = new AudioEngineWorkerThread(this); - if( i < m_numWorkers ) + if (i < m_numWorkers) { - wt->start( QThread::TimeCriticalPriority ); + wt->start(QThread::TimeCriticalPriority); } - m_workers.push_back( wt ); + m_workers.push_back(wt); } } @@ -154,24 +151,24 @@ AudioEngine::AudioEngine( bool renderOnly ) : AudioEngine::~AudioEngine() { - for( int w = 0; w < m_numWorkers; ++w ) + for (int w = 0; w < m_numWorkers; ++w) { m_workers[w]->quit(); } AudioEngineWorkerThread::startAndWaitForJobs(); - for( int w = 0; w < m_numWorkers; ++w ) + for (int w = 0; w < m_numWorkers; ++w) { - m_workers[w]->wait( 500 ); + m_workers[w]->wait(500); } - while( m_fifo->available() ) + while (m_fifo->available()) { delete[] m_fifo->read(); } - delete m_fifo; + delete m_fifo; delete m_midiClient; delete m_audioDev; @@ -188,12 +185,15 @@ AudioEngine::~AudioEngine() void AudioEngine::initDevices() { bool success_ful = false; - if( m_renderOnly ) { - m_audioDev = new AudioDummy( success_ful, this ); + if (m_renderOnly) + { + m_audioDev = new AudioDummy(success_ful, this); m_audioDevName = AudioDummy::name(); m_midiClient = new MidiDummy; m_midiClientName = MidiDummy::name(); - } else { + } + else + { m_audioDev = tryAudioDevices(); m_midiClient = tryMidiClients(); } @@ -208,8 +208,8 @@ void AudioEngine::startProcessing(bool needsFifo) { if (needsFifo) { - m_fifoWriter = new fifoWriter( this, m_fifo ); - m_fifoWriter->start( QThread::HighPriority ); + m_fifoWriter = new fifoWriter(this, m_fifo); + m_fifoWriter->start(QThread::HighPriority); } else { @@ -224,7 +224,7 @@ void AudioEngine::startProcessing(bool needsFifo) void AudioEngine::stopProcessing() { - if( m_fifoWriter != nullptr ) + if (m_fifoWriter != nullptr) { m_fifoWriter->finish(); m_fifoWriter->wait(); @@ -243,12 +243,8 @@ void AudioEngine::stopProcessing() sample_rate_t AudioEngine::baseSampleRate() const { - sample_rate_t sr = ConfigManager::inst()->value( "audioengine", "samplerate" ).toInt(); - if( sr < 44100 ) - { - sr = 44100; - } - return sr; + sample_rate_t sr = ConfigManager::inst()->value("audioengine", "samplerate").toInt(); + return (sr < 41000) ? 41000 : sr; } @@ -256,19 +252,12 @@ sample_rate_t AudioEngine::baseSampleRate() const sample_rate_t AudioEngine::outputSampleRate() const { - return m_audioDev != nullptr ? m_audioDev->sampleRate() : - baseSampleRate(); + return m_audioDev ? m_audioDev->sampleRate() : baseSampleRate(); } -sample_rate_t AudioEngine::inputSampleRate() const -{ - return m_audioDev != nullptr ? m_audioDev->sampleRate() : - baseSampleRate(); -} - bool AudioEngine::criticalXRuns() const { return cpuLoad() >= 99 && Engine::getSong()->isExporting() == false; @@ -277,29 +266,29 @@ bool AudioEngine::criticalXRuns() const -void AudioEngine::pushInputFrames( SampleFrame* _ab, const f_cnt_t _frames ) +void AudioEngine::pushInputFrames(SampleFrame* _ab, const f_cnt_t _frames) { requestChangeInModel(); - f_cnt_t frames = m_inputBufferFrames[ m_inputBufferWrite ]; + f_cnt_t frames = m_inputBufferFrames[m_inputBufferWrite]; auto size = m_inputBufferSize[m_inputBufferWrite]; - SampleFrame* buf = m_inputBuffer[ m_inputBufferWrite ]; + SampleFrame* buf = m_inputBuffer[m_inputBufferWrite]; - if( frames + _frames > size ) + if (frames + _frames > size) { size = std::max(size * 2, frames + _frames); auto ab = new SampleFrame[size]; - memcpy( ab, buf, frames * sizeof( SampleFrame ) ); - delete [] buf; + memcpy(ab, buf, frames * sizeof(SampleFrame)); + delete[] buf; - m_inputBufferSize[ m_inputBufferWrite ] = size; - m_inputBuffer[ m_inputBufferWrite ] = ab; + m_inputBufferSize[m_inputBufferWrite] = size; + m_inputBuffer[m_inputBufferWrite] = ab; buf = ab; } - memcpy( &buf[ frames ], _ab, _frames * sizeof( SampleFrame ) ); - m_inputBufferFrames[ m_inputBufferWrite ] += _frames; + memcpy(&buf[frames], _ab, _frames * sizeof(SampleFrame)); + m_inputBufferFrames[m_inputBufferWrite] += _frames; doneChangeInModel(); } @@ -310,7 +299,7 @@ void AudioEngine::renderStageNoteSetup() { AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::NoteSetup); - if( m_clearSignal ) + if (m_clearSignal) { m_clearSignal = false; clearInternal(); @@ -319,40 +308,39 @@ void AudioEngine::renderStageNoteSetup() // remove all play-handles that have to be deleted and delete // them if they still exist... // maybe this algorithm could be optimized... - ConstPlayHandleList::Iterator it_rem = m_playHandlesToRemove.begin(); - while( it_rem != m_playHandlesToRemove.end() ) + for (auto it_rem = m_playHandlesToRemove.begin(); it_rem != m_playHandlesToRemove.end();) { - PlayHandleList::Iterator it = std::find( m_playHandles.begin(), m_playHandles.end(), *it_rem ); + PlayHandleList::Iterator it = std::find(m_playHandles.begin(), m_playHandles.end(), *it_rem); - if( it != m_playHandles.end() ) + if (it != m_playHandles.end()) { - ( *it )->audioPort()->removePlayHandle( ( *it ) ); - if( ( *it )->type() == PlayHandle::Type::NotePlayHandle ) + (*it)->audioPort()->removePlayHandle(*it); + if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { - NotePlayHandleManager::release( (NotePlayHandle*) *it ); + NotePlayHandleManager::release(dynamic_cast(*it)); } - else delete *it; - m_playHandles.erase( it ); + else { delete *it; } + m_playHandles.erase(it); } - it_rem = m_playHandlesToRemove.erase( it_rem ); + it_rem = m_playHandlesToRemove.erase(it_rem); } swapBuffers(); // prepare master mix (clear internal buffers etc.) - Mixer * mixer = Engine::mixer(); + Mixer* mixer = Engine::mixer(); mixer->prepareMasterMix(); // create play-handles for new notes, samples etc. Engine::getSong()->processNextBuffer(); // add all play-handles that have to be added - for( LocklessListElement * e = m_newPlayHandles.popList(); e; ) + for (LocklessListElement* e = m_newPlayHandles.popList(); e;) { m_playHandles += e->value; - LocklessListElement * next = e->next; - m_newPlayHandles.free( e ); + LocklessListElement* next = e->next; + m_newPlayHandles.free(e); e = next; } } @@ -378,29 +366,24 @@ void AudioEngine::renderStageEffects() AudioEngineWorkerThread::startAndWaitForJobs(); // removed all play handles which are done - for( PlayHandleList::Iterator it = m_playHandles.begin(); - it != m_playHandles.end(); ) + for (auto it = m_playHandles.begin(); it != m_playHandles.end();) { - if( ( *it )->affinityMatters() && - ( *it )->affinity() != QThread::currentThread() ) + if ((*it)->affinityMatters() && (*it)->affinity() != QThread::currentThread()) { ++it; continue; } - if( ( *it )->isFinished() ) + if ((*it)->isFinished()) { - ( *it )->audioPort()->removePlayHandle( ( *it ) ); - if( ( *it )->type() == PlayHandle::Type::NotePlayHandle ) + (*it)->audioPort()->removePlayHandle(*it); + if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { - NotePlayHandleManager::release( (NotePlayHandle*) *it ); + NotePlayHandleManager::release(dynamic_cast(*it)); } - else delete *it; - it = m_playHandles.erase( it ); - } - else - { - ++it; + else { delete *it; } + it = m_playHandles.erase(it); } + else { ++it; } } } @@ -410,7 +393,7 @@ void AudioEngine::renderStageMix() { AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Mixing); - Mixer *mixer = Engine::mixer(); + Mixer* mixer = Engine::mixer(); mixer->masterMix(m_outputBufferWrite.get()); MixHelpers::multiply(m_outputBufferWrite.get(), m_masterGain, m_framesPerPeriod); @@ -456,6 +439,7 @@ void AudioEngine::swapBuffers() zeroSampleFrames(m_outputBufferWrite.get(), m_framesPerPeriod); } + void AudioEngine::clear() { m_clearSignal = true; @@ -467,10 +451,10 @@ void AudioEngine::clear() void AudioEngine::clearNewPlayHandles() { requestChangeInModel(); - for( LocklessListElement * e = m_newPlayHandles.popList(); e; ) + for (LocklessListElement* e = m_newPlayHandles.popList(); e;) { - LocklessListElement * next = e->next; - m_newPlayHandles.free( e ); + LocklessListElement* next = e->next; + m_newPlayHandles.free(e); e = next; } doneChangeInModel(); @@ -494,8 +478,7 @@ void AudioEngine::clearInternal() - -void AudioEngine::changeQuality(const struct qualitySettings & qs) +void AudioEngine::changeQuality(const struct qualitySettings& qs) { // don't delete the audio-device stopProcessing(); @@ -511,22 +494,22 @@ void AudioEngine::changeQuality(const struct qualitySettings & qs) -void AudioEngine::doSetAudioDevice( AudioDevice * _dev ) +void AudioEngine::doSetAudioDevice(AudioDevice* device) { // TODO: Use shared_ptr here in the future. // Currently, this is safe, because this is only called by // ProjectRenderer, and after ProjectRenderer calls this function, // it does not access the old device anymore. - if( m_audioDev != m_oldAudioDev ) {delete m_audioDev;} + if (m_audioDev != m_oldAudioDev) { delete m_audioDev; } - if( _dev ) + if (device) { - m_audioDev = _dev; + m_audioDev = device; } else { - printf( "param _dev == NULL in AudioEngine::setAudioDevice(...). " - "Trying any working audio-device\n" ); + printf("param _dev == NULL in AudioEngine::setAudioDevice(...). " + "Trying any working audio-device\n"); m_audioDev = tryAudioDevices(); } } @@ -534,21 +517,19 @@ void AudioEngine::doSetAudioDevice( AudioDevice * _dev ) -void AudioEngine::setAudioDevice(AudioDevice * _dev, - const struct qualitySettings & _qs, - bool _needs_fifo, - bool startNow) +void AudioEngine::setAudioDevice(AudioDevice* device, const struct qualitySettings& qs, + bool needs_fifo, bool startNow) { stopProcessing(); - m_qualitySettings = _qs; + m_qualitySettings = qs; - doSetAudioDevice( _dev ); + doSetAudioDevice(device); emit qualitySettingsChanged(); emit sampleRateChanged(); - if (startNow) {startProcessing( _needs_fifo );} + if (startNow) { startProcessing(needs_fifo); } } @@ -556,7 +537,7 @@ void AudioEngine::setAudioDevice(AudioDevice * _dev, void AudioEngine::storeAudioDevice() { - if( !m_oldAudioDev ) + if (!m_oldAudioDev) { m_oldAudioDev = m_audioDev; } @@ -567,7 +548,7 @@ void AudioEngine::storeAudioDevice() void AudioEngine::restoreAudioDevice() { - if( m_oldAudioDev && m_audioDev != m_oldAudioDev ) + if (m_oldAudioDev && m_audioDev != m_oldAudioDev) { stopProcessing(); delete m_audioDev; @@ -583,7 +564,7 @@ void AudioEngine::restoreAudioDevice() -void AudioEngine::removeAudioPort(AudioPort * port) +void AudioEngine::removeAudioPort(AudioPort* port) { requestChangeInModel(); @@ -596,79 +577,81 @@ void AudioEngine::removeAudioPort(AudioPort * port) } -bool AudioEngine::addPlayHandle( PlayHandle* handle ) +bool AudioEngine::addPlayHandle(PlayHandle* handle) { // Only add play handles if we have the CPU capacity to process them. // Instrument play handles are not added during playback, but when the // associated instrument is created, so add those unconditionally. if (handle->type() == PlayHandle::Type::InstrumentPlayHandle || !criticalXRuns()) { - m_newPlayHandles.push( handle ); - handle->audioPort()->addPlayHandle( handle ); + m_newPlayHandles.push(handle); + handle->audioPort()->addPlayHandle(handle); return true; } - if( handle->type() == PlayHandle::Type::NotePlayHandle ) + if (handle->type() == PlayHandle::Type::NotePlayHandle) { - NotePlayHandleManager::release( (NotePlayHandle*)handle ); + NotePlayHandleManager::release(dynamic_cast(handle)); } - else delete handle; + else { delete handle; } return false; } -void AudioEngine::removePlayHandle(PlayHandle * ph) +void AudioEngine::removePlayHandle(PlayHandle* ph) { requestChangeInModel(); // check thread affinity as we must not delete play-handles // which were created in a thread different than the audio engine thread - if (ph->affinityMatters() && ph->affinity() == QThread::currentThread()) - { - ph->audioPort()->removePlayHandle(ph); - bool removedFromList = false; - // Check m_newPlayHandles first because doing it the other way around - // creates a race condition - for( LocklessListElement * e = m_newPlayHandles.first(), - * ePrev = nullptr; e; ePrev = e, e = e->next ) + if (!ph->affinityMatters() || ph->affinity() != QThread::currentThread()) + { + m_playHandlesToRemove.push_back(ph); + doneChangesInModel(); + return; + } + + ph->audioPort()->removePlayHandle(ph); + bool removedFromList = false; + // Check m_newPlayHandles first because doing it the other way around + // creates a race condition + LocklessListElement* e = m_newPlayHandles.first(), *ePrev = nullptr; + while (e) + { + if (e->value == ph) { - if (e->value == ph) + if (ePrev) { - if( ePrev ) - { - ePrev->next = e->next; - } - else - { - m_newPlayHandles.setFirst( e->next ); - } - m_newPlayHandles.free( e ); - removedFromList = true; - break; + ePrev->next = e->next; } - } - // Now check m_playHandles - PlayHandleList::Iterator it = std::find(m_playHandles.begin(), m_playHandles.end(), ph); - if (it != m_playHandles.end()) - { - m_playHandles.erase(it); - removedFromList = true; - } - // Only deleting PlayHandles that were actually found in the list - // "fixes crash when previewing a preset under high load" - // (See tobydox's 2008 commit 4583e48) - if ( removedFromList ) - { - if (ph->type() == PlayHandle::Type::NotePlayHandle) + else { - NotePlayHandleManager::release(dynamic_cast(ph)); + m_newPlayHandles.setFirst(e->next); } - else { delete ph; } + m_newPlayHandles.free(e); + removedFromList = true; + break; } } - else + + // Now check m_playHandles + PlayHandleList::Iterator it = std::find(m_playHandles.begin(), m_playHandles.end(), ph); + if (it != m_playHandles.end()) { - m_playHandlesToRemove.push_back(ph); + m_playHandles.erase(it); + removedFromList = true; + } + + // Only deleting PlayHandles that were actually found in the list + // "fixes crash when previewing a preset under high load" + // (See tobydox's 2008 commit 4583e48) + if (removedFromList) + { + if (ph->type() == PlayHandle::Type::NotePlayHandle) + { + NotePlayHandleManager::release(dynamic_cast(ph)); + } + else { delete ph; } } doneChangeInModel(); } @@ -679,23 +662,19 @@ void AudioEngine::removePlayHandle(PlayHandle * ph) void AudioEngine::removePlayHandlesOfTypes(Track * track, PlayHandle::Types types) { requestChangeInModel(); - PlayHandleList::Iterator it = m_playHandles.begin(); - while( it != m_playHandles.end() ) + for (auto it = m_playHandles.begin(); it != m_playHandles.end();) { if ((*it)->isFromTrack(track) && ((*it)->type() & types)) { - ( *it )->audioPort()->removePlayHandle( ( *it ) ); - if( ( *it )->type() == PlayHandle::Type::NotePlayHandle ) + (*it)->audioPort()->removePlayHandle(*it); + if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { - NotePlayHandleManager::release( (NotePlayHandle*) *it ); + NotePlayHandleManager::release(dynamic_cast(*it)); } - else delete *it; - it = m_playHandles.erase( it ); - } - else - { - ++it; + else { delete *it; } + it = m_playHandles.erase(it); } + else { ++it; } } doneChangeInModel(); } @@ -838,12 +817,12 @@ bool AudioEngine::isMidiDevNameValid(QString name) return false; } -AudioDevice * AudioEngine::tryAudioDevices() +AudioDevice* AudioEngine::tryAudioDevices() { bool success_ful = false; - AudioDevice * dev = nullptr; - QString dev_name = ConfigManager::inst()->value( "audioengine", "audiodev" ); - if( !isAudioDevNameValid( dev_name ) ) + AudioDevice* dev = nullptr; + QString dev_name = ConfigManager::inst()->value("audioengine", "audiodev"); + if (!isAudioDevNameValid(dev_name)) { dev_name = ""; } @@ -851,10 +830,10 @@ AudioDevice * AudioEngine::tryAudioDevices() m_audioDevStartFailed = false; #ifdef LMMS_HAVE_SDL - if( dev_name == AudioSdl::name() || dev_name == "" ) + if (dev_name == AudioSdl::name() || dev_name == "") { - dev = new AudioSdl( success_ful, this ); - if( success_ful ) + dev = new AudioSdl(success_ful, this); + if (success_ful) { m_audioDevName = AudioSdl::name(); return dev; @@ -865,10 +844,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #ifdef LMMS_HAVE_ALSA - if( dev_name == AudioAlsa::name() || dev_name == "" ) + if (dev_name == AudioAlsa::name() || dev_name == "") { - dev = new AudioAlsa( success_ful, this ); - if( success_ful ) + dev = new AudioAlsa(success_ful, this); + if (success_ful) { m_audioDevName = AudioAlsa::name(); return dev; @@ -879,10 +858,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #ifdef LMMS_HAVE_PULSEAUDIO - if( dev_name == AudioPulseAudio::name() || dev_name == "" ) + if (dev_name == AudioPulseAudio::name() || dev_name == "") { - dev = new AudioPulseAudio( success_ful, this ); - if( success_ful ) + dev = new AudioPulseAudio(success_ful, this); + if (success_ful) { m_audioDevName = AudioPulseAudio::name(); return dev; @@ -893,10 +872,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #ifdef LMMS_HAVE_OSS - if( dev_name == AudioOss::name() || dev_name == "" ) + if (dev_name == AudioOss::name() || dev_name == "") { - dev = new AudioOss( success_ful, this ); - if( success_ful ) + dev = new AudioOss(success_ful, this); + if (success_ful) { m_audioDevName = AudioOss::name(); return dev; @@ -906,10 +885,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #endif #ifdef LMMS_HAVE_SNDIO - if( dev_name == AudioSndio::name() || dev_name == "" ) + if (dev_name == AudioSndio::name() || dev_name == "") { - dev = new AudioSndio( success_ful, this ); - if( success_ful ) + dev = new AudioSndio(success_ful, this); + if (success_ful) { m_audioDevName = AudioSndio::name(); return dev; @@ -920,10 +899,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #ifdef LMMS_HAVE_JACK - if( dev_name == AudioJack::name() || dev_name == "" ) + if (dev_name == AudioJack::name() || dev_name == "") { - dev = new AudioJack( success_ful, this ); - if( success_ful ) + dev = new AudioJack(success_ful, this); + if (success_ful) { m_audioDevName = AudioJack::name(); return dev; @@ -934,10 +913,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #ifdef LMMS_HAVE_PORTAUDIO - if( dev_name == AudioPortAudio::name() || dev_name == "" ) + if (dev_name == AudioPortAudio::name() || dev_name == "") { - dev = new AudioPortAudio( success_ful, this ); - if( success_ful ) + dev = new AudioPortAudio(success_ful, this); + if (success_ful) { m_audioDevName = AudioPortAudio::name(); return dev; @@ -948,10 +927,10 @@ AudioDevice * AudioEngine::tryAudioDevices() #ifdef LMMS_HAVE_SOUNDIO - if( dev_name == AudioSoundIo::name() || dev_name == "" ) + if (dev_name == AudioSoundIo::name() || dev_name == "") { - dev = new AudioSoundIo( success_ful, this ); - if( success_ful ) + dev = new AudioSoundIo(success_ful, this); + if (success_ful) { m_audioDevName = AudioSoundIo::name(); return dev; @@ -962,43 +941,43 @@ AudioDevice * AudioEngine::tryAudioDevices() // add more device-classes here... - //dev = new audioXXXX( SAMPLE_RATES[m_qualityLevel], success_ful, this ); - //if( sucess_ful ) + //dev = new audioXXXX(SAMPLE_RATES[m_qualityLevel], success_ful, this); + //if (sucess_ful) //{ // return dev; //} //delete dev - if( dev_name != AudioDummy::name() ) + if (dev_name != AudioDummy::name()) { - printf( "No audio-driver working - falling back to dummy-audio-" + printf("No audio-driver working - falling back to dummy-audio-" "driver\nYou can render your songs and listen to the output " - "files...\n" ); + "files...\n"); m_audioDevStartFailed = true; } m_audioDevName = AudioDummy::name(); - return new AudioDummy( success_ful, this ); + return new AudioDummy(success_ful, this); } -MidiClient * AudioEngine::tryMidiClients() +MidiClient* AudioEngine::tryMidiClients() { - QString client_name = ConfigManager::inst()->value( "audioengine", "mididev" ); - if( !isMidiDevNameValid( client_name ) ) + QString client_name = ConfigManager::inst()->value("audioengine", "mididev"); + if (!isMidiDevNameValid(client_name)) { client_name = ""; } #ifdef LMMS_HAVE_ALSA - if( client_name == MidiAlsaSeq::name() || client_name == "" ) + if (client_name == MidiAlsaSeq::name() || client_name == "") { auto malsas = new MidiAlsaSeq; - if( malsas->isRunning() ) + if (malsas->isRunning()) { m_midiClientName = MidiAlsaSeq::name(); return malsas; @@ -1006,10 +985,10 @@ MidiClient * AudioEngine::tryMidiClients() delete malsas; } - if( client_name == MidiAlsaRaw::name() || client_name == "" ) + if (client_name == MidiAlsaRaw::name() || client_name == "") { auto malsar = new MidiAlsaRaw; - if( malsar->isRunning() ) + if (malsar->isRunning()) { m_midiClientName = MidiAlsaRaw::name(); return malsar; @@ -1019,10 +998,10 @@ MidiClient * AudioEngine::tryMidiClients() #endif #ifdef LMMS_HAVE_JACK - if( client_name == MidiJack::name() || client_name == "" ) + if (client_name == MidiJack::name() || client_name == "") { auto mjack = new MidiJack; - if( mjack->isRunning() ) + if (mjack->isRunning()) { m_midiClientName = MidiJack::name(); return mjack; @@ -1032,10 +1011,10 @@ MidiClient * AudioEngine::tryMidiClients() #endif #ifdef LMMS_HAVE_OSS - if( client_name == MidiOss::name() || client_name == "" ) + if (client_name == MidiOss::name() || client_name == "") { auto moss = new MidiOss; - if( moss->isRunning() ) + if (moss->isRunning()) { m_midiClientName = MidiOss::name(); return moss; @@ -1045,10 +1024,10 @@ MidiClient * AudioEngine::tryMidiClients() #endif #ifdef LMMS_HAVE_SNDIO - if( client_name == MidiSndio::name() || client_name == "" ) + if (client_name == MidiSndio::name() || client_name == "") { - MidiSndio * msndio = new MidiSndio; - if( msndio->isRunning() ) + auto msndio = new MidiSndio; + if (msndio->isRunning()) { m_midiClientName = MidiSndio::name(); return msndio; @@ -1058,10 +1037,10 @@ MidiClient * AudioEngine::tryMidiClients() #endif #ifdef LMMS_BUILD_WIN32 - if( client_name == MidiWinMM::name() || client_name == "" ) + if (client_name == MidiWinMM::name() || client_name == "") { - MidiWinMM * mwmm = new MidiWinMM; -// if( moss->isRunning() ) + auto mwmm = new MidiWinMM; +// if (moss->isRunning()) { m_midiClientName = MidiWinMM::name(); return mwmm; @@ -1071,18 +1050,18 @@ MidiClient * AudioEngine::tryMidiClients() #endif #ifdef LMMS_BUILD_APPLE - printf( "trying midi apple...\n" ); - if( client_name == MidiApple::name() || client_name == "" ) + printf("trying midi apple...\n"); + if (client_name == MidiApple::name() || client_name == "") { - MidiApple * mapple = new MidiApple; + auto mapple = new MidiApple; m_midiClientName = MidiApple::name(); - printf( "Returning midi apple\n" ); + printf("Returning midi apple\n"); return mapple; } - printf( "midi apple didn't work: client_name=%s\n", client_name.toUtf8().constData()); + printf("midi apple didn't work: client_name=%s\n", client_name.toUtf8().constData()); #endif - if(client_name != MidiDummy::name()) + if (client_name != MidiDummy::name()) { if (client_name.isEmpty()) { @@ -1108,10 +1087,10 @@ MidiClient * AudioEngine::tryMidiClients() -AudioEngine::fifoWriter::fifoWriter( AudioEngine* audioEngine, Fifo * fifo ) : - m_audioEngine( audioEngine ), - m_fifo( fifo ), - m_writing( true ) +AudioEngine::fifoWriter::fifoWriter(AudioEngine* audioEngine, Fifo* fifo) : + m_audioEngine(audioEngine), + m_fifo(fifo), + m_writing(true) { setObjectName("AudioEngine::fifoWriter"); } @@ -1131,19 +1110,8 @@ void AudioEngine::fifoWriter::run() { disable_denormals(); -#if 0 -#if defined(LMMS_BUILD_LINUX) || defined(LMMS_BUILD_FREEBSD) -#ifdef LMMS_HAVE_SCHED_H - cpu_set_t mask; - CPU_ZERO( &mask ); - CPU_SET( 0, &mask ); - sched_setaffinity( 0, sizeof( mask ), &mask ); -#endif -#endif -#endif - const fpp_t frames = m_audioEngine->framesPerPeriod(); - while( m_writing ) + while (m_writing) { auto buffer = new SampleFrame[frames]; const SampleFrame* b = m_audioEngine->renderNextBuffer(); diff --git a/src/core/AudioEngineProfiler.cpp b/src/core/AudioEngineProfiler.cpp index 82a412cbb98..71a1d5e9a54 100644 --- a/src/core/AudioEngineProfiler.cpp +++ b/src/core/AudioEngineProfiler.cpp @@ -31,14 +31,14 @@ namespace lmms AudioEngineProfiler::AudioEngineProfiler() : m_periodTimer(), - m_cpuLoad( 0 ), + m_cpuLoad(0), m_outputFile() { } -void AudioEngineProfiler::finishPeriod( sample_rate_t sampleRate, fpp_t framesPerPeriod ) +void AudioEngineProfiler::finishPeriod(sample_rate_t sampleRate, fpp_t framesPerPeriod) { // Time taken to process all data and fill the audio buffer. const unsigned int periodElapsed = m_periodTimer.elapsed(); @@ -59,19 +59,19 @@ void AudioEngineProfiler::finishPeriod( sample_rate_t sampleRate, fpp_t framesPe m_detailLoad[i].store(newLoad * 0.05f + oldLoad * 0.95f, std::memory_order_relaxed); } - if( m_outputFile.isOpen() ) + if (m_outputFile.isOpen()) { - m_outputFile.write( QString( "%1\n" ).arg( periodElapsed ).toLatin1() ); + m_outputFile.write(QString("%1\n").arg(periodElapsed).toLatin1()); } } -void AudioEngineProfiler::setOutputFile( const QString& outputFile ) +void AudioEngineProfiler::setOutputFile(const QString& outputFile) { m_outputFile.close(); - m_outputFile.setFileName( outputFile ); - m_outputFile.open( QFile::WriteOnly | QFile::Truncate ); + m_outputFile.setFileName(outputFile); + m_outputFile.open(QFile::WriteOnly | QFile::Truncate); } } // namespace lmms diff --git a/src/core/AudioResampler.cpp b/src/core/AudioResampler.cpp index 8fb7d95a2aa..658b4841f89 100644 --- a/src/core/AudioResampler.cpp +++ b/src/core/AudioResampler.cpp @@ -28,11 +28,11 @@ #include #include -namespace lmms { +namespace lmms +{ AudioResampler::AudioResampler(int interpolationMode, int channels) - : m_interpolationMode(interpolationMode) - , m_channels(channels) + : m_interpolationMode(interpolationMode), m_channels(channels) , m_state(src_new(interpolationMode, channels, &m_error)) { if (!m_state) diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index e006be651a4..62e63c53f07 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -42,26 +42,26 @@ long AutomatableModel::s_periodCounter = 0; AutomatableModel::AutomatableModel( const float val, const float min, const float max, const float step, - Model* parent, const QString & displayName, bool defaultConstructed ) : - Model( parent, displayName, defaultConstructed ), - m_scaleType( ScaleType::Linear ), - m_minValue( min ), - m_maxValue( max ), - m_step( step ), - m_range( max - min ), - m_centerValue( m_minValue ), - m_valueChanged( false ), - m_setValueDepth( 0 ), - m_hasStrictStepSize( false ), - m_controllerConnection( nullptr ), - m_valueBuffer( static_cast( Engine::audioEngine()->framesPerPeriod() ) ), - m_lastUpdatedPeriod( -1 ), + Model* parent, const QString& displayName, bool defaultConstructed) : + Model(parent, displayName, defaultConstructed), + m_scaleType(ScaleType::Linear), + m_minValue(min), + m_maxValue(max), + m_step(step), + m_range(max - min), + m_centerValue(m_minValue), + m_valueChanged(false), + m_setValueDepth(0), + m_hasStrictStepSize(false), + m_controllerConnection(nullptr), + m_valueBuffer(static_cast(Engine::audioEngine()->framesPerPeriod())), + m_lastUpdatedPeriod(-1), m_hasSampleExactData(false), m_useControllerValue(true) { - m_value = fittedValue( val ); - setInitValue( val ); + m_value = fittedValue(val); + setInitValue(val); } @@ -69,20 +69,20 @@ AutomatableModel::AutomatableModel( AutomatableModel::~AutomatableModel() { - while( m_linkedModels.empty() == false ) + while (m_linkedModels.empty() == false) { m_linkedModels.back()->unlinkModel(this); - m_linkedModels.erase( m_linkedModels.end() - 1 ); + m_linkedModels.erase(m_linkedModels.end() - 1); } - if( m_controllerConnection ) + if (m_controllerConnection) { delete m_controllerConnection; } m_valueBuffer.clear(); - emit destroyed( id() ); + emit destroyed(id()); } @@ -90,7 +90,7 @@ AutomatableModel::~AutomatableModel() bool AutomatableModel::isAutomated() const { - return AutomationClip::isAutomated( this ); + return AutomationClip::isAutomated(this); } @@ -101,38 +101,39 @@ bool AutomatableModel::mustQuoteName(const QString& name) return !reg.match(name).hasMatch(); } -void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, const QString& name ) +void AutomatableModel::saveSettings(QDomDocument& doc, QDomElement& element, const QString& name) { bool mustQuote = mustQuoteName(name); - if( isAutomated() || m_scaleType != ScaleType::Linear ) + if (isAutomated() || m_scaleType != ScaleType::Linear) { // automation needs tuple of data (name, id, value) // scale type also needs an extra value // => it must be appended as a node - QDomElement me = doc.createElement( mustQuote ? QString("automatablemodel") : name ); - me.setAttribute( "id", ProjectJournal::idToSave( id() ) ); - me.setAttribute( "value", m_value ); - me.setAttribute( "scale_type", m_scaleType == ScaleType::Logarithmic ? "log" : "linear" ); - if(mustQuote) { - me.setAttribute( "nodename", name ); + QDomElement me = doc.createElement(mustQuote ? QString("automatablemodel") : name); + me.setAttribute("id", ProjectJournal::idToSave(id())); + me.setAttribute("value", m_value); + me.setAttribute("scale_type", m_scaleType == ScaleType::Logarithmic ? "log" : "linear"); + if (mustQuote) + { + me.setAttribute("nodename", name); } - element.appendChild( me ); + element.appendChild(me); } else { - if(mustQuote) + if (mustQuote) { - QDomElement me = doc.createElement( "automatablemodel" ); - me.setAttribute( "nodename", name ); - me.setAttribute( "value", m_value ); - element.appendChild( me ); + QDomElement me = doc.createElement("automatablemodel"); + me.setAttribute("nodename", name); + me.setAttribute("value", m_value); + element.appendChild(me); } else { // non automation, linear scale (default), can be saved as attribute - element.setAttribute( name, m_value ); + element.setAttribute(name, m_value); } } @@ -149,78 +150,77 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co QDomElement controllerElement; // get "connection" element (and create it if needed) - QDomNode node = element.namedItem( "connection" ); - if( node.isElement() ) + QDomNode node = element.namedItem("connection"); + if (node.isElement()) { controllerElement = node.toElement(); } else { - controllerElement = doc.createElement( "connection" ); - element.appendChild( controllerElement ); + controllerElement = doc.createElement("connection"); + element.appendChild(controllerElement); } bool mustQuote = mustQuoteName(name); QString elementName = mustQuote ? "controllerconnection" : name; - QDomElement element = doc.createElement( elementName ); - if(mustQuote) - element.setAttribute( "nodename", name ); - m_controllerConnection->saveSettings( doc, element ); + QDomElement element = doc.createElement(elementName); + if (mustQuote) + { + element.setAttribute("nodename", name); + } + m_controllerConnection->saveSettings(doc, element); - controllerElement.appendChild( element ); + controllerElement.appendChild(element); } } -void AutomatableModel::loadSettings( const QDomElement& element, const QString& name ) +void AutomatableModel::loadSettings(const QDomElement& element, const QString& name) { // compat code - QDomNode node = element.namedItem( AutomationClip::classNodeName() ); - if( node.isElement() ) + QDomNode node = element.namedItem(AutomationClip::classNodeName()); + if (node.isElement()) { - node = node.namedItem( name ); - if( node.isElement() ) + node = node.namedItem(name); + if (node.isElement()) { - AutomationClip * p = AutomationClip::globalAutomationClip( this ); - p->loadSettings( node.toElement() ); - setValue( p->valueAt( 0 ) ); + AutomationClip* p = AutomationClip::globalAutomationClip(this); + p->loadSettings(node.toElement()); + setValue(p->valueAt(0)); // in older projects we sometimes have odd automations // with just one value in - eliminate if necessary - if( !p->hasAutomation() ) - { - delete p; - } + if (!p->hasAutomation()) { delete p; } return; } // logscales were not existing at this point of time // so they can be ignored } - QDomNode connectionNode = element.namedItem( "connection" ); + QDomNode connectionNode = element.namedItem("connection"); // reads controller connection - if( connectionNode.isElement() ) + if (connectionNode.isElement()) { - QDomNode thisConnection = connectionNode.toElement().namedItem( name ); - if( !thisConnection.isElement() ) + QDomNode thisConnection = connectionNode.toElement().namedItem(name); + if (!thisConnection.isElement()) { - thisConnection = connectionNode.toElement().namedItem( "controllerconnection" ); + thisConnection = connectionNode.toElement().namedItem("controllerconnection"); QDomElement tcElement = thisConnection.toElement(); // sanity check - if( tcElement.isNull() || tcElement.attribute( "nodename" ) != name ) + if (tcElement.isNull() || tcElement.attribute("nodename") != name) { // no, that wasn't it, act as if we never found one thisConnection.clear(); } } - if( thisConnection.isElement() ) + if (thisConnection.isElement()) { setControllerConnection(new ControllerConnection(nullptr)); - m_controllerConnection->loadSettings( thisConnection.toElement() ); - //m_controllerConnection->setTargetName( displayName() ); + m_controllerConnection->loadSettings(thisConnection.toElement()); + //m_controllerConnection->setTargetName(displayName()); } } @@ -230,23 +230,23 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString& // // element => there is automation data, or scaletype information - node = element.namedItem( name ); // maybe we have luck? + node = element.namedItem(name); // maybe we have luck? // either: no node with name "name" found // => look for nodes with attribute name="nodename" // or: element with namedItem() "name" was found, but it's real nodename // is given as attribute and does not match // => look for the right node - if(node.isNull() || - ( node.isElement() && + if (node.isNull() || + (node.isElement() && node.toElement().hasAttribute("nodename") && node.toElement().attribute("nodename") != name)) { - for(QDomElement othernode = element.firstChildElement(); + for (QDomElement othernode = element.firstChildElement(); !othernode.isNull(); othernode = othernode.nextSiblingElement()) { - if((!othernode.hasAttribute("nodename") && + if ((!othernode.hasAttribute("nodename") && othernode.nodeName() == name) || othernode.attribute("nodename") == name) { @@ -255,32 +255,32 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString& } } } - if( node.isElement() ) + if (node.isElement()) { QDomElement nodeElement = node.toElement(); - changeID( nodeElement.attribute( "id" ).toInt() ); - setValue( LocaleHelper::toFloat( nodeElement.attribute( "value" ) ) ); - if( nodeElement.hasAttribute( "scale_type" ) ) + changeID(nodeElement.attribute("id").toInt()); + setValue(LocaleHelper::toFloat(nodeElement.attribute("value"))); + if (nodeElement.hasAttribute("scale_type")) { - if( nodeElement.attribute( "scale_type" ) == "linear" ) + if (nodeElement.attribute("scale_type") == "linear") { - setScaleType( ScaleType::Linear ); + setScaleType(ScaleType::Linear); } - else if( nodeElement.attribute( "scale_type" ) == "log" ) + else if (nodeElement.attribute("scale_type") == "log") { - setScaleType( ScaleType::Logarithmic ); + setScaleType(ScaleType::Logarithmic); } } } else { - setScaleType( ScaleType::Linear ); + setScaleType(ScaleType::Linear); - if( element.hasAttribute( name ) ) + if (element.hasAttribute(name)) // attribute => read the element's value from the attribute list { - setInitValue( LocaleHelper::toFloat( element.attribute( name ) ) ); + setInitValue(LocaleHelper::toFloat(element.attribute(name))); } else { @@ -292,14 +292,14 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString& -void AutomatableModel::setValue( const float value ) +void AutomatableModel::setValue(const float value) { m_oldValue = m_value; ++m_setValueDepth; const float old_val = m_value; - m_value = fittedValue( value ); - if( old_val != m_value ) + m_value = fittedValue(value); + if (old_val != m_value) { // add changes to history so user can undo it addJournalCheckPoint(); @@ -327,32 +327,33 @@ void AutomatableModel::setValue( const float value ) -template T AutomatableModel::logToLinearScale( T value ) const +template T AutomatableModel::logToLinearScale(T value) const { - return castValue( lmms::logToLinearScale( minValue(), maxValue(), static_cast( value ) ) ); + return castValue(lmms::logToLinearScale(minValue(), maxValue(), static_cast(value))); } -float AutomatableModel::scaledValue( float value ) const +float AutomatableModel::scaledValue(float value) const { return m_scaleType == ScaleType::Linear ? value - : logToLinearScale( ( value - minValue() ) / m_range ); + : logToLinearScale((value - minValue()) / m_range); } -float AutomatableModel::inverseScaledValue( float value ) const +float AutomatableModel::inverseScaledValue(float value) const { return m_scaleType == ScaleType::Linear ? value - : lmms::linearToLogScale( minValue(), maxValue(), value ); + : lmms::linearToLogScale(minValue(), maxValue(), value); } + template -void AutomatableModel::roundAt( T& value, const T& where ) const +void AutomatableModel::roundAt(T& value, const T& where) const { lmms::roundAt(value, where, m_step); } @@ -360,7 +361,7 @@ void AutomatableModel::roundAt( T& value, const T& where ) const -void AutomatableModel::setAutomatedValue( const float value ) +void AutomatableModel::setAutomatedValue(const float value) { setUseControllerValue(false); @@ -368,11 +369,11 @@ void AutomatableModel::setAutomatedValue( const float value ) ++m_setValueDepth; const float oldValue = m_value; - const float scaled_value = scaledValue( value ); + const float scaled_value = scaledValue(value); - m_value = fittedValue( scaled_value ); + m_value = fittedValue(scaled_value); - if( oldValue != m_value ) + if (oldValue != m_value) { // notify linked models for (const auto& linkedModel : m_linkedModels) @@ -392,23 +393,22 @@ void AutomatableModel::setAutomatedValue( const float value ) -void AutomatableModel::setRange( const float min, const float max, - const float step ) +void AutomatableModel::setRange(const float min, const float max, const float step) { - if( ( m_maxValue != max ) || ( m_minValue != min ) ) + if ((m_maxValue != max) || (m_minValue != min)) { m_minValue = min; m_maxValue = max; - if( m_minValue > m_maxValue ) + if (m_minValue > m_maxValue) { - qSwap( m_minValue, m_maxValue ); + qSwap(m_minValue, m_maxValue); } m_range = m_maxValue - m_minValue; - setStep( step ); + setStep(step); // re-adjust value - setValue( value() ); + setValue(value()); emit propertiesChanged(); } @@ -417,9 +417,9 @@ void AutomatableModel::setRange( const float min, const float max, -void AutomatableModel::setStep( const float step ) +void AutomatableModel::setStep(const float step) { - if( m_step != step ) + if (m_step != step) { m_step = step; emit propertiesChanged(); @@ -429,24 +429,24 @@ void AutomatableModel::setStep( const float step ) -float AutomatableModel::fittedValue( float value ) const +float AutomatableModel::fittedValue(float value) const { value = std::clamp(value, m_minValue, m_maxValue); - if( m_step != 0 && m_hasStrictStepSize ) + if (m_step != 0 && m_hasStrictStepSize) { - value = nearbyintf( value / m_step ) * m_step; + value = nearbyintf(value / m_step) * m_step; } - roundAt( value, m_maxValue ); - roundAt( value, m_minValue ); - roundAt( value, 0.0f ); + roundAt(value, m_maxValue); + roundAt(value, m_minValue); + roundAt(value, 0.0f); - if( value < m_minValue ) + if (value < m_minValue) { return m_minValue; } - else if( value > m_maxValue ) + else if (value > m_maxValue) { return m_maxValue; } @@ -458,30 +458,29 @@ float AutomatableModel::fittedValue( float value ) const -void AutomatableModel::linkModel( AutomatableModel* model ) +void AutomatableModel::linkModel(AutomatableModel* model) { - auto containsModel = std::find(m_linkedModels.begin(), m_linkedModels.end(), model) != m_linkedModels.end(); - if (!containsModel && model != this) - { - m_linkedModels.push_back( model ); + auto findModel = std::find(m_linkedModels.begin(), m_linkedModels.end(), model); + auto containsModel = findModel != m_linkedModels.end(); + if (containsModel && model == this) { return; } - if( !model->hasLinkedModels() ) - { - QObject::connect( this, SIGNAL(dataChanged()), - model, SIGNAL(dataChanged()), Qt::DirectConnection ); - } + m_linkedModels.push_back(model); + if (!model->hasLinkedModels()) + { + QObject::connect(this, SIGNAL(dataChanged()), model, + SIGNAL(dataChanged()), Qt::DirectConnection); } } -void AutomatableModel::unlinkModel( AutomatableModel* model ) +void AutomatableModel::unlinkModel(AutomatableModel* model) { auto it = std::find(m_linkedModels.begin(), m_linkedModels.end(), model); - if( it != m_linkedModels.end() ) + if (it != m_linkedModels.end()) { - m_linkedModels.erase( it ); + m_linkedModels.erase(it); } } @@ -490,7 +489,7 @@ void AutomatableModel::unlinkModel( AutomatableModel* model ) -void AutomatableModel::linkModels( AutomatableModel* model1, AutomatableModel* model2 ) +void AutomatableModel::linkModels(AutomatableModel* model1, AutomatableModel* model2) { auto model1ContainsModel2 = std::find(model1->m_linkedModels.begin(), model1->m_linkedModels.end(), model2) != model1->m_linkedModels.end(); if (!model1ContainsModel2 && model1 != model2) @@ -507,18 +506,18 @@ void AutomatableModel::linkModels( AutomatableModel* model1, AutomatableModel* m // connect the two dataChanged() signals) emit model1->dataChanged(); // finally: link the models - model1->linkModel( model2 ); - model2->linkModel( model1 ); + model1->linkModel(model2); + model2->linkModel(model1); } } -void AutomatableModel::unlinkModels( AutomatableModel* model1, AutomatableModel* model2 ) +void AutomatableModel::unlinkModels(AutomatableModel* model1, AutomatableModel* model2) { - model1->unlinkModel( model2 ); - model2->unlinkModel( model1 ); + model1->unlinkModel(model2); + model2->unlinkModel(model1); } @@ -526,23 +525,24 @@ void AutomatableModel::unlinkModels( AutomatableModel* model1, AutomatableModel* void AutomatableModel::unlinkAllModels() { - for( AutomatableModel* model : m_linkedModels ) + for (AutomatableModel* model : m_linkedModels) { - unlinkModels( this, model ); + unlinkModels(this, model); } } -void AutomatableModel::setControllerConnection( ControllerConnection* c ) +void AutomatableModel::setControllerConnection(ControllerConnection* c) { m_controllerConnection = c; - if( c ) + if (c) { - QObject::connect( m_controllerConnection, SIGNAL(valueChanged()), - this, SIGNAL(dataChanged()), Qt::DirectConnection ); - QObject::connect( m_controllerConnection, SIGNAL(destroyed()), this, SLOT(unlinkControllerConnection())); + QObject::connect(m_controllerConnection, SIGNAL(valueChanged()), + this, SIGNAL(dataChanged()), Qt::DirectConnection); + QObject::connect(m_controllerConnection, SIGNAL(destroyed()), this, + SLOT(unlinkControllerConnection())); m_valueChanged = true; emit dataChanged(); } @@ -551,19 +551,19 @@ void AutomatableModel::setControllerConnection( ControllerConnection* c ) -float AutomatableModel::controllerValue( int frameOffset ) const +float AutomatableModel::controllerValue(int frameOffset) const { - if( m_controllerConnection ) + if (m_controllerConnection) { float v = 0; switch(m_scaleType) { case ScaleType::Linear: - v = minValue() + ( range() * controllerConnection()->currentValue( frameOffset ) ); + v = minValue() + (range() * controllerConnection()->currentValue(frameOffset)); break; case ScaleType::Logarithmic: v = logToLinearScale( - controllerConnection()->currentValue( frameOffset )); + controllerConnection()->currentValue(frameOffset)); break; default: qFatal("AutomatableModel::controllerValue(int)" @@ -580,18 +580,18 @@ float AutomatableModel::controllerValue( int frameOffset ) const AutomatableModel* lm = m_linkedModels.front(); if (lm->controllerConnection() && lm->useControllerValue()) { - return fittedValue( lm->controllerValue( frameOffset ) ); + return fittedValue(lm->controllerValue(frameOffset)); } - return fittedValue( lm->m_value ); + return fittedValue(lm->m_value); } ValueBuffer * AutomatableModel::valueBuffer() { - QMutexLocker m( &m_valueBufferMutex ); + QMutexLocker m(&m_valueBufferMutex); // if we've already calculated the valuebuffer this period, return the cached buffer - if( m_lastUpdatedPeriod == s_periodCounter ) + if (m_lastUpdatedPeriod == s_periodCounter) { return m_hasSampleExactData ? &m_valueBuffer @@ -603,22 +603,23 @@ ValueBuffer * AutomatableModel::valueBuffer() if (m_controllerConnection && m_useControllerValue && m_controllerConnection->getController()->isSampleExact()) { auto vb = m_controllerConnection->valueBuffer(); - if( vb ) + + if (vb) { float * values = vb->values(); float * nvalues = m_valueBuffer.values(); - switch( m_scaleType ) + switch(m_scaleType) { case ScaleType::Linear: - for( int i = 0; i < m_valueBuffer.length(); i++ ) + for (int i = 0; i < m_valueBuffer.length(); i++) { - nvalues[i] = minValue() + ( range() * values[i] ); + nvalues[i] = minValue() + (range() * values[i]); } break; case ScaleType::Logarithmic: - for( int i = 0; i < m_valueBuffer.length(); i++ ) + for (int i = 0; i < m_valueBuffer.length(); i++) { - nvalues[i] = logToLinearScale( values[i] ); + nvalues[i] = logToLinearScale(values[i]); } break; default: @@ -655,9 +656,9 @@ ValueBuffer * AutomatableModel::valueBuffer() } } - if( m_oldValue != val ) + if (m_oldValue != val) { - m_valueBuffer.interpolate( m_oldValue, val ); + m_valueBuffer.interpolate(m_oldValue, val); m_oldValue = val; m_lastUpdatedPeriod = s_periodCounter; m_hasSampleExactData = true; @@ -674,9 +675,9 @@ ValueBuffer * AutomatableModel::valueBuffer() void AutomatableModel::unlinkControllerConnection() { - if( m_controllerConnection ) + if (m_controllerConnection) { - m_controllerConnection->disconnect( this ); + m_controllerConnection->disconnect(this); } m_controllerConnection = nullptr; @@ -685,14 +686,14 @@ void AutomatableModel::unlinkControllerConnection() -void AutomatableModel::setInitValue( const float value ) +void AutomatableModel::setInitValue(const float value) { - m_initValue = fittedValue( value ); - bool journalling = testAndSetJournalling( false ); - setValue( value ); + m_initValue = fittedValue(value); + bool journalling = testAndSetJournalling(false); + setValue(value); m_oldValue = m_value; - setJournalling( journalling ); - emit initValueChanged( value ); + setJournalling(journalling); + emit initValueChanged(value); } @@ -700,13 +701,13 @@ void AutomatableModel::setInitValue( const float value ) void AutomatableModel::reset() { - setValue( initValue() ); + setValue(initValue()); } -float AutomatableModel::globalAutomationValueAt( const TimePos& time ) +float AutomatableModel::globalAutomationValueAt(const TimePos& time) { // get clips that connect to this model auto clips = AutomationClip::clipsForModel(this); @@ -751,12 +752,12 @@ float AutomatableModel::globalAutomationValueAt( const TimePos& time ) } } - if( latestClip ) + if (latestClip) { // scale/fit the value appropriately and return it - const float value = latestClip->valueAt( time - latestClip->startPosition() ); - const float scaled_value = scaledValue( value ); - return fittedValue( scaled_value ); + const float value = latestClip->valueAt(time - latestClip->startPosition()); + const float scaled_value = scaledValue(value); + return fittedValue(scaled_value); } // if we still find no clip, the value at that time is undefined so // just return current value as the best we can do @@ -790,7 +791,7 @@ int FloatModel::getDigitCount() const { auto steptemp = step(); int digits = 0; - while ( steptemp < 1 ) + while (steptemp < 1) { steptemp = steptemp * 10.0f; digits++; @@ -800,19 +801,19 @@ int FloatModel::getDigitCount() const -QString FloatModel::displayValue( const float val ) const +QString FloatModel::displayValue(const float val) const { - return QString::number( castValue( scaledValue( val ) ) ); + return QString::number(castValue(scaledValue(val))); } -QString IntModel::displayValue( const float val ) const +QString IntModel::displayValue(const float val) const { - return QString::number( castValue( scaledValue( val ) ) ); + return QString::number(castValue(scaledValue(val))); } -QString BoolModel::displayValue( const float val ) const +QString BoolModel::displayValue(const float val) const { - return QString::number( castValue( scaledValue( val ) ) ); + return QString::number(castValue(scaledValue(val))); } diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index dc496fa044a..b5f88312a3c 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -45,32 +45,32 @@ const float AutomationClip::DEFAULT_MIN_VALUE = 0; const float AutomationClip::DEFAULT_MAX_VALUE = 1; -AutomationClip::AutomationClip( AutomationTrack * _auto_track ) : - Clip( _auto_track ), +AutomationClip::AutomationClip(AutomationTrack* auto_track) : + Clip(auto_track), #if (QT_VERSION < QT_VERSION_CHECK(5,14,0)) m_clipMutex(QMutex::Recursive), #endif - m_autoTrack( _auto_track ), + m_autoTrack(auto_track), m_objects(), - m_tension( 1.0 ), - m_progressionType( ProgressionType::Discrete ), - m_dragging( false ), - m_isRecording( false ), - m_lastRecordedValue( 0 ) + m_tension(1.0), + m_progressionType(ProgressionType::Discrete), + m_dragging(false), + m_isRecording(false), + m_lastRecordedValue(0) { - changeLength( TimePos( 1, 0 ) ); - if( getTrack() ) + changeLength(TimePos(1, 0)); + if (getTrack()) { - switch( getTrack()->trackContainer()->type() ) + switch(getTrack()->trackContainer()->type()) { case TrackContainer::Type::Pattern: - setAutoResize( true ); + setAutoResize(true); break; case TrackContainer::Type::Song: // move down default: - setAutoResize( false ); + setAutoResize(false); break; } } @@ -79,22 +79,21 @@ AutomationClip::AutomationClip( AutomationTrack * _auto_track ) : -AutomationClip::AutomationClip( const AutomationClip & _clip_to_copy ) : - Clip( _clip_to_copy.m_autoTrack ), +AutomationClip::AutomationClip(const AutomationClip& clip_to_copy) : + Clip(clip_to_copy.m_autoTrack), #if (QT_VERSION < QT_VERSION_CHECK(5,14,0)) m_clipMutex(QMutex::Recursive), #endif - m_autoTrack( _clip_to_copy.m_autoTrack ), - m_objects( _clip_to_copy.m_objects ), - m_tension( _clip_to_copy.m_tension ), - m_progressionType( _clip_to_copy.m_progressionType ) + m_autoTrack(clip_to_copy.m_autoTrack), + m_objects(clip_to_copy.m_objects), + m_tension(clip_to_copy.m_tension), + m_progressionType(clip_to_copy.m_progressionType) { // Locks the mutex of the copied AutomationClip to make sure it // doesn't change while it's being copied - QMutexLocker m(&_clip_to_copy.m_clipMutex); + QMutexLocker m(&clip_to_copy.m_clipMutex); - for( timeMap::const_iterator it = _clip_to_copy.m_timeMap.begin(); - it != _clip_to_copy.m_timeMap.end(); ++it ) + for (auto it = clip_to_copy.m_timeMap.begin(); it != clip_to_copy.m_timeMap.end(); ++it) { // Copies the automation node (in/out values and in/out tangents) m_timeMap[POS(it)] = it.value(); @@ -102,25 +101,25 @@ AutomationClip::AutomationClip( const AutomationClip & _clip_to_copy ) : m_timeMap[POS(it)].setClip(this); } if (!getTrack()){ return; } - switch( getTrack()->trackContainer()->type() ) + switch(getTrack()->trackContainer()->type()) { case TrackContainer::Type::Pattern: - setAutoResize( true ); + setAutoResize(true); break; case TrackContainer::Type::Song: // move down default: - setAutoResize( false ); + setAutoResize(false); break; } } -bool AutomationClip::addObject( AutomatableModel * _obj, bool _search_dup ) +bool AutomationClip::addObject(AutomatableModel* obj, bool _search_dup) { QMutexLocker m(&m_clipMutex); - if (_search_dup && std::find(m_objects.begin(), m_objects.end(), _obj) != m_objects.end()) + if (_search_dup && std::find(m_objects.begin(), m_objects.end(), obj) != m_objects.end()) { return false; } @@ -129,14 +128,13 @@ bool AutomationClip::addObject( AutomatableModel * _obj, bool _search_dup ) if (m_objects.empty() && hasAutomation() == false) { // then initialize first value - putValue( TimePos(0), _obj->inverseScaledValue( _obj->value() ), false ); + putValue(TimePos(0), obj->inverseScaledValue(obj->value()), false); } - m_objects.push_back(_obj); + m_objects.push_back(obj); - connect( _obj, SIGNAL(destroyed(lmms::jo_id_t)), - this, SLOT(objectDestroyed(lmms::jo_id_t)), - Qt::DirectConnection ); + connect(obj, SIGNAL(destroyed(lmms::jo_id_t)), + this, SLOT(objectDestroyed(lmms::jo_id_t)), Qt::DirectConnection); emit dataChanged(); @@ -146,16 +144,15 @@ bool AutomationClip::addObject( AutomatableModel * _obj, bool _search_dup ) -void AutomationClip::setProgressionType( - ProgressionType _new_progression_type ) +void AutomationClip::setProgressionType(ProgressionType new_progression_type) { QMutexLocker m(&m_clipMutex); - if ( _new_progression_type == ProgressionType::Discrete || - _new_progression_type == ProgressionType::Linear || - _new_progression_type == ProgressionType::CubicHermite ) + if (new_progression_type == ProgressionType::Discrete || + new_progression_type == ProgressionType::Linear || + new_progression_type == ProgressionType::CubicHermite) { - m_progressionType = _new_progression_type; + m_progressionType = new_progression_type; emit dataChanged(); } } @@ -163,14 +160,14 @@ void AutomationClip::setProgressionType( -void AutomationClip::setTension( QString _new_tension ) +void AutomationClip::setTension(QString new_tension) { QMutexLocker m(&m_clipMutex); bool ok; - float nt = LocaleHelper::toFloat(_new_tension, & ok); + float nt = LocaleHelper::toFloat(new_tension, &ok); - if( ok && nt > -0.01 && nt < 1.01 ) + if (ok && nt > -0.01 && nt < 1.01) { m_tension = nt; } @@ -179,7 +176,7 @@ void AutomationClip::setTension( QString _new_tension ) -const AutomatableModel * AutomationClip::firstObject() const +const AutomatableModel* AutomationClip::firstObject() const { QMutexLocker m(&m_clipMutex); @@ -345,12 +342,9 @@ void AutomationClip::removeNode(const TimePos & time) cleanObjects(); - m_timeMap.remove( time ); + m_timeMap.remove(time); timeMap::iterator it = m_timeMap.lowerBound(time); - if( it != m_timeMap.begin() ) - { - --it; - } + if (it != m_timeMap.begin()) { --it; } generateTangents(it, 3); updateLength(); @@ -452,12 +446,12 @@ void AutomationClip::recordValue(TimePos time, float value) { QMutexLocker m(&m_clipMutex); - if( value != m_lastRecordedValue ) + if (value != m_lastRecordedValue) { - putValue( time, value, true ); + putValue(time, value, true); m_lastRecordedValue = value; } - else if( valueAt( time ) != value ) + else if (valueAt(time) != value) { removeNode(time); } @@ -573,38 +567,38 @@ void AutomationClip::applyDragValue() -float AutomationClip::valueAt( const TimePos & _time ) const +float AutomationClip::valueAt(const TimePos& time) const { QMutexLocker m(&m_clipMutex); - if( m_timeMap.isEmpty() ) + if (m_timeMap.isEmpty()) { return 0; } // If we have a node at that time, just return its value - if (m_timeMap.contains(_time)) + if (m_timeMap.contains(time)) { // When the time is exactly the node's time, we want the inValue - return m_timeMap[_time].getInValue(); + return m_timeMap[time].getInValue(); } // lowerBound returns next value with equal or greater key. Since we already // checked if the key contains a node, we know the returned node has a greater - // key than _time. Therefore we take the previous element to calculate the current value - timeMap::const_iterator v = m_timeMap.lowerBound(_time); + // key than time. Therefore we take the previous element to calculate the current value + timeMap::const_iterator v = m_timeMap.lowerBound(time); - if( v == m_timeMap.begin() ) + if (v == m_timeMap.begin()) { return 0; } - if( v == m_timeMap.end() ) + if (v == m_timeMap.end()) { // When the time is after the last node, we want the outValue of it return OUTVAL(v - 1); } - return valueAt(v - 1, _time - POS(v - 1)); + return valueAt(v - 1, time - POS(v - 1)); } @@ -612,7 +606,7 @@ float AutomationClip::valueAt( const TimePos & _time ) const // This method will get the value at an offset from a node, so we use the outValue of // that node and the inValue of the next node for the calculations. -float AutomationClip::valueAt( timeMap::const_iterator v, int offset ) const +float AutomationClip::valueAt(timeMap::const_iterator v, int offset) const { QMutexLocker m(&m_clipMutex); @@ -620,16 +614,11 @@ float AutomationClip::valueAt( timeMap::const_iterator v, int offset ) const // value if we do if (offset == 0) { return INVAL(v); } - if (m_progressionType == ProgressionType::Discrete) - { - return OUTVAL(v); - } - else if( m_progressionType == ProgressionType::Linear ) - { - float slope = - (INVAL(v + 1) - OUTVAL(v)) - / (POS(v + 1) - POS(v)); + if (m_progressionType == ProgressionType::Discrete) { return OUTVAL(v); } + if (m_progressionType == ProgressionType::Linear) + { + float slope = (INVAL(v + 1) - OUTVAL(v)) / (POS(v + 1) - POS(v)); return OUTVAL(v) + offset * slope; } else /* ProgressionType::CubicHermite */ @@ -641,7 +630,7 @@ float AutomationClip::valueAt( timeMap::const_iterator v, int offset ) const // time as the article describes. We are interpolating a single // value: y. To make this work we map the values of x that this // segment spans to values of t for t = 0.0 -> 1.0 and scale the - // tangents _m1 and _m2 + // tangents m1 and m2 int numValues = (POS(v + 1) - POS(v)); float t = (float) offset / (float) numValues; float m1 = OUTTAN(v) * numValues * m_tension; @@ -659,12 +648,12 @@ float AutomationClip::valueAt( timeMap::const_iterator v, int offset ) const -float *AutomationClip::valuesAfter( const TimePos & _time ) const +float *AutomationClip::valuesAfter(const TimePos& time) const { QMutexLocker m(&m_clipMutex); - timeMap::const_iterator v = m_timeMap.lowerBound(_time); - if( v == m_timeMap.end() || (v+1) == m_timeMap.end() ) + timeMap::const_iterator v = m_timeMap.lowerBound(time); + if (v == m_timeMap.end() || (v+1) == m_timeMap.end()) { return nullptr; } @@ -672,9 +661,9 @@ float *AutomationClip::valuesAfter( const TimePos & _time ) const int numValues = POS(v + 1) - POS(v); auto ret = new float[numValues]; - for( int i = 0; i < numValues; i++ ) + for (int i = 0; i < numValues; i++) { - ret[i] = valueAt( v, i ); + ret[i] = valueAt(v, i); } return ret; @@ -820,40 +809,39 @@ void AutomationClip::flipX(int length) -void AutomationClip::saveSettings( QDomDocument & _doc, QDomElement & _this ) +void AutomationClip::saveSettings(QDomDocument& doc, QDomElement& _this) { QMutexLocker m(&m_clipMutex); - _this.setAttribute( "pos", startPosition() ); - _this.setAttribute( "len", length() ); - _this.setAttribute( "name", name() ); - _this.setAttribute( "prog", QString::number( static_cast(progressionType()) ) ); - _this.setAttribute( "tens", QString::number( getTension() ) ); - _this.setAttribute( "mute", QString::number( isMuted() ) ); + _this.setAttribute("pos", startPosition()); + _this.setAttribute("len", length()); + _this.setAttribute("name", name()); + _this.setAttribute("prog", QString::number(static_cast(progressionType()))); + _this.setAttribute("tens", QString::number(getTension())); + _this.setAttribute("mute", QString::number(isMuted())); if (const auto& c = color()) { _this.setAttribute("color", c->name()); } - for( timeMap::const_iterator it = m_timeMap.begin(); - it != m_timeMap.end(); ++it ) + for (timeMap::const_iterator it = m_timeMap.begin(); it != m_timeMap.end(); ++it) { - QDomElement element = _doc.createElement( "time" ); + QDomElement element = doc.createElement("time"); element.setAttribute("pos", POS(it)); element.setAttribute("value", INVAL(it)); element.setAttribute("outValue", OUTVAL(it)); element.setAttribute("inTan", INTAN(it)); element.setAttribute("outTan", OUTTAN(it)); element.setAttribute("lockedTan", static_cast(LOCKEDTAN(it))); - _this.appendChild( element ); + _this.appendChild(element); } for (const auto& object : m_objects) { if (object) { - QDomElement element = _doc.createElement( "object" ); + QDomElement element = doc.createElement("object"); element.setAttribute("id", ProjectJournal::idToSave(object->id())); _this.appendChild(element); } @@ -863,7 +851,7 @@ void AutomationClip::saveSettings( QDomDocument & _doc, QDomElement & _this ) -void AutomationClip::loadSettings( const QDomElement & _this ) +void AutomationClip::loadSettings(const QDomElement& _this) { QMutexLocker m(&m_clipMutex); @@ -874,22 +862,20 @@ void AutomationClip::loadSettings( const QDomElement & _this ) clear(); - movePosition( _this.attribute( "pos" ).toInt() ); - setName( _this.attribute( "name" ) ); - setProgressionType( static_cast( _this.attribute( - "prog" ).toInt() ) ); - setTension( _this.attribute( "tens" ) ); - setMuted(_this.attribute( "mute", QString::number( false ) ).toInt() ); + movePosition(_this.attribute("pos").toInt()); + setName(_this.attribute("name")); + setProgressionType(static_cast(_this.attribute("prog").toInt())); + setTension(_this.attribute("tens")); + setMuted(_this.attribute("mute", QString::number(false)).toInt()); - for( QDomNode node = _this.firstChild(); !node.isNull(); - node = node.nextSibling() ) + for (QDomNode node = _this.firstChild(); !node.isNull(); node = node.nextSibling()) { QDomElement element = node.toElement(); - if( element.isNull() ) + if (element.isNull()) { continue; } - if( element.tagName() == "time" ) + if (element.tagName() == "time") { int timeMapPos = element.attribute("pos").toInt(); float timeMapInValue = LocaleHelper::toFloat(element.attribute("value")); @@ -913,26 +899,26 @@ void AutomationClip::loadSettings( const QDomElement & _this ) shouldGenerateTangents = true; } } - else if( element.tagName() == "object" ) + else if (element.tagName() == "object") { m_idsToResolve.push_back(element.attribute("id").toInt()); } } - + if (_this.hasAttribute("color")) { setColor(QColor{_this.attribute("color")}); } - int len = _this.attribute( "len" ).toInt(); - if( len <= 0 ) + int len = _this.attribute("len").toInt(); + if (len <= 0) { // TODO: Handle with an upgrade method updateLength(); } else { - changeLength( len ); + changeLength(len); } if (shouldGenerateTangents) { generateTangents(); } @@ -945,7 +931,7 @@ QString AutomationClip::name() const { QMutexLocker m(&m_clipMutex); - if( !Clip::name().isEmpty() ) + if (!Clip::name().isEmpty()) { return Clip::name(); } @@ -953,42 +939,41 @@ QString AutomationClip::name() const { return m_objects.front()->fullDisplayName(); } - return tr( "Drag a control while pressing <%1>" ).arg(UI_CTRL_KEY); + return tr("Drag a control while pressing <%1>").arg(UI_CTRL_KEY); } -gui::ClipView * AutomationClip::createView( gui::TrackView * _tv ) +gui::ClipView* AutomationClip::createView(gui::TrackView* tv) { QMutexLocker m(&m_clipMutex); - return new gui::AutomationClipView( this, _tv ); + return new gui::AutomationClipView(this, tv); } -bool AutomationClip::isAutomated( const AutomatableModel * _m ) +bool AutomationClip::isAutomated(const AutomatableModel* model) { auto l = combineAllTracks(); for (const auto track : l) { - if (track->type() == Track::Type::Automation || track->type() == Track::Type::HiddenAutomation) + if (track->type() != Track::Type::Automation || track->type() != Track::Type::HiddenAutomation) + { continue; } // todo: move the continue to the line above once hidden automation is removed + + for (const auto& clip : track->getClips()) { - for (const auto& clip : track->getClips()) + const auto a = dynamic_cast(clip); + if (!a && !(a->hasAutomation())) { continue; } + + for (const auto& object : a->m_objects) { - const auto a = dynamic_cast(clip); - if( a && a->hasAutomation() ) + if (object == model) { - for (const auto& object : a->m_objects) - { - if (object == _m) - { - return true; - } - } + return true; } } } @@ -999,32 +984,32 @@ bool AutomationClip::isAutomated( const AutomatableModel * _m ) /** * @brief returns a list of all the automation clips that are connected to a specific model - * @param _m the model we want to look for + * @param model the model we want to look for */ -std::vector AutomationClip::clipsForModel(const AutomatableModel* _m) +std::vector AutomationClip::clipsForModel(const AutomatableModel* model) { - std::vector clips; + std::vector clips; auto l = combineAllTracks(); // go through all tracks... for (const auto track : l) { // we want only automation tracks... - if (track->type() == Track::Type::Automation || track->type() == Track::Type::HiddenAutomation ) + if (track->type() == Track::Type::Automation || track->type() == Track::Type::HiddenAutomation) { // go through all the clips... for (const auto& trackClip : track->getClips()) { auto a = dynamic_cast(trackClip); // check that the clip has automation - if( a && a->hasAutomation() ) + if (a && a->hasAutomation()) { // now check is the clip is connected to the model we want by going through all the connections // of the clip bool has_object = false; for (const auto& object : a->m_objects) { - if (object == _m) + if (object == model) { has_object = true; } @@ -1040,24 +1025,23 @@ std::vector AutomationClip::clipsForModel(const AutomatableMod -AutomationClip * AutomationClip::globalAutomationClip( - AutomatableModel * _m ) +AutomationClip* AutomationClip::globalAutomationClip(AutomatableModel* model) { AutomationTrack * t = Engine::getSong()->globalAutomationTrack(); for (const auto& clip : t->getClips()) { auto a = dynamic_cast(clip); - if( a ) + if (a) { for (const auto& object : a->m_objects) { - if (object == _m) { return a; } + if (object == model) { return a; } } } } auto a = new AutomationClip(t); - a->addObject( _m, false ); + a->addObject(model, false); return a; } @@ -1074,32 +1058,32 @@ void AutomationClip::resolveAllIDs() for (const auto& clip : track->getClips()) { auto a = dynamic_cast(clip); - if( a ) + if (a) { for (const auto& id : a->m_idsToResolve) { JournallingObject* o = Engine::projectJournal()->journallingObject(id); - if( o && dynamic_cast( o ) ) + if (o && dynamic_cast(o)) { - a->addObject( dynamic_cast( o ), false ); + a->addObject(dynamic_cast(o), false); } else { // FIXME: Remove this block once the automation system gets fixed // This is a temporary fix for https://github.com/LMMS/lmms/issues/3781 o = Engine::projectJournal()->journallingObject(ProjectJournal::idFromSave(id)); - if( o && dynamic_cast( o ) ) + if (o && dynamic_cast(o)) { - a->addObject( dynamic_cast( o ), false ); + a->addObject(dynamic_cast(o), false); } else { // FIXME: Remove this block once the automation system gets fixed // This is a temporary fix for https://github.com/LMMS/lmms/issues/4781 o = Engine::projectJournal()->journallingObject(ProjectJournal::idToSave(id)); - if( o && dynamic_cast( o ) ) + if (o && dynamic_cast(o)) { - a->addObject( dynamic_cast( o ), false ); + a->addObject(dynamic_cast(o), false); } } } @@ -1127,7 +1111,7 @@ void AutomationClip::clear() -void AutomationClip::objectDestroyed( jo_id_t _id ) +void AutomationClip::objectDestroyed(jo_id_t id) { QMutexLocker m(&m_clipMutex); @@ -1135,15 +1119,15 @@ void AutomationClip::objectDestroyed( jo_id_t _id ) // when switching samplerate) and real deletions because in the latter // case we had to remove ourselves if we're the global automation // clip of the destroyed object - m_idsToResolve.push_back(_id); + m_idsToResolve.push_back(id); for (auto objIt = m_objects.begin(); objIt != m_objects.end(); objIt++) { - Q_ASSERT( !(*objIt).isNull() ); - if( (*objIt)->id() == _id ) + Q_ASSERT(!(*objIt).isNull()); + if ((*objIt)->id() == id) { //Assign to objIt so that this loop work even break; is removed. - objIt = m_objects.erase( objIt ); + objIt = m_objects.erase(objIt); break; } } @@ -1158,16 +1142,10 @@ void AutomationClip::cleanObjects() { QMutexLocker m(&m_clipMutex); - for( objectVector::iterator it = m_objects.begin(); it != m_objects.end(); ) + for (objectVector::iterator it = m_objects.begin(); it != m_objects.end();) { - if( *it ) - { - ++it; - } - else - { - it = m_objects.erase( it ); - } + if (*it) { ++it; } + else { it = m_objects.erase(it); } } } diff --git a/src/core/AutomationNode.cpp b/src/core/AutomationNode.cpp index f15c28f8028..6fd8cb7a9af 100644 --- a/src/core/AutomationNode.cpp +++ b/src/core/AutomationNode.cpp @@ -73,7 +73,7 @@ void AutomationNode::setInValue(float value) m_inValue = value; // Recalculate the tangents from neighbor nodes - AutomationClip::timeMap & tm = m_clip->getTimeMap(); + AutomationClip::timeMap& tm = m_clip->getTimeMap(); // Get an iterator pointing to this node AutomationClip::timeMap::iterator it = tm.lowerBound(m_pos); @@ -93,7 +93,7 @@ void AutomationNode::setOutValue(float value) m_outValue = value; // Recalculate the tangents from neighbor nodes - AutomationClip::timeMap & tm = m_clip->getTimeMap(); + AutomationClip::timeMap& tm = m_clip->getTimeMap(); // Get an iterator pointing to this node AutomationClip::timeMap::iterator it = tm.lowerBound(m_pos); diff --git a/src/core/SampleRecordHandle.cpp b/src/core/SampleRecordHandle.cpp index f7003f3beff..e90218cf70e 100644 --- a/src/core/SampleRecordHandle.cpp +++ b/src/core/SampleRecordHandle.cpp @@ -121,7 +121,7 @@ std::shared_ptr SampleRecordHandle::createSampleBuffer() } // create according sample-buffer out of big buffer - return std::make_shared(std::move(bigBuffer), Engine::audioEngine()->inputSampleRate()); + return std::make_shared(std::move(bigBuffer), Engine::audioEngine()->outputSampleRate()); }