From d31089ceb51aa4280dd54a0656354f6bc66e5be0 Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Sun, 5 Jun 2016 00:50:26 +0200 Subject: [PATCH] Fixed removal of track when notes are playing --- include/AudioDevice.h | 4 +- include/AudioDummy.h | 1 + include/AudioPort.h | 1 - include/AudioPortAudio.h | 2 + include/BasicFilters.h | 1 - include/Controller.h | 2 +- include/DummyInstrument.h | 2 + include/EffectChain.h | 1 - include/FxMixer.h | 1 - include/InstrumentSoundShaping.h | 1 - include/Mixer.h | 29 +++++--- include/ProjectRenderer.h | 1 + include/SampleBuffer.h | 1 - include/SamplePlayHandle.h | 2 +- include/SampleRecordHandle.h | 3 +- include/VisualizationWidget.h | 2 +- plugins/GigPlayer/GigPlayer.cpp | 1 + .../audio_file_processor.cpp | 1 + plugins/bit_invader/bit_invader.cpp | 1 + plugins/carlabase/carla.cpp | 1 + plugins/kicker/kicker.cpp | 1 + plugins/lb302/lb302.h | 1 - plugins/nes/Nes.cpp | 1 + plugins/opl2/opl2instrument.cpp | 1 + plugins/organic/organic.cpp | 1 + plugins/papu/papu_instrument.cpp | 1 + plugins/sf2_player/sf2_player.cpp | 1 + plugins/sfxr/sfxr.cpp | 1 + plugins/sid/sid_instrument.cpp | 1 + plugins/stk/mallets/mallets.cpp | 1 + .../triple_oscillator/TripleOscillator.cpp | 1 + plugins/vestige/vestige.cpp | 1 + plugins/vibed/vibed.cpp | 1 + plugins/vst_base/VstPlugin.cpp | 1 + plugins/vst_base/VstPlugin.h | 1 - plugins/watsyn/Watsyn.cpp | 1 + plugins/zynaddsubfx/ZynAddSubFx.cpp | 1 + src/core/AutomatableModel.cpp | 1 + src/core/AutomationPattern.cpp | 1 + src/core/FxMixer.cpp | 1 + src/core/InstrumentFunctions.cpp | 1 + src/core/InstrumentSoundShaping.cpp | 1 + src/core/Mixer.cpp | 67 ++++++++++++++++++- src/core/NotePlayHandle.cpp | 1 + src/core/PresetPreviewPlayHandle.cpp | 1 + src/core/SampleBuffer.cpp | 1 + src/core/SamplePlayHandle.cpp | 1 + src/core/SampleRecordHandle.cpp | 1 + src/core/audio/AudioAlsa.cpp | 1 + src/core/audio/AudioDevice.cpp | 1 + src/core/audio/AudioFileOgg.cpp | 2 + src/core/audio/AudioFileWave.cpp | 1 + src/core/audio/AudioJack.cpp | 1 + src/core/audio/AudioOss.cpp | 1 + src/core/audio/AudioPort.cpp | 1 + src/core/audio/AudioPortAudio.cpp | 1 + src/core/audio/AudioPulseAudio.cpp | 1 + src/core/audio/AudioSdl.cpp | 1 + src/core/audio/AudioSoundIo.cpp | 1 + src/core/midi/MidiPort.cpp | 1 + src/gui/ControllerConnectionDialog.cpp | 1 + src/gui/FileBrowser.cpp | 1 + src/gui/FxMixerView.cpp | 1 + src/gui/editors/SongEditor.cpp | 1 + src/gui/widgets/VisualizationWidget.cpp | 1 + src/tracks/InstrumentTrack.cpp | 5 ++ src/tracks/SampleTrack.cpp | 2 + 67 files changed, 152 insertions(+), 25 deletions(-) diff --git a/include/AudioDevice.h b/include/AudioDevice.h index 0782035b7dd..fa7a6b2ea2a 100644 --- a/include/AudioDevice.h +++ b/include/AudioDevice.h @@ -28,12 +28,14 @@ #include #include #include +#include -#include "Mixer.h" +#include "lmms_basics.h" #include "TabWidget.h" class AudioPort; +class Mixer; class AudioDevice diff --git a/include/AudioDummy.h b/include/AudioDummy.h index 1b5a554f803..02b1ec9afb1 100644 --- a/include/AudioDummy.h +++ b/include/AudioDummy.h @@ -28,6 +28,7 @@ #include "AudioDevice.h" #include "AudioDeviceSetupWidget.h" #include "MicroTimer.h" +#include "Mixer.h" class AudioDummy : public AudioDevice, public QThread diff --git a/include/AudioPort.h b/include/AudioPort.h index 7412d5eb591..52d3b8ad048 100644 --- a/include/AudioPort.h +++ b/include/AudioPort.h @@ -29,7 +29,6 @@ #include #include -#include "Mixer.h" #include "MemoryManager.h" #include "PlayHandle.h" diff --git a/include/AudioPortAudio.h b/include/AudioPortAudio.h index ab9be60c140..8b920eea604 100644 --- a/include/AudioPortAudio.h +++ b/include/AudioPortAudio.h @@ -51,6 +51,8 @@ public slots: #include #endif +#include + #include "AudioDevice.h" #include "AudioDeviceSetupWidget.h" diff --git a/include/BasicFilters.h b/include/BasicFilters.h index 58c811c6fca..4acb551292c 100644 --- a/include/BasicFilters.h +++ b/include/BasicFilters.h @@ -39,7 +39,6 @@ #include #include "lmms_basics.h" -#include "Mixer.h" #include "templates.h" #include "lmms_constants.h" #include "interpolation.h" diff --git a/include/Controller.h b/include/Controller.h index e1d2f98621e..554dffbf631 100644 --- a/include/Controller.h +++ b/include/Controller.h @@ -28,9 +28,9 @@ #define CONTROLLER_H #include "Engine.h" -#include "Mixer.h" #include "Model.h" #include "JournallingObject.h" +#include "templates.h" #include "ValueBuffer.h" class ControllerDialog; diff --git a/include/DummyInstrument.h b/include/DummyInstrument.h index c369924b754..cd49aaa5703 100644 --- a/include/DummyInstrument.h +++ b/include/DummyInstrument.h @@ -32,6 +32,8 @@ #include +#include "Mixer.h" + class DummyInstrument : public Instrument { diff --git a/include/EffectChain.h b/include/EffectChain.h index 858938b0219..32150393cd0 100644 --- a/include/EffectChain.h +++ b/include/EffectChain.h @@ -28,7 +28,6 @@ #include "Model.h" #include "SerializingObject.h" -#include "Mixer.h" #include "AutomatableModel.h" class Effect; diff --git a/include/FxMixer.h b/include/FxMixer.h index 0c2ac02a5b5..1d1f60b035e 100644 --- a/include/FxMixer.h +++ b/include/FxMixer.h @@ -26,7 +26,6 @@ #define FX_MIXER_H #include "Model.h" -#include "Mixer.h" #include "EffectChain.h" #include "JournallingObject.h" #include "ThreadableJob.h" diff --git a/include/InstrumentSoundShaping.h b/include/InstrumentSoundShaping.h index 31e8cc75ef9..4e10bbdc2ec 100644 --- a/include/InstrumentSoundShaping.h +++ b/include/InstrumentSoundShaping.h @@ -25,7 +25,6 @@ #ifndef INSTRUMENT_SOUND_SHAPING_H #define INSTRUMENT_SOUND_SHAPING_H -#include "Mixer.h" #include "ComboBoxModel.h" diff --git a/include/Mixer.h b/include/Mixer.h index b57dc13d87f..8e57f074e36 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -29,21 +29,11 @@ #include "lmmsconfig.h" -#ifndef LMMS_USE_3RDPARTY_LIBSRC -#include -#else -#ifndef OUT_OF_TREE_BUILD -#include "src/3rdparty/samplerate/samplerate.h" -#else -#include -#endif -#endif - - #include #include #include #include +#include #include "lmms_basics.h" @@ -346,6 +336,9 @@ class EXPORT Mixer : public QObject inline bool isMetronomeActive() const { return m_metronomeActive; } inline void setMetronomeActive(bool value = true) { m_metronomeActive = value; } + void requestChangeInModel(); + void doneChangeInModel(); + signals: void qualitySettingsChanged(); @@ -388,6 +381,9 @@ class EXPORT Mixer : public QObject const surroundSampleFrame * renderNextBuffer(); + void runChangesInModel(); + + QVector m_audioPorts; @@ -420,6 +416,8 @@ class EXPORT Mixer : public QObject struct qualitySettings m_qualitySettings; float m_masterGain; + bool m_isProcessing; + // audio device stuff AudioDevice * m_audioDev; AudioDevice * m_oldAudioDev; @@ -444,6 +442,15 @@ class EXPORT Mixer : public QObject bool m_metronomeActive; + bool m_changesSignal; + bool m_waitForMixer; + unsigned int m_changes; + QMutex m_changesMutex; + QMutex m_doChangesMutex; + QMutex m_waitChangesMutex; + QWaitCondition m_changesMixerCondition; + QWaitCondition m_changesRequestCondition; + friend class LmmsCore; friend class MixerWorkerThread; diff --git a/include/ProjectRenderer.h b/include/ProjectRenderer.h index 9c68d578d0e..dfb6c6d176c 100644 --- a/include/ProjectRenderer.h +++ b/include/ProjectRenderer.h @@ -27,6 +27,7 @@ #include "AudioFileDevice.h" #include "lmmsconfig.h" +#include "Mixer.h" class ProjectRenderer : public QThread diff --git a/include/SampleBuffer.h b/include/SampleBuffer.h index dbb2f71ace6..c210af2ef90 100644 --- a/include/SampleBuffer.h +++ b/include/SampleBuffer.h @@ -38,7 +38,6 @@ #include "lmms_basics.h" #include "lmms_math.h" #include "shared_object.h" -#include "Mixer.h" #include "MemoryManager.h" diff --git a/include/SamplePlayHandle.h b/include/SamplePlayHandle.h index 847277a5b49..8c69c72c18f 100644 --- a/include/SamplePlayHandle.h +++ b/include/SamplePlayHandle.h @@ -25,9 +25,9 @@ #ifndef SAMPLE_PLAY_HANDLE_H #define SAMPLE_PLAY_HANDLE_H -#include "Mixer.h" #include "SampleBuffer.h" #include "AutomatableModel.h" +#include "PlayHandle.h" class BBTrack; class SampleTCO; diff --git a/include/SampleRecordHandle.h b/include/SampleRecordHandle.h index b6a44439674..76bfabf181e 100644 --- a/include/SampleRecordHandle.h +++ b/include/SampleRecordHandle.h @@ -29,7 +29,8 @@ #include #include -#include "Mixer.h" +#include "MidiTime.h" +#include "PlayHandle.h" #include "SampleBuffer.h" class BBTrack; diff --git a/include/VisualizationWidget.h b/include/VisualizationWidget.h index 5bc25c43dcd..ee2f1760ed5 100644 --- a/include/VisualizationWidget.h +++ b/include/VisualizationWidget.h @@ -29,7 +29,7 @@ #include #include -#include "Mixer.h" +#include "lmms_basics.h" class VisualizationWidget : public QWidget diff --git a/plugins/GigPlayer/GigPlayer.cpp b/plugins/GigPlayer/GigPlayer.cpp index ac07420dd62..999e21b18ba 100644 --- a/plugins/GigPlayer/GigPlayer.cpp +++ b/plugins/GigPlayer/GigPlayer.cpp @@ -40,6 +40,7 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "InstrumentPlayHandle.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "Knob.h" #include "Song.h" diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index 7225a28deb9..5bd0edd847d 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -35,6 +35,7 @@ #include "Engine.h" #include "Song.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "interpolation.h" #include "gui_templates.h" diff --git a/plugins/bit_invader/bit_invader.cpp b/plugins/bit_invader/bit_invader.cpp index 668a761c89e..8178e5adda7 100644 --- a/plugins/bit_invader/bit_invader.cpp +++ b/plugins/bit_invader/bit_invader.cpp @@ -32,6 +32,7 @@ #include "InstrumentTrack.h" #include "Knob.h" #include "LedCheckbox.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "Oscillator.h" #include "PixmapButton.h" diff --git a/plugins/carlabase/carla.cpp b/plugins/carlabase/carla.cpp index ad1b683a69f..caba64297d0 100644 --- a/plugins/carlabase/carla.cpp +++ b/plugins/carlabase/carla.cpp @@ -32,6 +32,7 @@ #include "gui_templates.h" #include "InstrumentPlayHandle.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include #include diff --git a/plugins/kicker/kicker.cpp b/plugins/kicker/kicker.cpp index bc27340399f..c47f63b9ecb 100644 --- a/plugins/kicker/kicker.cpp +++ b/plugins/kicker/kicker.cpp @@ -31,6 +31,7 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "Knob.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "KickerOsc.h" diff --git a/plugins/lb302/lb302.h b/plugins/lb302/lb302.h index 03cff135d1c..8b78bf11027 100644 --- a/plugins/lb302/lb302.h +++ b/plugins/lb302/lb302.h @@ -37,7 +37,6 @@ #include "InstrumentView.h" #include "LedCheckbox.h" #include "Knob.h" -#include "Mixer.h" #include "NotePlayHandle.h" #include diff --git a/plugins/nes/Nes.cpp b/plugins/nes/Nes.cpp index b23a03b9405..72587ae7e39 100644 --- a/plugins/nes/Nes.cpp +++ b/plugins/nes/Nes.cpp @@ -33,6 +33,7 @@ #include "Song.h" #include "lmms_math.h" #include "interpolation.h" +#include "Mixer.h" #include "Oscillator.h" #include "embed.cpp" diff --git a/plugins/opl2/opl2instrument.cpp b/plugins/opl2/opl2instrument.cpp index 54493bf92e8..3afcfb24082 100644 --- a/plugins/opl2/opl2instrument.cpp +++ b/plugins/opl2/opl2instrument.cpp @@ -40,6 +40,7 @@ #include "Engine.h" #include "InstrumentPlayHandle.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include #include diff --git a/plugins/organic/organic.cpp b/plugins/organic/organic.cpp index 16db225e4c2..13e42f977c6 100644 --- a/plugins/organic/organic.cpp +++ b/plugins/organic/organic.cpp @@ -33,6 +33,7 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "Knob.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "Oscillator.h" #include "PixmapButton.h" diff --git a/plugins/papu/papu_instrument.cpp b/plugins/papu/papu_instrument.cpp index 8e011816444..acf2042c520 100644 --- a/plugins/papu/papu_instrument.cpp +++ b/plugins/papu/papu_instrument.cpp @@ -32,6 +32,7 @@ #include "base64.h" #include "InstrumentTrack.h" #include "Knob.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "PixmapButton.h" #include "ToolTip.h" diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index 50a39c34952..86e732face9 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -33,6 +33,7 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "InstrumentPlayHandle.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "Knob.h" #include "Song.h" diff --git a/plugins/sfxr/sfxr.cpp b/plugins/sfxr/sfxr.cpp index 6d9b8a45112..540987b8d28 100644 --- a/plugins/sfxr/sfxr.cpp +++ b/plugins/sfxr/sfxr.cpp @@ -49,6 +49,7 @@ float frnd(float range) #include "Song.h" #include "MidiEvent.h" #include "MidiTime.h" +#include "Mixer.h" #include "embed.cpp" diff --git a/plugins/sid/sid_instrument.cpp b/plugins/sid/sid_instrument.cpp index 03090e94d58..1a02dd9fb00 100644 --- a/plugins/sid/sid_instrument.cpp +++ b/plugins/sid/sid_instrument.cpp @@ -35,6 +35,7 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "Knob.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "PixmapButton.h" #include "ToolTip.h" diff --git a/plugins/stk/mallets/mallets.cpp b/plugins/stk/mallets/mallets.cpp index 7bfc5483aad..e4ec07c0c48 100644 --- a/plugins/stk/mallets/mallets.cpp +++ b/plugins/stk/mallets/mallets.cpp @@ -37,6 +37,7 @@ #include "gui_templates.h" #include "GuiApplication.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "embed.cpp" diff --git a/plugins/triple_oscillator/TripleOscillator.cpp b/plugins/triple_oscillator/TripleOscillator.cpp index f314c64f0b8..3cb9c9417f6 100644 --- a/plugins/triple_oscillator/TripleOscillator.cpp +++ b/plugins/triple_oscillator/TripleOscillator.cpp @@ -33,6 +33,7 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "Knob.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "PixmapButton.h" #include "SampleBuffer.h" diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index 9db5ea352b5..14e1f207cf8 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -38,6 +38,7 @@ #include "InstrumentTrack.h" #include "VstPlugin.h" #include "MainWindow.h" +#include "Mixer.h" #include "GuiApplication.h" #include "PixmapButton.h" #include "StringPairDrag.h" diff --git a/plugins/vibed/vibed.cpp b/plugins/vibed/vibed.cpp index d74b654e20c..1697b5d0bd8 100644 --- a/plugins/vibed/vibed.cpp +++ b/plugins/vibed/vibed.cpp @@ -29,6 +29,7 @@ #include "vibed.h" #include "Engine.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "ToolTip.h" #include "base64.h" diff --git a/plugins/vst_base/VstPlugin.cpp b/plugins/vst_base/VstPlugin.cpp index d21b230b9e6..8f99c4b9734 100644 --- a/plugins/vst_base/VstPlugin.cpp +++ b/plugins/vst_base/VstPlugin.cpp @@ -48,6 +48,7 @@ #include "ConfigManager.h" #include "GuiApplication.h" #include "MainWindow.h" +#include "Mixer.h" #include "Song.h" #include "templates.h" #include "FileDialog.h" diff --git a/plugins/vst_base/VstPlugin.h b/plugins/vst_base/VstPlugin.h index 1ce6b9b22cd..b77e9ff31bf 100644 --- a/plugins/vst_base/VstPlugin.h +++ b/plugins/vst_base/VstPlugin.h @@ -32,7 +32,6 @@ #include #include -#include "Mixer.h" #include "JournallingObject.h" #include "communication.h" diff --git a/plugins/watsyn/Watsyn.cpp b/plugins/watsyn/Watsyn.cpp index a1a0747a186..f180f0549ea 100644 --- a/plugins/watsyn/Watsyn.cpp +++ b/plugins/watsyn/Watsyn.cpp @@ -32,6 +32,7 @@ #include "ToolTip.h" #include "Song.h" #include "lmms_math.h" +#include "Mixer.h" #include "interpolation.h" #include "embed.cpp" diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 14080f3bec3..83ec52fee98 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -42,6 +42,7 @@ #include "StringPairDrag.h" #include "RemoteZynAddSubFx.h" #include "LocalZynAddSubFx.h" +#include "Mixer.h" #include "ControllerConnection.h" #include "embed.cpp" diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 20b7b7d094a..077e68f94b1 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -27,6 +27,7 @@ #include "AutomationPattern.h" #include "ControllerConnection.h" #include "lmms_math.h" +#include "Mixer.h" float AutomatableModel::s_copiedValue = 0; long AutomatableModel::s_periodCounter = 0; diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 9750a86136b..1ff07128c56 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -28,6 +28,7 @@ #include "AutomationPatternView.h" #include "AutomationTrack.h" +#include "Note.h" #include "ProjectJournal.h" #include "BBTrackContainer.h" #include "Song.h" diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 084e6d6f6fc..95fcc424aa9 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -26,6 +26,7 @@ #include "BufferManager.h" #include "FxMixer.h" +#include "Mixer.h" #include "MixerWorkerThread.h" #include "MixHelpers.h" #include "Song.h" diff --git a/src/core/InstrumentFunctions.cpp b/src/core/InstrumentFunctions.cpp index 1083a3052d0..fd169fc37e4 100644 --- a/src/core/InstrumentFunctions.cpp +++ b/src/core/InstrumentFunctions.cpp @@ -28,6 +28,7 @@ #include "embed.h" #include "Engine.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "NotePlayHandle.h" #include "PresetPreviewPlayHandle.h" diff --git a/src/core/InstrumentSoundShaping.cpp b/src/core/InstrumentSoundShaping.cpp index 1dc6c033733..b006fadcdb4 100644 --- a/src/core/InstrumentSoundShaping.cpp +++ b/src/core/InstrumentSoundShaping.cpp @@ -31,6 +31,7 @@ #include "EnvelopeAndLfoParameters.h" #include "Instrument.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "NotePlayHandle.h" diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index ff42a0da6bc..8789d27e906 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -71,12 +71,17 @@ Mixer::Mixer( bool renderOnly ) : m_numWorkers( QThread::idealThreadCount()-1 ), m_qualitySettings( qualitySettings::Mode_Draft ), m_masterGain( 1.0f ), + m_isProcessing( false ), m_audioDev( NULL ), m_oldAudioDev( NULL ), m_audioDevStartFailed( false ), m_globalMutex( QMutex::Recursive ), m_profiler(), - m_metronomeActive(false) + m_metronomeActive(false), + m_changesSignal( false ), + m_waitForMixer( true ), + m_changes( 0 ), + m_doChangesMutex( QMutex::Recursive ) { for( int i = 0; i < 2; ++i ) { @@ -151,6 +156,8 @@ Mixer::Mixer( bool renderOnly ) : Mixer::~Mixer() { + runChangesInModel(); + for( int w = 0; w < m_numWorkers; ++w ) { m_workers[w]->quit(); @@ -208,6 +215,8 @@ void Mixer::startProcessing( bool _needs_fifo ) } m_audioDev->startProcessing(); + + m_isProcessing = true; } @@ -215,6 +224,8 @@ void Mixer::startProcessing( bool _needs_fifo ) void Mixer::stopProcessing() { + m_isProcessing = false; + if( m_fifoWriter != NULL ) { m_fifoWriter->finish(); @@ -447,6 +458,8 @@ const surroundSampleFrame * Mixer::renderNextBuffer() emit nextAudioBuffer( m_readBuf ); + runChangesInModel(); + // and trigger LFOs EnvelopeAndLfoParameters::instances()->trigger(); Controller::triggerFrameCounter(); @@ -734,6 +747,58 @@ bool Mixer::hasNotePlayHandles() +void Mixer::requestChangeInModel() +{ + m_changesMutex.lock(); + m_changes++; + m_changesMutex.unlock(); + + m_doChangesMutex.lock(); + if ( m_isProcessing && m_waitForMixer ) + { + m_waitForMixer = false; + m_waitChangesMutex.lock(); + m_changesSignal = true; + m_changesRequestCondition.wait( &m_waitChangesMutex ); + m_waitChangesMutex.unlock(); + } +} + + + + +void Mixer::doneChangeInModel() +{ + m_changesMutex.lock(); + bool moreChanges = --m_changes; + m_changesMutex.unlock(); + + if( !moreChanges ) + { + m_waitForMixer = true; + m_changesSignal = false; + m_changesMixerCondition.wakeOne(); + } + m_doChangesMutex.unlock(); +} + + + + +void Mixer::runChangesInModel() +{ + if( m_changesSignal ) + { + m_waitChangesMutex.lock(); + m_changesRequestCondition.wakeOne(); + m_changesMixerCondition.wait( &m_waitChangesMutex ); + m_waitChangesMutex.unlock(); + } +} + + + + AudioDevice * Mixer::tryAudioDevices() { bool success_ful = false; diff --git a/src/core/NotePlayHandle.cpp b/src/core/NotePlayHandle.cpp index d027fef1a60..4cd377becbe 100644 --- a/src/core/NotePlayHandle.cpp +++ b/src/core/NotePlayHandle.cpp @@ -31,6 +31,7 @@ #include "Instrument.h" #include "MidiEvent.h" #include "MidiPort.h" +#include "Mixer.h" #include "Song.h" diff --git a/src/core/PresetPreviewPlayHandle.cpp b/src/core/PresetPreviewPlayHandle.cpp index 35b049ae0d3..96f1295837f 100644 --- a/src/core/PresetPreviewPlayHandle.cpp +++ b/src/core/PresetPreviewPlayHandle.cpp @@ -31,6 +31,7 @@ #include "Instrument.h" #include "InstrumentTrack.h" #include "MidiPort.h" +#include "Mixer.h" #include "DataFile.h" #include "NotePlayHandle.h" #include "PluginFactory.h" diff --git a/src/core/SampleBuffer.cpp b/src/core/SampleBuffer.cpp index 7040babcba0..12103c2776e 100644 --- a/src/core/SampleBuffer.cpp +++ b/src/core/SampleBuffer.cpp @@ -59,6 +59,7 @@ #include "endian_handling.h" #include "Engine.h" #include "interpolation.h" +#include "Mixer.h" #include "templates.h" #include "FileDialog.h" diff --git a/src/core/SamplePlayHandle.cpp b/src/core/SamplePlayHandle.cpp index 1bcf6691ef8..0d222583bba 100644 --- a/src/core/SamplePlayHandle.cpp +++ b/src/core/SamplePlayHandle.cpp @@ -27,6 +27,7 @@ #include "BBTrack.h" #include "Engine.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "Pattern.h" #include "SampleBuffer.h" #include "SampleTrack.h" diff --git a/src/core/SampleRecordHandle.cpp b/src/core/SampleRecordHandle.cpp index a16f5633008..a082b2f5d7a 100644 --- a/src/core/SampleRecordHandle.cpp +++ b/src/core/SampleRecordHandle.cpp @@ -27,6 +27,7 @@ #include "BBTrack.h" #include "Engine.h" #include "InstrumentTrack.h" +#include "Mixer.h" #include "Pattern.h" #include "SampleBuffer.h" #include "SampleTrack.h" diff --git a/src/core/audio/AudioAlsa.cpp b/src/core/audio/AudioAlsa.cpp index e903b436cb1..93ac1698328 100644 --- a/src/core/audio/AudioAlsa.cpp +++ b/src/core/audio/AudioAlsa.cpp @@ -34,6 +34,7 @@ #include "ConfigManager.h" #include "Engine.h" #include "LcdSpinBox.h" +#include "Mixer.h" #include "gui_templates.h" #include "templates.h" diff --git a/src/core/audio/AudioDevice.cpp b/src/core/audio/AudioDevice.cpp index 7acbdbbf1aa..690a2b0126a 100644 --- a/src/core/audio/AudioDevice.cpp +++ b/src/core/audio/AudioDevice.cpp @@ -27,6 +27,7 @@ #include "AudioDevice.h" #include "ConfigManager.h" #include "debug.h" +#include "Mixer.h" diff --git a/src/core/audio/AudioFileOgg.cpp b/src/core/audio/AudioFileOgg.cpp index 798418bf2ac..2df401becf4 100644 --- a/src/core/audio/AudioFileOgg.cpp +++ b/src/core/audio/AudioFileOgg.cpp @@ -34,6 +34,8 @@ #include #include +#include "Mixer.h" + AudioFileOgg::AudioFileOgg( const sample_rate_t _sample_rate, const ch_cnt_t _channels, diff --git a/src/core/audio/AudioFileWave.cpp b/src/core/audio/AudioFileWave.cpp index cbb0d6c5f0a..1c57088a3ee 100644 --- a/src/core/audio/AudioFileWave.cpp +++ b/src/core/audio/AudioFileWave.cpp @@ -25,6 +25,7 @@ #include "AudioFileWave.h" #include "endian_handling.h" +#include "Mixer.h" AudioFileWave::AudioFileWave( const sample_rate_t _sample_rate, diff --git a/src/core/audio/AudioJack.cpp b/src/core/audio/AudioJack.cpp index 137c5b44533..481ad6ba1c9 100644 --- a/src/core/audio/AudioJack.cpp +++ b/src/core/audio/AudioJack.cpp @@ -40,6 +40,7 @@ #include "LcdSpinBox.h" #include "AudioPort.h" #include "MainWindow.h" +#include "Mixer.h" diff --git a/src/core/audio/AudioOss.cpp b/src/core/audio/AudioOss.cpp index 4a92b3cf5e8..dbc46ee27ff 100644 --- a/src/core/audio/AudioOss.cpp +++ b/src/core/audio/AudioOss.cpp @@ -32,6 +32,7 @@ #include "endian_handling.h" #include "LcdSpinBox.h" +#include "Mixer.h" #include "Engine.h" #include "gui_templates.h" #include "templates.h" diff --git a/src/core/audio/AudioPort.cpp b/src/core/audio/AudioPort.cpp index 7d26bd367bc..5c17c1bbb75 100644 --- a/src/core/audio/AudioPort.cpp +++ b/src/core/audio/AudioPort.cpp @@ -27,6 +27,7 @@ #include "EffectChain.h" #include "FxMixer.h" #include "Engine.h" +#include "Mixer.h" #include "MixHelpers.h" #include "BufferManager.h" #include "ValueBuffer.h" diff --git a/src/core/audio/AudioPortAudio.cpp b/src/core/audio/AudioPortAudio.cpp index b2ddf1d9799..997939ec115 100644 --- a/src/core/audio/AudioPortAudio.cpp +++ b/src/core/audio/AudioPortAudio.cpp @@ -48,6 +48,7 @@ void AudioPortAudioSetupUtil::updateChannels() #include "templates.h" #include "ComboBox.h" #include "LcdSpinBox.h" +#include "Mixer.h" AudioPortAudio::AudioPortAudio( bool & _success_ful, Mixer * _mixer ) : diff --git a/src/core/audio/AudioPulseAudio.cpp b/src/core/audio/AudioPulseAudio.cpp index 4463bab8a6c..827d1f5e454 100644 --- a/src/core/audio/AudioPulseAudio.cpp +++ b/src/core/audio/AudioPulseAudio.cpp @@ -32,6 +32,7 @@ #include "endian_handling.h" #include "ConfigManager.h" #include "LcdSpinBox.h" +#include "Mixer.h" #include "gui_templates.h" #include "templates.h" #include "Engine.h" diff --git a/src/core/audio/AudioSdl.cpp b/src/core/audio/AudioSdl.cpp index 4ebd2c878b4..2f0ba0ec20d 100644 --- a/src/core/audio/AudioSdl.cpp +++ b/src/core/audio/AudioSdl.cpp @@ -33,6 +33,7 @@ #include "debug.h" #include "ConfigManager.h" #include "gui_templates.h" +#include "Mixer.h" #include "templates.h" diff --git a/src/core/audio/AudioSoundIo.cpp b/src/core/audio/AudioSoundIo.cpp index 89d21f0a91d..ed573becf9f 100644 --- a/src/core/audio/AudioSoundIo.cpp +++ b/src/core/audio/AudioSoundIo.cpp @@ -36,6 +36,7 @@ #include "templates.h" #include "ComboBox.h" #include "LcdSpinBox.h" +#include "Mixer.h" AudioSoundIo::AudioSoundIo( bool & outSuccessful, Mixer * _mixer ) : AudioDevice( tLimit( diff --git a/src/core/midi/MidiPort.cpp b/src/core/midi/MidiPort.cpp index 7185c6dc7e9..7a745e2e0e8 100644 --- a/src/core/midi/MidiPort.cpp +++ b/src/core/midi/MidiPort.cpp @@ -27,6 +27,7 @@ #include "MidiPort.h" #include "MidiClient.h" +#include "Note.h" #include "Song.h" diff --git a/src/gui/ControllerConnectionDialog.cpp b/src/gui/ControllerConnectionDialog.cpp index d4485519a2f..1a5faa1b7b9 100644 --- a/src/gui/ControllerConnectionDialog.cpp +++ b/src/gui/ControllerConnectionDialog.cpp @@ -34,6 +34,7 @@ #include "MidiController.h" #include "MidiClient.h" #include "MidiPortMenu.h" +#include "Mixer.h" #include "LcdSpinBox.h" #include "LedCheckbox.h" #include "ComboBox.h" diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index 828800ba4af..e4ebabbae92 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -46,6 +46,7 @@ #include "Instrument.h" #include "InstrumentTrack.h" #include "MainWindow.h" +#include "Mixer.h" #include "DataFile.h" #include "PluginFactory.h" #include "PresetPreviewPlayHandle.h" diff --git a/src/gui/FxMixerView.cpp b/src/gui/FxMixerView.cpp index 70eba5ba414..5ce2d2030df 100644 --- a/src/gui/FxMixerView.cpp +++ b/src/gui/FxMixerView.cpp @@ -43,6 +43,7 @@ #include "embed.h" #include "GuiApplication.h" #include "MainWindow.h" +#include "Mixer.h" #include "gui_templates.h" #include "InstrumentTrack.h" #include "Song.h" diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index b7ea656954b..46253c80802 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -47,6 +47,7 @@ #include "LcdSpinBox.h" #include "MainWindow.h" #include "MeterDialog.h" +#include "Mixer.h" #include "TextFloat.h" #include "TimeLineWidget.h" #include "ToolTip.h" diff --git a/src/gui/widgets/VisualizationWidget.cpp b/src/gui/widgets/VisualizationWidget.cpp index a99ec577dcf..042ae8bf007 100644 --- a/src/gui/widgets/VisualizationWidget.cpp +++ b/src/gui/widgets/VisualizationWidget.cpp @@ -30,6 +30,7 @@ #include "GuiApplication.h" #include "gui_templates.h" #include "MainWindow.h" +#include "Mixer.h" #include "embed.h" #include "Engine.h" #include "ToolTip.h" diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 17262fd9c27..4d5dadd8291 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -69,6 +69,7 @@ #include "MainWindow.h" #include "MidiClient.h" #include "MidiPortMenu.h" +#include "Mixer.h" #include "MixHelpers.h" #include "DataFile.h" #include "NotePlayHandle.h" @@ -154,11 +155,15 @@ int InstrumentTrack::baseNote() const InstrumentTrack::~InstrumentTrack() { + Engine::mixer()->requestChangeInModel(); + // kill all running notes and the iph silenceAllNotes( true ); // now we're save deleting the instrument if( m_instrument ) delete m_instrument; + + Engine::mixer()->doneChangeInModel(); } diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index ec9752b4e97..f089b5754c6 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -44,11 +44,13 @@ #include "StringPairDrag.h" #include "Knob.h" #include "MainWindow.h" +#include "Mixer.h" #include "GuiApplication.h" #include "EffectRackView.h" #include "TrackLabelButton.h" #include "ConfigManager.h" #include "panning_constants.h" +#include "volume.h" SampleTCO::SampleTCO( Track * _track ) :