Skip to content

Commit

Permalink
Added sync button
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKauss committed Oct 7, 2023
1 parent 2d22249 commit 3e0419f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/SlicerT/SlicerT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void PhaseVocoder::getFrames(std::vector<float>& outData, int start, int frames)
if (m_originalBuffer.size() < 2048) { return; }
m_dataLock.lock();

if (m_scaleRatio == 1) { // directly copy original data
memcpy(outData.data(), m_originalBuffer.data() + start, frames*sizeof(float));
m_dataLock.unlock();
return;
}

int windowMargin = s_overSampling / 2; // numbers of windows before full quality
int startWindow = std::max(0.0f, (float)start / m_outStepSize - windowMargin);
int endWindow = std::min((float)m_numWindows, (float)(start + frames) / m_outStepSize + windowMargin);
Expand Down Expand Up @@ -287,6 +293,7 @@ SlicerT::SlicerT(InstrumentTrack* instrumentTrack)
, m_fadeOutFrames(400.0f, 0.0f, 8192.0f, 1.0f, this, tr("FadeOut"))
, m_originalBPM(1, 1, 999, this, tr("Original bpm"))
, m_sliceSnap(this, tr("Slice snap"))
, m_enableSync(true, this, tr("BPM sync"))
, m_originalSample()
, m_phaseVocoder()
, m_parentTrack(instrumentTrack)
Expand All @@ -306,7 +313,8 @@ void SlicerT::playNote(NotePlayHandle* handle, sampleFrame* workingBuffer)
if (m_originalSample.frames() < 2048) { return; }

// update current speed ratio, in case bpm changed
const float speedRatio = (float)m_originalBPM.value() / Engine::getSong()->getTempo();
float speedRatio = (float)m_originalBPM.value() / Engine::getSong()->getTempo();
if (!m_enableSync.value()) { speedRatio = 1; } // disable timeshift
m_phaseVocoder.setScaleRatio(speedRatio);

// current playback status
Expand Down Expand Up @@ -497,7 +505,7 @@ void SlicerT::writeToMidi(std::vector<Note>* outClip)
if (m_originalSample.frames() < 2048) { return; }

// update incase bpm changed
const float speedRatio = (float)m_originalBPM.value() / Engine::getSong()->getTempo();
float speedRatio = (float)m_originalBPM.value() / Engine::getSong()->getTempo();
m_phaseVocoder.setScaleRatio(speedRatio);

// calculate how many "beats" are in the sample
Expand Down
1 change: 1 addition & 0 deletions plugins/SlicerT/SlicerT.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public slots:
FloatModel m_fadeOutFrames;
IntModel m_originalBPM;
ComboBoxModel m_sliceSnap;
BoolModel m_enableSync;

// sample buffers
SampleBuffer m_originalSample;
Expand Down
6 changes: 6 additions & 0 deletions plugins/SlicerT/SlicerTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SlicerTUI::SlicerTUI(SlicerT* instrument, QWidget* parent)
, m_fadeOutKnob(this)
, m_bpmBox(3, "21pink", this)
, m_snapSetting(this, "Slice snap")
, m_syncToggle("Sync", this, "SyncToggle", LedCheckBox::LedColor::Green)
, m_resetButton(this, nullptr)
, m_midiExportButton(this, nullptr)
, m_wf(248, 128, instrument, this)
Expand All @@ -69,6 +70,11 @@ SlicerTUI::SlicerTUI(SlicerT* instrument, QWidget* parent)
m_snapSetting.setToolTip(tr("Set slice snapping for detection"));
m_snapSetting.setModel(&m_slicerTParent->m_sliceSnap);

// sync toggle
m_syncToggle.move(135, 187);
m_syncToggle.setToolTip(tr("Enable BPM sync"));
m_syncToggle.setModel(&m_slicerTParent->m_enableSync);

// bpm spin box
m_bpmBox.move(135, 203);
m_bpmBox.setToolTip(tr("Original sample BPM"));
Expand Down
2 changes: 2 additions & 0 deletions plugins/SlicerT/SlicerTUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "InstrumentView.h"
#include "Knob.h"
#include "LcdSpinBox.h"
#include "LedCheckBox.h"
#include "PixmapButton.h"
#include "WaveForm.h"

Expand Down Expand Up @@ -78,6 +79,7 @@ protected slots:
SlicerTKnob m_fadeOutKnob;
LcdSpinBox m_bpmBox;
ComboBox m_snapSetting;
LedCheckBox m_syncToggle;

// buttons
PixmapButton m_resetButton;
Expand Down

0 comments on commit 3e0419f

Please sign in to comment.