From 56ad171551a6f4127962457f729344ee42821230 Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Tue, 26 Mar 2024 10:01:10 +0530 Subject: [PATCH 01/28] AudioEngineProfiler.cpp cleaned as per conventions HOPEFULLY --- src/core/AudioEngineProfiler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 From 3748815ec254f4ab0d7dc8931026d52caf403f53 Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Tue, 26 Mar 2024 10:05:32 +0530 Subject: [PATCH 02/28] AudioEngine.cpp. Still unsure of some. --- src/core/AudioEngine.cpp | 315 ++++++++++++++++++++------------------- 1 file changed, 160 insertions(+), 155 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 04e3c7c7ce5..489ca5d8298 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -73,31 +73,31 @@ static thread_local bool s_runningChange; -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_qualitySettings( qualitySettings::Mode::Draft ), - m_masterGain( 1.0f ), - m_audioDev( nullptr ), - m_oldAudioDev( nullptr ), - m_audioDevStartFailed( false ), + m_numWorkers(QThread::idealThreadCount() - 1), + m_newPlayHandles(PlayHandle::MaxNumber), + m_qualitySettings(qualitySettings::Mode::Draft), + m_masterGain(1.0f), + m_audioDev(nullptr), + m_oldAudioDev(nullptr), + m_audioDevStartFailed(false), m_profiler(), m_metronomeActive(false), 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 ]; - BufferManager::clear( m_inputBuffer[i], m_inputBufferSize[i] ); + m_inputBuffer[i] = new sampleFrame[DEFAULT_BUFFER_SIZE * 100]; + BufferManager::clear(m_inputBuffer[i], m_inputBufferSize[i]); } // determine FIFO size and number of frames per period @@ -105,26 +105,26 @@ 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(); + (fpp_t) 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", + ConfigManager::inst()->setValue("audioengine", "framesperaudiobuffer", - QString::number( DEFAULT_BUFFER_SIZE ) ); + 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; @@ -132,10 +132,10 @@ 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); int outputBufferSize = m_framesPerPeriod * sizeof(surroundSampleFrame); m_outputBufferRead = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); @@ -144,14 +144,14 @@ AudioEngine::AudioEngine( bool renderOnly ) : BufferManager::clear(m_outputBufferRead, m_framesPerPeriod); BufferManager::clear(m_outputBufferWrite, 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); } } @@ -160,19 +160,19 @@ 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(); } @@ -196,12 +196,14 @@ 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(); } @@ -216,8 +218,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 { @@ -232,7 +234,7 @@ void AudioEngine::startProcessing(bool needsFifo) void AudioEngine::stopProcessing() { - if( m_fifoWriter != nullptr ) + if (m_fifoWriter != nullptr) { m_fifoWriter->finish(); m_fifoWriter->wait(); @@ -251,8 +253,8 @@ void AudioEngine::stopProcessing() sample_rate_t AudioEngine::baseSampleRate() const { - sample_rate_t sr = ConfigManager::inst()->value( "audioengine", "samplerate" ).toInt(); - if( sr < 44100 ) + sample_rate_t sr = ConfigManager::inst()->value("audioengine", "samplerate").toInt(); + if (sr < 44100) { sr = 44100; } @@ -296,29 +298,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 ]; - int size = m_inputBufferSize[ m_inputBufferWrite ]; - sampleFrame * buf = m_inputBuffer[ m_inputBufferWrite ]; + f_cnt_t frames = m_inputBufferFrames[m_inputBufferWrite]; + int size = m_inputBufferSize[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 ) ); + 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(); } @@ -329,7 +331,7 @@ void AudioEngine::renderStageNoteSetup() { AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::NoteSetup); - if( m_clearSignal ) + if (m_clearSignal) { m_clearSignal = false; clearInternal(); @@ -339,22 +341,25 @@ void AudioEngine::renderStageNoteSetup() // them if they still exist... // maybe this algorithm could be optimized... ConstPlayHandleList::Iterator it_rem = m_playHandlesToRemove.begin(); - while( it_rem != m_playHandlesToRemove.end() ) + while (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((NotePlayHandle*) *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(); @@ -369,11 +374,11 @@ void AudioEngine::renderStageNoteSetup() 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 ); + m_newPlayHandles.free(e); e = next; } } @@ -399,24 +404,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 (PlayHandleList::Iterator 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((NotePlayHandle*) *it); } else delete *it; - it = m_playHandles.erase( it ); + it = m_playHandles.erase(it); } else { @@ -537,10 +542,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 ); + m_newPlayHandles.free(e); e = next; } doneChangeInModel(); @@ -608,22 +613,22 @@ void AudioEngine::changeQuality(const struct qualitySettings & qs) -void AudioEngine::doSetAudioDevice( AudioDevice * _dev ) +void AudioEngine::doSetAudioDevice(AudioDevice * _dev) { // 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 (_dev) { m_audioDev = _dev; } 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(); } } @@ -640,12 +645,12 @@ void AudioEngine::setAudioDevice(AudioDevice * _dev, m_qualitySettings = _qs; - doSetAudioDevice( _dev ); + doSetAudioDevice(_dev); emit qualitySettingsChanged(); emit sampleRateChanged(); - if (startNow) {startProcessing( _needs_fifo );} + if (startNow) { startProcessing(_needs_fifo); } } @@ -653,7 +658,7 @@ void AudioEngine::setAudioDevice(AudioDevice * _dev, void AudioEngine::storeAudioDevice() { - if( !m_oldAudioDev ) + if (!m_oldAudioDev) { m_oldAudioDev = m_audioDev; } @@ -664,7 +669,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; @@ -693,21 +698,21 @@ 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((NotePlayHandle*)handle); } else delete handle; @@ -726,20 +731,20 @@ void AudioEngine::removePlayHandle(PlayHandle * 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 ) + for (LocklessListElement * e = m_newPlayHandles.first(), + * ePrev = nullptr; e; ePrev = e, e = e->next) { if (e->value == ph) { - if( ePrev ) + if (ePrev) { ePrev->next = e->next; } else { - m_newPlayHandles.setFirst( e->next ); + m_newPlayHandles.setFirst(e->next); } - m_newPlayHandles.free( e ); + m_newPlayHandles.free(e); removedFromList = true; break; } @@ -754,7 +759,7 @@ void AudioEngine::removePlayHandle(PlayHandle * ph) // 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 (removedFromList) { if (ph->type() == PlayHandle::Type::NotePlayHandle) { @@ -777,17 +782,17 @@ void AudioEngine::removePlayHandlesOfTypes(Track * track, PlayHandle::Types type { requestChangeInModel(); PlayHandleList::Iterator it = m_playHandles.begin(); - while( it != m_playHandles.end() ) + while (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((NotePlayHandle*) *it); } else delete *it; - it = m_playHandles.erase( it ); + it = m_playHandles.erase(it); } else { @@ -941,8 +946,8 @@ AudioDevice * AudioEngine::tryAudioDevices() { bool success_ful = false; AudioDevice * dev = nullptr; - QString dev_name = ConfigManager::inst()->value( "audioengine", "audiodev" ); - if( !isAudioDevNameValid( dev_name ) ) + QString dev_name = ConfigManager::inst()->value("audioengine", "audiodev"); + if (!isAudioDevNameValid(dev_name)) { dev_name = ""; } @@ -950,10 +955,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; @@ -964,10 +969,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; @@ -978,10 +983,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; @@ -992,10 +997,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; @@ -1005,10 +1010,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; @@ -1019,10 +1024,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; @@ -1033,10 +1038,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; @@ -1047,10 +1052,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; @@ -1068,18 +1073,18 @@ AudioDevice * AudioEngine::tryAudioDevices() //} //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); } @@ -1087,17 +1092,17 @@ AudioDevice * AudioEngine::tryAudioDevices() 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; @@ -1105,10 +1110,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; @@ -1118,10 +1123,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; @@ -1131,10 +1136,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; @@ -1144,10 +1149,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() ) + if (msndio->isRunning()) { m_midiClientName = MidiSndio::name(); return msndio; @@ -1157,10 +1162,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() ) +// if ( moss->isRunning() ) { m_midiClientName = MidiWinMM::name(); return mwmm; @@ -1170,18 +1175,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; 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()) { @@ -1207,10 +1212,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"); } @@ -1234,19 +1239,19 @@ void AudioEngine::fifoWriter::run() #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 ); + 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 surroundSampleFrame[frames]; const surroundSampleFrame * b = m_audioEngine->renderNextBuffer(); - memcpy( buffer, b, frames * sizeof( surroundSampleFrame ) ); + memcpy(buffer, b, frames * sizeof(surroundSampleFrame)); m_fifo->write(buffer); } From a205f53c2c293a2982078c92dc5615fb84786aea Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Tue, 26 Mar 2024 10:43:51 +0530 Subject: [PATCH 03/28] AudioResampler.cpp. Is confusing. --- src/core/AudioResampler.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/AudioResampler.cpp b/src/core/AudioResampler.cpp index 5f6b6a23955..e0520f71a41 100644 --- a/src/core/AudioResampler.cpp +++ b/src/core/AudioResampler.cpp @@ -28,12 +28,13 @@ #include #include -namespace lmms { +namespace lmms +{ -AudioResampler::AudioResampler(int interpolationMode, int channels) - : m_interpolationMode(interpolationMode) - , m_channels(channels) - , m_state(src_new(interpolationMode, channels, &m_error)) +AudioResampler::AudioResampler(int interpolationMode, int channels) : + m_interpolationMode(interpolationMode), + m_channels(channels), + m_state(src_new(interpolationMode, channels, &m_error)) { if (!m_state) { From 2888966fb9f91474d46697922ddbc69b2f88d837 Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Tue, 26 Mar 2024 11:04:44 +0530 Subject: [PATCH 04/28] AutomatableModel.cpp. Basic changes. --- src/core/AutomatableModel.cpp | 343 +++++++++++++++++----------------- 1 file changed, 173 insertions(+), 170 deletions(-) diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index c701f28e36d..76ced6e4d55 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,48 +150,50 @@ 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() ) + if (!p->hasAutomation()) { delete p; } @@ -200,27 +203,27 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString& // 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 +233,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 +258,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 +295,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 +330,32 @@ 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); } //! @todo: this should be moved into a maths header template -void roundAt( T& value, const T& where, const T& step_size ) +void roundAt(T& value, const T& where, const T& step_size) { if (std::abs(value - where) < typeInfo::minEps() * std::abs(step_size)) @@ -365,7 +368,7 @@ void roundAt( T& value, const T& where, const T& step_size ) 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); } @@ -373,7 +376,7 @@ void AutomatableModel::roundAt( T& value, const T& where ) const -void AutomatableModel::setAutomatedValue( const float value ) +void AutomatableModel::setAutomatedValue(const float value) { setUseControllerValue(false); @@ -381,11 +384,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) @@ -405,23 +408,23 @@ 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(); } @@ -430,9 +433,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(); @@ -442,24 +445,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; } @@ -471,17 +474,17 @@ 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 ); + m_linkedModels.push_back(model); - if( !model->hasLinkedModels() ) + if (!model->hasLinkedModels()) { - QObject::connect( this, SIGNAL(dataChanged()), - model, SIGNAL(dataChanged()), Qt::DirectConnection ); + QObject::connect(this, SIGNAL(dataChanged()), + model, SIGNAL(dataChanged()), Qt::DirectConnection); } } } @@ -489,12 +492,12 @@ void AutomatableModel::linkModel( AutomatableModel* model ) -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); } } @@ -503,7 +506,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) @@ -520,18 +523,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); } @@ -539,23 +542,23 @@ 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(); } @@ -564,26 +567,26 @@ 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)" "lacks implementation for a scale type"); break; } - if( typeInfo::isEqual( m_step, 1 ) && m_hasStrictStepSize ) + if (typeInfo::isEqual(m_step, 1) && m_hasStrictStepSize) { return std::round(v); } @@ -593,18 +596,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 @@ -617,22 +620,22 @@ ValueBuffer * AutomatableModel::valueBuffer() if (m_controllerConnection && m_useControllerValue && m_controllerConnection->getController()->isSampleExact()) { 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: @@ -669,9 +672,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; @@ -688,9 +691,9 @@ ValueBuffer * AutomatableModel::valueBuffer() void AutomatableModel::unlinkControllerConnection() { - if( m_controllerConnection ) + if (m_controllerConnection) { - m_controllerConnection->disconnect( this ); + m_controllerConnection->disconnect(this); } m_controllerConnection = nullptr; @@ -699,14 +702,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); } @@ -714,13 +717,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); @@ -765,12 +768,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 @@ -804,7 +807,7 @@ int FloatModel::getDigitCount() const { auto steptemp = step(); int digits = 0; - while ( steptemp < 1 ) + while (steptemp < 1) { steptemp = steptemp * 10.0f; digits++; @@ -814,19 +817,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))); } From 9fd9367ced733e6624d1edb23e4e792a5794e37f Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Tue, 26 Mar 2024 11:12:54 +0530 Subject: [PATCH 05/28] AutomationClip.cpp general. --- src/core/AutomationClip.cpp | 200 ++++++++++++++++++------------------ 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index 6035502704d..ecfb268c0d6 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,22 @@ 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); - for( timeMap::const_iterator it = _clip_to_copy.m_timeMap.begin(); - it != _clip_to_copy.m_timeMap.end(); ++it ) + for (timeMap::const_iterator 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,21 +102,21 @@ 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); @@ -129,14 +129,14 @@ 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); - connect( _obj, SIGNAL(destroyed(lmms::jo_id_t)), + connect(_obj, SIGNAL(destroyed(lmms::jo_id_t)), this, SLOT(objectDestroyed(lmms::jo_id_t)), - Qt::DirectConnection ); + Qt::DirectConnection); emit dataChanged(); @@ -147,13 +147,13 @@ bool AutomationClip::addObject( AutomatableModel * _obj, bool _search_dup ) void AutomationClip::setProgressionType( - ProgressionType _new_progression_type ) + ProgressionType _new_progression_type) { QMutexLocker m(&m_clipMutex); - if ( _new_progression_type == ProgressionType::Discrete || + if (_new_progression_type == ProgressionType::Discrete || _new_progression_type == ProgressionType::Linear || - _new_progression_type == ProgressionType::CubicHermite ) + _new_progression_type == ProgressionType::CubicHermite) { m_progressionType = _new_progression_type; emit dataChanged(); @@ -163,14 +163,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); - if( ok && nt > -0.01 && nt < 1.01 ) + if (ok && nt > -0.01 && nt < 1.01) { m_tension = nt; } @@ -345,9 +345,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() ) + if (it != m_timeMap.begin()) { --it; } @@ -452,12 +452,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,11 +573,11 @@ 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; } @@ -594,11 +594,11 @@ float AutomationClip::valueAt( const TimePos & _time ) const // 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); @@ -612,7 +612,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); @@ -624,7 +624,7 @@ float AutomationClip::valueAt( timeMap::const_iterator v, int offset ) const { return OUTVAL(v); } - else if( m_progressionType == ProgressionType::Linear ) + else if (m_progressionType == ProgressionType::Linear) { float slope = (INVAL(v + 1) - OUTVAL(v)) @@ -659,12 +659,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() ) + if (v == m_timeMap.end() || (v+1) == m_timeMap.end()) { return nullptr; } @@ -672,9 +672,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 +820,40 @@ 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 +863,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 +874,22 @@ 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,7 +913,7 @@ 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()); } @@ -924,15 +924,15 @@ void AutomationClip::loadSettings( const QDomElement & _this ) 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 +945,7 @@ QString AutomationClip::name() const { QMutexLocker m(&m_clipMutex); - if( !Clip::name().isEmpty() ) + if (!Clip::name().isEmpty()) { return Clip::name(); } @@ -953,24 +953,24 @@ 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 * _m) { auto l = combineAllTracks(); for (const auto track : l) @@ -980,7 +980,7 @@ bool AutomationClip::isAutomated( const AutomatableModel * _m ) for (const auto& clip : track->getClips()) { const auto a = dynamic_cast(clip); - if( a && a->hasAutomation() ) + if (a && a->hasAutomation()) { for (const auto& object : a->m_objects) { @@ -1010,14 +1010,14 @@ std::vector AutomationClip::clipsForModel(const AutomatableMod 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 @@ -1041,13 +1041,13 @@ std::vector AutomationClip::clipsForModel(const AutomatableMod AutomationClip * AutomationClip::globalAutomationClip( - AutomatableModel * _m ) + AutomatableModel * _m) { 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) { @@ -1057,7 +1057,7 @@ AutomationClip * AutomationClip::globalAutomationClip( } auto a = new AutomationClip(t); - a->addObject( _m, false ); + a->addObject(_m, false); return a; } @@ -1074,32 +1074,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 +1127,7 @@ void AutomationClip::clear() -void AutomationClip::objectDestroyed( jo_id_t _id ) +void AutomationClip::objectDestroyed(jo_id_t _id) { QMutexLocker m(&m_clipMutex); @@ -1139,11 +1139,11 @@ void AutomationClip::objectDestroyed( jo_id_t _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,15 +1158,15 @@ 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 ) + if (*it) { ++it; } else { - it = m_objects.erase( it ); + it = m_objects.erase(it); } } } From 6cd960f4fb90350cdf02b68bb367c1742acb58a6 Mon Sep 17 00:00:00 2001 From: Monospace-V <76674645+Monospace-V@users.noreply.github.com> Date: Thu, 28 Mar 2024 19:11:51 +0530 Subject: [PATCH 06/28] Update src/core/AudioEngine.cpp Oh. big important Co-authored-by: saker --- src/core/AudioEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 489ca5d8298..882f3d55995 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -117,7 +117,7 @@ AudioEngine::AudioEngine(bool renderOnly) : { ConfigManager::inst()->setValue("audioengine", "framesperaudiobuffer", - QString::number DEFAULT_BUFFER_SIZE)); + QString::number(DEFAULT_BUFFER_SIZE)); m_framesPerPeriod = DEFAULT_BUFFER_SIZE; } From f5a58c95874f916c03e33283f0a8e8f5ae9dfb9e Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Fri, 29 Mar 2024 08:50:23 +0530 Subject: [PATCH 07/28] AudioEngine.cpp: minor changes --- src/core/AudioEngine.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 882f3d55995..f1f715e99d6 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -202,7 +202,8 @@ void AudioEngine::initDevices() m_audioDevName = AudioDummy::name(); m_midiClient = new MidiDummy; m_midiClientName = MidiDummy::name(); - } else + } + else { m_audioDev = tryAudioDevices(); m_midiClient = tryMidiClients(); @@ -1066,8 +1067,8 @@ 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; //} @@ -1165,7 +1166,7 @@ MidiClient * AudioEngine::tryMidiClients() if (client_name == MidiWinMM::name() || client_name == "") { MidiWinMM * mwmm = new MidiWinMM; -// if ( moss->isRunning() ) +// if (moss->isRunning()) { m_midiClientName = MidiWinMM::name(); return mwmm; From 35ec6579f8c70ddabe64a6696ae7915d866ff6b1 Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Sat, 30 Mar 2024 08:37:21 +0530 Subject: [PATCH 08/28] AutomatableModel.cpp quick clean I suppose. Amen --- src/core/AutomatableModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 582ce080089..4b78133ed03 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -620,8 +620,8 @@ ValueBuffer * AutomatableModel::valueBuffer() { auto vb = m_controllerConnection->valueBuffer(); - if (vb) + if (vb) { float * values = vb->values(); float * nvalues = m_valueBuffer.values(); From 5bd403eb6ebd2a5898920ee4c93c7575eba1d381 Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Sat, 30 Mar 2024 09:26:53 +0530 Subject: [PATCH 09/28] AudioEngine.cpp, AutomationClip.cpp: whitespace cleanup --- src/core/AudioEngine.cpp | 2 +- src/core/AutomationClip.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index f1f715e99d6..11f3a2c3757 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -107,7 +107,7 @@ AudioEngine::AudioEngine(bool renderOnly) : // size from user configuration if (renderOnly == false) { - m_framesPerPeriod = + m_framesPerPeriod = (fpp_t) ConfigManager::inst()->value("audioengine", "framesperaudiobuffer").toInt(); // if the value read from user configuration is not set or diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index 1ae74ad3e3b..734c10d02fe 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -918,7 +918,7 @@ void AutomationClip::loadSettings(const QDomElement & _this) m_idsToResolve.push_back(element.attribute("id").toInt()); } } - + if (_this.hasAttribute("color")) { setColor(QColor{_this.attribute("color")}); From 767815d0d3c7a718b4db4e0c2cdbd58fc6dc2e83 Mon Sep 17 00:00:00 2001 From: Monospace-V Date: Mon, 1 Apr 2024 08:17:41 +0530 Subject: [PATCH 10/28] AudioEngine.cpp: Minor else block --- src/core/AudioEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 11f3a2c3757..33238bf7d89 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -792,7 +792,7 @@ void AudioEngine::removePlayHandlesOfTypes(Track * track, PlayHandle::Types type { NotePlayHandleManager::release((NotePlayHandle*) *it); } - else delete *it; + else { delete *it; } it = m_playHandles.erase(it); } else From 1e6ad514b45fef94114c3e1affd8bc744646ec2f Mon Sep 17 00:00:00 2001 From: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> Date: Sat, 22 Jun 2024 10:49:34 +0530 Subject: [PATCH 11/28] Avoid C style casts Co-authored-by: Kevin Zander --- src/core/AudioEngine.cpp | 10 +++++----- src/core/AutomationClip.cpp | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index a0a63287610..6ba21c15484 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -108,7 +108,7 @@ AudioEngine::AudioEngine(bool renderOnly) : if (renderOnly == false) { m_framesPerPeriod = - (fpp_t) ConfigManager::inst()->value("audioengine", "framesperaudiobuffer").toInt(); + 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 @@ -340,7 +340,7 @@ void AudioEngine::renderStageNoteSetup() (*it)->audioPort()->removePlayHandle((*it)); if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { - NotePlayHandleManager::release((NotePlayHandle*) *it); + NotePlayHandleManager::release(dynamic_cast(*it)); } else { @@ -408,7 +408,7 @@ void AudioEngine::renderStageEffects() (*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); @@ -701,7 +701,7 @@ bool AudioEngine::addPlayHandle(PlayHandle* handle) if (handle->type() == PlayHandle::Type::NotePlayHandle) { - NotePlayHandleManager::release((NotePlayHandle*)handle); + NotePlayHandleManager::release(dynamic_cast(handle)); } else delete handle; @@ -778,7 +778,7 @@ void AudioEngine::removePlayHandlesOfTypes(Track * track, PlayHandle::Types type (*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); diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index 734c10d02fe..489e5ec245d 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -876,8 +876,7 @@ void AutomationClip::loadSettings(const QDomElement & _this) movePosition(_this.attribute("pos").toInt()); setName(_this.attribute("name")); - setProgressionType(static_cast(_this.attribute( - "prog").toInt())); + setProgressionType(static_cast(_this.attribute("prog").toInt())); setTension(_this.attribute("tens")); setMuted(_this.attribute("mute", QString::number(false)).toInt()); From f5f901e6b77700e023d3dcf301f8671c8c832f18 Mon Sep 17 00:00:00 2001 From: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> Date: Sat, 22 Jun 2024 10:58:29 +0530 Subject: [PATCH 12/28] some more spacing fixes Co-authored-by: Kevin Zander --- src/core/AudioEngine.cpp | 23 +++++++++++------------ src/core/AutomatableModel.cpp | 7 +++---- src/core/AutomationClip.cpp | 26 ++++++++++++-------------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 6ba21c15484..974eb555587 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -288,7 +288,7 @@ 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(); @@ -337,7 +337,7 @@ void AudioEngine::renderStageNoteSetup() if (it != m_playHandles.end()) { - (*it)->audioPort()->removePlayHandle((*it)); + (*it)->audioPort()->removePlayHandle(*it); if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { NotePlayHandleManager::release(dynamic_cast(*it)); @@ -364,7 +364,7 @@ void AudioEngine::renderStageNoteSetup() 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; @@ -394,8 +394,7 @@ void AudioEngine::renderStageEffects() AudioEngineWorkerThread::startAndWaitForJobs(); // removed all play handles which are done - for (PlayHandleList::Iterator it = m_playHandles.begin(); - it != m_playHandles.end();) + for (PlayHandleList::Iterator it = m_playHandles.begin(); it != m_playHandles.end();) { if ((*it)->affinityMatters() && (*it)->affinity() != QThread::currentThread()) @@ -405,7 +404,7 @@ void AudioEngine::renderStageEffects() } if ((*it)->isFinished()) { - (*it)->audioPort()->removePlayHandle((*it)); + (*it)->audioPort()->removePlayHandle(*it); if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { NotePlayHandleManager::release(dynamic_cast(*it)); @@ -532,7 +531,7 @@ 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); @@ -602,7 +601,7 @@ void AudioEngine::changeQuality(const struct qualitySettings & qs) -void AudioEngine::doSetAudioDevice(AudioDevice * _dev) +void AudioEngine::doSetAudioDevice(AudioDevice* _dev) { // TODO: Use shared_ptr here in the future. // Currently, this is safe, because this is only called by @@ -720,8 +719,8 @@ void AudioEngine::removePlayHandle(PlayHandle * 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) + for (LocklessListElement* e = m_newPlayHandles.first(), *ePrev = nullptr; + e; ePrev = e, e = e->next) { if (e->value == ph) { @@ -775,7 +774,7 @@ void AudioEngine::removePlayHandlesOfTypes(Track * track, PlayHandle::Types type { if ((*it)->isFromTrack(track) && ((*it)->type() & types)) { - (*it)->audioPort()->removePlayHandle((*it)); + (*it)->audioPort()->removePlayHandle(*it); if ((*it)->type() == PlayHandle::Type::NotePlayHandle) { NotePlayHandleManager::release(dynamic_cast(*it)); @@ -1201,7 +1200,7 @@ MidiClient * AudioEngine::tryMidiClients() -AudioEngine::fifoWriter::fifoWriter(AudioEngine* audioEngine, Fifo * fifo) : +AudioEngine::fifoWriter::fifoWriter(AudioEngine* audioEngine, Fifo* fifo) : m_audioEngine(audioEngine), m_fifo(fifo), m_writing(true) diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 4b78133ed03..7d47cb357e2 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -42,7 +42,7 @@ 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, const QString& displayName, bool defaultConstructed) : Model(parent, displayName, defaultConstructed), m_scaleType(ScaleType::Linear), m_minValue(min), @@ -188,7 +188,7 @@ void AutomatableModel::loadSettings(const QDomElement& element, const QString& n node = node.namedItem(name); if (node.isElement()) { - AutomationClip * p = AutomationClip::globalAutomationClip(this); + AutomationClip* p = AutomationClip::globalAutomationClip(this); p->loadSettings(node.toElement()); setValue(p->valueAt(0)); // in older projects we sometimes have odd automations @@ -408,8 +408,7 @@ 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)) { diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index 489e5ec245d..249991e8247 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -116,7 +116,7 @@ AutomationClip::AutomationClip(const AutomationClip & _clip_to_copy) : } } -bool AutomationClip::addObject(AutomatableModel * _obj, bool _search_dup) +bool AutomationClip::addObject(AutomatableModel* _obj, bool _search_dup) { QMutexLocker m(&m_clipMutex); @@ -836,8 +836,7 @@ void AutomationClip::saveSettings(QDomDocument & _doc, QDomElement & _this) _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"); element.setAttribute("pos", POS(it)); @@ -880,8 +879,7 @@ void AutomationClip::loadSettings(const QDomElement & _this) 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()) @@ -958,18 +956,18 @@ QString AutomationClip::name() const -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* _m) { auto l = combineAllTracks(); for (const auto track : l) @@ -1078,27 +1076,27 @@ void AutomationClip::resolveAllIDs() 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); } } } From 14b2634fb3d2c40e8fcfbc2949e1b212b4f95aae Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Sat, 22 Jun 2024 11:27:10 +0530 Subject: [PATCH 13/28] more style fixes per veratil's review --- src/core/AudioResampler.cpp | 7 +-- src/core/AutomationClip.cpp | 106 ++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 64 deletions(-) diff --git a/src/core/AudioResampler.cpp b/src/core/AudioResampler.cpp index 8e39a75c934..658b4841f89 100644 --- a/src/core/AudioResampler.cpp +++ b/src/core/AudioResampler.cpp @@ -31,10 +31,9 @@ namespace lmms { -AudioResampler::AudioResampler(int interpolationMode, int channels) : - m_interpolationMode(interpolationMode), - m_channels(channels), - m_state(src_new(interpolationMode, channels, &m_error)) +AudioResampler::AudioResampler(int interpolationMode, int channels) + : m_interpolationMode(interpolationMode), m_channels(channels) + , m_state(src_new(interpolationMode, channels, &m_error)) { if (!m_state) { diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index 249991e8247..fe148b09278 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -45,12 +45,12 @@ 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), @@ -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(); @@ -146,16 +145,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(); } } @@ -573,7 +571,7 @@ void AutomationClip::applyDragValue() -float AutomationClip::valueAt(const TimePos & _time) const +float AutomationClip::valueAt(const TimePos& time) const { QMutexLocker m(&m_clipMutex); @@ -583,16 +581,16 @@ float AutomationClip::valueAt(const TimePos & _time) const } // 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()) { @@ -604,7 +602,7 @@ float AutomationClip::valueAt(const TimePos & _time) const return OUTVAL(v - 1); } - return valueAt(v - 1, _time - POS(v - 1)); + return valueAt(v - 1, time - POS(v - 1)); } @@ -620,16 +618,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 +634,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,11 +652,11 @@ 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); + timeMap::const_iterator v = m_timeMap.lowerBound(time); if (v == m_timeMap.end() || (v+1) == m_timeMap.end()) { return nullptr; @@ -820,7 +813,7 @@ void AutomationClip::flipX(int length) -void AutomationClip::saveSettings(QDomDocument & _doc, QDomElement & _this) +void AutomationClip::saveSettings(QDomDocument& doc, QDomElement& _this) { QMutexLocker m(&m_clipMutex); @@ -838,7 +831,7 @@ void AutomationClip::saveSettings(QDomDocument & _doc, QDomElement & _this) 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)); @@ -852,7 +845,7 @@ void AutomationClip::saveSettings(QDomDocument & _doc, QDomElement & _this) { if (object) { - QDomElement element = _doc.createElement("object"); + QDomElement element = doc.createElement("object"); element.setAttribute("id", ProjectJournal::idToSave(object->id())); _this.appendChild(element); } @@ -862,7 +855,7 @@ void AutomationClip::saveSettings(QDomDocument & _doc, QDomElement & _this) -void AutomationClip::loadSettings(const QDomElement & _this) +void AutomationClip::loadSettings(const QDomElement& _this) { QMutexLocker m(&m_clipMutex); @@ -967,7 +960,7 @@ gui::ClipView* AutomationClip::createView(gui::TrackView* tv) -bool AutomationClip::isAutomated(const AutomatableModel* _m) +bool AutomationClip::isAutomated(const AutomatableModel* model) { auto l = combineAllTracks(); for (const auto track : l) @@ -981,7 +974,7 @@ bool AutomationClip::isAutomated(const AutomatableModel* _m) { for (const auto& object : a->m_objects) { - if (object == _m) + if (object == model) { return true; } @@ -996,9 +989,9 @@ 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; auto l = combineAllTracks(); @@ -1021,7 +1014,7 @@ std::vector AutomationClip::clipsForModel(const AutomatableMod bool has_object = false; for (const auto& object : a->m_objects) { - if (object == _m) + if (object == model) { has_object = true; } @@ -1037,8 +1030,7 @@ 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()) @@ -1048,13 +1040,13 @@ AutomationClip * AutomationClip::globalAutomationClip( { 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; } @@ -1124,7 +1116,7 @@ void AutomationClip::clear() -void AutomationClip::objectDestroyed(jo_id_t _id) +void AutomationClip::objectDestroyed(jo_id_t id) { QMutexLocker m(&m_clipMutex); @@ -1132,12 +1124,12 @@ 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) + if ((*objIt)->id() == id) { //Assign to objIt so that this loop work even break; is removed. objIt = m_objects.erase(objIt); @@ -1157,14 +1149,8 @@ void AutomationClip::cleanObjects() 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); } } } From 1bec3b3a9e0b606e5a2bd4b138952cc4b9f3710d Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Sat, 22 Jun 2024 12:25:26 +0530 Subject: [PATCH 14/28] more style changes + de nested a complex function --- src/core/AudioEngine.cpp | 87 ++++++++++++++--------------------- src/core/AutomatableModel.cpp | 29 +++++------- src/core/AutomationClip.cpp | 49 +++++++++----------- 3 files changed, 68 insertions(+), 97 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 974eb555587..4f0126a7b1c 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -24,20 +24,19 @@ #include "AudioEngine.h" -#include "MixHelpers.h" -#include "denormals.h" - #include "lmmsconfig.h" +#include "denormals.h" #include "AudioEngineWorkerThread.h" #include "AudioPort.h" -#include "Mixer.h" -#include "Song.h" +#include "ConfigManager.h" #include "EnvelopeAndLfoParameters.h" +#include "MemoryHelper.h" +#include "Mixer.h" +#include "MixHelpers.h" #include "NotePlayHandle.h" -#include "ConfigManager.h" +#include "Song.h" #include "SamplePlayHandle.h" -#include "MemoryHelper.h" // platform-specific audio-interface-classes #include "AudioAlsa.h" @@ -138,8 +137,8 @@ AudioEngine::AudioEngine(bool renderOnly) : BufferManager::init(m_framesPerPeriod); int outputBufferSize = m_framesPerPeriod * sizeof(surroundSampleFrame); - m_outputBufferRead = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); - m_outputBufferWrite = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); + m_outputBufferRead = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); + m_outputBufferWrite = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); BufferManager::clear(m_outputBufferRead, m_framesPerPeriod); BufferManager::clear(m_outputBufferWrite, m_framesPerPeriod); @@ -301,7 +300,7 @@ void AudioEngine::pushInputFrames(sampleFrame* _ab, const f_cnt_t _frames) size = std::max(size * 2, frames + _frames); auto ab = new sampleFrame[size]; memcpy(ab, buf, frames * sizeof(sampleFrame)); - delete [] buf; + delete[] buf; m_inputBufferSize[m_inputBufferWrite] = size; m_inputBuffer[m_inputBufferWrite] = ab; @@ -342,10 +341,7 @@ void AudioEngine::renderStageNoteSetup() { NotePlayHandleManager::release(dynamic_cast(*it)); } - else - { - delete *it; - } + else { delete *it; } m_playHandles.erase(it); } @@ -355,7 +351,7 @@ void AudioEngine::renderStageNoteSetup() swapBuffers(); // prepare master mix (clear internal buffers etc.) - Mixer * mixer = Engine::mixer(); + Mixer* mixer = Engine::mixer(); mixer->prepareMasterMix(); handleMetronome(); @@ -396,8 +392,7 @@ void AudioEngine::renderStageEffects() // removed all play handles which are done for (PlayHandleList::Iterator it = m_playHandles.begin(); it != m_playHandles.end();) { - if ((*it)->affinityMatters() && - (*it)->affinity() != QThread::currentThread()) + if ((*it)->affinityMatters() && (*it)->affinity() != QThread::currentThread()) { ++it; continue; @@ -409,13 +404,10 @@ void AudioEngine::renderStageEffects() { NotePlayHandleManager::release(dynamic_cast(*it)); } - else delete *it; + else { delete *it; } it = m_playHandles.erase(it); } - else - { - ++it; - } + else { ++it; } } } @@ -425,7 +417,7 @@ void AudioEngine::renderStageMix() { AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Mixing); - Mixer *mixer = Engine::mixer(); + Mixer* mixer = Engine::mixer(); mixer->masterMix(m_outputBufferWrite); MixHelpers::multiply(m_outputBufferWrite, m_masterGain, m_framesPerPeriod); @@ -440,7 +432,7 @@ void AudioEngine::renderStageMix() -const surroundSampleFrame *AudioEngine::renderNextBuffer() +const surroundSampleFrame* AudioEngine::renderNextBuffer() { const auto lock = std::lock_guard{m_changeMutex}; @@ -478,7 +470,7 @@ void AudioEngine::handleMetronome() { static tick_t lastMetroTicks = -1; - Song * song = Engine::getSong(); + Song* song = Engine::getSong(); Song::PlayMode currentPlayMode = song->playMode(); bool metronomeSupported = @@ -492,19 +484,13 @@ void AudioEngine::handleMetronome() } // stop crash with metronome if empty project - if (song->countTracks() == 0) - { - return; - } + if (song->countTracks() == 0) { return; } tick_t ticks = song->getPlayPos(currentPlayMode).getTicks(); tick_t ticksPerBar = TimePos::ticksPerBar(); int numerator = song->getTimeSigModel().getNumerator(); - if (ticks == lastMetroTicks) - { - return; - } + if (ticks == lastMetroTicks) { return; } if (ticks % (ticksPerBar / 1) == 0) { @@ -559,7 +545,7 @@ void AudioEngine::clearInternal() -AudioEngine::StereoSample AudioEngine::getPeakValues(sampleFrame * ab, const f_cnt_t frames) const +AudioEngine::StereoSample AudioEngine::getPeakValues(sampleFrame* ab, const f_cnt_t frames) const { sample_t peakLeft = 0.0f; sample_t peakRight = 0.0f; @@ -585,7 +571,7 @@ AudioEngine::StereoSample AudioEngine::getPeakValues(sampleFrame * ab, const f_c -void AudioEngine::changeQuality(const struct qualitySettings & qs) +void AudioEngine::changeQuality(const struct qualitySettings& qs) { // don't delete the audio-device stopProcessing(); @@ -601,7 +587,7 @@ 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 @@ -609,9 +595,9 @@ void AudioEngine::doSetAudioDevice(AudioDevice* _dev) // it does not access the old device anymore. if (m_audioDev != m_oldAudioDev) { delete m_audioDev; } - if (_dev) + if (device) { - m_audioDev = _dev; + m_audioDev = device; } else { @@ -624,16 +610,14 @@ 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(); @@ -673,7 +657,7 @@ void AudioEngine::restoreAudioDevice() -void AudioEngine::removeAudioPort(AudioPort * port) +void AudioEngine::removeAudioPort(AudioPort* port) { requestChangeInModel(); @@ -702,13 +686,13 @@ bool AudioEngine::addPlayHandle(PlayHandle* 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 @@ -782,10 +766,7 @@ void AudioEngine::removePlayHandlesOfTypes(Track * track, PlayHandle::Types type else { delete *it; } it = m_playHandles.erase(it); } - else - { - ++it; - } + else { ++it; } } doneChangeInModel(); } @@ -930,10 +911,10 @@ bool AudioEngine::isMidiDevNameValid(QString name) return false; } -AudioDevice * AudioEngine::tryAudioDevices() +AudioDevice* AudioEngine::tryAudioDevices() { bool success_ful = false; - AudioDevice * dev = nullptr; + AudioDevice* dev = nullptr; QString dev_name = ConfigManager::inst()->value("audioengine", "audiodev"); if (!isAudioDevNameValid(dev_name)) { diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 7d47cb357e2..5b7043be4eb 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -193,10 +193,7 @@ void AutomatableModel::loadSettings(const QDomElement& element, const QString& n 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 @@ -357,8 +354,7 @@ float AutomatableModel::inverseScaledValue(float value) const template void roundAt(T& value, const T& where, const T& step_size) { - if (std::abs(value - where) - < typeInfo::minEps() * std::abs(step_size)) + if (std::abs(value - where) < (typeInfo::minEps() * std::abs(step_size))) { value = where; } @@ -475,16 +471,15 @@ float AutomatableModel::fittedValue(float value) const 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); } } @@ -557,7 +552,8 @@ void AutomatableModel::setControllerConnection(ControllerConnection* 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(destroyed()), this, + SLOT(unlinkControllerConnection())); m_valueChanged = true; emit dataChanged(); } @@ -617,7 +613,6 @@ ValueBuffer * AutomatableModel::valueBuffer() if (m_controllerConnection && m_useControllerValue && m_controllerConnection->getController()->isSampleExact()) { - auto vb = m_controllerConnection->valueBuffer(); if (vb) diff --git a/src/core/AutomationClip.cpp b/src/core/AutomationClip.cpp index fe148b09278..940e6af70e9 100644 --- a/src/core/AutomationClip.cpp +++ b/src/core/AutomationClip.cpp @@ -79,7 +79,7 @@ AutomationClip::AutomationClip(AutomationTrack* auto_track) : -AutomationClip::AutomationClip(const AutomationClip & clip_to_copy) : +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), @@ -115,11 +115,11 @@ AutomationClip::AutomationClip(const AutomationClip & clip_to_copy) : } } -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; } @@ -128,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(); @@ -161,12 +160,12 @@ void AutomationClip::setProgressionType(ProgressionType new_progression_type) -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) { @@ -177,7 +176,7 @@ void AutomationClip::setTension(QString _new_tension) -const AutomatableModel * AutomationClip::firstObject() const +const AutomatableModel* AutomationClip::firstObject() const { QMutexLocker m(&m_clipMutex); @@ -345,10 +344,7 @@ void AutomationClip::removeNode(const TimePos & 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(); @@ -965,20 +961,19 @@ 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 == model) - { - return true; - } - } + return true; } } } @@ -993,7 +988,7 @@ bool AutomationClip::isAutomated(const AutomatableModel* model) */ std::vector AutomationClip::clipsForModel(const AutomatableModel* model) { - std::vector clips; + std::vector clips; auto l = combineAllTracks(); // go through all tracks... From b92e5ffe52b78d924387e828d88180dac75d8ebd Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Sat, 22 Jun 2024 12:27:17 +0530 Subject: [PATCH 15/28] missed AutomationNode.cpp --- src/core/AutomationNode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); From 1797c0f6a77591772dcf8c66d2edcd51e8afeb89 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Sat, 22 Jun 2024 12:32:48 +0530 Subject: [PATCH 16/28] ate a ; --- src/core/AutomatableModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 5b7043be4eb..b4b9fa0ad6c 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -471,7 +471,7 @@ float AutomatableModel::fittedValue(float value) const void AutomatableModel::linkModel(AutomatableModel* model) { - auto findModel = std::find(m_linkedModels.begin(), m_linkedModels.end(), model) + auto findModel = std::find(m_linkedModels.begin(), m_linkedModels.end(), model); auto containsModel = findModel != m_linkedModels.end(); if (containsModel && model == this) { return; } From 8b28039c9b13b3412fe0739399c7b31d6be02be3 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 19:18:01 +0530 Subject: [PATCH 17/28] adjusted AudioEngine further --- src/core/AudioEngine.cpp | 46 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 087d1f0fe9e..e3f5325c3ee 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -110,9 +110,8 @@ AudioEngine::AudioEngine(bool renderOnly) : // save it to the configuration 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; } @@ -168,8 +167,8 @@ AudioEngine::~AudioEngine() { delete[] m_fifo->read(); } - delete m_fifo; + delete m_fifo; delete m_midiClient; delete m_audioDev; @@ -245,11 +244,7 @@ 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; + return (sr < 41000) ? 41000 : sr; } @@ -278,8 +273,7 @@ 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(); @@ -321,8 +315,7 @@ 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); @@ -380,7 +373,7 @@ 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()) { @@ -454,8 +447,6 @@ void AudioEngine::swapBuffers() } - - void AudioEngine::clear() { m_clearSignal = true; @@ -534,7 +525,7 @@ void AudioEngine::doSetAudioDevice(AudioDevice* device) void AudioEngine::setAudioDevice(AudioDevice* device, const struct qualitySettings& qs, - bool _needs_fifo, bool startNow) + bool needs_fifo, bool startNow) { stopProcessing(); @@ -545,7 +536,7 @@ void AudioEngine::setAudioDevice(AudioDevice* device, const struct qualitySettin emit qualitySettingsChanged(); emit sampleRateChanged(); - if (startNow) { startProcessing(_needs_fifo); } + if (startNow) { startProcessing(needs_fifo); } } @@ -980,7 +971,7 @@ AudioDevice* AudioEngine::tryAudioDevices() -MidiClient * AudioEngine::tryMidiClients() +MidiClient* AudioEngine::tryMidiClients() { QString client_name = ConfigManager::inst()->value("audioengine", "mididev"); if (!isMidiDevNameValid(client_name)) @@ -1041,7 +1032,7 @@ MidiClient * AudioEngine::tryMidiClients() #ifdef LMMS_HAVE_SNDIO if (client_name == MidiSndio::name() || client_name == "") { - MidiSndio * msndio = new MidiSndio; + auto msndio = new MidiSndio; if (msndio->isRunning()) { m_midiClientName = MidiSndio::name(); @@ -1054,7 +1045,7 @@ MidiClient * AudioEngine::tryMidiClients() #ifdef LMMS_BUILD_WIN32 if (client_name == MidiWinMM::name() || client_name == "") { - MidiWinMM * mwmm = new MidiWinMM; + auto mwmm = new MidiWinMM; // if (moss->isRunning()) { m_midiClientName = MidiWinMM::name(); @@ -1068,7 +1059,7 @@ MidiClient * AudioEngine::tryMidiClients() 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"); return mapple; @@ -1125,17 +1116,6 @@ 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) { From 63006e9cbf7976ec26d8f68ef506b1f6625f4f99 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 19:24:28 +0530 Subject: [PATCH 18/28] one more to AudioEngine --- src/core/AudioEngine.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index e3f5325c3ee..b5d8c0c465b 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -617,8 +617,7 @@ void AudioEngine::removePlayHandle(PlayHandle* 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) + for (auto e = m_newPlayHandles.first(), *ePrev = nullptr; e; ePrev = e, e = e->next) { if (e->value == ph) { @@ -667,8 +666,7 @@ 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)) { From e8ad49e421acfe91370857d06c90099eb4c067ed Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 20:02:18 +0530 Subject: [PATCH 19/28] fix build --- src/core/AudioEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index b5d8c0c465b..992af9a3118 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -617,7 +617,7 @@ void AudioEngine::removePlayHandle(PlayHandle* ph) bool removedFromList = false; // Check m_newPlayHandles first because doing it the other way around // creates a race condition - for (auto e = m_newPlayHandles.first(), *ePrev = nullptr; e; ePrev = e, e = e->next) + for (auto e = m_newPlayHandles.first(); *ePrev = nullptr; e; ePrev = e, e = e->next) { if (e->value == ph) { From 86d49e8053cb8da86815c82febadb8bf549c4185 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 20:24:39 +0530 Subject: [PATCH 20/28] fix build correctly --- src/core/AudioEngine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 992af9a3118..e663a68adf9 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -617,7 +617,8 @@ void AudioEngine::removePlayHandle(PlayHandle* ph) bool removedFromList = false; // Check m_newPlayHandles first because doing it the other way around // creates a race condition - for (auto e = m_newPlayHandles.first(); *ePrev = nullptr; e; ePrev = e, e = e->next) + LocklessListElement* e = m_newPlayHandles.first(), *ePrev = nullptr; + while (e) { if (e->value == ph) { From 7059b50944aa7a991dc48f477eec6e3aaee9e3dc Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:44:53 +0530 Subject: [PATCH 21/28] a bit of denesting --- src/core/AudioEngine.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index e663a68adf9..72f9bffc88c 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -252,8 +252,7 @@ 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(); } @@ -261,8 +260,7 @@ sample_rate_t AudioEngine::outputSampleRate() const sample_rate_t AudioEngine::inputSampleRate() const { - return m_audioDev != nullptr ? m_audioDev->sampleRate() : - baseSampleRate(); + return m_audioDev ? m_audioDev->sampleRate() : baseSampleRate(); } bool AudioEngine::criticalXRuns() const From ad7a20609dd50eddae3b588fa05b00346fac48ff Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:46:27 +0530 Subject: [PATCH 22/28] removed redundant inputSampleRate function --- include/AudioEngine.h | 1 - src/core/AudioEngine.cpp | 5 ----- src/core/SampleRecordHandle.cpp | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) 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 72f9bffc88c..b99de4532ec 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -258,11 +258,6 @@ sample_rate_t AudioEngine::outputSampleRate() const -sample_rate_t AudioEngine::inputSampleRate() const -{ - return m_audioDev ? m_audioDev->sampleRate() : baseSampleRate(); -} - bool AudioEngine::criticalXRuns() const { return cpuLoad() >= 99 && Engine::getSong()->isExporting() == false; 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()); } From 72deea4d0fcb5f9ad1f8a5de54519e369b727227 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:47:52 +0530 Subject: [PATCH 23/28] missed styling here --- src/core/AudioEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index b99de4532ec..8fef1c47b9e 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -339,7 +339,7 @@ void AudioEngine::renderStageNoteSetup() for (LocklessListElement* e = m_newPlayHandles.popList(); e;) { m_playHandles += e->value; - LocklessListElement * next = e->next; + LocklessListElement* next = e->next; m_newPlayHandles.free(e); e = next; } From 831ef4cb05329e0922ddaaf154fb943a21a4f99b Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:49:03 +0530 Subject: [PATCH 24/28] why this if statement? --- src/core/AudioEngine.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 8fef1c47b9e..62e83482ffc 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -368,11 +368,6 @@ void AudioEngine::renderStageEffects() // removed all play handles which are done for (auto it = m_playHandles.begin(); it != m_playHandles.end();) { - if ((*it)->affinityMatters() && (*it)->affinity() != QThread::currentThread()) - { - ++it; - continue; - } if ((*it)->isFinished()) { (*it)->audioPort()->removePlayHandle(*it); From 7ad5f5eda006110a0f6cc02fa45c37284780eabd Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:49:50 +0530 Subject: [PATCH 25/28] revert last commit --- src/core/AudioEngine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 62e83482ffc..8fef1c47b9e 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -368,6 +368,11 @@ void AudioEngine::renderStageEffects() // removed all play handles which are done for (auto it = m_playHandles.begin(); it != m_playHandles.end();) { + if ((*it)->affinityMatters() && (*it)->affinity() != QThread::currentThread()) + { + ++it; + continue; + } if ((*it)->isFinished()) { (*it)->audioPort()->removePlayHandle(*it); From e44881fc7f29c5fc505bc60daf575b143d6feec7 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:50:36 +0530 Subject: [PATCH 26/28] missed style here too --- src/core/AudioEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 8fef1c47b9e..6318818da09 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -453,7 +453,7 @@ void AudioEngine::clearNewPlayHandles() requestChangeInModel(); for (LocklessListElement* e = m_newPlayHandles.popList(); e;) { - LocklessListElement * next = e->next; + LocklessListElement* next = e->next; m_newPlayHandles.free(e); e = next; } From c330d1d4b7d78e258ed07d129ee88ea977895716 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:57:53 +0530 Subject: [PATCH 27/28] simplified AudioEngine::removePlayHandle --- src/core/AudioEngine.cpp | 79 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 6318818da09..6e8bd50cf5b 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -601,55 +601,56 @@ bool AudioEngine::addPlayHandle(PlayHandle* handle) 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 - LocklessListElement* e = m_newPlayHandles.first(), *ePrev = nullptr; - while (e) + if (!ph->affinityMatters() || ph->affinity() != QThread::currentThread()) + { + m_playHandlesToRemove.push_back(ph); + return; + } + + requestChangeInModel(); + 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(); } From 4a7a95130283b8498d3700e9e360c97462a91c91 Mon Sep 17 00:00:00 2001 From: Rossmaxx Date: Thu, 26 Sep 2024 21:59:27 +0530 Subject: [PATCH 28/28] fixed an error prone area --- src/core/AudioEngine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 6e8bd50cf5b..8a7ace10e30 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -601,15 +601,16 @@ bool AudioEngine::addPlayHandle(PlayHandle* handle) 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()) { m_playHandlesToRemove.push_back(ph); + doneChangesInModel(); return; } - requestChangeInModel(); ph->audioPort()->removePlayHandle(ph); bool removedFromList = false; // Check m_newPlayHandles first because doing it the other way around