Play multiple audio files sequentially from an array ( list )

Hi All,
I am new to Juce. I am a musician and computer science student. I built a few midi only plugins with juce thus far and I am attempting to tackle the Audio side. I learnt C at university and know a bit of C++ .
I thought I would start with an ear training application that selects notes randomly and plays them back.
I have created short samples of each note using my DAW.
I figured trying to play samples might be easier than synthesis at my stage …

I was hoping to store the names of all the files in an array and select them somehow randomly … Possibly a 2 dimensional array with notes from different octaves in each column.

I edited the playing sound files tutorial.
I can add a sound file as a binary resource and play it like this :
C5 is an mp3 file C5.mp3 which is 4 second sample of a DX7 playing midi note C5.

    AudioFormatReader* reader = formatManager.createReaderFor( new MemoryInputStream(BinaryData::C5_mp3, BinaryData::C5_mp3Size, false));
    if (reader != nullptr)
    {
        ScopedPointer<AudioFormatReaderSource> newSource = new AudioFormatReaderSource (reader, true);
        transportSource.setSource (newSource, 0, nullptr, reader->sampleRate);
        playButton.setEnabled (true);
        readerSource = newSource.release();
        transportSource.start();

I am not sure how to go about clearing out those classes from the buffer and reloading and playing a new file …

I also dont know how to add load a filename if it is stored say as a char array ( string array ) … Perhaps I will rename all the samples 60.mp3 etc …
Lets say I randomly select the integers 55, 60 and 65 how would I load the filenames play those 3 mp3 files 55.mp3 60.mp3 and 65.mp3 sequentially ?

I know it’s probably not very kosher to ask for help with your code in a forum like this but it’s a bit like running at a brick wall arriving at all the documentation and nested classes for the first time …
Any advice would be greatly appreciated.

Thanks in advance …
Sean
www.seanwayland.com

Well I am talking to myself here but why not …
I managed to figure out how to play 2 files :
private:
enum TransportState
{
Initial,
Stopped,
Starting,
Playing,
Finished
};

void changeState (TransportState newState)
{
    if (state != newState)
    {
        state = newState;
        
        switch (state)
        {
            
            case Initial:
                
                transportSource.setPosition (0.0);
                filesPlayed = 0;
                break;
                
                
            case Stopped:                           // [3]

// stopButton.setEnabled (false);
// playButton.setEnabled (true);
// transportSource.setPosition (0.0);
filesPlayed ++;
if (filesPlayed == 1)
{
playfiletwo();
}

                break;
                
            case Starting:                          // [4]
                playButton.setEnabled (true);
                transportSource.start();
                break;
                
            case Playing:                           // [5]

// stopButton.setEnabled (true);
break;

            case Finished:
                playButton.setEnabled (true);// [6]
                transportSource.stop();
                transportSource.setPosition (0.0);
                break;
        }
    }
}


void playfileone()
{
AudioFormatReader* reader = formatManager.createReaderFor( new MemoryInputStream(BinaryData::C5_mp3, BinaryData::C5_mp3Size, false));
if (reader != nullptr)
{
    ScopedPointer<AudioFormatReaderSource> newSource = new AudioFormatReaderSource (reader, true);
    transportSource.setSource (newSource, 0, nullptr, reader->sampleRate);
    playButton.setEnabled (true);
    readerSource = newSource.release();
}
if (reader == nullptr)
{
    playButton.setEnabled (false);
}
transportSource.setPosition (0.0);
changeState (Starting);
}

void playfiletwo()
{
    AudioFormatReader* reader2 = formatManager.createReaderFor( new MemoryInputStream(BinaryData::C6_mp3, BinaryData::C6_mp3Size, false));
    if (reader2 != nullptr)
    {
        ScopedPointer<AudioFormatReaderSource> newSource2 = new AudioFormatReaderSource (reader2, true);
        transportSource.setSource (newSource2, 0, nullptr, reader2->sampleRate);
        playButton.setEnabled (true);
        readerSource = newSource2.release();
    }
    if (reader2 == nullptr)
    {
        playButton.setEnabled (false);
    }
transportSource.setPosition (0.0);
changeState (Starting);

}


void playButtonClicked()
{
    
    playfileone();
    
    

    


    

    
}

Next step is how to pass a string to load the sample file …

Sean