Last active
March 22, 2021 07:14
-
-
Save MonteLogic/788578e9f4a0bd39960a3f1e67237c56 to your computer and use it in GitHub Desktop.
Why is 'statement three' outputting to the console but 'statement four' is not?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This a gist about an audio plugin that plays a single audio player. | |
On line 83 of MainComponent.cpp I am getting the error: C2280 'LoadSaveXmlFile::LoadSaveXmlFile(void)': attempting to reference a deleted function | |
How do I undo a deleted function error and make Statement four output to the console? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PATHS> | |
<PATH ID="01" Locale="C:\Users\foo\Desktop\AudioFileOne.mp3" /> | |
<PATH ID="02" Locale="C:\Users\foo\Desktop\AudioFileTwo.mp3" /> | |
</PATHS> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
loadSaveXml.h | |
Created: 20 Mar 2021 7:47:59am | |
Author: dc | |
============================================================================== | |
*/ | |
#pragma once | |
#include "MainComponent.h" | |
#include "../JuceLibraryCode/JuceHeader.h" | |
//============================================================================== | |
class LoadSaveXmlFile : public juce::Component, | |
public juce::XmlElement | |
{ | |
public: | |
// How come this isn't being displayed in the console? | |
void loadData() { | |
auto dir = juce::File::getCurrentWorkingDirectory(); | |
auto myXmlFile = dir.getChildFile("Resources").getChildFile("FilePaths.xml"); | |
if (myXmlFile.exists()) | |
{ | |
parsedXML = juce::XmlDocument::parse(myXmlFile); | |
logToConsole(); | |
} | |
} | |
private: | |
std::unique_ptr<juce::XmlElement> parsedXML; | |
void logToConsole() { | |
Logger::outputDebugString("Statement Four"); | |
} | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
This file was auto-generated! | |
It contains the basic startup code for a JUCE application. | |
============================================================================== | |
*/ | |
#include "../JuceLibraryCode/JuceHeader.h" | |
#include "MainComponent.h" | |
#include "loadSaveXml.h" | |
//============================================================================== | |
class simpleAudioPlayerApplication : public JUCEApplication | |
{ | |
public: | |
//============================================================================== | |
simpleAudioPlayerApplication() {} | |
const String getApplicationName() override { return ProjectInfo::projectName; } | |
const String getApplicationVersion() override { return ProjectInfo::versionString; } | |
bool moreThanOneInstanceAllowed() override { return true; } | |
//============================================================================== | |
void initialise (const String& commandLine) override | |
{ | |
// This method is where you should put your application's initialisation code.. | |
mainWindow.reset (new MainWindow (getApplicationName())); | |
} | |
void shutdown() override | |
{ | |
// Add your application's shutdown code here.. | |
mainWindow = nullptr; // (deletes our window) | |
} | |
//============================================================================== | |
void systemRequestedQuit() override | |
{ | |
// This is called when the app is being asked to quit: you can ignore this | |
// request and let the app carry on running, or call quit() to allow the app to close. | |
quit(); | |
} | |
void anotherInstanceStarted (const String& commandLine) override | |
{ | |
// When another instance of the app is launched while this one is running, | |
// this method is invoked, and the commandLine parameter tells you what | |
// the other instance's command-line arguments were. | |
} | |
//============================================================================== | |
/* | |
This class implements the desktop window that contains an instance of | |
our MainComponent class. | |
*/ | |
class MainWindow : public DocumentWindow | |
{ | |
public: | |
MainWindow (String name) : DocumentWindow (name, | |
Desktop::getInstance().getDefaultLookAndFeel() | |
.findColour (ResizableWindow::backgroundColourId), | |
DocumentWindow::allButtons) | |
{ | |
setUsingNativeTitleBar (true); | |
setContentOwned (new MainComponent(), true); | |
setResizable (true, true); | |
centreWithSize (getWidth(), getHeight()); | |
setVisible (true); | |
} | |
void closeButtonPressed() override | |
{ | |
// This is called when the user tries to close this window. Here, we'll just | |
// ask the app to quit when this happens, but you can change this to do | |
// whatever you need. | |
JUCEApplication::getInstance()->systemRequestedQuit(); | |
} | |
/* Note: Be careful if you override any DocumentWindow methods - the base | |
class uses a lot of them, so by overriding you might break its functionality. | |
It's best to do all your work in your content component instead, but if | |
you really have to override any DocumentWindow methods, make sure your | |
subclass also calls the superclass's method. | |
*/ | |
private: | |
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow) | |
}; | |
private: | |
std::unique_ptr<MainWindow> mainWindow; | |
}; | |
//============================================================================== | |
// This macro generates the main() routine that launches the app. | |
START_JUCE_APPLICATION (simpleAudioPlayerApplication) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
This file was auto-generated! | |
============================================================================== | |
*/ | |
#include "MainComponent.h" | |
#include "loadSaveXml.h" | |
//============================================================================== | |
MainComponent::MainComponent() : juce::AudioAppComponent(otherDeviceManager), state(Stopped), openButton("Open"), playButton("Play"), stopButton("Stop"), thirdButton("Future file path") | |
{ | |
otherDeviceManager.initialise(2, 2, nullptr, true); | |
audioSettings.reset(new AudioDeviceSelectorComponent(otherDeviceManager, 0, 2, 0, 2, true, true, true, true)); | |
addAndMakeVisible(audioSettings.get()); | |
setAudioChannels (2, 2); | |
openButton.onClick = [this] { openButtonClicked(); }; | |
addAndMakeVisible(&openButton); | |
playButton.onClick = [this] { playButtonClicked(); }; | |
playButton.setColour(TextButton::buttonColourId, Colours::green); | |
playButton.setEnabled(true); | |
addAndMakeVisible(&playButton); | |
stopButton.onClick = [this] { stopButtonClicked(); }; | |
stopButton.setColour(TextButton::buttonColourId, Colours::red); | |
stopButton.setEnabled(false); | |
addAndMakeVisible(&stopButton); | |
addAndMakeVisible(&thirdButton); | |
formatManager.registerBasicFormats(); | |
transport.addChangeListener(this); | |
setSize (400, 700); | |
} | |
MainComponent::~MainComponent() | |
{ | |
// This shuts down the audio device and clears the audio source. | |
shutdownAudio(); | |
} | |
//============================================================================== | |
void MainComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate) | |
{ | |
transport.prepareToPlay(samplesPerBlockExpected, sampleRate); | |
} | |
void MainComponent::openButtonClicked() | |
{ | |
//StandalonePluginHolder | |
//choose a file | |
FileChooser chooser ("Choose a Wav or AIFF File", File::getSpecialLocation(File::userDesktopDirectory), "*.wav; *.mp3"); | |
//if the user chooses a file | |
if (chooser.browseForFileToOpen()) | |
{ | |
File myFile; | |
//what did the user choose? | |
myFile = chooser.getResult(); | |
// This is ^^ where the file is chosen. | |
Logger::outputDebugString("Statement three"); | |
// String ipsumString = myFile.getFileExtension(); | |
String ipsumString = myFile.getFullPathName(); | |
LoadSaveXmlFile x; | |
x.loadData(); | |
// TextButton showFilename { "File name inserted here" }; | |
thirdButton.setEnabled(false); | |
thirdButton.setButtonText(ipsumString); | |
//addAndMakeVisible(showFilename); | |
//read the file | |
AudioFormatReader* reader = formatManager.createReaderFor(myFile); | |
if (reader != nullptr) | |
{ | |
//get the file ready to play | |
std::unique_ptr<AudioFormatReaderSource> tempSource (new AudioFormatReaderSource (reader, true)); | |
transport.setSource(tempSource.get()); | |
transportStateChanged(Stopped); | |
playSource.reset(tempSource.release()); | |
} | |
} | |
} | |
void MainComponent::playButtonClicked() | |
{ | |
transportStateChanged(Starting); | |
} | |
void MainComponent::stopButtonClicked() | |
{ | |
transportStateChanged(Stopping); | |
} | |
void MainComponent::transportStateChanged(TransportState newState) | |
{ | |
if (newState != state) | |
{ | |
state = newState; | |
switch (state) { | |
case Stopped: | |
playButton.setEnabled(true); | |
transport.setPosition(0.0); | |
break; | |
case Playing: | |
playButton.setEnabled(true); | |
break; | |
case Starting: | |
stopButton.setEnabled(true); | |
playButton.setEnabled(false); | |
transport.start(); | |
break; | |
case Stopping: | |
playButton.setEnabled(true); | |
stopButton.setEnabled(false); | |
transport.stop(); | |
break; | |
} | |
} | |
} | |
void MainComponent::changeListenerCallback (ChangeBroadcaster *source) | |
{ | |
if (source == &transport) | |
{ | |
if (transport.isPlaying()) | |
{ | |
transportStateChanged(Playing); | |
} | |
else | |
{ | |
transportStateChanged(Stopped); | |
} | |
} | |
} | |
void MainComponent::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) | |
{ | |
bufferToFill.clearActiveBufferRegion(); | |
transport.getNextAudioBlock(bufferToFill); | |
} | |
void MainComponent::releaseResources() | |
{ | |
// This will be called when the audio device stops, or when it is being | |
// restarted due to a setting change. | |
// For more details, see the help for AudioProcessor::releaseResources() | |
} | |
//============================================================================== | |
void MainComponent::paint (Graphics& g) | |
{ | |
// (Our component is opaque, so we must completely fill the background with a solid colour) | |
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId)); | |
// You can add your drawing code here! | |
} | |
void MainComponent::resized() | |
{ | |
openButton.setBounds(10, 10, getWidth() - 20, 30); | |
playButton.setBounds(10, 50, getWidth() - 20, 30); | |
stopButton.setBounds(10, 90, getWidth() - 20, 30); | |
thirdButton.setBounds(10, 130, getWidth() - 20, 30); | |
audioSettings->setBounds(10, 200, getWidth() - 20, 100); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
This file was auto-generated! | |
============================================================================== | |
*/ | |
#pragma once | |
#include "../JuceLibraryCode/JuceHeader.h" | |
//============================================================================== | |
/* | |
This component lives inside our window, and this is where you should put all | |
your controls and content. | |
*/ | |
class MainComponent : public AudioAppComponent, | |
public ChangeListener | |
{ | |
public: | |
//============================================================================== | |
MainComponent(); | |
~MainComponent(); | |
//============================================================================== | |
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; | |
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override; | |
void releaseResources() override; | |
//============================================================================== | |
void paint (Graphics& g) override; | |
void resized() override; | |
private: | |
AudioDeviceManager otherDeviceManager; | |
std::unique_ptr <AudioDeviceSelectorComponent> audioSettings; | |
juce::Font font { 14.0f }; | |
int numRows = 0; | |
enum TransportState | |
{ | |
Stopped, | |
Starting, | |
Stopping, | |
Playing | |
}; | |
TransportState state; | |
void openButtonClicked(); | |
void playButtonClicked(); | |
void stopButtonClicked(); | |
void transportStateChanged(TransportState newState); | |
void changeListenerCallback (ChangeBroadcaster *source) override; | |
AudioFormatManager formatManager; | |
std::unique_ptr<AudioFormatReaderSource> playSource; | |
AudioTransportSource transport; | |
TextButton openButton; | |
TextButton playButton; | |
TextButton stopButton; | |
TextButton thirdButton; | |
//============================================================================== | |
// Your private member variables go here... | |
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment