Reduce plugin width by 102px and fix bottom panel layout to scale proportionally

This commit is contained in:
Armin 2026-07-22 23:10:55 +02:00
commit f035e89ba9
9 changed files with 305 additions and 106 deletions

View file

@ -8,6 +8,7 @@ MonoslicerProcessor::MonoslicerProcessor()
apvts(*this, nullptr, "Parameters", createParameterLayout())
{
formatManager.registerBasicFormats();
sliceManager.setBeforeChangeCallback([this]() { pushUndoState(); });
}
MonoslicerProcessor::~MonoslicerProcessor() {}
@ -444,6 +445,27 @@ void MonoslicerProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::M
}
if (currentActiveSlice.load() < 0)
currentPlaybackSample.store(-1);
float peakL = 0.0f;
float peakR = 0.0f;
if (buffer.getNumChannels() > 0)
{
auto* data = buffer.getReadPointer(0);
for (int i = 0; i < buffer.getNumSamples(); ++i)
peakL = juce::jmax(peakL, std::abs(data[i]));
}
if (buffer.getNumChannels() > 1)
{
auto* data = buffer.getReadPointer(1);
for (int i = 0; i < buffer.getNumSamples(); ++i)
peakR = juce::jmax(peakR, std::abs(data[i]));
}
else
{
peakR = peakL;
}
outputLevelL.store(peakL);
outputLevelR.store(peakR);
}
void MonoslicerProcessor::handleNoteOn(int noteNumber, float velocity)
@ -496,6 +518,7 @@ void MonoslicerProcessor::loadAudioFile(const juce::File& file)
std::unique_ptr<juce::AudioFormatReader> reader(formatManager.createReaderFor(file));
if (reader)
{
pushUndoState();
int numSamples = static_cast<int>(reader->lengthInSamples);
sampleBuffer.setSize(static_cast<int>(reader->numChannels), numSamples);
reader->read(&sampleBuffer, 0, numSamples, 0, true, true);
@ -509,6 +532,7 @@ void MonoslicerProcessor::loadAudioFile(const juce::File& file)
void MonoslicerProcessor::clearSample()
{
pushUndoState();
sampleBuffer.setSize(0, 0);
currentFile = juce::File{};
folderFiles.clear();
@ -517,6 +541,66 @@ void MonoslicerProcessor::clearSample()
selectedSlice.store(-1);
}
void MonoslicerProcessor::pushUndoState()
{
if (restoringFromUndo) return;
undoStack.push_back({ currentFile, sliceManager.getSlices() });
if (static_cast<int>(undoStack.size()) > maxUndoDepth)
undoStack.erase(undoStack.begin());
redoStack.clear();
}
void MonoslicerProcessor::undo()
{
if (undoStack.empty()) return;
redoStack.push_back({ currentFile, sliceManager.getSlices() });
auto state = std::move(undoStack.back());
undoStack.pop_back();
restoringFromUndo = true;
if (state.file.existsAsFile())
{
loadAudioFile(state.file);
sliceManager.setSlices(state.slices);
}
else
{
sampleBuffer.setSize(0, 0);
currentFile = juce::File{};
folderFiles.clear();
currentFileIndex = -1;
sliceManager.setSampleBuffer(&sampleBuffer, loadedSampleRate);
selectedSlice.store(-1);
}
restoringFromUndo = false;
}
void MonoslicerProcessor::redo()
{
if (redoStack.empty()) return;
undoStack.push_back({ currentFile, sliceManager.getSlices() });
auto state = std::move(redoStack.back());
redoStack.pop_back();
restoringFromUndo = true;
if (state.file.existsAsFile())
{
loadAudioFile(state.file);
sliceManager.setSlices(state.slices);
}
else
{
sampleBuffer.setSize(0, 0);
currentFile = juce::File{};
folderFiles.clear();
currentFileIndex = -1;
sliceManager.setSampleBuffer(&sampleBuffer, loadedSampleRate);
selectedSlice.store(-1);
}
restoringFromUndo = false;
}
bool MonoslicerProcessor::canUndo() const { return !undoStack.empty(); }
bool MonoslicerProcessor::canRedo() const { return !redoStack.empty(); }
void MonoslicerProcessor::refreshFolderList()
{
folderFiles.clear();
@ -678,6 +762,8 @@ void MonoslicerProcessor::stretchToBeats(int numBeats, float bpm)
{
if (sampleBuffer.getNumSamples() == 0 || bpm <= 0.0f || numBeats <= 0) return;
pushUndoState();
double sr = static_cast<double>(loadedSampleRate);
int currentLength = sampleBuffer.getNumSamples();
double currentDuration = static_cast<double>(currentLength) / sr;