help with external

Feb 6, 2007 at 2:26pm

help with external

Hi,

i m trying to create an external which will search and list all the sound files on a hard drive but i don’t really know where to start. Does anyone know how i could go about doing this?

Thank you
Chris

#30143
Feb 6, 2007 at 7:24pm

#95724
Feb 6, 2007 at 7:54pm

basically, it would be as follows (this obviously isn’t real code)..

list_files(dir_path)
{
if(dir_path is an actual directory)
{
for each file in dir
{
if(file is a directory) then list_files(file)
else if(is_sound_file(file) then output absolute path to file
}
}
}

is_sound_file(file)
{
file_ext = substring of file path after the last ‘.’
file_ext = to_lowercase(file_ext)
sf_exts = ["wav", "aif", "aiff", ... ]
for each ext in sf_exts, if file_ext == ext then return true
since no matches, return false
}

#95725
Feb 8, 2007 at 10:58am

Quote: thezer0ist@gmail.com wrote on Tue, 06 February 2007 12:54
—————————————————-
> basically, it would be as follows (this obviously isn’t real code)..
>
> list_files(dir_path)
> {
> if(dir_path is an actual directory)
> {
> for each file in dir
> {
> if(file is a directory) then list_files(file)
> else if(is_sound_file(file) then output absolute path to file
> }
> }
> }
>
> is_sound_file(file)
> {
> file_ext = substring of file path after the last ‘.’
> file_ext = to_lowercase(file_ext)
> sf_exts = ["wav", "aif", "aiff", ... ]
> for each ext in sf_exts, if file_ext == ext then return true
> since no matches, return false
> }
—————————————————-

Hi,

could you posibbly eloaborate on this? I don’t really understand it.

Thank you
Chris

#95726
Feb 8, 2007 at 3:42pm

do you want actual code?

#95727
Feb 8, 2007 at 7:46pm

This is pretty simple… well for someone who’s taken a few data
structures courses.

I’m not sure if max has built-in platform independent directory
listing routines, but if you’re on os x then in terminal:

man opendir.

Here’s the shortest version I can come up with: you are just doing a
tree-traversal, so you do:

files = findFilesIn(rootDirectory); // the boot-strap call, gotta
start somewhere.

where
List findFilesIn(char* dir, char** types) {

List filesList = List_new();
dirList = list_dir(dir);

for entry in dirList {
if( isDirectory(entry) ) {
List_append(filesList, findFilesIn(entry, types)); //the recursive
call
}
else {
if(fileIsOneOf(entry, types)) {
List_add(filesList, entry); // we’ve found a suitable entry,
let’s save it.
}
}
}

return filesList;
}

It’s just a recursive tree walk, you only add leaves that pass your
filter to a serialization and you join the result of each recursive
descent.
much easier to do in JS IMO because otherwise you’d have to build a
quick list abstraction. Your isDirectory and list_dir functions
might need to fork for cross-platform support.

… know that this sort of thing will probably take a _long_ time if
your rootDirectory is /.

_Mark
On Feb 8, 2007, at 7:42 AM, thezer0ist wrote:

>
> do you want actual code?

#95728
Feb 8, 2007 at 10:17pm

Thank you for the code, but i am a little bit confused still.

Does this code not need

#include “ext.h”
void *this_class;

at the top?

Also, what about inlets and outlets? Where will the list be shown?

Thanks
Chris

Quote: Mark Pauley wrote on Thu, 08 February 2007 12:46
—————————————————-
> This is pretty simple… well for someone who’s taken a few data
> structures courses.
>
> I’m not sure if max has built-in platform independent directory
> listing routines, but if you’re on os x then in terminal:
>
> man opendir.
>
>
>
> Here’s the shortest version I can come up with: you are just doing a
> tree-traversal, so you do:
>
> files = findFilesIn(rootDirectory); // the boot-strap call, gotta
> start somewhere.
>
> where
> List findFilesIn(char* dir, char** types) {
>
> List filesList = List_new();
> dirList = list_dir(dir);
>
> for entry in dirList {
> if( isDirectory(entry) ) {
> List_append(filesList, findFilesIn(entry, types)); //the recursive
> call
> }
> else {
> if(fileIsOneOf(entry, types)) {
> List_add(filesList, entry); // we’ve found a suitable entry,
> let’s save it.
> }
> }
> }
>
> return filesList;
> }
>
> It’s just a recursive tree walk, you only add leaves that pass your
> filter to a serialization and you join the result of each recursive
> descent.
> much easier to do in JS IMO because otherwise you’d have to build a
> quick list abstraction. Your isDirectory and list_dir functions
> might need to fork for cross-platform support.
>
> … know that this sort of thing will probably take a _long_ time if
> your rootDirectory is /.
>
—————————————————-

#95729
Feb 8, 2007 at 10:33pm

On 07-02-08, at 1418, Chris Hipgrave wrote:
>
> Thank you for the code, but i am a little bit confused still.
>
> Does this code not need
>
> #include “ext.h”
> void *this_class;
>
> at the top?
>
> Also, what about inlets and outlets? Where will the list be shown?
>
mark was just demonstrating some pseudocode for a tree traversal, not
writing up a whole external for you. it’s up to you to (a) convert it
to the language of your choice and (b) integrate it into the
appropriate code for a max external.

r.

#95730
Feb 8, 2007 at 10:39pm

Ah right, i see.

thank you for explaining.

#95731

You must be logged in to reply to this topic.