Ok, I’ll put it sometimes next week, have to clean it before.
That’s funny because I just set up my first GitHub account yesterday,
I’ve uploaded my first library here https://github.com/aybe/GLA
In the mean time if someone fluent in JUCE can see the code and tell anything wrong,
I’ve spent quite some time trying to avoid ‘new’ as said in the docs,
but I concluded that it’s (mostly) unavoidable at least for my case,
pretty much all members are global, I couldn’t initialize them like int i(0);
I couldn’t put the AudioFormatReader in a ScopedPointer, in the samples it’s like that
so I left it as is.
Beside that I’ve seen how ScopedPointer works when cleaning stuff,
read a few docs etc but it’ll still take some time for me to digest all that,
at least now JUCE does not complain about leaks when I exit the program !
Oh and yes, I thought I could reduce compilation time by removing some modules,
build time did not improve much but my executable got bigger, how come ?
ScopedPointer<AudioFormatManager> audioFormatManager;
AudioFormatReader* audioFormatReader;
ScopedPointer<AudioFormatReaderSource> audioFormatReaderSource;
ScopedPointer<AudioTransportSource> audioTransportSource;
ScopedPointer<AudioSourcePlayer> audioSourcePlayer;
ScopedPointer<AudioDeviceManager> audioDeviceManager;
ScopedPointer<MyTimer1> myTimer1;
ScopedPointer<Image> _image;
ScopedPointer<ImageComponent> _imageComponent;
//==============================================================================
void initialise (const String& commandLine)
{
// Do your application's initialisation code here..
mainWindow = new MainAppWindow();
//mainWindow->setResizable(false, false);
//mainWindow->setResizeLimits(256, 256, 256, 256);
// Load a file
File & currentDir = File::getCurrentWorkingDirectory();
File & audioFile = currentDir.getChildFile("audio.mp3");
/* Create required classes for playback */
if (audioFile.exists())
{
audioFormatManager = (new AudioFormatManager());
audioFormatManager->registerBasicFormats();
audioFormatReader = (audioFormatManager->createReaderFor(audioFile));
audioFormatReaderSource = (new AudioFormatReaderSource(audioFormatReader,true));
audioTransportSource = (new AudioTransportSource());
audioTransportSource->setSource(audioFormatReaderSource, 0, nullptr, 44100.0, 2);
audioTransportSource->start();
audioSourcePlayer = (new AudioSourcePlayer());
audioSourcePlayer->setSource(audioTransportSource);
audioDeviceManager = (new AudioDeviceManager());
audioDeviceManager->initialise(2, 2, 0, true);
audioDeviceManager->addAudioCallback(audioSourcePlayer);
}
_image = new Image(Image::ARGB,256,256,true);
_imageComponent = new ImageComponent();
_imageComponent->setBounds(0, 0, 256, 256);
_imageComponent->setImage(*_image);
mainWindow->setContentNonOwned(_imageComponent, true);
myTimer1 = (new MyTimer1(_imageComponent));
myTimer1->startTimer((int)(1.0f / 30 * 1000));
}
//==============================================================================
void systemRequestedQuit()
{
if (myTimer)
{
myTimer->stopTimer();
}
if (myTimer1)
{
myTimer1->stopTimer();
}
if (audioTransportSource)
{
audioTransportSource->stop();
audioTransportSource->setSource(nullptr);
}
if (audioDeviceManager)
{
audioDeviceManager->removeAudioCallback(audioSourcePlayer);
audioDeviceManager->closeAudioDevice();
}
quit();
}