Add drag and drop opening of files, and allow for 3 channel audio files

pre-release-3
James H Ball 2025-01-07 12:17:38 +00:00
rodzic dd3d051793
commit c31f15afb4
4 zmienionych plików z 34 dodań i 8 usunięć

Wyświetl plik

@ -35,3 +35,24 @@ void SosciPluginEditor::resized() {
}
visualiser.setBounds(area);
}
bool SosciPluginEditor::isInterestedInFileDrag(const juce::StringArray& files) {
if (files.size() != 1) {
return false;
}
juce::File file(files[0]);
return
file.hasFileExtension("wav") ||
file.hasFileExtension("mp3") ||
file.hasFileExtension("aiff") ||
file.hasFileExtension("flac") ||
file.hasFileExtension("ogg");
}
void SosciPluginEditor::filesDropped(const juce::StringArray& files, int x, int y) {
if (files.size() != 1) {
return;
}
juce::File file(files[0]);
audioProcessor.loadAudioFile(file);
}

Wyświetl plik

@ -9,13 +9,15 @@
#include "components/SosciMainMenuBarModel.h"
#include "components/SvgButton.h"
class SosciPluginEditor : public CommonPluginEditor {
class SosciPluginEditor : public CommonPluginEditor, public juce::FileDragAndDropTarget {
public:
SosciPluginEditor(SosciAudioProcessor&);
~SosciPluginEditor() override;
void paint(juce::Graphics&) override;
void resized() override;
bool isInterestedInFileDrag(const juce::StringArray& files) override;
void filesDropped(const juce::StringArray& files, int x, int y) override;
private:
SosciAudioProcessor& audioProcessor;

Wyświetl plik

@ -28,7 +28,6 @@ void SosciAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::M
if (readingFromWav) {
point = wavParser->getSample();
point.z = 1.0f;
} else {
float x = input.getNumChannels() > 0 ? inputArray[0][sample] : 0.0f;
float y = input.getNumChannels() > 1 ? inputArray[1][sample] : 0.0f;
@ -47,13 +46,13 @@ void SosciAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::M
point = { x, y, brightness };
}
// no negative brightness
point.z = juce::jlimit(0.0, 1.0, point.z);
for (auto& effect : permanentEffects) {
point = effect->apply(sample, point);
}
// no negative brightness
point.z = juce::jmax(0.0, juce::jmin(1.0, point.z));
// this is the point that the visualiser will draw
threadManager.write(point);

Wyświetl plik

@ -12,7 +12,7 @@ WavParser::WavParser(CommonAudioProcessor& p, std::unique_ptr<juce::InputStream>
afSource = new juce::AudioFormatReaderSource(reader, true);
totalSamples = afSource->getTotalLength();
afSource->setLooping(true);
source = std::make_unique<juce::ResamplingAudioSource>(afSource, true);
source = std::make_unique<juce::ResamplingAudioSource>(afSource, true, reader->numChannels);
fileSampleRate = reader->sampleRate;
audioBuffer.setSize(reader->numChannels, 1);
setSampleRate(audioProcessor.currentSampleRate);
@ -52,9 +52,13 @@ OsciPoint WavParser::getSample() {
}
if (audioBuffer.getNumChannels() == 1) {
return OsciPoint(audioBuffer.getSample(0, 0), audioBuffer.getSample(0, 0));
return OsciPoint(audioBuffer.getSample(0, 0), audioBuffer.getSample(0, 0), 1.0);
} else if (audioBuffer.getNumChannels() == 2) {
return OsciPoint(audioBuffer.getSample(0, 0), audioBuffer.getSample(1, 0), 1.0);
} else if (audioBuffer.getNumChannels() >= 3) {
return OsciPoint(audioBuffer.getSample(0, 0), audioBuffer.getSample(1, 0), audioBuffer.getSample(2, 0));
} else {
return OsciPoint(audioBuffer.getSample(0, 0), audioBuffer.getSample(1, 0));
return OsciPoint();
}
}