My Sampler Project


#1

It will have the obligatory "load sample" button but I would also like to have two additional buttons left and right of the load button that will iterate the currently loaded sample's directory in either direction (up and down). Is this possible to do within the plugin framework? Any pointers on where I might get started or code examples?


#2

While the question isn't clear, I'd be inclined to say 'no', there isn't anything in the framework to do what you want. But only because it doesn't make sense as a framwork function.  If I were tackling the problem, I would simply build a list of sample files in the 'current directory', and then use that list to implement the next/previous functionality.


#3

Thanks cpr..sorry that the question isn't clear. Maybe that's why I'm not getting many responses smiley. I'm a graduating senior this year and would like to pursue a career in development. So I have only recently began this journey. 

From your suggestion I suppose I could use a DirectoryIterator to store the wav files listed to an array? Or vector? If so can you assist me with loading an element from said array or vector?


#4

Probably easier to use File::findChildFiles().


#5

 

This function is called when a user selects a file.  I update a combo box with the files in the same folder. 

void EasyFileBrowser::loadFileAndFolder(const File & f) {


    int selecteditem=0;

    

    // Hack to fix extension filtering in JUCE

    StringArray validExtensions;

    validExtensions.add(".wav");

    validExtensions.add(".aiff");

    validExtensions.add(".mp3");

    validExtensions.add(".flac");

    validExtensions.add(".aif");

    validExtensions.add(".ogg");

    

    fileComboBox->clear();

    

    currentFolder = f.getParentDirectory();

    currentFileName = f.getFileName();

    

    // TODO: fix possible bug in Juce: extension handling

    

    DirectoryIterator di(currentFolder, false, "*.wav;*.aiff;*.aif;*.mp3;*.ogg;*.flac", File::findFiles);

    int items = 1;

    while (di.next()) {

        

        File myFile = di.getFile();

        if (validExtensions.contains(myFile.getFileExtension())) {

            fileComboBox->addItem(myFile.getFileName(), items);

            if (myFile.getFileName() == currentFileName) {

                selecteditem = items;

            }

            items++;

        }

    }

    // Choose the file the user selected.

    fileComboBox->setSelectedId(selecteditem);

    setNewFile(f); 


    

}

Then I have some buttons for previous and next (and open) - here's the handler for those...

void EasyFileBrowser::buttonClicked(Button * b) {

    int currentIndex = fileComboBox->getSelectedItemIndex();

    if (b == buttonNext) { 

        if (currentIndex != (fileComboBox->getNumItems()-1)) fileComboBox->setSelectedItemIndex(currentIndex+1);

    }

    if (b == buttonPrev) {

        if (currentIndex != 0) fileComboBox->setSelectedItemIndex(currentIndex-1);

    }

    if (b == buttonOpen) {

        File f;

        if (lastLocation.isEmpty())

            f = File::getSpecialLocation(File::userHomeDirectory);

        else

            f = File(lastLocation);

        

        FileChooser fc ("Select a file", f, "*.wav;*.aif;*.aiff");

        

        if (fc.browseForFileToOpen()) {

            currentFile = fc.getResult();

            lastLocation = currentFile.getParentDirectory().getFullPathName();

            loadFileAndFolder(currentFile);


        }

    }

}

These look like the important instance variables: 


    ScopedPointer<PictureTextButton> buttonNext;
    ScopedPointer<PictureTextButton> buttonPrev;
    ScopedPointer<PictureTextButton> buttonOpen;
    Thumbnail * myThumbnail;
    ScopedPointer<ComboBox> fileComboBox;
    XmlEasyFileBrowser * myXci; 
    
    StringArray fileList;

Hopefully that'll get you started - I've no idea what the bug is I mentioned in my comments :)  


#6

Please tell me the OP thanked you via PM for this, given the effort you put into answering his request!?!?