Skip to content

Commit

Permalink
a bunch of scheduling changes: queue all non-audio-thread notes to fi…
Browse files Browse the repository at this point in the history
…x thread safety issues, timestamp all control updates (BespokeSynth#904)

* add timestamps to all control updates for sample-accurate actions

this allows modulators to trigger controls with sample-accurate timing, rather than just grossly quantizing to the most recent rendering block, as it did before

* queue all non-audio thread notes

this step eliminates randomly-occurring stuck notes in a stress test case that I had, and gives good peace of mind to know that all note events are happening via a single thread. anything that could trigger notes via the UI (mouse clicks, adjusting dropdowns with the keyboard, etc) will now queue up the notes to occur on the audio thread

* fix issue with script-driven notes playing later than desired

* add bool to NextBufferTime() to specify if lookahead should be included
  • Loading branch information
awwbees authored Sep 27, 2022
1 parent 4626fd9 commit 2b40316
Show file tree
Hide file tree
Showing 445 changed files with 1,704 additions and 1,518 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "libs/link"]
path = libs/link
url = https://github.com/Ableton/link.git
[submodule "libs/readerwriterqueue"]
path = libs/readerwriterqueue
url = https://github.com/cameron314/readerwriterqueue.git
4 changes: 2 additions & 2 deletions Source/ADSRDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class ADSRDisplay : public IUIControl
}

//IUIControl
void SetFromMidiCC(float slider, bool setViaModulator = false) override {}
void SetValue(float value) override {}
void SetFromMidiCC(float slider, double time, bool setViaModulator) override {}
void SetValue(float value, double time) override {}
bool CanBeTargetedBy(PatchCableSource* source) const override { return false; }
void SaveState(FileStreamOut& out) override;
void LoadState(FileStreamIn& in, bool shouldSetValue = true) override;
Expand Down
4 changes: 2 additions & 2 deletions Source/AbletonLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ void AbletonLink::DrawModule()
DrawTextNormal("peers: " + ofToString(mNumPeers) + "\ntempo: " + ofToString(mTempo) + "\nbeat: " + ofToString(mLastReceivedBeat), 3, 40);
}

void AbletonLink::CheckboxUpdated(Checkbox* checkbox)
void AbletonLink::CheckboxUpdated(Checkbox* checkbox, double time)
{
}

void AbletonLink::FloatSliderUpdated(FloatSlider* slider, float oldVal)
void AbletonLink::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
}
4 changes: 2 additions & 2 deletions Source/AbletonLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class AbletonLink : public IDrawableModule, public IAudioPoller, public IFloatSl

void SetEnabled(bool enabled) override { mEnabled = enabled; }

void CheckboxUpdated(Checkbox* checkbox) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override;
void CheckboxUpdated(Checkbox* checkbox, double time) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override;

private:
//IDrawableModule
Expand Down
2 changes: 1 addition & 1 deletion Source/Amplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Amplifier : public IAudioProcessor, public IDrawableModule, public IFloatS
void SetEnabled(bool enabled) override { mEnabled = enabled; }

//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override {}
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override {}

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
10 changes: 5 additions & 5 deletions Source/Arpeggiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ bool Arpeggiator::MouseMoved(float x, float y)
return false;
}

void Arpeggiator::CheckboxUpdated(Checkbox* checkbox)
void Arpeggiator::CheckboxUpdated(Checkbox* checkbox, double time)
{
if (checkbox == mEnabledCheckbox)
{
mChordMutex.lock();
mChord.clear();
mChordMutex.unlock();

mNoteOutput.Flush(gTime);
mNoteOutput.Flush(time);
}
}

Expand Down Expand Up @@ -276,17 +276,17 @@ void Arpeggiator::UpdateInterval()
transportListenerInfo->mInterval = mInterval;
}

void Arpeggiator::ButtonClicked(ClickButton* button)
void Arpeggiator::ButtonClicked(ClickButton* button, double time)
{
}

void Arpeggiator::DropdownUpdated(DropdownList* list, int oldVal)
void Arpeggiator::DropdownUpdated(DropdownList* list, int oldVal, double time)
{
if (list == mIntervalSelector)
UpdateInterval();
}

