Re: Question About Importing Soundfiles

[email protected] Sat, 24 Apr 2021 09:41:39 +0800
Newsgroups gmane.comp.audio.supercollider.user
Message-ID <CAFniQ7WSXmoMaidLr50HhBha1_FRKCQ9D7r=4_3jyjM0wZ=0WA@mail.gmail.com>
On Sat, Apr 24, 2021 at 6:16 AM <[email protected]> wrote:
> there's the Dialog class.  check its helpfile.  perhaps useful.

+1

Another trick I would recommend for file dialogs is to keep a record
of the last-accessed directory, and then provide the directory to the
`path` argument.

This is because file dialogs, by default, always start with your home
directory. Most software remembers the last location and will go back
to that location the next time a dialog is opened. I always found it
annoying to have to navigate through the same directories again and
again.

I've used Archive to keep track of this between sessions -- adding
this to Fredrik's example:

//--example demonstrating Dialog and Buffer write
s.boot;
(
var win = Window();
var buffer = Buffer.alloc(s, 0);

win.layout = VLayout(
    Button().states_([["load"]])
    .action_({
        Dialog.openPanel(
            { |path|
                path.postln;
                Archive.put(\lastSoundfileDir, path.dirname);
                buffer.allocRead(path);
            },
            path: Archive.at(\lastSoundfileDir)
        )
    }),
    Button().states_([["play"]])
    .action_({ buffer.play }),
    Button().states_([["save"]])
    .action_({
        Dialog.savePanel(
            { |path|
                Archive.put(\lastSoundfileDir, path.dirname);
                buffer.write(path)
            },
            path: Archive.at(\lastSoundfileDir)
        )
    }),
);
win.front;
)

The Archive is automatically saved to disk when sclang shuts down
(including recompiling the classlib!) so this should behave
transparently.

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/