Skip to content

Commit

Permalink
Add default audio file that plays once on standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshball committed Jan 7, 2025
1 parent 0901461 commit 5f237df
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
Binary file added Resources/audio/sosci.flac
Binary file not shown.
8 changes: 8 additions & 0 deletions Source/CommonPluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ CommonAudioProcessor::CommonAudioProcessor()
permanentEffects.push_back(thresholdEffect);
effects.push_back(volumeEffect);
effects.push_back(thresholdEffect);

wavParser.setLooping(false);
}

void CommonAudioProcessor::addAllParameters() {
Expand Down Expand Up @@ -187,6 +189,12 @@ double CommonAudioProcessor::getSampleRate() {
void CommonAudioProcessor::loadAudioFile(const juce::File& file) {
auto stream = std::make_unique<juce::FileInputStream>(file);
if (stream->openedOk()) {
loadAudioFile(std::move(stream));
}
}

void CommonAudioProcessor::loadAudioFile(std::unique_ptr<juce::InputStream> stream) {
if (stream != nullptr) {
juce::SpinLock::ScopedLockType lock(wavParserLock);
wavParser.parse(std::move(stream));

Expand Down
1 change: 1 addition & 0 deletions Source/CommonPluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CommonAudioProcessor : public juce::AudioProcessor, public SampleRateMana
void changeProgramName(int index, const juce::String& newName) override;
double getSampleRate() override;
void loadAudioFile(const juce::File& file);
void loadAudioFile(std::unique_ptr<juce::InputStream> stream);
void stopAudioFile();
void addAudioPlayerListener(AudioPlayerListener* listener);
void removeAudioPlayerListener(AudioPlayerListener* listener);
Expand Down
6 changes: 6 additions & 0 deletions Source/SosciPluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#include "audio/EffectParameter.h"

SosciAudioProcessor::SosciAudioProcessor() {
// demo audio file on standalone only
if (juce::JUCEApplicationBase::isStandaloneApp()) {
std::unique_ptr<juce::InputStream> stream = std::make_unique<juce::MemoryInputStream>(BinaryData::sosci_flac, BinaryData::sosci_flacSize, false);
loadAudioFile(std::move(stream));
}

addAllParameters();
}

Expand Down
5 changes: 2 additions & 3 deletions Source/components/AudioPlayerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ AudioPlayerComponent::AudioPlayerComponent(CommonAudioProcessor& processor) : au
playButton.setTooltip("Play audio file");
pauseButton.setTooltip("Pause audio file");

repeatButton.setToggleState(true, juce::dontSendNotification);

playButton.onClick = [this]() {
audioProcessor.wavParser.setPaused(false);
if (audioProcessor.wavParser.isInitialised()) {
Expand Down Expand Up @@ -73,6 +71,8 @@ AudioPlayerComponent::~AudioPlayerComponent() {

// must hold lock
void AudioPlayerComponent::setup() {
repeatButton.setToggleState(audioProcessor.wavParser.isLooping(), juce::dontSendNotification);

if (audioProcessor.wavParser.isInitialised()) {
slider.setVisible(true);
repeatButton.setVisible(true);
Expand All @@ -88,7 +88,6 @@ void AudioPlayerComponent::setup() {
};
playButton.setVisible(audioProcessor.wavParser.isPaused());
pauseButton.setVisible(!audioProcessor.wavParser.isPaused());
audioProcessor.wavParser.setLooping(repeatButton.getToggleState());
} else {
slider.setVisible(false);
repeatButton.setVisible(false);
Expand Down
3 changes: 3 additions & 0 deletions sosci.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
pluginManufacturerCode="Jhba" pluginCode="Sosc" pluginAUMainType="'aufx'">
<MAINGROUP id="j5Ge2T" name="sosci">
<GROUP id="{5ABCED88-0059-A7AF-9596-DBF91DDB0292}" name="Resources">
<GROUP id="{42A9EAA7-6D00-065D-0F8B-755E9B552173}" name="audio">
<FILE id="bv80Wk" name="sosci.flac" compile="0" resource="1" file="Resources/audio/sosci.flac"/>
</GROUP>
<GROUP id="{1C0FC3AA-01F6-8768-381C-200ED18AB5F2}" name="fonts">
<FILE id="R0Gs1t" name="FiraSans-Bold.ttf" compile="0" resource="1"
file="Resources/fonts/FiraSans-Bold.ttf"/>
Expand Down

0 comments on commit 5f237df

Please sign in to comment.