void Arpeggiator::IntSliderUpdated(IntSlider* slider, int oldVal)
void Arpeggiator::IntSliderUpdated(IntSlider* slider, int oldVal, double time)
{
if (slider == mArpStepSlider)
{
Expand Down
10 changes: 5 additions & 5 deletions Source/Arpeggiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ class Arpeggiator : public NoteEffectBase, public IDrawableModule, public ITimeL
void OnScaleChanged() override;

//IButtonListener
void ButtonClicked(ClickButton* button) override;
void ButtonClicked(ClickButton* button, double time) override;

void CheckboxUpdated(Checkbox* checkbox) override;
void CheckboxUpdated(Checkbox* checkbox, double time) override;
//IDropdownListener
void DropdownUpdated(DropdownList* list, int oldVal) override;
void DropdownUpdated(DropdownList* list, int oldVal, double time) override;
//IIntSliderListener
void IntSliderUpdated(IntSlider* slider, int oldVal) override;
void IntSliderUpdated(IntSlider* slider, int oldVal, double time) override;
//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override {}
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override {}

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
6 changes: 3 additions & 3 deletions Source/AudioLevelToCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void AudioLevelToCV::CreateUIControls()
mReleaseSlider->SetMode(FloatSlider::kSquare);

//update mAttackFactor and mReleaseFactor
FloatSliderUpdated(mAttackSlider, 0);
FloatSliderUpdated(mReleaseSlider, 0);
FloatSliderUpdated(mAttackSlider, 0, gTime);
FloatSliderUpdated(mReleaseSlider, 0, gTime);

GetPatchCableSource()->SetEnabled(false);

Expand Down Expand Up @@ -129,7 +129,7 @@ float AudioLevelToCV::Value(int samplesIn)
return ofMap(mModulationBuffer[samplesIn], 0, 1, GetMin(), GetMax(), K(clamp));
}

void AudioLevelToCV::FloatSliderUpdated(FloatSlider* slider, float oldVal)
void AudioLevelToCV::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
if (slider == mAttackSlider)
mAttackFactor = powf(.01f, 1.0f / (mAttack * gSampleRateMs));
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioLevelToCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AudioLevelToCV : public IAudioProcessor, public IDrawableModule, public IF
bool Active() const override { return mEnabled; }

//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override;

void SaveLayout(ofxJSONElement& moduleInfo) override;
void LoadLayout(const ofxJSONElement& moduleInfo) override;
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AudioMeter : public IAudioProcessor, public IDrawableModule, public IFloat
void SetEnabled(bool enabled) override { mEnabled = enabled; }

//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override {}
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override {}

void LoadLayout(const ofxJSONElement& moduleInfo) override;
void SetUpFromSaveData() override;
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void AudioRouter::GetModuleDimensions(float& width, float& height)
height = 8 + h;
}

void AudioRouter::RadioButtonUpdated(RadioButton* radio, int oldVal)
void AudioRouter::RadioButtonUpdated(RadioButton* radio, int oldVal, double time)
{
if (radio == mRouteSelector)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AudioRouter : public IAudioProcessor, public IDrawableModule, public IRadi
void PostRepatch(PatchCableSource* cableSource, bool fromUserClick) override;

//IRadioButtonListener
void RadioButtonUpdated(RadioButton* button, int oldVal) override;
void RadioButtonUpdated(RadioButton* button, int oldVal, double time) override;

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void AudioSend::DrawModule()
mCrossfadeCheckbox->Draw();
}

void AudioSend::FloatSliderUpdated(FloatSlider* slider, float oldVal)
void AudioSend::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Source/AudioSend.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AudioSend : public IAudioProcessor, public IDrawableModule, public IFloatS
void SetEnabled(bool enabled) override { mEnabled = enabled; }
int GetNumTargets() override { return 2; }

void FloatSliderUpdated(FloatSlider* slider, float oldVal) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override;

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioToCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AudioToCV : public IAudioProcessor, public IDrawableModule, public IFloatS
bool Active() const override { return mEnabled; }

//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override {}
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override {}

void SaveLayout(ofxJSONElement& moduleInfo) override;
void LoadLayout(const ofxJSONElement& moduleInfo) override;
Expand Down
4 changes: 2 additions & 2 deletions Source/AudioToPulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void AudioToPulse::CreateUIControls()
mReleaseSlider->SetMode(FloatSlider::kSquare);

//update mReleaseFactor
FloatSliderUpdated(mReleaseSlider, 0);
FloatSliderUpdated(mReleaseSlider, 0, gTime);

GetPatchCableSource()->SetConnectionType(kConnectionType_Pulse);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ void AudioToPulse::Process(double time)
GetBuffer()->Reset();
}

void AudioToPulse::FloatSliderUpdated(FloatSlider* slider, float oldVal)
void AudioToPulse::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
if (slider == mReleaseSlider)
mReleaseFactor = powf(.01f, 1.0f / (mRelease * gSampleRateMs));
Expand Down
2 changes: 1 addition & 1 deletion Source/AudioToPulse.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AudioToPulse : public IDrawableModule, public IPulseSource, public IAudioP

void Process(double time) override;

void FloatSliderUpdated(FloatSlider* slider, float oldVal) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override;

void SaveLayout(ofxJSONElement& moduleInfo) override;
void LoadLayout(const ofxJSONElement& moduleInfo) override;
Expand Down
2 changes: 1 addition & 1 deletion Source/Autotalent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ void Autotalent::DrawModule()
ofLine(x, 90, x, 90 - ofMap(mConfidence, 0, 1, 0, 50));
}

