2026-07-21 02:06:45 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include <juce_audio_processors/juce_audio_processors.h>
|
|
|
|
|
#include <juce_dsp/juce_dsp.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
2026-07-22 23:10:55 +02:00
|
|
|
#include <functional>
|
2026-07-21 02:06:45 +02:00
|
|
|
|
|
|
|
|
class SliceManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct Slice
|
|
|
|
|
{
|
|
|
|
|
int startSample;
|
|
|
|
|
int endSample;
|
2026-07-22 23:10:55 +02:00
|
|
|
int midiNote; // full MIDI note (60 = C4, 61 = C#4, ..., 83 = B5)
|
2026-07-21 02:06:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SliceManager();
|
|
|
|
|
|
|
|
|
|
void setSampleBuffer(juce::AudioBuffer<float>* buffer, double sampleRate);
|
|
|
|
|
void setSensitivity(float s);
|
|
|
|
|
void setBassGain(float g);
|
|
|
|
|
void setTrebleGain(float g);
|
|
|
|
|
|
|
|
|
|
void autoSlice();
|
|
|
|
|
void clearSlices();
|
|
|
|
|
void addSliceManual(int samplePos);
|
|
|
|
|
void removeSliceAt(int samplePos, int tolerance = 5);
|
|
|
|
|
void moveSlice(int fromSample, int toSample);
|
|
|
|
|
|
|
|
|
|
void trimStart(int sample);
|
|
|
|
|
void trimEnd(int sample);
|
|
|
|
|
|
2026-07-21 23:15:37 +02:00
|
|
|
std::vector<Slice> getSlices() const;
|
|
|
|
|
int getNumSlices() const;
|
|
|
|
|
Slice getSlice(int index) const;
|
|
|
|
|
|
|
|
|
|
void setSlices(const std::vector<Slice>& newSlices);
|
2026-07-21 02:06:45 +02:00
|
|
|
|
2026-07-22 23:10:55 +02:00
|
|
|
void setBeforeChangeCallback(std::function<void()> cb) { beforeChangeCallback = std::move(cb); }
|
|
|
|
|
|
2026-07-21 02:06:45 +02:00
|
|
|
int findSliceIndexForSample(int samplePos) const;
|
|
|
|
|
|
|
|
|
|
juce::AudioBuffer<float>* getMutableBuffer() { return sampleBuffer; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void sortSlices();
|
|
|
|
|
void assignMidiNotes();
|
|
|
|
|
|
2026-07-21 23:15:37 +02:00
|
|
|
mutable juce::CriticalSection mutex;
|
2026-07-21 02:06:45 +02:00
|
|
|
std::vector<Slice> slices;
|
|
|
|
|
juce::AudioBuffer<float>* sampleBuffer = nullptr;
|
|
|
|
|
double currentSampleRate = 44100.0;
|
|
|
|
|
|
|
|
|
|
float sensitivity = 0.5f;
|
|
|
|
|
float bassGain = 1.0f;
|
|
|
|
|
float trebleGain = 1.0f;
|
|
|
|
|
|
2026-07-22 23:10:55 +02:00
|
|
|
std::function<void()> beforeChangeCallback;
|
|
|
|
|
|
2026-07-21 02:06:45 +02:00
|
|
|
std::vector<float> computeEnvelope(const float* channelData, int numSamples);
|
|
|
|
|
std::vector<float> lowpassFilter(const std::vector<float>& input, float cutoffHz);
|
|
|
|
|
std::vector<float> highpassFilter(const std::vector<float>& input, float cutoffHz);
|
|
|
|
|
std::vector<float> detectOnsets(const std::vector<float>& envelope, float threshold);
|
|
|
|
|
};
|