AKWF browser and converter

You can download the wave forms from here:

Specifically the all in one zip:
http://www.adventurekid.se/AKRTfiles/AKWF/AKWF.zip

This script will load the wave forms into a UI. When a waveform is selected it will convert it to the the SC wavetable format and load into a buffer - (it’s assumed the waveforms are in the akwf 600 sample format and will upsample to 4096 samples)

(
~akwfView = {|root|
    
    var upsample = 4096;
    var view;
    var folders, wavetables, loadwavs, list;
    var wtView = View().layout_(VLayout());
    
    folders = {|dir|
        var folders = PathName(dir).folders.collect({|pn| pn.folderName});
        folders;
    };

    loadwavs = {|path|

        var files = PathName(path)
        .files
        .select({|pn| pn.extension == "wav" });

        wavetables = Array.new(files.size);
        wtView.children.do({|child|
            child.remove()
        });

        fork {
            files.do({|pn|
                var file = SoundFile.openRead(pn.fullPath);
                var data = Signal.newClear(file.numFrames);
                file.readData(data);
                data = data.resamp1(upsample);
                wavetables.add(data);
            });

            {
                var layout;
                layout = HLayout();
                wavetables.do({|data, index|

                    var sfv;
                    sfv = SoundFileView()
                    .gridOn_(false)
                    .drawsRMS_(false)
                    .drawsBoundingLines_(false)
                    .waveColors_( Color.rand )
                    .mouseDownAction_({|ctrl, x, y, modifiers, buttonNumber, clickCount|
                        {
                            var wt = wavetables[index];
                            wt = wt.as(Signal).asWavetable;
                            view.changed(\wtselected, wt);
                        }.defer;
                    });

                    sfv.setData(data, channels: 1);

                    if ( index ==  (wavetables.size -1) ) {
                        wtView.layout.add(layout);
                    } {
                        if (index > 0 and: { index.mod(7) == 0 } ) {
                            wtView.layout.add(layout);
                            layout = HLayout();
                        } {
                            
                        }
                    };
                    
                    layout.add(sfv);
                });

            }.defer
        };
    };

    list = folders.(root);
    view = View().layout_(VLayout());
    view.layout.add(
        PopUpMenu()
        .items_([""] ++ list)
        .action_({|ctrl|
            if (ctrl.item != "") {
                var path = "%/%".format(root, ctrl.item);
                loadwavs.(path);
            }
        })
    );
    
    view.layout.add(StaticText().string_("select a folder from the drop down"));
    
    view.layout.add(StaticText().string_("click a waveform to hear it played"));
    
    view.layout.add(wtView);
    view.minWidth_(500)
};

SynthDef(\wtosc, {|buf, freq|
    var sig, env;
    sig = Osc.ar(buf, freq);
    env = Env.perc.ar;
    sig = sig * env * \amp.kr(0.1);
    Out.ar(\out.kr(0), Splay.ar(sig));
}).add;

Pdef(\wtosc, 
    Pbind(
        \instrument, \wtosc,
        \degree, Place([0, 2, 1, [3, 4]], inf),
        \dur, 0.25,
    )
);
)

/*
Download the waveforms from here:
https://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/
*/
(
// update the path to the root folder
var path = "/path/to/AKWF";
~view = ~akwfView.(path).front;
~view.addDependant({|obj, what, wt|
    Buffer.loadCollection(Server.default, wt, action:{|buf|
        Pdef(\wtosc).set(\buf, buf.bufnum);
        if (Pdef(\wtosc).isPlaying.not) {
            Pdef(\wtosc).play
        }
    });
});
~view.onClose = {|ctrl|
    ctrl.release;
    Pdef(\wtosc).stop
};
)
7 Likes