Hello. So for my current project I am trying to include a TableListBox component that updates as the directory is changed. I wish to include only audio file formats and allow them to be played through my application. My current approach is to create a class to update an XML file to include all the audio file names in the selected directory and allow playback (also I am fairly new to XML documents and was wondering if the only extra thing I need to add, other than the labels, is the file directory of the audio file). Is there any examples or guidance on how to do something like this? Or is this the wrong approach all together? Thank you.
Strictly functionally speaking I don’t see why there would be a need to have the data as XML. There probably are easier and more efficient data structures you could use.
Of course if might be useful to save and load the XML between runs of the application to make the directory scanning appear faster. “Appear” because of course the directory contents might have changed between runs and you will need to rescan the directory anyway.
Is there any examples of using TableListBox to browse audio files that you know? The only examples I can find is using XML.
Just use the XML-based approach if you have it already working?
XML isn’t the best choice for an in-memory data structure, though, that’s all what I meant with the above.
I now noticed you mentioned you want your TableListBox to update as the directory on disk changes. Unfortunately I don’t think there’s a readily available solution for that in JUCE. You will have to implement it in some manner yourself.
Thank you for your help. Is there another class that I can use other than TableListBox that you think would be better for my application? Also is my method of including the file directory the best way if XML is the best option?
The TableListBox is just a GUI design thing. Use it if it is what you like to have for the GUI. The other things are not really related to that.
In any case, I am already kind of confused about what you are actually trying to do.
Okay I think I just need to play around more with the class using the API. Thank you for your help.
If you’re trying to update a table list box from a file directory, you might like to try using a DirectoryContentsList. You can add filters for audio files, too.
You can then set then populate the TableListBox by using the DirectoryContentsList::getNumFiles () method, and the DirectoryContentsList::getFile (int index) to get data about a “row”.
Or even better still, use the JUCE DirectoryContentsDisplayComponent:
If its not from a directory, but rather a custom data structure you need, try using ValueTrees. They operate very much like XML, and you can attach listeners to them to get callbacks when the structure changes. You can get ValueTree from XML and get XML from a ValueTree.
You can populate a TableListBox by getting the number of children on a node ( ValueTree::getNumChildren () ), and get individual children ( getChild (int index) ). If you go this route, I’d recommend using CachedValue<> as it makes it super easy to access data in a ValueTree:
But that doesn’t actively keep track of changes in the directory after it has scanned all the files, right? I think the original poster also wants to know when files have been added, removed and modified after the initial scanning.
JUCE doesn’t having anything like that. The only way to get notifications like that would be poll the directory contents using a timer. Not an elegant solution, but would work
JUCE doesn’t having anything like that. The only way to get notifications like that would be poll the directory contents using a timer. Not an elegant solution, but would work.
I’ve written a class before that uses File::findChildFiles for a directory. It keeps a ‘current state’ directory, rescans the directory on a timer and compares it against the ‘current state’. If there are any differences, it notifies through a ListenerList (either file added or file removed), and then updates the current state.
It would be nice if JUCE had a better solution for this
This is perfect. I am not trying to update the TableList as files are added to the file directory (sorry for the misunderstanding).
Just for some added background, my project is to implement a feedforward calculation from a neural network model to rank audio files similarity with other audio files. I want it so that when a file directory is selected using a FileTreeComponent (I have figured this out) the audio files in the file directory are sorted based on ranking in the TableListComponent and are able to be played.
Thank you both for your help.
For clarification these audio files are recorded by the user in a DAW and then the file is selected.