From a870186365b73a636f50451af55c142346887137 Mon Sep 17 00:00:00 2001 From: Shinya Nishimoto <67353276+nisshan-x@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:40:32 +0900 Subject: [PATCH 1/3] Fix slicer timing and capture lengths in non-quarter meters --- Makefile | 6 +++ dpf | 2 +- plugins/LiveCut/LiveCut.cpp | 3 +- plugins/LiveCut/lib/BBCutter.cpp | 10 ++++- tests/meter_regression.cpp | 63 ++++++++++++++++++++++++++++++++ tests/run-meter-tests.sh | 15 ++++++++ 6 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 tests/meter_regression.cpp create mode 100644 tests/run-meter-tests.sh diff --git a/Makefile b/Makefile index ad3d535..6bf794c 100644 --- a/Makefile +++ b/Makefile @@ -50,3 +50,9 @@ clean: # -------------------------------------------------------------- .PHONY: dgl plugins tests + +# Headless meter regression tests. +test-meter: + bash tests/run-meter-tests.sh "$(CURDIR)" + +.PHONY: test-meter diff --git a/dpf b/dpf index f581516..e82b7dd 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit f5815166356e85a5fe244f6024c2e401f04b10fa +Subproject commit e82b7dd3864e04ab365c1ad6c1fdd5d9a136644c diff --git a/plugins/LiveCut/LiveCut.cpp b/plugins/LiveCut/LiveCut.cpp index 684d816..c19fadb 100644 --- a/plugins/LiveCut/LiveCut.cpp +++ b/plugins/LiveCut/LiveCut.cpp @@ -1349,7 +1349,8 @@ class HyperCut : public Plugin const double bar = timePos.bbt.bar - 1; const double beat = timePos.bbt.beat - 1; const double beatFraction = timePos.bbt.ticksPerBeat > 0.0 ? timePos.bbt.tick / timePos.bbt.ticksPerBeat : 0.0; - ppqPos = (bar * beats_per_bar) + beat + beatFraction; + // BBT beats use the time-signature denominator; PPQ uses quarter notes. + ppqPos = ((bar * beats_per_bar) + beat + beatFraction) * (4.0 / beat_unit); freeRunPpq = ppqPos; } else diff --git a/plugins/LiveCut/lib/BBCutter.cpp b/plugins/LiveCut/lib/BBCutter.cpp index cc330c4..c2a67ea 100644 --- a/plugins/LiveCut/lib/BBCutter.cpp +++ b/plugins/LiveCut/lib/BBCutter.cpp @@ -1217,6 +1217,7 @@ void BBCutter::SetSampleRate(double v) void BBCutter::SetTimeInfos(double bpm,double num,double den,double srate) { + const bool meterChanged = numerator != num || denominator != den; bool changed = false; if(tempo != bpm) { @@ -1239,7 +1240,13 @@ void BBCutter::SetTimeInfos(double bpm,double num,double den,double srate) changed = true; } if(changed) + { + // SamplesPerBar must follow the current meter, not the constructor's 4/4. + beatsPerBar = 4.0 * numerator / denominator; UpdateRates(); + } + if(meterChanged) + ResetPhrase(); } void BBCutter::UpdateRates() @@ -1300,7 +1307,8 @@ void BBCutter::Unit(long bar, long sd) void BBCutter::SetPosition(long bar, long sd) { - const long delta = sd - (unitsdone % long(UnitsPerBar(subdiv,numerator,denominator))); + // sd already counts subdivisions of one whole bar, in every meter. + const long delta = sd - (unitsdone % subdiv); unitsinsideblock += delta; unitsdone += delta; Unit(bar,sd); diff --git a/tests/meter_regression.cpp b/tests/meter_regression.cpp new file mode 100644 index 0000000..8fce749 --- /dev/null +++ b/tests/meter_regression.cpp @@ -0,0 +1,63 @@ +#include "DistrhoPluginInternal.hpp" +#include "DistrhoVST3TimePosition.hpp" +#include "BBCutter.h" +#include +#include +#include +#include +#include +using namespace DISTRHO; +static int failures = 0; +static void check(bool ok, const char* text) { if(!ok) { std::fprintf(stderr,"FAIL: %s\n",text); ++failures; } } +static bool near(double a,double b) { return std::fabs(a-b)<1.e-7; } +static v3_process_context context(int n,int d,double q,double start) { + v3_process_context c={}; c.state=V3_PROCESS_CTX_PROJECT_TIME_VALID|V3_PROCESS_CTX_TIME_SIG_VALID|V3_PROCESS_CTX_BAR_POSITION_VALID|V3_PROCESS_CTX_TEMPO_VALID|V3_PROCESS_CTX_PLAYING; + c.time_sig_numerator=n;c.time_sig_denom=d;c.project_time_quarters=q;c.bar_position_quarters=start;c.bpm=190.;return c; +} +static void timingTests() { + TimePosition::BarBeatTick b; + fillVST3BarBeatTick(context(19,16,4.75,4.75),b);check(b.valid&&b.bar==2&&b.beat==1&&near(b.tick,0.),"19/16 bar boundary is 4.75 quarters"); + fillVST3BarBeatTick(context(19,16,4.875,4.75),b);check(b.beat==1&&near(b.tick,960.),"19/16 half of a sixteenth-note beat"); + fillVST3BarBeatTick(context(1,16,.25,.25),b);check(b.valid&&b.bar==2&&b.beat==1,"sub-quarter bar has no integer-division-by-zero"); + fillVST3BarBeatTick(context(17,32,2.125,2.125),b);check(b.valid&&b.bar==2&&b.beat==1,"17/32 fractional bar"); + fillVST3BarBeatTick(context(7,8,4.25,4.),b);check(b.beat==1&&near(b.tick,960.)&&near(b.barStartTick,15360.),"use host bar start following a meter change"); + fillVST3BarBeatTick(context(19,16,-.125,-4.75),b);check(b.valid&&b.bar==0&&b.beat==19&&near(b.tick,960.),"negative PPQ count-in"); + auto c=context(19,16,4.75,0.);c.state&=~V3_PROCESS_CTX_BAR_POSITION_VALID;fillVST3BarBeatTick(c,b);check(b.bar==2&&b.beat==1,"fallback without host bar-start field"); + c=context(19,0,0.,0.);fillVST3BarBeatTick(c,b);check(!b.valid,"reject invalid denominator"); + c=context(19,16,std::numeric_limits::quiet_NaN(),0.);fillVST3BarBeatTick(c,b);check(!b.valid,"reject non-finite PPQ"); + c=context(4,4,0.,0.);c.state=0;fillVST3BarBeatTick(c,b);check(!b.valid,"reject missing timing flags"); + LivePlayer player;BBCutter cutter(player);cutter.SetTimeInfos(190.,19.,16.,48000.);check(near(cutter.SamplesPerBar(),48000.*60./190.*4.75),"capture duration follows 19/16"); + cutter.SetTimeInfos(190.,7.,8.,48000.);check(near(cutter.SamplesPerBar(),48000.*60./190.*3.5),"capture duration follows meter changes"); +} +static void set(PluginExporter& p,const char* symbol,float value) { + for(uint32_t i=0;i& meters,int subdiv,bool loop,double sr=8000.,int frames=128) { + d_nextBufferSize=frames;d_nextSampleRate=sr;PluginExporter p(nullptr,nullptr,nullptr,nullptr);set(p,"livecut_cutproc",.5f);set(p,"livecut_subdiv",float(subdiv)); + const double bpm=190.;std::vector starts(1,0.);double longestBar=0.; + for(const auto& m:meters){double len=m.n*4./m.d;starts.push_back(starts.back()+len*8.);longestBar=std::max(longestBar,len*60./bpm);} + const double duration=starts.back()*60./bpm; + std::vector a(frames),b(frames),l(frames),r(frames);const float* in[]={a.data(),b.data()};float* out[]={l.data(),r.data()};long zero=0,longest=0;bool finite=true; + for(long f=0;f=starts[seg+1])++seg; + const Meter m=meters[seg];const double barLength=m.n*4./m.d;double local=q-starts[seg];if(loop)local=std::fmod(local,barLength*4.); + const double pos=starts[seg]+local;const double barStart=starts[seg]+std::floor(local/barLength)*barLength; + auto c=context(m.n,m.d,pos,barStart);TimePosition t;t.clear();t.playing=true;t.frame=f;t.bbt.beatsPerMinute=bpm;fillVST3BarBeatTick(c,t.bbt);p.setTimePosition(t); + for(int i=0;ilongestBar+2.*frames/sr+.02){std::fprintf(stderr,"FAIL: audio %d/%d subdiv-index=%d loop=%d longest silence=%.5fs bar=%.5fs\n",meters[0].n,meters[0].d,subdiv,loop,longestSilence,longestBar);++failures;} + return longestSilence; +} +int main(){timingTests();const Meter meters[]={{4,4},{3,4},{5,4},{6,8},{7,8},{5,8},{19,16},{1,16},{17,32}};int cases=0; + for(const auto& m:meters)for(int div=0;div<7;++div)for(bool loop:{false,true}){audioTest({m},div,loop);++cases;} + std::vector mixed={{4,4},{19,16},{7,8},{5,16},{17,32},{3,4},{4,4}};for(int div=0;div<7;++div){audioTest(mixed,div,false);++cases;} + // User-like sample rate and host buffer size, with repeated 19/16 bars. + audioTest({{19,16}},1,true,48000.,256);++cases; + std::printf("%s: timing checks + %d audio cases (EUCLID, 9 meters, 7 subdivisions, loops, changing meter).\n",failures?"FAILED":"PASS",cases); + return failures?1:0;} diff --git a/tests/run-meter-tests.sh b/tests/run-meter-tests.sh new file mode 100644 index 0000000..ed82301 --- /dev/null +++ b/tests/run-meter-tests.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail +source_dir="${1:?Usage: bash tests/run_tests.sh /path/to/patched/hypercut}" +test_dir="$(cd "$(dirname "$0")" && pwd)" +probe_dir="$(mktemp -d "${TMPDIR:-/tmp}/hypercut-meter-tests.XXXXXX")" +trap 'rm -rf "$probe_dir"' EXIT +"${CXX:-c++}" -std=c++14 -O2 -Wno-deprecated-declarations -DDISTRHO_PLUGIN_TARGET_VST3 \ + -I"$source_dir/plugins/LiveCut" -I"$source_dir/plugins/LiveCut/lib" \ + -I"$source_dir/dpf/distrho" -I"$source_dir/dpf/distrho/src" \ + "$test_dir/meter_regression.cpp" "$source_dir/plugins/LiveCut/LiveCut.cpp" \ + "$source_dir/plugins/LiveCut/lib/BBCutter.cpp" "$source_dir/plugins/LiveCut/lib/BitCrusher.cpp" \ + "$source_dir/plugins/LiveCut/lib/Comb.cpp" "$source_dir/plugins/LiveCut/lib/DelayLine.cpp" \ + "$source_dir/plugins/LiveCut/lib/FirstOrderLowpass.cpp" "$source_dir/dpf/distrho/src/DistrhoPlugin.cpp" \ + -o "$probe_dir/meter-regression" +"$probe_dir/meter-regression" From 0b455734e276805c8c97d0c9dbf524e42a6eccbd Mon Sep 17 00:00:00 2001 From: nisshan-x Date: Mon, 30 Nov 2026 01:11:54 +0900 Subject: [PATCH 2/3] Resync slicer immediately on meter changes and test all algorithms --- plugins/LiveCut/LiveCut.cpp | 2 +- plugins/LiveCut/lib/BBCutter.cpp | 18 ++- plugins/LiveCut/lib/BBCutter.h | 2 + tests/meter_regression.cpp | 209 +++++++++++++++++++++++++------ tests/run-meter-tests.sh | 2 +- 5 files changed, 192 insertions(+), 41 deletions(-) diff --git a/plugins/LiveCut/LiveCut.cpp b/plugins/LiveCut/LiveCut.cpp index c19fadb..4490cd8 100644 --- a/plugins/LiveCut/LiveCut.cpp +++ b/plugins/LiveCut/LiveCut.cpp @@ -1461,7 +1461,7 @@ class HyperCut : public Plugin } }; - if (positionInMeasure != oldpositionInMeasure) + if (positionInMeasure != oldpositionInMeasure || bbcutter.NeedsResync()) { oldpositionInMeasure = positionInMeasure; advance(oldmeasure, oldpositionInMeasure); diff --git a/plugins/LiveCut/lib/BBCutter.cpp b/plugins/LiveCut/lib/BBCutter.cpp index c2a67ea..d2fa5e3 100644 --- a/plugins/LiveCut/lib/BBCutter.cpp +++ b/plugins/LiveCut/lib/BBCutter.cpp @@ -431,6 +431,8 @@ void SQPusherCutProc::ChooseCuts(std::vector &cuts, if(fill==true) { + while(fillpos &cuts, cuts[i].amp = Math::randomfloat(minamp,maxamp); cuts[i].cents = Math::randomfloat(mindetune,maxdetune); } - unitsdone = long(double(subdiv)*beatsdone/4.0); + unitsinblock = std::max(1L, long(double(subdiv)*beatsdone/4.0 + 0.5)); if(unitsinblock>unitsleft) unitsinblock=unitsleft; //will automatically interrupt cutsequence before its end fillpos++; @@ -468,7 +470,7 @@ void SQPusherCutProc::ChooseCuts(std::vector &cuts, if(beatpos == 2) temp=1; - unitsinblock = long(double(temp*8.0)/double(subdiv)); + unitsinblock = std::max(1L, long(double(temp)*double(subdiv)/8.0 + 0.5)); if(unitsinblock>unitsleft) unitsinblock=unitsleft; //will automatically interrupt cutsequence before its end @@ -1132,6 +1134,7 @@ BBCutter::BBCutter(LivePlayer &player) , slicestart(0) , mincutquarters(0.0) , phraselimit(0) +, resyncPending(false) , strategy(&cutproc11) { procs.reserve(kNumCutProcs); @@ -1246,7 +1249,10 @@ void BBCutter::SetTimeInfos(double bpm,double num,double den,double srate) UpdateRates(); } if(meterChanged) + { ResetPhrase(); + resyncPending = true; + } } void BBCutter::UpdateRates() @@ -1307,6 +1313,14 @@ void BBCutter::Unit(long bar, long sd) void BBCutter::SetPosition(long bar, long sd) { + if(resyncPending) + { + resyncPending = false; + // Rejoin immediately, including buffers arriving after unit zero. + Phrase(bar, sd); + unitsdone = sd; + unitsinblock = unitsinsideblock = 0; + } // sd already counts subdivisions of one whole bar, in every meter. const long delta = sd - (unitsdone % subdiv); unitsinsideblock += delta; diff --git a/plugins/LiveCut/lib/BBCutter.h b/plugins/LiveCut/lib/BBCutter.h index 56df912..2b3b777 100644 --- a/plugins/LiveCut/lib/BBCutter.h +++ b/plugins/LiveCut/lib/BBCutter.h @@ -598,6 +598,7 @@ class BBCutter inline unsigned long GetGateMask() const { return gate.GetMask(); } // forget the current phrase: a fresh phrase starts on the next bar line void ResetPhrase() { totalunits = 0; unitsdone = 0; unitsinblock = 0; unitsinsideblock = 0; } + inline bool NeedsResync() const { return resyncPending; } // cap new phrases to this many bars (0 = no cap), used by fill mode void SetPhraseLimit(long bars) { phraselimit = bars; } // minimum cut length in quarter notes (0 = no limit). Shorter cuts are merged. @@ -656,6 +657,7 @@ class BBCutter GateCutProc gate; double mincutquarters; long phraselimit; + bool resyncPending; CutProc *strategy; std::vector procs; ListenerManager listenermanager; diff --git a/tests/meter_regression.cpp b/tests/meter_regression.cpp index 8fce749..7a05e5b 100644 --- a/tests/meter_regression.cpp +++ b/tests/meter_regression.cpp @@ -7,57 +7,192 @@ #include #include using namespace DISTRHO; + static int failures = 0; -static void check(bool ok, const char* text) { if(!ok) { std::fprintf(stderr,"FAIL: %s\n",text); ++failures; } } +static void check(bool ok, const char* text) { + if(!ok) { std::fprintf(stderr,"FAIL: %s\n",text); ++failures; } +} static bool near(double a,double b) { return std::fabs(a-b)<1.e-7; } static v3_process_context context(int n,int d,double q,double start) { - v3_process_context c={}; c.state=V3_PROCESS_CTX_PROJECT_TIME_VALID|V3_PROCESS_CTX_TIME_SIG_VALID|V3_PROCESS_CTX_BAR_POSITION_VALID|V3_PROCESS_CTX_TEMPO_VALID|V3_PROCESS_CTX_PLAYING; - c.time_sig_numerator=n;c.time_sig_denom=d;c.project_time_quarters=q;c.bar_position_quarters=start;c.bpm=190.;return c; + v3_process_context c={}; + c.state=V3_PROCESS_CTX_PROJECT_TIME_VALID|V3_PROCESS_CTX_TIME_SIG_VALID|V3_PROCESS_CTX_BAR_POSITION_VALID|V3_PROCESS_CTX_TEMPO_VALID|V3_PROCESS_CTX_PLAYING; + c.time_sig_numerator=n;c.time_sig_denom=d; + c.project_time_quarters=q;c.bar_position_quarters=start;c.bpm=190.; + return c; } static void timingTests() { TimePosition::BarBeatTick b; - fillVST3BarBeatTick(context(19,16,4.75,4.75),b);check(b.valid&&b.bar==2&&b.beat==1&&near(b.tick,0.),"19/16 bar boundary is 4.75 quarters"); - fillVST3BarBeatTick(context(19,16,4.875,4.75),b);check(b.beat==1&&near(b.tick,960.),"19/16 half of a sixteenth-note beat"); - fillVST3BarBeatTick(context(1,16,.25,.25),b);check(b.valid&&b.bar==2&&b.beat==1,"sub-quarter bar has no integer-division-by-zero"); - fillVST3BarBeatTick(context(17,32,2.125,2.125),b);check(b.valid&&b.bar==2&&b.beat==1,"17/32 fractional bar"); - fillVST3BarBeatTick(context(7,8,4.25,4.),b);check(b.beat==1&&near(b.tick,960.)&&near(b.barStartTick,15360.),"use host bar start following a meter change"); - fillVST3BarBeatTick(context(19,16,-.125,-4.75),b);check(b.valid&&b.bar==0&&b.beat==19&&near(b.tick,960.),"negative PPQ count-in"); - auto c=context(19,16,4.75,0.);c.state&=~V3_PROCESS_CTX_BAR_POSITION_VALID;fillVST3BarBeatTick(c,b);check(b.bar==2&&b.beat==1,"fallback without host bar-start field"); - c=context(19,0,0.,0.);fillVST3BarBeatTick(c,b);check(!b.valid,"reject invalid denominator"); - c=context(19,16,std::numeric_limits::quiet_NaN(),0.);fillVST3BarBeatTick(c,b);check(!b.valid,"reject non-finite PPQ"); - c=context(4,4,0.,0.);c.state=0;fillVST3BarBeatTick(c,b);check(!b.valid,"reject missing timing flags"); - LivePlayer player;BBCutter cutter(player);cutter.SetTimeInfos(190.,19.,16.,48000.);check(near(cutter.SamplesPerBar(),48000.*60./190.*4.75),"capture duration follows 19/16"); - cutter.SetTimeInfos(190.,7.,8.,48000.);check(near(cutter.SamplesPerBar(),48000.*60./190.*3.5),"capture duration follows meter changes"); + fillVST3BarBeatTick(context(19,16,4.75,4.75),b); + check(b.valid&&b.bar==2&&b.beat==1&&near(b.tick,0.),"19/16 bar boundary"); + fillVST3BarBeatTick(context(19,16,4.875,4.75),b); + check(b.beat==1&&near(b.tick,960.),"19/16 fractional beat"); + fillVST3BarBeatTick(context(1,16,.25,.25),b); + check(b.valid&&b.bar==2&&b.beat==1,"1/16 bar boundary"); + fillVST3BarBeatTick(context(17,32,2.125,2.125),b); + check(b.valid&&b.bar==2&&b.beat==1,"17/32 bar boundary"); + fillVST3BarBeatTick(context(7,8,4.25,4.),b); + check(b.beat==1&&near(b.tick,960.)&&near(b.barStartTick,15360.),"host bar start after meter change"); + fillVST3BarBeatTick(context(19,16,-.125,-4.75),b); + check(b.valid&&b.bar==0&&b.beat==19&&near(b.tick,960.),"negative count-in"); + auto c=context(19,16,4.75,0.); + c.state&=~V3_PROCESS_CTX_BAR_POSITION_VALID; + fillVST3BarBeatTick(c,b); + check(b.bar==2&&b.beat==1,"fallback without host bar start"); + c=context(19,0,0.,0.);fillVST3BarBeatTick(c,b); + check(!b.valid,"invalid denominator"); + c=context(19,16,std::numeric_limits::quiet_NaN(),0.); + fillVST3BarBeatTick(c,b);check(!b.valid,"non-finite position"); + c=context(4,4,0.,0.);c.state=0;fillVST3BarBeatTick(c,b); + check(!b.valid,"missing timing flags"); + LivePlayer player;BBCutter cutter(player); + cutter.SetTimeInfos(190.,19.,16.,48000.); + check(near(cutter.SamplesPerBar(),48000.*60./190.*4.75),"19/16 capture duration"); + cutter.SetTimeInfos(190.,7.,8.,48000.); + check(near(cutter.SamplesPerBar(),48000.*60./190.*3.5),"changed capture duration"); } static void set(PluginExporter& p,const char* symbol,float value) { - for(uint32_t i=0;i& meters,int subdiv,bool loop,double sr=8000.,int frames=128) { - d_nextBufferSize=frames;d_nextSampleRate=sr;PluginExporter p(nullptr,nullptr,nullptr,nullptr);set(p,"livecut_cutproc",.5f);set(p,"livecut_subdiv",float(subdiv)); - const double bpm=190.;std::vector starts(1,0.);double longestBar=0.; - for(const auto& m:meters){double len=m.n*4./m.d;starts.push_back(starts.back()+len*8.);longestBar=std::max(longestBar,len*60./bpm);} + +static double audioTest(const std::vector& meters,int subdiv,bool loop, + double sr=8000.,int frames=8,int algo=3,int warp=-1,int seed=42,int bars=8) { + d_nextBufferSize=frames;d_nextSampleRate=sr; + PluginExporter p(nullptr,nullptr,nullptr,nullptr); + const float values[]={0.f,1.f,2.f,.5f,1.5f,0.f}; + set(p,"livecut_cutproc",values[algo]); + set(p,"livecut_subdiv",float(subdiv)); + set(p,"livecut_seed",float(seed)); + set(p,"livecut_mix",1.f);set(p,"livecut_slicer",1.f); + set(p,"livecut_minamp",1.f);set(p,"livecut_maxamp",1.f); + set(p,"livecut_duty",1.f);set(p,"livecut_fillduty",1.f); + set(p,"livecut_minpitch",0.f);set(p,"livecut_maxpitch",0.f); + set(p,"livecut_fade",.01f); + for(const char* sym:{"livecut_crusher","livecut_comb","livecut_filter", + "livecut_reverb","livecut_chroma","livecut_transient","livecut_freeze", + "livecut_limiter","livecut_fillmode"})set(p,sym,0.f); + set(p,"livecut_gate",algo==5?1.f:0.f); + set(p,"livecut_gatemode",1.f); + set(p,"livecut_gatepat1",65535.f);set(p,"livecut_gatepat2",65535.f); + if(warp>=0){ + set(p,"livecut_straight",warp==0?1.f:0.f); + set(p,"livecut_regular",warp==1?1.f:0.f); + set(p,"livecut_ritard",warp==3?1.f:0.f); + set(p,"livecut_speed",.9f); + } + const double bpm=190.; + std::vector starts(1,0.); + double longestBar=0.; + for(const auto& m:meters){ + double len=m.n*4./m.d; + starts.push_back(starts.back()+len*bars); + longestBar=std::max(longestBar,len*60./bpm); + } const double duration=starts.back()*60./bpm; - std::vector a(frames),b(frames),l(frames),r(frames);const float* in[]={a.data(),b.data()};float* out[]={l.data(),r.data()};long zero=0,longest=0;bool finite=true; + const double warmup=meters[0].n*4./meters[0].d*60./bpm+2.*frames/sr; + const int divisions[]={6,8,12,16,18,24,32}; + // SQPusher rounds fractional-beat fills to its integer unit grid. + const double allowance=.008+2.*frames/sr+ + (algo==2?.6*longestBar/divisions[subdiv]:0.); + std::vector a(frames),b(frames),l(frames),r(frames); + const float* in[]={a.data(),b.data()}; + float* out[]={l.data(),r.data()}; + long zero=0,longest=0;bool finite=true; for(long f=0;f=starts[seg+1])++seg; - const Meter m=meters[seg];const double barLength=m.n*4./m.d;double local=q-starts[seg];if(loop)local=std::fmod(local,barLength*4.); - const double pos=starts[seg]+local;const double barStart=starts[seg]+std::floor(local/barLength)*barLength; - auto c=context(m.n,m.d,pos,barStart);TimePosition t;t.clear();t.playing=true;t.frame=f;t.bbt.beatsPerMinute=bpm;fillVST3BarBeatTick(c,t.bbt);p.setTimePosition(t); + double q=f/sr*bpm/60.; + size_t seg=0; + while(seg+1=starts[seg+1])++seg; + const Meter m=meters[seg]; + const double barLength=m.n*4./m.d; + double local=q-starts[seg]; + if(loop)local=std::fmod(local,barLength*4.); + const double pos=starts[seg]+local; + const double barStart=starts[seg]+std::floor(local/barLength)*barLength; + auto c=context(m.n,m.d,pos,barStart); + TimePosition t;t.clear();t.playing=true;t.frame=f; + t.bbt.beatsPerMinute=bpm; + fillVST3BarBeatTick(c,t.bbt);p.setTimePosition(t); for(int i=0;i=warmup&&std::fabs(l[i])+std::fabs(r[i])<1.e-8)++zero; + else zero=0; + longest=std::max(longest,zero); + } + } + check(finite,"audio has no NaN/Inf"); + double silence=longest/sr; + // Startup grace is never reapplied at meter changes. + if(silence>allowance){ + std::fprintf(stderr, + "FAIL: AUDIO algo=%d warp=%d subdiv=%d loop=%d seed=%d sr=%.0f buffer=%d silence=%.5fs allowed=%.5fs\n", + algo,warp,subdiv,loop,seed,sr,frames,silence,allowance); + ++failures; + } + return silence; +} +static void resyncTests() { + const int divs[]={6,8,12,16,18,24,32}; + for(int algo=0;algo<6;++algo) + for(int div:divs) + for(int sd=0;sd0&&player.GetBufferSize()>0,"playable cuts after resync"); + cutter.SetTimeInfos(190.,12.,16.,48000.); + check(!cutter.NeedsResync(),"unchanged meter preserves phrase"); + } +} +int main(int argc,char**) { + const std::vector user={ + {4,4},{4,4},{9,16},{12,16},{7,16},{9,16},{12,16}, + {9,16},{12,16},{7,16},{9,16},{12,16}}; + if(argc>1){ + audioTest(user,3,false,48000.,256,1,0,42,1); + return failures?1:0; + } + timingTests();resyncTests();int cases=0; + const Meter meters[]={ + {4,4},{3,4},{5,4},{6,8},{7,8},{5,8},{19,16},{1,16},{17,32}}; + const std::vector mixed={ + {4,4},{4,4},{19,16},{7,8},{5,16},{17,32},{3,4},{9,16},{12,16}}; + const char* names[]={"CutProc11","WarpCut","SQPusher","Euclid","Ratchet","Gate"}; + for(int algo=0;algo<6;++algo){ + const int before=failures; + for(const auto& m:meters)for(int div=0;div<7;++div) + for(bool loop:{false,true}){ + audioTest({m},div,loop,8000.,8,algo);++cases; + } + for(int div=0;div<7;++div)for(int buffer:{64,256})for(int seed:{1,42}){ + audioTest(user,div,false,48000.,buffer,algo,-1,seed,1);++cases; + audioTest(mixed,div,false,44100.,buffer,algo,-1,seed,1);++cases; + } + std::printf("%s: %s\n",failures==before?"PASS":"FAIL",names[algo]); + std::fflush(stdout); + } + for(int warp=0;warp<4;++warp){ + const int before=failures; + for(int div=0;div<7;++div)for(int buffer:{64,256})for(int seed:{1,42}){ + audioTest(user,div,false,48000.,buffer,1,warp,seed,1);++cases; + } + std::printf("%s: WarpCut mode %d\n",failures==before?"PASS":"FAIL",warp); + std::fflush(stdout); } - check(finite,"audio has no NaN/Inf");double longestSilence=longest/sr; - // A newly loaded slicer waits for a bar boundary; allow that startup plus two host buffers. - if(longestSilence>longestBar+2.*frames/sr+.02){std::fprintf(stderr,"FAIL: audio %d/%d subdiv-index=%d loop=%d longest silence=%.5fs bar=%.5fs\n",meters[0].n,meters[0].d,subdiv,loop,longestSilence,longestBar);++failures;} - return longestSilence; + std::printf( + "%s: timing + resync checks + %d audio cases; all 6 algorithms and 4 WarpCut modes.\n", + failures?"FAILED":"PASS",cases); + return failures?1:0; } -int main(){timingTests();const Meter meters[]={{4,4},{3,4},{5,4},{6,8},{7,8},{5,8},{19,16},{1,16},{17,32}};int cases=0; - for(const auto& m:meters)for(int div=0;div<7;++div)for(bool loop:{false,true}){audioTest({m},div,loop);++cases;} - std::vector mixed={{4,4},{19,16},{7,8},{5,16},{17,32},{3,4},{4,4}};for(int div=0;div<7;++div){audioTest(mixed,div,false);++cases;} - // User-like sample rate and host buffer size, with repeated 19/16 bars. - audioTest({{19,16}},1,true,48000.,256);++cases; - std::printf("%s: timing checks + %d audio cases (EUCLID, 9 meters, 7 subdivisions, loops, changing meter).\n",failures?"FAILED":"PASS",cases); - return failures?1:0;} diff --git a/tests/run-meter-tests.sh b/tests/run-meter-tests.sh index ed82301..46eef72 100644 --- a/tests/run-meter-tests.sh +++ b/tests/run-meter-tests.sh @@ -12,4 +12,4 @@ trap 'rm -rf "$probe_dir"' EXIT "$source_dir/plugins/LiveCut/lib/Comb.cpp" "$source_dir/plugins/LiveCut/lib/DelayLine.cpp" \ "$source_dir/plugins/LiveCut/lib/FirstOrderLowpass.cpp" "$source_dir/dpf/distrho/src/DistrhoPlugin.cpp" \ -o "$probe_dir/meter-regression" -"$probe_dir/meter-regression" +"$probe_dir/meter-regression" "${@:2}" From 359ba48e51d18b9f44f9d29e5963073fc955393d Mon Sep 17 00:00:00 2001 From: nisshan-x Date: Mon, 30 Nov 2026 01:41:20 +0900 Subject: [PATCH 3/3] Align SQPusher changes with upstream to resolve merge conflicts --- plugins/LiveCut/lib/BBCutter.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/LiveCut/lib/BBCutter.cpp b/plugins/LiveCut/lib/BBCutter.cpp index d2fa5e3..de45975 100644 --- a/plugins/LiveCut/lib/BBCutter.cpp +++ b/plugins/LiveCut/lib/BBCutter.cpp @@ -431,8 +431,12 @@ void SQPusherCutProc::ChooseCuts(std::vector &cuts, if(fill==true) { + // Two pre-baked slots in the original table (cs[6][3], cs[8][2]) are empty. Skip them: + // LivePlayer::OnBlock() ignores an empty list, which would keep replaying the previous cuts + // while the scheduler moved on — exactly the kind of stuck 16th-note pattern being fixed. while(fillpos &cuts, cuts[i].amp = Math::randomfloat(minamp,maxamp); cuts[i].cents = Math::randomfloat(mindetune,maxdetune); } + // Beats in the fill segment -> grid units. unitsdone is passed by value, so advancing it + // here has no effect on the caller; the block length is what tells BBCutter::Unit when to + // choose the next segment of the pre-baked fill. unitsinblock = std::max(1L, long(double(subdiv)*beatsdone/4.0 + 0.5)); if(unitsinblock>unitsleft) unitsinblock=unitsleft; //will automatically interrupt cutsequence before its end @@ -470,7 +477,11 @@ void SQPusherCutProc::ChooseCuts(std::vector &cuts, if(beatpos == 2) temp=1; - unitsinblock = std::max(1L, long(double(temp)*double(subdiv)/8.0 + 0.5)); + // temp quavers (or temp*2 semiquavers) last temp*0.5 beats, i.e. temp*subdiv/8 grid units. + // The old temp*8/subdiv was inverted: at subdiv 8 it happened to be right, but above 8 it + // shrank towards 0 (always 0 at 32), so BBCutter::Block re-armed the player on every unit + // and only the first 16th of each freshly chosen pattern was ever heard. + unitsinblock = std::max(1L, long(double(temp*subdiv)/8.0 + 0.5)); if(unitsinblock>unitsleft) unitsinblock=unitsleft; //will automatically interrupt cutsequence before its end