Costa Rica

NEOART

Using FLOD for the first time (Part 2).

Welcome back to the second part of how to start using FLOD.

Loading a module without the FileLoader

If you already know the format of the module you want to load you can skip the FileLoader and create directly the tracker you need like this:

var player = window.neoart.Tracker.Soundtracker();

You can find a complete reference of available trackers and packers here.

Handling zip archives

By not using the FileLoader some of the functionality included in it must be taken care of manually, if you're using a zip archive you must decompress it before sending the module to the tracker.

To do that you must first convert your "arraybuffer" to a ByteArray object.

var stream = new ByteArray(file);

After that you can check if the file is a zip archive by testing the first 4 bytes and decompress it like this:

if (stream.uint == 67324752) {
  if (Flip) {
    var archive = new Flip(stream);

    if (archive.entries.length > 0) {
      stream = archive.uncompress(archive.entries[0]);
    }
  } else {
    throw "Unzip support is not available.";
  }
}

the code above will result in the variable "stream" to contain the unpacked first file in the zip archive. If you want to deal with multiple files in the same archive you can easily do that by iterating through the entries collection of the "archive" variable.

Unpacking the module

You will also have to manually handle the unpacking in case the module is in one of the supported Amiga packers format; if you're not sure about the format I would suggest to use the FileLoader class instead.

var packer = window.neoart.Packers.ProPacker1();
var output = packer.depack(file);

if (packer.format) {
  player.load(output);
}

This will unpack a ProPacker1 packed module and play it in FLOD.

Final code

So, to resume, a complete "load" function will look something like this:

var player = window.neoart.Trackers.Soundtracker();

function load(file) {
  var stream = new ByteArray(file);

  if (stream.uint == 67324752) {
    if (Flip) {
      var archive = new Flip(stream);

      if (archive.entries.length > 0) {
        stream = archive.uncompress(archive.entries[0]);
      }
    } else {
      throw "Unzip support is not available.";
    }
  }

  var packer = window.neoart.Packers.ProPacker1();
  var output = packer.depack(stream);

  if (packer.format) {
    player.load(output);
  }
}

Back to part 1  Using FLOD for the First Time