void Autotalent::ButtonClicked(ClickButton* button)
void Autotalent::ButtonClicked(ClickButton* button, double time)
{
if (button == mSetFromScaleButton)
{
Expand Down
10 changes: 5 additions & 5 deletions Source/Autotalent.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class Autotalent : public IAudioProcessor, public IIntSliderListener, public IFl

void SetEnabled(bool enabled) override { mEnabled = enabled; }

void CheckboxUpdated(Checkbox* checkbox) override {}
void CheckboxUpdated(Checkbox* checkbox, double time) override {}
//IIntSliderListener
void IntSliderUpdated(IntSlider* slider, int oldVal) override {}
void IntSliderUpdated(IntSlider* slider, int oldVal, double time) override {}
//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override {}
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override {}
//IRadioButtonListener
void RadioButtonUpdated(RadioButton* radio, int oldVal) override {}
void RadioButtonUpdated(RadioButton* radio, int oldVal, double time) override {}
//IButtonListener
void ButtonClicked(ClickButton* button) override;
void ButtonClicked(ClickButton* button, double time) override;

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
6 changes: 3 additions & 3 deletions Source/BandVocoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void BandVocoder::CalcFilters()
}
}

void BandVocoder::CheckboxUpdated(Checkbox* checkbox)
void BandVocoder::CheckboxUpdated(Checkbox* checkbox, double time)
{
if (checkbox == mEnabledCheckbox)
{
Expand All @@ -265,15 +265,15 @@ void BandVocoder::CheckboxUpdated(Checkbox* checkbox)
}
}

void BandVocoder::IntSliderUpdated(IntSlider* slider, int oldVal)
void BandVocoder::IntSliderUpdated(IntSlider* slider, int oldVal, double time)
{
if (slider == mNumBandsSlider)
{
CalcFilters();
}
}

void BandVocoder::FloatSliderUpdated(FloatSlider* slider, float oldVal)
void BandVocoder::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
if (slider == mFBaseSlider || slider == mFRangeSlider || slider == mQSlider || slider == mSpacingStyleSlider)
{
Expand Down
6 changes: 3 additions & 3 deletions Source/BandVocoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class BandVocoder : public IAudioProcessor, public IDrawableModule, public IFloa

void SetEnabled(bool enabled) override { mEnabled = enabled; }

void CheckboxUpdated(Checkbox* checkbox) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override;
void IntSliderUpdated(IntSlider* slider, int oldVal) override;
void CheckboxUpdated(Checkbox* checkbox, double time) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override;
void IntSliderUpdated(IntSlider* slider, int oldVal, double time) override;

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
10 changes: 5 additions & 5 deletions Source/BeatBloks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,15 @@ void BeatBloks::DropdownClicked(DropdownList* list)
{
}

void BeatBloks::DropdownUpdated(DropdownList* list, int oldVal)
void BeatBloks::DropdownUpdated(DropdownList* list, int oldVal, double time)
{
}

void BeatBloks::UpdateSample()
{
}

void BeatBloks::ButtonClicked(ClickButton* button)
void BeatBloks::ButtonClicked(ClickButton* button, double time)
{
if (button == mWriteButton)
{
Expand Down Expand Up @@ -916,7 +916,7 @@ BeatBloks::Blok* BeatBloks::RemoveBlokAt(int x)
return nullptr;
}

void BeatBloks::CheckboxUpdated(Checkbox* checkbox)
void BeatBloks::CheckboxUpdated(Checkbox* checkbox, double time)
{
if (checkbox == mPlayCheckbox)
{
Expand All @@ -936,7 +936,7 @@ void BeatBloks::GetModuleDimensions(float& width, float& height)
height = mRemixBufferY + mBufferH + 45;
}

void BeatBloks::FloatSliderUpdated(FloatSlider* slider, float oldVal)
void BeatBloks::FloatSliderUpdated(FloatSlider* slider, float oldVal, double time)
{
if (slider == mClipStartSlider)
{
Expand Down Expand Up @@ -966,7 +966,7 @@ void BeatBloks::FloatSliderUpdated(FloatSlider* slider, float oldVal)
}
}

void BeatBloks::IntSliderUpdated(IntSlider* slider, int oldVal)
void BeatBloks::IntSliderUpdated(IntSlider* slider, int oldVal, double time)
{
}

Expand Down
10 changes: 5 additions & 5 deletions Source/BeatBloks.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ class BeatBloks : public IAudioSource, public IDrawableModule, public IFloatSlid
bool MouseMoved(float x, float y) override;


void CheckboxUpdated(Checkbox* checkbox) override;
void CheckboxUpdated(Checkbox* checkbox, double time) override;
//IFloatSliderListener
void FloatSliderUpdated(FloatSlider* slider, float oldVal) override;
void FloatSliderUpdated(FloatSlider* slider, float oldVal, double time) override;
//IFloatSliderListener
void IntSliderUpdated(IntSlider* slider, int oldVal) override;
void IntSliderUpdated(IntSlider* slider, int oldVal, double time) override;
//IDropdownListener
void DropdownClicked(DropdownList* list) override;
void DropdownUpdated(DropdownList* list, int oldVal) override;
void DropdownUpdated(DropdownList* list, int oldVal, double time) override;
//IButtonListener
void ButtonClicked(ClickButton* button) override;
void ButtonClicked(ClickButton* button, double time) override;

virtual void LoadLayout(const ofxJSONElement& moduleInfo) override;
virtual void SetUpFromSaveData() override;
Expand Down
Loading

0 comments on commit 2b40316

Please sign in to comment.